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 1998-11-09 11:05:37 +00:00
parent 30f7b9b0b8
commit 187adaade4
3 changed files with 64 additions and 45 deletions

View file

@ -20,7 +20,7 @@
# Things to do after installing # Things to do after installing
after-install:: after-install::
$(INSTALL) -m 05755 $(GNUSTEP_OBJ_DIR)/gdomap $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR) $(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 # Things to do before uninstalling
# before-uninstall:: # before-uninstall::

View file

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

View file

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