2000-07-04 11:05:46 +00:00
|
|
|
|
/* Interface for GNU Objective-C version of NSConnection
|
|
|
|
|
Copyright (C) 1997,2000 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
|
|
Original by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
|
Version for OPENSTEP by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Created: August 1997, updated June 2000
|
|
|
|
|
|
|
|
|
|
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
|
2005-05-22 03:32:16 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
2000-07-04 11:05:46 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __NSConnection_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
|
#define __NSConnection_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
|
|
|
|
|
|
#include <Foundation/NSObject.h>
|
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
|
#include <Foundation/NSTimer.h>
|
|
|
|
|
#include <Foundation/NSRunLoop.h>
|
|
|
|
|
#include <Foundation/NSMapTable.h>
|
|
|
|
|
|
|
|
|
|
@class NSDistantObject;
|
|
|
|
|
@class NSPort;
|
|
|
|
|
@class NSPortNameServer;
|
|
|
|
|
@class NSData;
|
2000-12-08 19:06:00 +00:00
|
|
|
|
@class NSInvocation;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Keys for the NSDictionary returned by [NSConnection -statistics]
|
|
|
|
|
*/
|
|
|
|
|
/* These in OPENSTEP 4.2 */
|
2004-07-29 15:30:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* Key for dictionary returned by [NSConnection-statistics]: number of
|
|
|
|
|
* messages replied to so far by the remote connection.
|
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
|
GS_EXPORT NSString* const NSConnectionRepliesReceived;
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Key for dictionary returned by [NSConnection-statistics]: number of
|
|
|
|
|
* messages sent so far to the remote connection.
|
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
|
GS_EXPORT NSString* const NSConnectionRepliesSent;
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Key for dictionary returned by [NSConnection-statistics]: number of
|
|
|
|
|
* messages received so far from the remote connection.
|
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
|
GS_EXPORT NSString* const NSConnectionRequestsReceived;
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Key for dictionary returned by [NSConnection-statistics]: number of
|
|
|
|
|
* messages sent so far to the remote connection.
|
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
|
GS_EXPORT NSString* const NSConnectionRequestsSent;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
/* These Are GNUstep extras */
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GNUstep-specific key for dictionary returned by [NSConnection-statistics]:
|
|
|
|
|
* number of local objects currently in use remotely.
|
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
|
GS_EXPORT NSString* const NSConnectionLocalCount; /* Objects sent out */
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GNUstep-specific key for dictionary returned by [NSConnection-statistics]:
|
|
|
|
|
* number of remote objects currently in use.
|
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
|
GS_EXPORT NSString* const NSConnectionProxyCount; /* Objects received */
|
2000-07-04 11:05:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NSConnection class interface.
|
|
|
|
|
*
|
|
|
|
|
* A few methods are in the specification but not yet implemented.
|
|
|
|
|
*/
|
|
|
|
|
@interface NSConnection : NSObject
|
|
|
|
|
{
|
|
|
|
|
@private
|
|
|
|
|
BOOL _isValid;
|
|
|
|
|
BOOL _independentQueueing;
|
|
|
|
|
BOOL _authenticateIn;
|
|
|
|
|
BOOL _authenticateOut;
|
|
|
|
|
BOOL _multipleThreads;
|
|
|
|
|
NSPort *_receivePort;
|
|
|
|
|
NSPort *_sendPort;
|
|
|
|
|
unsigned _requestDepth;
|
|
|
|
|
unsigned _messageCount;
|
|
|
|
|
unsigned _reqOutCount;
|
|
|
|
|
unsigned _reqInCount;
|
|
|
|
|
unsigned _repOutCount;
|
|
|
|
|
unsigned _repInCount;
|
2000-07-05 12:23:00 +00:00
|
|
|
|
#ifndef _IN_CONNECTION_M
|
|
|
|
|
#define GSIMapTable void*
|
|
|
|
|
#endif
|
|
|
|
|
GSIMapTable _localObjects;
|
|
|
|
|
GSIMapTable _localTargets;
|
|
|
|
|
GSIMapTable _remoteProxies;
|
|
|
|
|
GSIMapTable _replyMap;
|
|
|
|
|
#ifndef _IN_CONNECTION_M
|
|
|
|
|
#undef GSIMapTable
|
|
|
|
|
#endif
|
2000-07-04 11:05:46 +00:00
|
|
|
|
NSTimeInterval _replyTimeout;
|
|
|
|
|
NSTimeInterval _requestTimeout;
|
|
|
|
|
NSMutableArray *_requestModes;
|
|
|
|
|
NSMutableArray *_runLoops;
|
|
|
|
|
NSMutableArray *_requestQueue;
|
|
|
|
|
id _delegate;
|
|
|
|
|
NSRecursiveLock *_refGate;
|
|
|
|
|
NSMutableArray *_cachedDecoders;
|
|
|
|
|
NSMutableArray *_cachedEncoders;
|
2000-07-04 19:53:39 +00:00
|
|
|
|
NSString *_registeredName;
|
|
|
|
|
NSPortNameServer *_nameServer;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSArray*) allConnections;
|
|
|
|
|
+ (NSConnection*) connectionWithReceivePort: (NSPort*)r
|
|
|
|
|
sendPort: (NSPort*)s;
|
|
|
|
|
+ (NSConnection*) connectionWithRegisteredName: (NSString*)n
|
|
|
|
|
host: (NSString*)h;
|
|
|
|
|
+ (NSConnection*) connectionWithRegisteredName: (NSString*)n
|
|
|
|
|
host: (NSString*)h
|
|
|
|
|
usingNameServer: (NSPortNameServer*)s;
|
|
|
|
|
+ (id) currentConversation;
|
|
|
|
|
+ (NSConnection*) defaultConnection;
|
2001-12-17 14:31:42 +00:00
|
|
|
|
+ (NSDistantObject*) rootProxyForConnectionWithRegisteredName: (NSString*)n
|
|
|
|
|
host: (NSString*)h;
|
|
|
|
|
+ (NSDistantObject*) rootProxyForConnectionWithRegisteredName: (NSString*)n
|
|
|
|
|
host: (NSString*)h usingNameServer: (NSPortNameServer*)s;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void) addRequestMode: (NSString*)mode;
|
2001-12-17 14:31:42 +00:00
|
|
|
|
- (void) addRunLoop: (NSRunLoop*)loop;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
- (id) delegate;
|
|
|
|
|
- (void) enableMultipleThreads;
|
|
|
|
|
- (BOOL) independentConversationQueueing;
|
|
|
|
|
- (id) initWithReceivePort: (NSPort*)r
|
|
|
|
|
sendPort: (NSPort*)s;
|
|
|
|
|
- (void) invalidate;
|
|
|
|
|
- (BOOL) isValid;
|
|
|
|
|
- (NSArray*)localObjects;
|
|
|
|
|
- (BOOL) multipleThreadsEnabled;
|
|
|
|
|
- (NSPort*) receivePort;
|
|
|
|
|
- (BOOL) registerName: (NSString*)name;
|
|
|
|
|
- (BOOL) registerName: (NSString*)name withNameServer: (NSPortNameServer*)svr;
|
|
|
|
|
- (NSArray*) remoteObjects;
|
|
|
|
|
- (void) removeRequestMode: (NSString*)mode;
|
2001-12-17 14:31:42 +00:00
|
|
|
|
- (void) removeRunLoop: (NSRunLoop *)loop;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
- (NSTimeInterval) replyTimeout;
|
|
|
|
|
- (NSArray*) requestModes;
|
|
|
|
|
- (NSTimeInterval) requestTimeout;
|
|
|
|
|
- (id) rootObject;
|
|
|
|
|
- (NSDistantObject*) rootProxy;
|
|
|
|
|
- (void) runInNewThread;
|
|
|
|
|
- (NSPort*) sendPort;
|
|
|
|
|
- (void) setDelegate: anObj;
|
|
|
|
|
- (void) setIndependentConversationQueueing: (BOOL)flag;
|
2001-12-17 14:31:42 +00:00
|
|
|
|
- (void) setReplyTimeout: (NSTimeInterval)to;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
- (void) setRequestMode: (NSString*)mode;
|
2001-12-17 14:31:42 +00:00
|
|
|
|
- (void) setRequestTimeout: (NSTimeInterval)to;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
- (void) setRootObject: anObj;
|
|
|
|
|
- (NSDictionary*) statistics;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* This category contains legacy methods from the original GNU 'Connection'
|
|
|
|
|
* class, and useful extensions to [NSConnection].
|
2000-07-04 11:05:46 +00:00
|
|
|
|
*/
|
|
|
|
|
@interface NSConnection (GNUstepExtensions) <GCFinalization>
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* Alternative convenience constructor, not specified in OpenStep, where you
|
|
|
|
|
* registe root anObject under given name in one step.
|
|
|
|
|
*/
|
2001-12-17 14:31:42 +00:00
|
|
|
|
+ (NSConnection*) newRegisteringAtName: (NSString*)name
|
2000-07-04 11:05:46 +00:00
|
|
|
|
withRootObject: (id)anObject;
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* Performs local and remote cleanup.
|
|
|
|
|
*/
|
2000-07-04 11:05:46 +00:00
|
|
|
|
- (void) gcFinalize;
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* [NSDistantObject -forward::] calls this to send the message over the wire.
|
|
|
|
|
*/
|
2000-07-04 11:05:46 +00:00
|
|
|
|
- (retval_t) forwardForProxy: (NSDistantObject*)object
|
|
|
|
|
selector: (SEL)sel
|
2001-12-17 14:31:42 +00:00
|
|
|
|
argFrame: (arglist_t)argframe;
|
2004-06-22 22:27:39 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [NSDistantObject -forwardInvocation:] calls this to send the message over
|
|
|
|
|
* the wire.
|
|
|
|
|
*/
|
2000-12-08 19:06:00 +00:00
|
|
|
|
- (void) forwardInvocation: (NSInvocation *)inv
|
|
|
|
|
forProxy: (NSDistantObject*)object;
|
2004-06-22 22:27:39 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns type code (@encode()-compatible) for given remote method.
|
|
|
|
|
*/
|
2000-07-04 11:05:46 +00:00
|
|
|
|
- (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface Object (NSConnectionDelegate)
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* This method may be used to ask a delegate's permission to create
|
2000-07-04 11:05:46 +00:00
|
|
|
|
* a new connection from the old one.
|
|
|
|
|
* This method should be implemented in preference to the
|
|
|
|
|
* [makeNewConnection:sender:] which is obsolete.
|
|
|
|
|
*/
|
|
|
|
|
- (BOOL) connection: (NSConnection*)parent
|
|
|
|
|
shouldMakeNewConnection: (NSConnection*)newConnection;
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
2000-07-04 11:05:46 +00:00
|
|
|
|
* This is the old way of doing the same thing as
|
|
|
|
|
* [connection:shouldMakeNewConnection:]
|
|
|
|
|
* It is obsolete - don't use it.
|
|
|
|
|
*/
|
|
|
|
|
- (BOOL) makeNewConnection: (NSConnection*)newConnection
|
|
|
|
|
sender: (NSConnection*)parent;
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
2000-07-04 11:05:46 +00:00
|
|
|
|
* If the delegate responds to this method, it will be used to ask the
|
|
|
|
|
* delegate's permission to establish a new connection from the old one.
|
|
|
|
|
* Often this is used so that the delegate can register for invalidation
|
|
|
|
|
* notification on new child connections.
|
|
|
|
|
* This is a GNUstep extension
|
|
|
|
|
* Normally return newConn.
|
|
|
|
|
*/
|
|
|
|
|
- (NSConnection*) connection: (NSConnection*)ancestorConn
|
|
|
|
|
didConnect: (NSConnection*)newConn;
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
2000-07-04 14:37:18 +00:00
|
|
|
|
* These are like the MacOS-X delegate methods, except that we provide the
|
|
|
|
|
* components in mutable arrays, so that the delegate can alter the data
|
|
|
|
|
* items in the array. Of course, you must do that WITH CARE.
|
|
|
|
|
*/
|
|
|
|
|
- (BOOL) authenticateComponents: (NSMutableArray*)components
|
2000-07-04 11:05:46 +00:00
|
|
|
|
withData: (NSData*)authenticationData;
|
2004-06-22 22:27:39 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* These are like the MacOS-X delegate methods, except that we provide the
|
|
|
|
|
* components in mutable arrays, so that the delegate can alter the data
|
|
|
|
|
* items in the array. Of course, you must do that WITH CARE.
|
|
|
|
|
*/
|
2000-07-04 14:37:18 +00:00
|
|
|
|
- (NSData*) authenticationDataForComponents: (NSMutableArray*)components;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* This informal protocol allows an object to control the details of how an
|
|
|
|
|
* object is sent over the wire in distributed objects Port communications.
|
|
|
|
|
*/
|
2000-07-04 11:05:46 +00:00
|
|
|
|
@interface Object (NSPortCoder)
|
2004-06-22 22:27:39 +00:00
|
|
|
|
/**
|
2000-07-04 11:05:46 +00:00
|
|
|
|
* Must return the class that will be created on the remote side
|
|
|
|
|
* of the connection. If the class to be created is not the same
|
|
|
|
|
* as that of the object returned by replacementObjectForPortCoder:
|
|
|
|
|
* then the class must be capable of recognising the object it
|
|
|
|
|
* actually gets in its initWithCoder: method.
|
|
|
|
|
* The default operation is to return NSDistantObject unless the
|
|
|
|
|
* object is being sent bycopy, in which case the objects actual
|
|
|
|
|
* class is returned. To force bycopy operation the object should
|
|
|
|
|
* return its own class.
|
|
|
|
|
*/
|
2004-06-22 22:27:39 +00:00
|
|
|
|
- (Class) classForPortCoder;
|
|
|
|
|
|
|
|
|
|
/**
|
2000-07-04 11:05:46 +00:00
|
|
|
|
* This message is sent to an object about to be encoded for sending
|
|
|
|
|
* over the wire. The default action is to return an NSDistantObject
|
|
|
|
|
* which is a local proxy for the object unless the object is being
|
|
|
|
|
* sent bycopy, in which case the actual object is returned.
|
2004-06-22 22:27:39 +00:00
|
|
|
|
* To force bycopy, an object should return itself.
|
2000-07-04 11:05:46 +00:00
|
|
|
|
*/
|
2004-06-22 22:27:39 +00:00
|
|
|
|
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder;
|
2000-07-04 11:05:46 +00:00
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NSRunLoop mode, NSNotification name and NSException strings.
|
|
|
|
|
*/
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [NSRunLoop] mode for [NSConnection] objects waiting for replies.
|
|
|
|
|
* Mainly used internally by distributed objects system.
|
|
|
|
|
*/
|
2002-05-08 05:43:15 +00:00
|
|
|
|
GS_EXPORT NSString * const NSConnectionReplyMode;
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Posted when an [NSConnection] is deallocated or it is notified its port is
|
|
|
|
|
* deactivated. (Note, connections to remote ports don't get such a
|
|
|
|
|
* notification.) Receivers should deregister themselves for notifications
|
|
|
|
|
* from the given connection.
|
|
|
|
|
*/
|
2002-05-08 05:43:15 +00:00
|
|
|
|
GS_EXPORT NSString * const NSConnectionDidDieNotification;
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Posted when an [NSConnection] is initialized.
|
|
|
|
|
*/
|
2002-05-08 05:43:15 +00:00
|
|
|
|
GS_EXPORT NSString * const NSConnectionDidInitializeNotification; /* OPENSTEP */
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Raised by an [NSConnection] on receiving a message that it or its delegate
|
|
|
|
|
* cannot authenticate.
|
|
|
|
|
*/
|
2002-05-08 05:43:15 +00:00
|
|
|
|
GS_EXPORT NSString * const NSFailedAuthenticationException; /* MacOS-X */
|
2000-07-04 11:05:46 +00:00
|
|
|
|
|
|
|
|
|
#endif /* __NSConnection_h_GNUSTEP_BASE_INCLUDE */
|