Fix accidentally exposed private headers.

Implement code to handle windows messages on a per-window basis.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21916 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-10-30 10:42:42 +00:00
parent 0e803760c6
commit 43f720e62a
10 changed files with 94 additions and 28 deletions

View file

@ -4,6 +4,16 @@
Tidy indentation. Fix variable declaration not at start of block
(broke compile for older gcc versions). Avoid repeated system
calls to get process ID.
* Headers/Additions/GNUstepBase/GSRunLoopCtxt.h: Move private header to
Source directory.
* Headers/Additions/GNUstepBase/GSRunLoopWatcher.h: ditto
* Headers/Foundation/NSRunLoop.h: Add event type for handling windows
messages.
* Source/GNUmakefile: Don't install private headers in public area.
* Source/win32/GSRunLoopCtxt.m: Add code to handle windows messages.
* Source/win32/GSRunLoopWatcher.m: update header path.
* Source/win32/NSRunLoopWin32.m: update header path.
* Source/win32/NSUserDefaultsWin32.m: update header path.
2005-10-29 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -109,8 +109,9 @@ GS_EXPORT NSString * const NSDefaultRunLoopMode;
*/
typedef enum {
#ifdef __MINGW32__
ET_HANDLE,
ET_RPORT /* Watch for message arriving on port. */
ET_HANDLE, /* Watch for an I/O event on a handle. */
ET_RPORT, /* Watch for message arriving on port. */
ET_WINMSG, /* Watch for a message on a window handle. */
#else
ET_RDESC, /* Watch for descriptor becoming readable. */
ET_WDESC, /* Watch for descriptor becoming writeable. */

View file

@ -119,8 +119,6 @@ GNUstep.h \
behavior.h \
preface.h \
objc-gnu2next.h \
GSRunLoopCtxt.h \
GSRunLoopWatcher.h
GNU_HEADERS = $(ADD_HEADERS)

View file

@ -46,6 +46,7 @@ typedef struct{
@private
#if defined(__MINGW32__)
NSMapTable *handleMap;
NSMapTable *winMsgMap;
#else
NSMapTable *_efdMap;
NSMapTable *_rfdMap;

View file

@ -40,8 +40,8 @@
#include "Foundation/NSRunLoop.h"
#include "Foundation/NSThread.h"
#include "Foundation/NSDebug.h"
#include "GNUstepBase/GSRunLoopCtxt.h"
#include "GNUstepBase/GSRunLoopWatcher.h"
#include "GSRunLoopCtxt.h"
#include "GSRunLoopWatcher.h"
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>

View file

@ -9,8 +9,8 @@
#include "config.h"
#include "GNUstepBase/preface.h"
#include "GNUstepBase/GSRunLoopCtxt.h"
#include "GNUstepBase/GSRunLoopWatcher.h"
#include "../GSRunLoopCtxt.h"
#include "../GSRunLoopWatcher.h"
#include <Foundation/NSDebug.h>
#include <Foundation/NSNotificationQueue.h>
#include <Foundation/NSPort.h>
@ -59,6 +59,10 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
{
NSFreeMapTable(handleMap);
}
if (winMsgMap != 0)
{
NSFreeMapTable(winMsgMap);
}
[super dealloc];
}
@ -122,6 +126,8 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
handleMap = NSCreateMapTable(NSIntMapKeyCallBacks,
WatcherMapValueCallBacks, 0);
winMsgMap = NSCreateMapTable(NSIntMapKeyCallBacks,
WatcherMapValueCallBacks, 0);
msgTarget = nil;
}
@ -134,6 +140,7 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
GSRunLoopWatcher *watcher;
HANDLE *handleArray;
int num_handles;
int num_winMsgs;
unsigned i;
void *handle;
int wait_timeout;
@ -151,9 +158,11 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
}
NSResetMapTable(handleMap);
NSResetMapTable(winMsgMap);
i = GSIArrayCount(watchers);
num_handles = 0;
num_winMsgs = 0;
while (i-- > 0)
{
GSRunLoopWatcher *info;
@ -196,6 +205,11 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
}
}
break;
case ET_WINMSG:
winMsgMap = (HANDLE)(int)info->data;
NSMapInsert(winMsgMap, (void*)handle, info);
num_winMsgs++;
break;
}
}
@ -212,25 +226,66 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
handleArray = (HANDLE*)NSZoneMalloc(NSDefaultMallocZone(),
sizeof(HANDLE) * num_handles);
hEnum = NSEnumerateMapTable(handleMap);
i = 0;
hEnum = NSEnumerateMapTable(handleMap);
while (NSNextMapEnumeratorPair(&hEnum, &handle, (void**)&watcher))
{
handleArray[i++] = (HANDLE)handle;
}
NSEndMapTableEnumeration(&hEnum);
do_wait = YES;
do
{
num_handles = i;
wait_return = MsgWaitForMultipleObjects(num_handles, handleArray,
NO, wait_timeout, QS_ALLEVENTS);
NO, wait_timeout, QS_ALLINPUT);
NSDebugMLLog(@"NSRunLoop", @"wait returned %d", wait_return);
// if there are windows message
if (wait_return == WAIT_OBJECT_0 + num_handles)
{
MSG msg;
INT bRet;
if (num_winMsgs > 0)
{
hEnum = NSEnumerateMapTable(winMsgMap);
while (NSNextMapEnumeratorPair(&hEnum, &handle, (void**)&watcher))
{
if (watcher->_invalidated == NO)
{
bRet = PeekMessage(&msg, handle, 0, 0, PM_NOREMOVE);
if (bRet != 0)
{
i = [contexts count];
while (i-- > 0)
{
GSRunLoopCtxt *c = [contexts objectAtIndex: i];
if (c != self)
{
[c endEvent: (void*)handle type: ET_WINMSG];
}
}
/*
* The watcher is still valid - so call its receivers
* event handling method.
*/
(*watcher->handleEvent)(watcher->receiver,
eventSel, watcher->data, watcher->type,
(void*)(gsaddr)handle, mode);
NSEndMapTableEnumeration(&hEnum);
NSZoneFree(NSDefaultMallocZone(), handleArray);
completed = YES;
return NO;
}
}
}
NSEndMapTableEnumeration(&hEnum);
}
if (msgTarget != nil)
{
[msgTarget performSelector: msgSelector withObject: nil];
@ -238,23 +293,18 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
completed = YES;
return NO;
}
else
{
MSG msg;
INT bRet;
while ((bRet = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
DispatchMessage(&msg);
}
}
}
while ((bRet = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
DispatchMessage(&msg);
}
}
--wait_timeout;
}
else

