Tidied gdnc - many buggfixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3183 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-11-09 11:05:37 +00:00
parent e4906a1239
commit 7fb0a5ae2c
3 changed files with 64 additions and 45 deletions

View file

@ -20,7 +20,7 @@
# Things to do after installing
after-install::
$(INSTALL) -m 05755 $(GNUSTEP_OBJ_DIR)/gdomap $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR)
$(INSTALL) -m 05755 $(GNUSTEP_OBJ_DIR)/gdnc $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR)
$(INSTALL) -m 0755 $(GNUSTEP_OBJ_DIR)/gdnc $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR)
# Things to do before uninstalling
# before-uninstall::

View file

@ -24,26 +24,26 @@
#define GDNC_SERVICE @"GDNCServer"
@protocol GDNCClient
- (void) postNotificationName: (NSString*)name
object: (NSString*)object
userInfo: (NSData*)info
selector: (SEL)aSelector
to: (unsigned long)observer;
- (oneway void) postNotificationName: (NSString*)name
object: (NSString*)object
userInfo: (NSData*)info
selector: (NSString*)aSelector
to: (unsigned long)observer;
@end
@protocol GDNCProtocol
- (void) addObserver: (unsigned long)anObserver
selector: (SEL)aSelector
selector: (NSString*)aSelector
name: (NSString*)notificationname
object: (NSString*)anObject
suspensionBehavior: (NSNotificationSuspensionBehavior)suspensionBehavior
for: (id<GDNCClient>)client;
- (void) postNotificationName: (NSString*)notificationName
object: (NSString*)anObject
userInfo: (NSData*)d
deliverImmediately: (BOOL)deliverImmediately
for: (id<GDNCClient>)client;
- (oneway void) postNotificationName: (NSString*)notificationName
object: (NSString*)anObject
userInfo: (NSData*)d
deliverImmediately: (BOOL)deliverImmediately
for: (id<GDNCClient>)client;
- (void) registerClient: (id<GDNCClient>)client;

View file

