1994-11-04 16:29:24 +00:00
|
|
|
|
/* Implementation of GNU Objective-C Proxy for remote object messaging
|
1997-03-04 15:51:20 +00:00
|
|
|
|
Copyright (C) 1994, 1995, 1996, 1997 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>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
Date: July 1994
|
|
|
|
|
|
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
|
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdarg.h>
|
1996-04-17 15:34:35 +00:00
|
|
|
|
#include <gnustep/base/preface.h>
|
1996-04-17 15:23:00 +00:00
|
|
|
|
#include <gnustep/base/Proxy.h>
|
|
|
|
|
#include <gnustep/base/Connection.h>
|
|
|
|
|
#include <gnustep/base/Port.h>
|
|
|
|
|
#include <gnustep/base/TcpPort.h>
|
|
|
|
|
#include <gnustep/base/ConnectedCoder.h>
|
1996-03-06 14:16:04 +00:00
|
|
|
|
#include <Foundation/NSException.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
1996-04-16 23:28:14 +00:00
|
|
|
|
static int debug_proxy = 0;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
#if NeXT_runtime
|
|
|
|
|
static id tmp_kludge_protocol = nil;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
@implementation Proxy
|
|
|
|
|
|
|
|
|
|
/* Required by NeXT runtime */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
+ (void) initialize
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-03 01:37:59 +00:00
|
|
|
|
return;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if NeXT_runtime
|
|
|
|
|
+ setProtocolForProxies: (Protocol*)p
|
|
|
|
|
{
|
|
|
|
|
tmp_kludge_protocol = p;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-03-06 14:16:04 +00:00
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* This is the designated initializer. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-06 14:16:04 +00:00
|
|
|
|
+ newForRemoteTarget: (unsigned)target connection: (Connection*)connection
|
|
|
|
|
{
|
|
|
|
|
Proxy *new_proxy;
|
|
|
|
|
|
1996-03-07 18:09:06 +00:00
|
|
|
|
assert ([connection isValid]);
|
|
|
|
|
|
1996-03-06 14:16:04 +00:00
|
|
|
|
/* If there already is a proxy for this target/connection combination,
|
|
|
|
|
don't create a new one, just return the old one. */
|
|
|
|
|
if ((new_proxy = [connection proxyForTarget: target]))
|
1996-03-07 18:09:06 +00:00
|
|
|
|
{
|
|
|
|
|
return new_proxy;
|
|
|
|
|
}
|
1996-03-06 14:16:04 +00:00
|
|
|
|
|
|
|
|
|
/* There isn't one already created; make a new proxy object,
|
|
|
|
|
and set its ivars. */
|
|
|
|
|
new_proxy = class_create_instance (self);
|
|
|
|
|
new_proxy->_target = target;
|
|
|
|
|
new_proxy->_connection = connection;
|
|
|
|
|
new_proxy->_retain_count = 0;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#if NeXT_runtime
|
1996-03-06 14:16:04 +00:00
|
|
|
|
new_proxy->_method_types = coll_hash_new(32,
|
1994-11-04 16:29:24 +00:00
|
|
|
|
elt_hash_void_ptr,
|
|
|
|
|
elt_compare_void_ptrs);
|
1996-03-06 14:16:04 +00:00
|
|
|
|
new_proxy->protocol = nil;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if (debug_proxy)
|
1996-03-06 14:16:04 +00:00
|
|
|
|
printf("Created new proxy=0x%x target 0x%x conn 0x%x\n",
|
|
|
|
|
(unsigned)new_proxy,
|
|
|
|
|
(unsigned)new_proxy->_target,
|
|
|
|
|
(unsigned)connection);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-06 14:16:04 +00:00
|
|
|
|
/* Register this proxy with the connection. */
|
|
|
|
|
[connection addProxy: new_proxy];
|
|
|
|
|
|
|
|
|
|
return new_proxy;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- notImplemented: (SEL)aSel
|
|
|
|
|
{
|
1996-03-26 19:35:47 +00:00
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Proxy notImplemented %s", sel_get_name(aSel)];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- self
|
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1997-03-04 15:51:20 +00:00
|
|
|
|
- awakeAfterUsingCoder: aDecoder
|
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#if NeXT_runtime
|
|
|
|
|
+ class
|
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
#else
|
1995-01-26 17:55:52 +00:00
|
|
|
|
+ (Class) class
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1995-01-26 17:55:52 +00:00
|
|
|
|
return (Class)self;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-03-06 14:16:04 +00:00
|
|
|
|
- (void) invalidateProxy
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-07 18:09:06 +00:00
|
|
|
|
/* xxx Who calls this? */
|
|
|
|
|
/* xxx What should go here? */
|
1996-03-06 14:16:04 +00:00
|
|
|
|
[_connection removeProxy: self];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isProxy
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: aRmc
|
|
|
|
|
{
|
1996-03-19 01:05:46 +00:00
|
|
|
|
if (![_connection isValid])
|
1996-03-19 01:48:39 +00:00
|
|
|
|
[NSException
|
|
|
|
|
raise: NSGenericException
|
|
|
|
|
format: @"Trying to encode an invalid Proxy.\n"
|
|
|
|
|
@"You should request ConnectionBecameInvalidNotification's and\n"
|
|
|
|
|
@"remove all references to the Proxy's of invalid Connections."];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[self classForConnectedCoder: aRmc]
|
|
|
|
|
encodeObject: self withConnectedCoder: aRmc];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- classForConnectedCoder: aRmc;
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
return object_get_class (self);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-06 14:16:04 +00:00
|
|
|
|
static inline BOOL class_is_kind_of (Class self, Class aClassObject)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1995-03-08 23:04:52 +00:00
|
|
|
|
Class class;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
for (class = self; class!=Nil; class = class_get_super_class(class))
|
|
|
|
|
if (class==aClassObject)
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-06 14:16:04 +00:00
|
|
|
|
|
|
|
|
|
/* Encoding and Decoding Proxies on the wire. */
|
|
|
|
|
|
|
|
|
|
/* This is the proxy tag; it indicates where the local object is,
|
|
|
|
|
and determines whether the reply port to the Connection-where-the-
|
|
|
|
|
proxy-is-local needs to encoded/decoded or not. */
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROXY_LOCAL_FOR_RECEIVER = 0,
|
|
|
|
|
PROXY_LOCAL_FOR_SENDER,
|
|
|
|
|
PROXY_REMOTE_FOR_BOTH
|
|
|
|
|
};
|
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
+ (void) encodeObject: anObject withConnectedCoder: aRmc
|
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
unsigned proxy_target;
|
|
|
|
|
unsigned char proxy_tag;
|
|
|
|
|
Connection *encoder_connection;
|
|
|
|
|
|
|
|
|
|
encoder_connection = [aRmc connection];
|
|
|
|
|
assert (encoder_connection);
|
1996-03-19 01:05:46 +00:00
|
|
|
|
if (![encoder_connection isValid])
|
1996-03-19 01:48:39 +00:00
|
|
|
|
[NSException
|
|
|
|
|
raise: NSGenericException
|
|
|
|
|
format: @"Trying to encode to an invalid Connection.\n"
|
|
|
|
|
@"You should request ConnectionBecameInvalidNotification's and\n"
|
|
|
|
|
@"remove all references to the Proxy's of invalid Connections."];
|
1996-03-06 14:16:04 +00:00
|
|
|
|
|
|
|
|
|
/* Find out if anObject is a proxy or not. */
|
|
|
|
|
if (class_is_kind_of (object_get_class (anObject), self))
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
/* anObject is a Proxy, or a Proxy subclass */
|
1996-03-06 14:16:04 +00:00
|
|
|
|
Connection *proxy_connection = [anObject connectionForProxy];
|
|
|
|
|
proxy_target = [anObject targetForProxy];
|
|
|
|
|
if (encoder_connection == proxy_connection)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
/* This proxy is a local object on the other side */
|
|
|
|
|
proxy_tag = PROXY_LOCAL_FOR_RECEIVER;
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
fprintf(stderr, "Sending a proxy, will be local 0x%x "
|
|
|
|
|
"connection 0x%x\n",
|
|
|
|
|
[anObject targetForProxy],
|
|
|
|
|
(unsigned)proxy_connection);
|
|
|
|
|
[aRmc encodeValueOfCType: @encode(typeof(proxy_tag))
|
|
|
|
|
at: &proxy_tag
|
|
|
|
|
withName: @"Proxy is local for receiver"];
|
|
|
|
|
[aRmc encodeValueOfCType: @encode(typeof(proxy_target))
|
|
|
|
|
at: &proxy_target
|
|
|
|
|
withName: @"Proxy target"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* This proxy will still be remote on the other side */
|
1996-03-06 14:16:04 +00:00
|
|
|
|
OutPort *proxy_connection_out_port = [proxy_connection outPort];
|
|
|
|
|
|
|
|
|
|
assert (proxy_connection_out_port);
|
1996-03-18 21:57:29 +00:00
|
|
|
|
assert ([proxy_connection_out_port isValid]);
|
1996-03-06 14:16:04 +00:00
|
|
|
|
assert (proxy_connection_out_port != [encoder_connection outPort]);
|
|
|
|
|
/* xxx Remove this after debugging, because it won't be true
|
|
|
|
|
for connections across different hosts. */
|
|
|
|
|
assert ([(id)proxy_connection_out_port portNumber]
|
|
|
|
|
!= [(id)[encoder_connection outPort] portNumber]);
|
|
|
|
|
assert ([proxy_connection inPort] == [encoder_connection inPort]);
|
|
|
|
|
proxy_tag = PROXY_REMOTE_FOR_BOTH;
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if (debug_proxy)
|
1996-03-06 14:16:04 +00:00
|
|
|
|
fprintf(stderr, "Sending triangle-connection proxy 0x%x "
|
|
|
|
|
"proxy-conn 0x%x to-conn 0x%x\n",
|
|
|
|
|
[anObject targetForProxy],
|
|
|
|
|
(unsigned)proxy_connection, (unsigned)encoder_connection);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
/* It's remote here, so we need to tell other side where to form
|
|
|
|
|
triangle connection to */
|
1996-03-06 14:16:04 +00:00
|
|
|
|
[aRmc encodeValueOfCType: @encode(typeof(proxy_tag))
|
|
|
|
|
at: &proxy_tag
|
|
|
|
|
withName: @"Proxy is remote for both sender and receiver"];
|
|
|
|
|
[aRmc encodeValueOfCType: @encode(typeof(proxy_target))
|
|
|
|
|
at: &proxy_target
|
|
|
|
|
withName: @"Proxy target"];
|
|
|
|
|
[aRmc encodeBycopyObject: proxy_connection_out_port
|
1996-03-01 15:54:57 +00:00
|
|
|
|
withName: @"Proxy outPort"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
/* anObject is a non-Proxy object, e.g. NSObject. */
|
1996-03-06 14:16:04 +00:00
|
|
|
|
/* But now were sending this object across the wire in proxy form. */
|
|
|
|
|
proxy_target = PTR2LONG(anObject);
|
|
|
|
|
proxy_tag = PROXY_LOCAL_FOR_SENDER;
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
fprintf(stderr, "Sending a proxy for local 0x%x\n",
|
|
|
|
|
(unsigned)anObject);
|
|
|
|
|
/* Let the connection know that we're going; this also retains anObj;
|
|
|
|
|
it's OK to send -addLocalObject: more than once for the same
|
|
|
|
|
object, because it will only really get added and retained once. */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[aRmc connection] addLocalObject: anObject];
|
1996-03-06 14:16:04 +00:00
|
|
|
|
|
|
|
|
|
[aRmc encodeValueOfCType: @encode(typeof(proxy_tag))
|
|
|
|
|
at: &proxy_tag
|
|
|
|
|
withName: @"Proxy is local for the sender"];
|
|
|
|
|
[aRmc encodeValueOfCType: @encode(typeof(proxy_target))
|
|
|
|
|
at: &proxy_target
|
|
|
|
|
withName: @"Proxy target"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ newWithCoder: aRmc
|
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
unsigned char proxy_tag;
|
|
|
|
|
unsigned target;
|
|
|
|
|
id decoder_connection;
|
|
|
|
|
|
|
|
|
|
if ([aRmc class] != [ConnectedDecoder class])
|
1996-03-19 01:48:39 +00:00
|
|
|
|
[NSException
|
|
|
|
|
raise: NSGenericException
|
|
|
|
|
format: @"Proxy objects only decode with ConnectedDecoder class"];
|
1996-03-06 14:16:04 +00:00
|
|
|
|
|
|
|
|
|
decoder_connection = [aRmc connection];
|
|
|
|
|
assert (decoder_connection);
|
|
|
|
|
|
|
|
|
|
/* First get the tag, so we know what values need to be decoded. */
|
|
|
|
|
[aRmc decodeValueOfCType: @encode(typeof(proxy_tag))
|
|
|
|
|
at: &proxy_tag
|
1996-03-01 15:54:57 +00:00
|
|
|
|
withName: NULL];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-03-06 14:16:04 +00:00
|
|
|
|
switch (proxy_tag)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
|
|
|
|
|
case PROXY_LOCAL_FOR_RECEIVER:
|
|
|
|
|
/* This was a proxy on the other side of the connection, but
|
|
|
|
|
here it's local. Just get the target address, make sure
|
|
|
|
|
that it is indeed the address of a local object that we
|
|
|
|
|
vended to the remote connection, then simply return the target
|
|
|
|
|
casted to (id). */
|
|
|
|
|
[aRmc decodeValueOfCType: @encode(typeof(target))
|
|
|
|
|
at: &target
|
|
|
|
|
withName: NULL];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if (debug_proxy)
|
1996-03-19 00:55:27 +00:00
|
|
|
|
fprintf(stderr, "Receiving a proxy for local object 0x%x "
|
1996-03-06 14:16:04 +00:00
|
|
|
|
"connection 0x%x\n", target, (unsigned)decoder_connection);
|
|
|
|
|
if (![[decoder_connection class] includesLocalObject: (id)target])
|
|
|
|
|
[NSException raise: @"ProxyDecodedBadTarget"
|
|
|
|
|
format: @"No local object with given address"];
|
|
|
|
|
return (id) target;
|
|
|
|
|
|
|
|
|
|
case PROXY_LOCAL_FOR_SENDER:
|
|
|
|
|
/* This was a local object on the other side of the connection,
|
|
|
|
|
but here it's a proxy object. Get the target address, and
|
|
|
|
|
send [Proxy +newForRemoteTarget:connection:]; this will return
|
|
|
|
|
the proxy object we already created for this target, or create
|
|
|
|
|
a new proxy object if necessary. */
|
|
|
|
|
[aRmc decodeValueOfCType: @encode(typeof(target))
|
|
|
|
|
at: &target
|
|
|
|
|
withName: NULL];
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if (debug_proxy)
|
1996-03-06 14:16:04 +00:00
|
|
|
|
fprintf(stderr, "Receiving a proxy, was local 0x%x connection 0x%x\n",
|
|
|
|
|
(unsigned)target, (unsigned)decoder_connection);
|
|
|
|
|
return [self newForRemoteTarget: target
|
|
|
|
|
connection: decoder_connection];
|
|
|
|
|
|
|
|
|
|
case PROXY_REMOTE_FOR_BOTH:
|
|
|
|
|
/* This was a proxy on the other side of the connection, and it
|
|
|
|
|
will be a proxy on this side too; that is, the local version
|
|
|
|
|
of this object is not on this host, not on the host the
|
|
|
|
|
ConnectedDecoder is connected to, but on a *third* host.
|
|
|
|
|
This is why I call this a "triangle connection". In addition
|
|
|
|
|
to decoding the target, we decode the OutPort object that we
|
|
|
|
|
will use to talk directly to this third host. We send
|
|
|
|
|
[Connection +newForInPort:outPort:ancestorConnection:]; this
|
|
|
|
|
will either return the connection already created for this
|
|
|
|
|
inPort/outPort pair, or create a new connection if necessary. */
|
|
|
|
|
{
|
|
|
|
|
Connection *proxy_connection;
|
|
|
|
|
id proxy_connection_out_port = nil;
|
|
|
|
|
|
|
|
|
|
[aRmc decodeValueOfCType: @encode(typeof(target))
|
|
|
|
|
at: &target
|
|
|
|
|
withName: NULL];
|
|
|
|
|
[aRmc decodeObjectAt: &proxy_connection_out_port
|
|
|
|
|
withName: NULL];
|
|
|
|
|
assert (proxy_connection_out_port);
|
|
|
|
|
proxy_connection = [[decoder_connection class]
|
|
|
|
|
newForInPort: [decoder_connection inPort]
|
|
|
|
|
outPort: proxy_connection_out_port
|
|
|
|
|
ancestorConnection: decoder_connection];
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
fprintf(stderr, "Receiving a triangle-connection proxy 0x%x "
|
|
|
|
|
"connection 0x%x\n", target, (unsigned)proxy_connection);
|
1996-03-07 18:09:06 +00:00
|
|
|
|
assert (proxy_connection != decoder_connection);
|
|
|
|
|
assert ([proxy_connection isValid]);
|
1996-03-06 14:16:04 +00:00
|
|
|
|
return [self newForRemoteTarget: target
|
|
|
|
|
connection: proxy_connection];
|
|
|
|
|
}
|
|
|
|
|
default:
|
1996-03-26 19:35:47 +00:00
|
|
|
|
/* xxx This should be something different than NSGenericException. */
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Bad proxy tag"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
1996-03-06 14:16:04 +00:00
|
|
|
|
/* Not reached. */
|
|
|
|
|
return nil;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned) targetForProxy
|
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
return _target;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- connectionForProxy
|
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
return _connection;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (const char *) selectorTypeForProxy: (SEL)selector
|
|
|
|
|
{
|
|
|
|
|
#if NeXT_runtime
|
|
|
|
|
#if 0
|
|
|
|
|
{
|
|
|
|
|
/* This is bogosity. You are required to include all methods sent
|
|
|
|
|
by any proxies in the protocol you pass to
|
|
|
|
|
+setProtocolForProxy: */
|
|
|
|
|
struct objc_method_description *md;
|
|
|
|
|
md = [tmp_kludge_protocol descriptionForInstanceMethod:selector];
|
|
|
|
|
if (md)
|
|
|
|
|
return md->types;
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
#elif 0
|
|
|
|
|
{
|
|
|
|
|
/* This is disgusting bogosity. This only works if some other
|
|
|
|
|
class in the executable responds to this method. */
|
|
|
|
|
/* xxx Look in the class hash table at all classes... */
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
{
|
|
|
|
|
elt e;
|
|
|
|
|
const char *t;
|
|
|
|
|
e = coll_hash_value_for_key(_method_types, selector);
|
|
|
|
|
t = e.char_ptr_u;
|
|
|
|
|
if (!t)
|
|
|
|
|
{
|
|
|
|
|
/* This isn't what we want, unless the remote machine has
|
|
|
|
|
the same architecture as us. */
|
|
|
|
|
t = [connection _typeForSelector:selector remoteTarget:target];
|
|
|
|
|
coll_hash_add(&_method_types, (void*)selector, t);
|
|
|
|
|
}
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
#endif /* 1 */
|
1996-03-06 14:16:04 +00:00
|
|
|
|
#else /* NeXT_runtime */
|
|
|
|
|
return sel_get_type (selector);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* xxx Clean up all this junk below */
|
|
|
|
|
|
|
|
|
|
- (oneway void) release
|
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
if (!_retain_count--)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
[self invalidateProxy];
|
|
|
|
|
[self dealloc];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- retain
|
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
_retain_count++;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
#if NeXT_runtime
|
1996-03-06 14:16:04 +00:00
|
|
|
|
coll_hash_delete (_method_types);
|
|
|
|
|
object_dispose ((Object*)self);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#else
|
1996-03-01 15:54:57 +00:00
|
|
|
|
NSDeallocateObject ((id)self);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- forward: (SEL)aSel :(arglist_t)frame
|
|
|
|
|
{
|
1996-03-01 15:54:57 +00:00
|
|
|
|
if (debug_proxy)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
printf("Proxy forwarding %s\n", sel_get_name(aSel));
|
1996-03-19 01:05:46 +00:00
|
|
|
|
if (![_connection isValid])
|
1996-03-19 01:48:39 +00:00
|
|
|
|
[NSException
|
|
|
|
|
raise: NSGenericException
|
|
|
|
|
format: @"Trying to send message to an invalid Proxy.\n"
|
|
|
|
|
@"You should request ConnectionBecameInvalidNotification's and\n"
|
|
|
|
|
@"remove all references to the Proxy's of invalid Connections."];
|
1996-03-06 14:16:04 +00:00
|
|
|
|
return [_connection forwardForProxy: self
|
|
|
|
|
selector: aSel
|
|
|
|
|
argFrame: frame];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We need to make an effort to pass errors back from the server
|
|
|
|
|
to the client */
|
|
|
|
|
|
|
|
|
|
- (unsigned) retainCount
|
|
|
|
|
{
|
1996-03-06 14:16:04 +00:00
|
|
|
|
return _retain_count;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-11-08 19:59:46 +00:00
|
|
|
|
- autorelease
|
|
|
|
|
{
|
|
|
|
|
/* xxx Problems here if the Connection goes away? */
|
1996-03-01 15:54:57 +00:00
|
|
|
|
[[NSObject autoreleaseClass] addObject: self];
|
1994-11-08 19:59:46 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1995-03-23 03:29:35 +00:00
|
|
|
|
- (NSZone*) zone
|
|
|
|
|
{
|
|
|
|
|
return NULL; /* xxx Fix this. */
|
|
|
|
|
}
|
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1996-03-01 15:54:57 +00:00
|
|
|
|
|
1995-04-08 18:28:31 +00:00
|
|
|
|
@implementation Protocol (RemoteSelfCoding)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
/* Perhaps Protocol's should be sent bycopy? */
|
|
|
|
|
|
|
|
|
|
- classForConnectedCoder: aRmc;
|
|
|
|
|
{
|
|
|
|
|
return [Proxy class];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|