Improve server startup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13067 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-03-10 08:05:25 +00:00
parent 1808c67d6d
commit 12a5601159
3 changed files with 55 additions and 16 deletions

View file

@ -4,6 +4,8 @@
* Headers/gnustep/base/NSNumberFormatter.h:
* Headers/gnustep/base/NSObject.h:
Minor fixes to build with STRICT_OPENSTEP
* Source/NSDistributedNotificationCentre.m: Attempt to start server
automatically for other machines. Improve log messages.
Sat Mar 9 15:21:04 2002 Adam Fedor <fedor@yogi.doc.com>

View file

@ -320,6 +320,7 @@ static NSDistributedNotificationCenter *defCenter = nil;
if (_remote == nil)
{
NSString *host;
NSString *description;
/*
* Connect to the NSDistributedNotificationCenter for this host.
@ -340,11 +341,29 @@ static NSDistributedNotificationCenter *defCenter = nil;
* indicate that we may start a gdnc server locally.
*/
h = [NSHost hostWithName: host];
if ([h isEqual: [NSHost currentHost]] == YES)
if (h == nil)
{
NSLog(@"Unknown -NSHost '%@' ignored", host);
}
else if ([h isEqual: [NSHost currentHost]] == YES)
{
host = @"";
}
else
{
host = [h name];
}
}
if ([host length] == 0)
{
description = @"local host";
}
else
{
description = host;
}
_remote = RETAIN([NSConnection rootProxyForConnectionWithRegisteredName:
GDNC_SERVICE host: host]);
if (_remote == nil && [host isEqual: @""] == NO)
@ -371,30 +390,45 @@ static NSDistributedNotificationCenter *defCenter = nil;
object: c];
[_remote registerClient: (id<GDNCClient>)self];
}
else if ([host isEqual: @""] == YES)
else
{
static BOOL recursion = NO;
if (recursion == NO)
{
static NSString *cmd = nil;
static NSArray *args = nil;
NSLog(@"\nI couldn't contact the notification server for %@ -\n"
@"so I'm attempting to to start one - which will take a few seconds.\n"
@"It is recommended that you start the notification server (gdnc) either at\n"
@"login or (better) when your computer is started up.\n", description);
if (cmd == nil)
cmd = MAKE_GDNC_CMD;
{
#if 1
cmd = RETAIN([[NSSearchPathForDirectoriesInDomains(
GSToolsDirectory, NSSystemDomainMask, YES) objectAtIndex: 0]
stringByAppendingPathComponent: @"gdnc"]);
#else
cmd = MAKE_GDNC_CMD;
#endif
if ([host length] > 0)
{
args = [[NSArray alloc] initWithObjects:
@"-NSHost", host, nil];
}
}
NSLog(@"NSDistributedNotificationCenter failed to contact GDNC server.\n");
NSLog(@"Attempting to start GDNC process - this will take several seconds.\n");
[NSTask launchedTaskWithLaunchPath: cmd arguments: nil];
[NSTask launchedTaskWithLaunchPath: cmd arguments: args];
[NSTimer scheduledTimerWithTimeInterval: 5.0
invocation: nil
repeats: NO];
[[NSRunLoop currentRunLoop] runUntilDate:
[NSDate dateWithTimeIntervalSinceNow: 5.0]];
NSLog(@"Retrying connection to the GDNC server.\n");
recursion = YES;
[self _connect];
recursion = NO;
NSLog(@"Connection to GDNC server established.\n");
}
else
{
@ -404,11 +438,6 @@ NSLog(@"Connection to GDNC server established.\n");
MAKE_GDNC_ERR];
}
}
else
{
[NSException raise: NSInternalInconsistencyException
format: @"unable to contact GDNC server for %@", host];
}
}
}

View file

@ -4,9 +4,7 @@
(The Tcp*Port classes, however, do test the notification mechanism
further.) */
#include <Foundation/NSNotification.h>
#include <Foundation/NSString.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/Foundation.h>
@interface Observer : NSObject
- (void) gotNotificationFoo: not;
@ -78,6 +76,16 @@ int main ()
postNotificationName: foo
object: o1];
[[NSDistributedNotificationCenter defaultCenter]
addObserver: observer1
selector: @selector(gotNotificationFooNoObject:)
name: foo
object: nil];
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName: foo
object: @"hello"];
[arp release];
exit (0);