2001-12-17 14:31:42 +00:00
|
|
|
|
/** Implementation of NSPortNameServer class for Distributed Objects
|
2000-02-24 22:45:18 +00:00
|
|
|
|
Copyright (C) 1998,1999,2000 Free Software Foundation, Inc.
|
1998-10-29 12:50:23 +00:00
|
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Created: October 1998
|
|
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
|
|
<title>NSPortNameServer class reference</title>
|
|
|
|
|
$Date$ $Revision$
|
1998-10-29 12:50:23 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "Foundation/NSString.h"
|
|
|
|
|
#include "Foundation/NSByteOrder.h"
|
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
|
#include "Foundation/NSAutoreleasePool.h"
|
|
|
|
|
#include "Foundation/NSLock.h"
|
|
|
|
|
#include "Foundation/NSFileHandle.h"
|
|
|
|
|
#include "Foundation/NSRunLoop.h"
|
|
|
|
|
#include "Foundation/NSNotificationQueue.h"
|
|
|
|
|
#include "Foundation/NSPort.h"
|
|
|
|
|
#include "Foundation/NSMapTable.h"
|
|
|
|
|
#include "Foundation/NSSet.h"
|
|
|
|
|
#include "Foundation/NSHost.h"
|
|
|
|
|
#include "Foundation/NSTask.h"
|
|
|
|
|
#include "Foundation/NSDate.h"
|
|
|
|
|
#include "Foundation/NSTimer.h"
|
|
|
|
|
#include "Foundation/NSPathUtilities.h"
|
|
|
|
|
#include "Foundation/NSPortNameServer.h"
|
|
|
|
|
#include "Foundation/NSDebug.h"
|
2000-09-13 21:10:52 +00:00
|
|
|
|
#ifdef __MINGW__
|
2002-02-26 09:43:04 +00:00
|
|
|
|
#include <winsock2.h>
|
2000-09-13 21:10:52 +00:00
|
|
|
|
#include <wininet.h>
|
|
|
|
|
#else
|
2000-08-07 22:00:31 +00:00
|
|
|
|
#include <netinet/in.h>
|
1999-06-24 19:30:29 +00:00
|
|
|
|
#include <arpa/inet.h>
|
2000-09-13 21:10:52 +00:00
|
|
|
|
#endif
|
1998-10-29 12:50:23 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Protocol definition stuff for talking to gdomap process.
|
|
|
|
|
*/
|
|
|
|
|
#include "../Tools/gdomap.h"
|
|
|
|
|
|
|
|
|
|
#define stringify_it(X) #X
|
1998-11-27 20:39:08 +00:00
|
|
|
|
#define make_gdomap_port(X) stringify_it(X)
|
1998-10-29 12:50:23 +00:00
|
|
|
|
|
1999-09-21 19:07:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSPortNameServer
|
1998-10-29 12:50:23 +00:00
|
|
|
|
|
|
|
|
|
+ (id) allocWithZone: (NSZone*)aZone
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"attempt to create extra port name server"];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
if (self == [NSPortNameServer class])
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 09:49:31 +00:00
|
|
|
|
+ (id) systemDefaultPortNameServer
|
1998-10-29 12:50:23 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
return [NSSocketPortNameServer sharedInstance];
|
|
|
|
|
// return [NSMessagePortNameServer sharedInstance];
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"attempt to deallocate default port name server"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSPort*) portForName: (NSString*)name
|
|
|
|
|
{
|
|
|
|
|
return [self portForName: name onHost: nil];
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-05 17:47:54 +00:00
|
|
|
|
- (NSPort*) portForName: (NSString*)name
|
|
|
|
|
onHost: (NSString*)host
|
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return nil;
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) registerPort: (NSPort*)port
|
|
|
|
|
forName: (NSString*)name
|
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return NO;
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-15 09:08:27 +00:00
|
|
|
|
- (BOOL) removePortForName: (NSString*)name
|
1998-10-29 12:50:23 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return NO;
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2003-07-15 05:21:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* Some extensions to make cleaning up port names easier.
|
|
|
|
|
*/
|
1998-10-30 08:40:03 +00:00
|
|
|
|
@implementation NSPortNameServer (GNUstep)
|
2003-07-15 05:21:34 +00:00
|
|
|
|
/** Return all names for port
|
2000-02-04 18:14:13 +00:00
|
|
|
|
*/
|
|
|
|
|
- (NSArray*) namesForPort: (NSPort*)port
|
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return nil;
|
2000-02-04 18:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-15 05:21:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* Remove all names for port. Probably inefficient ... subclasses
|
|
|
|
|
* should override this.
|
1998-10-30 08:40:03 +00:00
|
|
|
|
*/
|
2001-07-15 09:08:27 +00:00
|
|
|
|
- (BOOL) removePort: (NSPort*)port
|
1998-10-30 08:40:03 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
NSEnumerator *e = [[self namesForPort: port] objectEnumerator];
|
|
|
|
|
NSString *n;
|
|
|
|
|
BOOL removed = NO;
|
1998-10-30 08:40:03 +00:00
|
|
|
|
|
2003-07-15 05:21:34 +00:00
|
|
|
|
while ((n = [e nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([self removePort: port forName: n] == YES)
|
1998-10-30 08:40:03 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
removed = YES;
|
1998-10-30 08:40:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-07-15 05:21:34 +00:00
|
|
|
|
return removed;
|
2000-02-04 18:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-15 05:21:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* Remove the name if and only if it is registered by the given port.
|
2000-02-04 18:14:13 +00:00
|
|
|
|
*/
|
2001-07-15 09:08:27 +00:00
|
|
|
|
- (BOOL) removePort: (NSPort*)port forName: (NSString*)name
|
2000-02-04 18:14:13 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return NO;
|
1998-10-30 08:40:03 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
1999-09-21 19:07:27 +00:00
|
|
|
|
|