@ -30,6 +30,8 @@
#include <Foundation/NSHashTable.h>
#include <Foundation/NSMapTable.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSProcessInfo.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSDistributedNotificationCenter.h>
#include "gdnc.h"
@ -63,6 +65,7 @@
tmp->name = [notificationName retain];
tmp->object = [notificationObject retain];
tmp->info = [notificationData retain];
return [tmp autorelease];
}
@end
@ -104,7 +107,7 @@
unsigned observer;
NSString *notificationName;
NSString *notificationObject;
SEL selector;
NSString *selector;
GDNCClient *client;
NSMutableArray *queue;
NSNotificationSuspensionBehavior behavior;
@ -116,6 +119,7 @@
- (void) dealloc
{
[queue release];
[selector release];
[notificationName release];
[notificationObject release];
[super dealloc];
@ -124,6 +128,7 @@
- (id) init
{
queue = [[NSMutableArray alloc] initWithCapacity: 1];
return self;
}
@end
@ -138,7 +143,7 @@
}
- (void) addObserver: (unsigned long)anObserver
selector: (SEL)aSelector
selector: (NSString*)aSelector
name: (NSString*)notificationname
object: (NSString*)anObject
suspensionBehavior: (NSNotificationSuspensionBehavior)suspensionBehavior
@ -242,7 +247,7 @@
}
- (void) addObserver: (unsigned long)anObserver
selector: (SEL)aSelector
selector: (NSString*)aSelector
name: (NSString*)notificationName
object: (NSString*)anObject
suspensionBehavior: (NSNotificationSuspensionBehavior)suspensionBehavior
@ -275,7 +280,7 @@
obs->observer = anObserver;
obs->client = info;
obs->behavior = suspensionBehavior;
obs->selector = aSelector;
obs->selector = [aSelector copy];
[info->observers addObject: obs];
[obs release];
NSHashInsert(allObservers, obs);
@ -304,7 +309,7 @@
anObject = tmp->notificationObject;
}
obs->notificationName = [anObject retain];
obs->notificationObject = [anObject retain];
[objList addObject: obs];
}
@ -427,7 +432,7 @@
*/
for (pos = [byName count]; pos > 0; pos--)
{
GDNCObserver *obs = [byName objectAtIndex: pos];
GDNCObserver *obs = [byName objectAtIndex: pos - 1];
if (obs->notificationObject == nil ||
[obs->notificationObject isEqual: notificationObject])
@ -437,7 +442,7 @@
}
for (pos = [byObject count]; pos > 0; pos--)
{
GDNCObserver *obs = [byObject objectAtIndex: pos];
GDNCObserver *obs = [byObject objectAtIndex: pos - 1];
if (obs->notificationName == nil ||
[obs->notificationName isEqual: notificationName])
@ -465,11 +470,11 @@
*/
for (pos = [observers count]; pos > 0; pos--)
{
GDNCObserver *obs = [observers objectAtIndex: pos];
GDNCObserver *obs = [observers objectAtIndex: pos - 1];
if (obs->client->suspended == NO || deliverImmediately == YES)
{
[obs->queue addObject: d];
[obs->queue addObject: notification];
}
else
{
@ -479,13 +484,13 @@
break;
case NSNotificationSuspensionBehaviorCoalesce:
[obs->queue removeAllObjects];
[obs->queue addObject: d];
[obs->queue addObject: notification];
break;
case NSNotificationSuspensionBehaviorHold:
[obs->queue addObject: d];
[obs->queue addObject: notification];
break;
case NSNotificationSuspensionBehaviorDeliverImmediately:
[obs->queue addObject: d];
[obs->queue addObject: notification];
break;
}
}
@ -497,7 +502,7 @@
*/
for (pos = [observers count]; pos > 0; pos--)
{
GDNCObserver *obs = [observers objectAtIndex: pos];
GDNCObserver *obs = [observers objectAtIndex: pos - 1];
if (obs->client->suspended == NO || deliverImmediately == YES)
{
@ -543,7 +548,7 @@
objList = [observersForObjects objectForKey: obs->notificationObject];
if (objList != nil)
{
[objList removeObject: obs];
[objList removeObjectIdenticalTo: obs];
}
}
if (obs->notificationName)
@ -553,10 +558,11 @@
namList = [observersForNames objectForKey: obs->notificationName];
if (namList != nil)
{
[namList removeObject: obs];
[namList removeObjectIdenticalTo: obs];
}
}
NSHashRemove(allObservers, obs);
[obs->client->observers removeObjectIdenticalTo: obs];
}
- (void) removeObserversForClients: (NSMapTable*)clients
@ -630,7 +636,7 @@
{
GDNCObserver *obs;
obs = [byName objectAtIndex: pos];
obs = [byName objectAtIndex: pos - 1];
if ([byObject indexOfObjectIdenticalTo: obs] != NSNotFound)
{
[self removeObserver: obs];
@ -640,7 +646,7 @@
{
GDNCObserver *obs;
obs = [byObject objectAtIndex: pos];
obs = [byObject objectAtIndex: pos - 1];
if ([byName indexOfObjectIdenticalTo: obs] != NSNotFound)
{
[self removeObserver: obs];
@ -743,26 +749,39 @@ main()
{
GDNCServer *server;
NSAutoreleasePool *pool;
NSString *str;
BOOL shouldFork = YES;
switch (fork())
pool = [NSAutoreleasePool new];
str = [[NSUserDefaults standardUserDefaults] stringForKey: @"debug"];
if (str != nil && [str caseInsensitiveCompare: @"yes"] == NSOrderedSame)
{
case -1:
fprintf(stderr, "gdnc - fork failed - bye.\n");
exit(1);
shouldFork = NO;
}
[pool release];
case 0:
/*
* Try to run in background.
*/
#ifdef NeXT
setpgrp(0, getpid());
#else
setsid();
#endif
break;
if (shouldFork)
{
switch (fork())
{
case -1:
fprintf(stderr, "gdnc - fork failed - bye.\n");
exit(1);
default:
exit(0);
case 0:
/*
* Try to run in background.
*/
#ifdef NeXT
setpgrp(0, getpid());
#else
setsid();
#endif
break;
default:
exit(0);
}
}
pool = [NSAutoreleasePool new];