2001-12-17 14:31:42 +00:00
|
|
|
/** Implementation of abstract superclass port for use with NSConnection
|
1998-10-30 08:40:03 +00:00
|
|
|
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1997-09-09 15:30:24 +00:00
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
Created: August 1997
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1997-09-01 21:59:51 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
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
|
2019-12-09 23:36:00 +00:00
|
|
|
Lesser General Public License for more details.
|
1997-09-01 21:59:51 +00:00
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1997-09-01 21:59:51 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2024-11-07 13:37:59 +00:00
|
|
|
Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
<title>NSPort class reference</title>
|
|
|
|
$Date$ $Revision$
|
1997-09-01 21:59:51 +00:00
|
|
|
*/
|
|
|
|
|
2010-02-19 08:12:46 +00:00
|
|
|
#import "common.h"
|
2010-02-14 10:48:10 +00:00
|
|
|
#define EXPOSE_NSPort_IVARS 1
|
|
|
|
#import "Foundation/NSException.h"
|
|
|
|
#import "Foundation/NSNotification.h"
|
|
|
|
#import "Foundation/NSNotificationQueue.h"
|
|
|
|
#import "Foundation/NSPort.h"
|
|
|
|
#import "Foundation/NSPortCoder.h"
|
|
|
|
#import "Foundation/NSPortNameServer.h"
|
|
|
|
#import "Foundation/NSRunLoop.h"
|
|
|
|
#import "Foundation/NSAutoreleasePool.h"
|
|
|
|
#import "Foundation/NSUserDefaults.h"
|
|
|
|
#import "GSPrivate.h"
|
1997-09-01 21:59:51 +00:00
|
|
|
|
2003-07-15 05:21:34 +00:00
|
|
|
|
|
|
|
@class NSMessagePort;
|
2000-07-02 18:57:05 +00:00
|
|
|
|
2005-11-01 20:37:34 +00:00
|
|
|
@implementation NSObject(NSPortDelegateMethods)
|
|
|
|
- (void) handlePortMessage: (NSPortMessage*)aMessage
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
@implementation NSPort
|
|
|
|
|
2006-10-05 19:27:15 +00:00
|
|
|
static Class NSPort_abstract_class;
|
|
|
|
static Class NSPort_concrete_class;
|
2000-07-02 18:57:05 +00:00
|
|
|
|
|
|
|
+ (id) allocWithZone: (NSZone*)aZone
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
if (self == NSPort_abstract_class)
|
|
|
|
{
|
|
|
|
return NSAllocateObject(NSPort_concrete_class, 0, aZone);
|
|
|
|
}
|
2000-07-03 11:47:17 +00:00
|
|
|
else
|
2000-08-07 22:00:31 +00:00
|
|
|
{
|
|
|
|
return NSAllocateObject(self, 0, aZone);
|
|
|
|
}
|
2000-07-02 18:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSPort class])
|
|
|
|
{
|
2005-11-21 09:59:42 +00:00
|
|
|
NSUserDefaults *defs;
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
NSPort_abstract_class = self;
|
2005-11-21 12:07:20 +00:00
|
|
|
NSPort_concrete_class = [NSMessagePort class];
|
2005-11-21 09:59:42 +00:00
|
|
|
|
|
|
|
defs = [NSUserDefaults standardUserDefaults];
|
|
|
|
if ([defs objectForKey: @"NSPortIsMessagePort"] != nil
|
|
|
|
&& [defs boolForKey: @"NSPortIsMessagePort"] == NO)
|
2004-08-07 00:44:15 +00:00
|
|
|
{
|
2005-11-21 09:59:42 +00:00
|
|
|
NSPort_concrete_class = [NSSocketPort class];
|
2004-08-07 00:44:15 +00:00
|
|
|
}
|
2000-07-02 18:57:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
+ (NSPort*) port
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
if (self == NSPort_abstract_class)
|
|
|
|
return AUTORELEASE([NSPort_concrete_class new]);
|
|
|
|
else
|
|
|
|
return AUTORELEASE([self new]);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
+ (NSPort*) portWithMachPort: (NSInteger)machPort
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
2000-06-27 16:18:02 +00:00
|
|
|
return AUTORELEASE([[self alloc] initWithMachPort: machPort]);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-10-30 08:40:03 +00:00
|
|
|
- (id) copyWithZone: (NSZone*)aZone
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
return RETAIN(self);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-10-30 08:40:03 +00:00
|
|
|
- (id) delegate
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return _delegate;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2000-06-27 16:18:02 +00:00
|
|
|
[(NSPortCoder*)aCoder encodePortObject: self];
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-10-30 08:40:03 +00:00
|
|
|
- (id) init
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-10-30 08:40:03 +00:00
|
|
|
self = [super init];
|
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-10-30 08:40:03 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
2000-06-27 16:18:02 +00:00
|
|
|
id obj = [(NSPortCoder*)aCoder decodePortObject];
|
|
|
|
|
|
|
|
if (obj != self)
|
|
|
|
{
|
2010-02-25 18:49:31 +00:00
|
|
|
DESTROY(self);
|
2000-06-27 16:18:02 +00:00
|
|
|
self = RETAIN(obj);
|
|
|
|
}
|
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
- (id) initWithMachPort: (NSInteger)machPort
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[self shouldNotImplement: _cmd];
|
1998-10-30 08:40:03 +00:00
|
|
|
return nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-10-30 08:40:03 +00:00
|
|
|
/*
|
|
|
|
* subclasses should override this method and call [super invalidate]
|
|
|
|
* in their versions of the method.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (void) invalidate
|
|
|
|
{
|
2011-02-28 19:49:57 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
2000-08-07 22:00:31 +00:00
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
_is_valid = NO;
|
1999-06-17 10:53:24 +00:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName: NSPortDidBecomeInvalidNotification
|
|
|
|
object: self];
|
2011-05-27 11:48:44 +00:00
|
|
|
[arp drain];
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isValid
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return _is_valid;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSInteger) machPort
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[self shouldNotImplement: _cmd];
|
|
|
|
return 0;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (id) retain
|
|
|
|
{
|
|
|
|
return [super retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) autorelease
|
|
|
|
{
|
|
|
|
return [super autorelease];
|
|
|
|
}
|
|
|
|
|
2011-07-31 15:31:39 +00:00
|
|
|
- (oneway void) release
|
1997-09-09 15:30:24 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_is_valid && [self retainCount] == 1)
|
1998-10-30 08:40:03 +00:00
|
|
|
{
|
|
|
|
/*
|
2000-08-07 22:00:31 +00:00
|
|
|
* If the port is about to have a final release deallocate it
|
|
|
|
* we must invalidate it.
|
|
|
|
* Bracket with retain/release pair to prevent recursion.
|
1998-10-30 08:40:03 +00:00
|
|
|
*/
|
|
|
|
[super retain];
|
|
|
|
[self invalidate];
|
|
|
|
[super release];
|
1997-09-09 15:30:24 +00:00
|
|
|
}
|
1998-10-30 08:40:03 +00:00
|
|
|
[super release];
|
1997-09-09 15:30:24 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (void) setDelegate: (id) anObject
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
2000-11-09 05:03:42 +00:00
|
|
|
NSAssert(anObject == nil
|
|
|
|
|| [anObject respondsToSelector: @selector(handlePortMessage:)],
|
2000-07-03 11:47:17 +00:00
|
|
|
NSInvalidArgumentException);
|
1999-09-16 07:21:34 +00:00
|
|
|
_delegate = anObject;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (void) addConnection: (NSConnection*)aConnection
|
|
|
|
toRunLoop: (NSRunLoop*)aLoop
|
|
|
|
forMode: (NSString*)aMode
|
|
|
|
{
|
2000-02-25 13:56:20 +00:00
|
|
|
[aLoop addPort: self forMode: aMode];
|
1999-03-02 08:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeConnection: (NSConnection*)aConnection
|
|
|
|
fromRunLoop: (NSRunLoop*)aLoop
|
|
|
|
forMode: (NSString*)aMode
|
|
|
|
{
|
2000-02-25 13:56:20 +00:00
|
|
|
[aLoop removePort: self forMode: aMode];
|
1999-03-02 08:58:30 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSUInteger) reservedSpaceLength
|
1999-03-02 08:58:30 +00:00
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-09 02:56:20 +00:00
|
|
|
- (BOOL) sendBeforeDate: (NSDate*)when
|
2000-02-21 14:38:12 +00:00
|
|
|
components: (NSMutableArray*)components
|
1999-03-02 08:58:30 +00:00
|
|
|
from: (NSPort*)receivingPort
|
2009-02-23 20:42:32 +00:00
|
|
|
reserved: (NSUInteger)length
|
2000-07-02 18:57:05 +00:00
|
|
|
{
|
|
|
|
return [self sendBeforeDate: when
|
|
|
|
msgid: 0
|
|
|
|
components: components
|
|
|
|
from: receivingPort
|
|
|
|
reserved: length];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) sendBeforeDate: (NSDate*)when
|
2009-02-23 20:42:32 +00:00
|
|
|
msgid: (NSInteger)msgid
|
2000-07-02 18:57:05 +00:00
|
|
|
components: (NSMutableArray*)components
|
|
|
|
from: (NSPort*)receivingPort
|
2009-02-23 20:42:32 +00:00
|
|
|
reserved: (NSUInteger)length
|
1999-03-02 08:58:30 +00:00
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
1999-09-09 02:56:20 +00:00
|
|
|
return YES;
|
1999-03-02 08:58:30 +00:00
|
|
|
}
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
@end
|
|
|
|
|
2010-09-10 08:56:55 +00:00
|
|
|
/*
|
|
|
|
* This is a callback method used by the NSRunLoop class to determine which
|
|
|
|
* descriptors to watch for the port. Subclasses override it.
|
|
|
|
*/
|
|
|
|
@implementation NSPort (GNUstep)
|
|
|
|
- (void) getFds: (NSInteger*)fds count: (NSInteger*)count
|
|
|
|
{
|
|
|
|
*count = 0;
|
|
|
|
}
|
|
|
|
@end
|