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
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
|
Written by: Andrew Kachites 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
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
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.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/Port.h>
|
|
|
|
|
#include <base/Coder.h> /* for Coding protocol in Object category */
|
1999-06-17 11:02:32 +00:00
|
|
|
|
#include <Foundation/NSNotification.h>
|
1998-11-19 21:26:27 +00:00
|
|
|
|
#include <Foundation/NSException.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];
|
1999-09-16 07:21:34 +00:00
|
|
|
|
_is_valid = YES;
|
1996-03-01 16:06:03 +00:00
|
|
|
|
return self;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- (void) close
|
|
|
|
|
{
|
|
|
|
|
[self invalidate];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-12 19:42:10 +00:00
|
|
|
|
+ (Class) outPacketClass
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (Class) outPacketClass
|
1996-03-01 16:06:03 +00:00
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility: _cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-20 05:12:26 +00:00
|
|
|
|
- (Class) classForPortCoder
|
1996-03-01 16:06:03 +00:00
|
|
|
|
{
|
|
|
|
|
/* Make sure that Connection's always send us bycopy,
|
|
|
|
|
i.e. as our own class, not a Proxy class. */
|
|
|
|
|
return [self class];
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- replacementObjectForPortCoder: aRmc
|
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-16 20:35:40 +00:00
|
|
|
|
+ newForReceivingFromRegisteredName: (NSString*)name fromPort: (int)port
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
1996-11-24 17:30:39 +00:00
|
|
|
|
+ newForReceivingFromRegisteredName: (NSString*)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
|
|
|
|
}
|
|
|
|
|
|
2000-06-16 11:06:06 +00:00
|
|
|
|
- (void) setReceivedPacketInvocation: (id)invocation
|
1996-03-12 14:50:46 +00:00
|
|
|
|
{
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert(!_packet_invocation, NSInternalInconsistencyException);
|
1996-03-12 14:50:46 +00:00
|
|
|
|
_packet_invocation = invocation;
|
|
|
|
|
}
|
|
|
|
|
|
1996-11-24 17:30:39 +00:00
|
|
|
|
- (void) addToRunLoop: run_loop forMode: (NSString*)mode
|
1996-03-12 14:50:46 +00:00
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
}
|
|
|
|
|
|
1996-11-24 17:30:39 +00:00
|
|
|
|
- (void) removeFromRunLoop: run_loop forMode: (NSString*)mode
|
1996-03-12 14:50:46 +00:00
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-01 16:06:03 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation OutPort
|
|
|
|
|
|
1996-11-24 17:30:39 +00:00
|
|
|
|
+ newForSendingToRegisteredName: (NSString*)name
|
|
|
|
|
onHost: (NSString*)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
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (BOOL) sendPacket: packet timeout: (NSTimeInterval)t
|
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
|
|
|
|
|
|
|
|
|
|
|
1996-03-12 19:42:10 +00:00
|
|
|
|
@implementation InPacket
|
|
|
|
|
|
|
|
|
|
/* The designated initializer. */
|
|
|
|
|
- initForReceivingWithCapacity: (unsigned)c
|
|
|
|
|
receivingInPort: ip
|
|
|
|
|
replyOutPort: op
|
|
|
|
|
{
|
1998-02-05 22:06:20 +00:00
|
|
|
|
self = [super initWithCapacity: c prefix: 0];
|
|
|
|
|
if (self)
|
|
|
|
|
{
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([op isValid], NSInternalInconsistencyException);
|
|
|
|
|
NSAssert(!ip || [ip isValid], NSInternalInconsistencyException);
|
1998-02-05 22:06:20 +00:00
|
|
|
|
_reply_out_port = op;
|
|
|
|
|
_receiving_in_port = ip;
|
|
|
|
|
}
|
1996-03-12 19:42:10 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
1996-03-01 16:06:03 +00:00
|
|
|
|
|
1996-03-12 19:42:10 +00:00
|
|
|
|
- replyOutPort
|
|
|
|
|
{
|
|
|
|
|
return _reply_out_port;
|
|
|
|
|
}
|
1996-03-01 16:06:03 +00:00
|
|
|
|
|
1996-03-12 19:42:10 +00:00
|
|
|
|
- receivingInPort
|
|
|
|
|
{
|
|
|
|
|
return _receiving_in_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation OutPacket
|
|
|
|
|
|
|
|
|
|
/* The designated initializer. */
|
1996-03-01 16:06:03 +00:00
|
|
|
|
- initForSendingWithCapacity: (unsigned)c
|
1996-03-12 19:42:10 +00:00
|
|
|
|
replyInPort: ip
|
1996-03-01 16:06:03 +00:00
|
|
|
|
{
|
1998-02-05 22:06:20 +00:00
|
|
|
|
self = [super initWithCapacity: c prefix: [[self class] prefixSize]];
|
|
|
|
|
if (self)
|
|
|
|
|
{
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([ip isValid], NSInternalInconsistencyException);
|
1998-02-05 22:06:20 +00:00
|
|
|
|
_reply_in_port = ip;
|
|
|
|
|
}
|
1996-03-01 16:06:03 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-12 19:42:10 +00:00
|
|
|
|
+ (unsigned) prefixSize
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- replyInPort
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-12 19:42:10 +00:00
|
|
|
|
return _reply_in_port;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
1996-03-03 00:36:53 +00:00
|
|
|
|
|