1994-11-04 16:29:24 +00:00
|
|
|
|
/* Implementation of abstract superclass port for use with Connection
|
1996-02-01 17:04:17 +00:00
|
|
|
|
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
1996-03-01 16:06:03 +00:00
|
|
|
|
Created: July 1994
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C Class 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
|
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <objects/Port.h>
|
|
|
|
|
#include <objects/Coder.h> /* for Coding protocol in Object category */
|
1996-03-03 00:36:53 +00:00
|
|
|
|
#include <objects/Notification.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
@implementation Port
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
/* This is the designated initializer. */
|
|
|
|
|
- init
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 16:06:03 +00:00
|
|
|
|
[super init];
|
|
|
|
|
is_valid = YES;
|
|
|
|
|
retain_count = 0;
|
|
|
|
|
return self;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- retain
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 16:06:03 +00:00
|
|
|
|
retain_count++;
|
|
|
|
|
return self;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- (oneway void) release
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 16:06:03 +00:00
|
|
|
|
if (!retain_count--)
|
|
|
|
|
[self dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned) retainCount
|
|
|
|
|
{
|
|
|
|
|
return retain_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isValid
|
|
|
|
|
{
|
|
|
|
|
return is_valid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) close
|
|
|
|
|
{
|
|
|
|
|
[self invalidate];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) invalidate
|
|
|
|
|
{
|
1996-03-07 02:30:04 +00:00
|
|
|
|
assert (is_valid);
|
|
|
|
|
|
|
|
|
|
[NotificationDispatcher
|
|
|
|
|
postNotificationName: PortBecameInvalidNotification
|
|
|
|
|
object: self];
|
|
|
|
|
is_valid = NO;
|
1996-03-01 16:06:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (Class) packetClass
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility: _cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- (Class) classForConnectedCoder: aRmc
|
|
|
|
|
{
|
|
|
|
|
/* Make sure that Connection's always send us bycopy,
|
|
|
|
|
i.e. as our own class, not a Proxy class. */
|
|
|
|
|
return [self class];
|
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- (void) encodeWithCoder: (id <Encoding>)anEncoder
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 16:06:03 +00:00
|
|
|
|
[super encodeWithCoder: anEncoder];
|
|
|
|
|
/* xxx What else? */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- initWithCoder: (id <Decoding>)coder
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 16:06:03 +00:00
|
|
|
|
self = [super initWithCoder: coder];
|
|
|
|
|
/* xxx What else? */
|
|
|
|
|
return self;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation InPort
|
|
|
|
|
|
1996-03-12 14:50:46 +00:00
|
|
|
|
- init
|
|
|
|
|
{
|
|
|
|
|
[super init];
|
|
|
|
|
_packet_invocation = nil;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
+ newForReceivingFromRegisteredName: (id <String>)name
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-01 17:04:17 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
1996-03-01 16:06:03 +00:00
|
|
|
|
return nil;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
+ newForReceiving
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 16:06:03 +00:00
|
|
|
|
return [self newForReceivingFromRegisteredName: nil];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- receivePacketWithTimeout: (int)milliseconds
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-01 17:04:17 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
1996-03-01 16:06:03 +00:00
|
|
|
|
return nil;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-12 14:50:46 +00:00
|
|
|
|
- (void) setPacketInvocation: (id <Invoking>)invocation
|
|
|
|
|
{
|
|
|
|
|
_packet_invocation = invocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) addToRunLoop: run_loop forMode: (id <String>)mode
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) removeFromRunLoop: run_loop forMode: (id <String>)mode
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation OutPort
|
|
|
|
|
|
|
|
|
|
+ newForSendingToRegisteredName: (id <String>)name
|
|
|
|
|
onHost: (id <String>)hostname
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-01 17:04:17 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
1996-03-01 16:06:03 +00:00
|
|
|
|
return nil;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- (BOOL) sendPacket: packet withTimeout: (int)milliseconds
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-01 17:04:17 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
1996-03-01 16:06:03 +00:00
|
|
|
|
return NO;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation Packet
|
|
|
|
|
|
|
|
|
|
/* xxx There should be a designated initializer for the Packet class.
|
|
|
|
|
Currently some subclasses and users, bypass this by calling
|
|
|
|
|
MemoryStream initializers. */
|
|
|
|
|
|
|
|
|
|
- initForSendingWithCapacity: (unsigned)c
|
|
|
|
|
replyPort: p
|
|
|
|
|
{
|
|
|
|
|
[super initWithCapacity: c];
|
|
|
|
|
reply_port = p;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- replyPort
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-01 16:06:03 +00:00
|
|
|
|
return reply_port;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
1996-03-03 00:36:53 +00:00
|
|
|
|
|
|
|
|
|
NSString *PortBecameInvalidNotification = @"PortBecameInvalidNotification";
|