View file

@ -1,7 +1,7 @@
#include "config.h"
#include "GNUstepBase/preface.h"
#include "GNUstepBase/GSRunLoopWatcher.h"
#include "../GSRunLoopWatcher.h"
#include <Foundation/NSException.h>
#include <Foundation/NSPort.h>

View file

@ -1,7 +1,7 @@
#include "config.h"
#include "GNUstepBase/preface.h"
#include "Foundation/NSRunLoop.h"
#include "GNUstepBase/GSRunLoopCtxt.h"
#include "../GSRunLoopCtxt.h"
@implementation NSRunLoop (mingw32)
/**

View file

@ -365,11 +365,13 @@ struct NSUserDefaultsWin32_DomainInfo
NSLog(@"Failed to query modify time on registry %@ (%x)",
dName, rc);
NSEndMapTableEnumeration(&iter);
return YES;
}
ti = -12622780800.0 + lasttime.QuadPart / 10000000.0;
if ([lastSyncDate timeIntervalSinceReferenceDate] < ti)
{
NSEndMapTableEnumeration(&iter);
return YES;
}
}
@ -395,6 +397,7 @@ struct NSUserDefaultsWin32_DomainInfo
}
else
{
NSEndMapTableEnumeration(&iter);
return YES;
}
}
@ -407,11 +410,13 @@ struct NSUserDefaultsWin32_DomainInfo
{
NSLog(@"Failed to query time on HKEY_LOCAL_MACHINE\\%@ (%x)",
dPath, rc);
NSEndMapTableEnumeration(&iter);
return YES;
}
ti = -12622780800.0 + lasttime.QuadPart / 10000000.0;
if ([lastSyncDate timeIntervalSinceReferenceDate] < ti)
{
NSEndMapTableEnumeration(&iter);
return YES;
}
}
@ -434,6 +439,7 @@ struct NSUserDefaultsWin32_DomainInfo
}
else
{
NSEndMapTableEnumeration(&iter);
return YES;
}
}