1994-11-04 16:29:24 +00:00
|
|
|
/* Interface for GNU Objective-C connection for remote object messaging
|
1996-03-01 15:54:57 +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 15:54:57 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __Connection_h_OBJECTS_INCLUDE
|
|
|
|
#define __Connection_h_OBJECTS_INCLUDE
|
|
|
|
|
|
|
|
#include <objects/stdobjects.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <objc/hash.h>
|
|
|
|
#include <objc/Protocol.h>
|
|
|
|
#include <objects/Lock.h>
|
|
|
|
#include <objects/InvalidationListening.h>
|
|
|
|
#include <objects/Collecting.h>
|
|
|
|
#include <objects/Dictionary.h>
|
1995-04-03 03:24:45 +00:00
|
|
|
#include <objects/NSString.h>
|
1996-03-01 15:54:57 +00:00
|
|
|
#include <Foundation/NSMapTable.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
@class Proxy;
|
|
|
|
@class Port;
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
@interface Connection : NSObject
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
unsigned is_valid:1;
|
|
|
|
unsigned delay_dialog_interruptions:1;
|
|
|
|
unsigned tcp_port_filler:6;
|
|
|
|
unsigned retain_count:24;
|
1994-11-04 16:29:24 +00:00
|
|
|
Port *in_port;
|
|
|
|
Port *out_port;
|
|
|
|
unsigned message_count;
|
1996-03-01 15:54:57 +00:00
|
|
|
NSMapTable *local_targets;
|
|
|
|
NSMapTable *remote_proxies;
|
1994-11-04 16:29:24 +00:00
|
|
|
int in_timeout;
|
|
|
|
int out_timeout;
|
1996-03-01 15:54:57 +00:00
|
|
|
Class port_class;
|
|
|
|
Class encoding_class;
|
|
|
|
NSMapTable *incoming_xref_2_const_ptr;
|
|
|
|
NSMapTable *outgoing_const_ptr_2_xref;
|
|
|
|
id delegate;
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
/* Setting and getting class configuration */
|
|
|
|
+ (Class) defaultPortClass;
|
|
|
|
+ (void) setDefaultPortClass: (Class) aPortClass;
|
|
|
|
+ (Class) defaultProxyClass;
|
|
|
|
+ (void) setDefaultProxyClass: (Class) aClass;
|
1994-11-04 16:29:24 +00:00
|
|
|
+ (int) defaultOutTimeout;
|
1996-03-01 15:54:57 +00:00
|
|
|
+ (void) setDefaultOutTimeout: (int)to;
|
1994-11-04 16:29:24 +00:00
|
|
|
+ (int) defaultInTimeout;
|
1996-03-01 15:54:57 +00:00
|
|
|
+ (void) setDefaultInTimeout: (int)to;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
/* Querying the state of all the connections */
|
1994-11-04 16:29:24 +00:00
|
|
|
+ (int) messagesReceived;
|
|
|
|
+ (id <Collecting>) allConnections;
|
|
|
|
+ (unsigned) connectionsCount;
|
|
|
|
+ (unsigned) connectionsCountWithInPort: (Port*)aPort;
|
|
|
|
|
1995-03-12 19:59:20 +00:00
|
|
|
/* Use these when you're release'ing an object that may have been vended
|
1994-11-04 16:29:24 +00:00
|
|
|
or registered for invalidation notification */
|
1996-03-01 15:54:57 +00:00
|
|
|
+ (void) removeLocalObject: anObj;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Registering your server object on the network.
|
|
|
|
These methods create a new connection object that must be "run" in order
|
|
|
|
to start handling requests from clients.
|
|
|
|
These method names may change when we get the capability to register
|
|
|
|
ports with names after the ports have been created. */
|
|
|
|
/* I want the second method name to clearly indicate that we're not
|
|
|
|
connecting to a pre-existing registration name, we're registering a
|
|
|
|
new name, and this method will fail if that name has already been
|
|
|
|
registered. This is why I don't like "newWithRegisteredName:" ---
|
|
|
|
it's unclear if we're connecting to another Connection that already
|
|
|
|
registered with that name. */
|
1996-03-01 15:54:57 +00:00
|
|
|
+ (Connection*) newWithRootObject: anObj;
|
|
|
|
+ (Connection*) newRegisteringAtName: (id <String>)n withRootObject: anObj;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
/* Get a proxy to a remote server object.
|
|
|
|
A new connection is created if necessary. */
|
1995-04-03 03:24:45 +00:00
|
|
|
+ (Proxy*) rootProxyAtName: (id <String>)name onHost: (id <String>)host;
|
|
|
|
+ (Proxy*) rootProxyAtName: (id <String>)name;
|
1994-11-04 16:29:24 +00:00
|
|
|
+ (Proxy*) rootProxyAtPort: (Port*)anOutPort;
|
|
|
|
+ (Proxy*) rootProxyAtPort: (Port*)anOutPort withInPort: (Port*)anInPort;
|
|
|
|
|
|
|
|
/* This is the designated initializer for the Connection class.
|
|
|
|
You don't need to call it yourself. */
|
1996-03-01 15:54:57 +00:00
|
|
|
+ (Connection*) newForInPort: (Port*)anInPort outPort: (Port*)anOutPort
|
|
|
|
ancestorConnection: (Connection*)ancestor;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Make a connection object start listening for incoming requests. After
|
|
|
|
`timeout' milliseconds without receiving anything, return. */
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) runConnectionWithTimeout: (int)timeout;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Same as above, but never time out. */
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) runConnection;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* When you get an invalidation notification from a connection, use
|
|
|
|
this method in order to find out if any of the proxy objects you're
|
|
|
|
using are going away. */
|
1996-03-01 15:54:57 +00:00
|
|
|
- (id <Collecting>) proxies;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* If you somehow have a connection to a server, but don't have it's
|
|
|
|
a proxy to its root object yet, you can use this to get it. */
|
1996-03-01 15:54:57 +00:00
|
|
|
- (Proxy*) rootProxy;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
/* For getting the root object of a connection or port */
|
1994-11-04 16:29:24 +00:00
|
|
|
- rootObject;
|
|
|
|
+ rootObjectForInPort: (Port*)aPort;
|
|
|
|
|
|
|
|
/* Used for setting the root object of a connection that we
|
|
|
|
created without one, or changing the root object of a connection
|
|
|
|
that already has one. */
|
1996-03-01 15:54:57 +00:00
|
|
|
+ (void) setRootObject: anObj forInPort: (Port*)aPort;
|
|
|
|
- setRootObject: anObj;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
/* Querying and setting some instance variables */
|
1994-11-04 16:29:24 +00:00
|
|
|
- (int) outTimeout;
|
|
|
|
- (int) inTimeout;
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) setOutTimeout: (int)to;
|
|
|
|
- (void) setInTimeout: (int)to;
|
|
|
|
- (Class) portClass;
|
|
|
|
- (void) setPortClass: aPortClass;
|
|
|
|
- (Class) proxyClass;
|
|
|
|
- (Class) encodingClass;
|
|
|
|
- (Class) decodingClass;
|
|
|
|
- outPort;
|
|
|
|
- inPort;
|
1994-11-04 16:29:24 +00:00
|
|
|
- delegate;
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) setDelegate: anObj;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) invalidate;
|
|
|
|
|
|
|
|
/* Only subclassers and power-users need worry about these */
|
1994-11-04 16:29:24 +00:00
|
|
|
- (Proxy*) proxyForTarget: (unsigned)target;
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) addProxy: (Proxy*)aProxy;
|
1994-11-04 16:29:24 +00:00
|
|
|
- (BOOL) includesProxyForTarget: (unsigned)target;
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) removeProxy: (Proxy*)aProxy;
|
1994-11-04 16:29:24 +00:00
|
|
|
- (id <Collecting>) localObjects;
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) addLocalObject: anObj;
|
1994-11-04 16:29:24 +00:00
|
|
|
- (BOOL) includesLocalObject: anObj;
|
1996-03-01 15:54:57 +00:00
|
|
|
- (void) removeLocalObject: anObj;
|
|
|
|
- (retval_t) forwardForProxy: (Proxy*)object
|
|
|
|
selector: (SEL)sel
|
|
|
|
argFrame: (arglist_t)frame;
|
|
|
|
- (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target;
|
|
|
|
- (unsigned) _encoderReferenceForConstPtr: (const void*)ptr;
|
|
|
|
- (const void*) _decoderConstPtrAtReference: (unsigned)xref;
|
|
|
|
- (unsigned) _encoderCreateReferenceForConstPtr: (const void*)ptr;
|
|
|
|
- (unsigned) _decoderCreateReferenceForConstPtr: (const void*)ptr;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
extern NSString *ConnectionBecameInvalidNotification;
|
|
|
|
|
1995-04-08 18:26:30 +00:00
|
|
|
@protocol ConnectedSelfCoding
|
1994-11-04 16:29:24 +00:00
|
|
|
+ (void) encodeObject: anObj withConnectedCoder: aRmc;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface Object (ConnectionDelegate)
|
|
|
|
- (Connection*) connection: ancestorConn didConnect: newConn;
|
|
|
|
/* 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.
|
|
|
|
Normally return newConn. */
|
|
|
|
@end
|
|
|
|
|
|
|
|
#if 0 /* Put in Coder.m until ObjC runtime category-loading bug is fixed */
|
|
|
|
|
|
|
|
@interface Object (ConnectionRequests)
|
|
|
|
- classForConnectedCoder: aRmc;
|
|
|
|
/* Must return the class that will be created on the remote side
|
|
|
|
of the connection.
|
|
|
|
Used by the remote objects system to determine how the receiver
|
|
|
|
should be encoded across the network.
|
|
|
|
In general, you can:
|
|
|
|
return [Proxy class] to send a proxy of the receiver;
|
|
|
|
return [self class] to send the receiver bycopy.
|
|
|
|
The Object class implementation returns [Proxy class]. */
|
|
|
|
+ (void) encodeObject: anObject withConnectedCoder: aRmc;
|
|
|
|
/* This message is sent to the class returned by -classForConnectedCoder:
|
|
|
|
The Proxy class implementation encodes a proxy for anObject.
|
|
|
|
The Object class implementation encodes the receiver itself. */
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface Object (Retaining) <Retaining>
|
|
|
|
/* Make sure objects don't crash when you send them <Retaining> messages.
|
|
|
|
These implementations, however, do nothing. */
|
|
|
|
@end
|
|
|
|
|
|
|
|
#endif /* 0 Put in Coder.m */
|
|
|
|
|
|
|
|
#define CONNECTION_DEFAULT_TIMEOUT 15000 /* in milliseconds */
|
|
|
|
|
|
|
|
#endif /* __Connection_h_OBJECTS_INCLUDE */
|