2001-12-17 14:31:42 +00:00
|
|
|
|
/** Implementation for GNU Objective-C version of NSDistantObject
|
1997-09-01 21:59:51 +00:00
|
|
|
|
Copyright (C) 1997 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Based on code by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
|
Created: August 1997
|
|
|
|
|
|
|
|
|
|
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
|
2006-10-21 09:49:18 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
|
|
<title>NSDistantObject class reference</title>
|
|
|
|
|
$Date$ $Revision$
|
1997-09-01 21:59:51 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "config.h"
|
2003-07-31 23:49:32 +00:00
|
|
|
|
#include "GNUstepBase/preface.h"
|
|
|
|
|
#include "GNUstepBase/DistributedObjects.h"
|
2005-03-07 11:19:34 +00:00
|
|
|
|
#include "GNUstepBase/GSObjCRuntime.h"
|
2004-08-05 00:03:30 +00:00
|
|
|
|
#include "Foundation/NSDebug.h"
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "Foundation/NSLock.h"
|
|
|
|
|
#include "Foundation/NSPort.h"
|
|
|
|
|
#include "Foundation/NSMethodSignature.h"
|
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
|
#include "Foundation/NSObjCRuntime.h"
|
|
|
|
|
#include "Foundation/NSInvocation.h"
|
2005-06-17 14:51:57 +00:00
|
|
|
|
#include <objc/Protocol.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2006-03-08 11:28:59 +00:00
|
|
|
|
|
|
|
|
|
@interface NSDistantObject(GNUstepExtensions) <GCFinalization>
|
|
|
|
|
- (Class) classForPortCoder;
|
|
|
|
|
- (const char *) selectorTypeForProxy: (SEL)selector;
|
|
|
|
|
- (id) forward: (SEL)aSel :(arglist_t)frame;
|
|
|
|
|
- (void) gcFinalize;
|
|
|
|
|
@end
|
|
|
|
|
|
2003-07-04 17:34:48 +00:00
|
|
|
|
#define DO_FORWARD_INVOCATION(_SELX, _ARG1) ({ \
|
2000-12-08 19:06:00 +00:00
|
|
|
|
sig = [self methodSignatureForSelector: @selector(_SELX)]; \
|
2004-08-05 00:03:30 +00:00
|
|
|
|
if (sig != nil) \
|
|
|
|
|
{ \
|
|
|
|
|
inv = [NSInvocation invocationWithMethodSignature: sig]; \
|
|
|
|
|
[inv setSelector: @selector(_SELX)]; \
|
|
|
|
|
[inv setTarget: self]; \
|
|
|
|
|
[inv setArgument: (void*)&_ARG1 atIndex: 2]; \
|
|
|
|
|
[self forwardInvocation: inv]; \
|
|
|
|
|
[inv getReturnValue: &m]; \
|
|
|
|
|
} \
|
|
|
|
|
else \
|
|
|
|
|
{ \
|
|
|
|
|
NSWarnLog(@"DO_FORWARD_INVOCATION failed, got nil signature for '%@'.", \
|
|
|
|
|
NSStringFromSelector(@selector(_SELX))); \
|
|
|
|
|
}})
|
2000-12-08 19:06:00 +00:00
|
|
|
|
|
|
|
|
|
|
1999-01-30 06:29:08 +00:00
|
|
|
|
static int debug_proxy = 0;
|
|
|
|
|
static Class placeHolder = 0;
|
|
|
|
|
static Class distantObjectClass = 0;
|
|
|
|
|
|
2000-07-04 09:44:05 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
@defs(NSDistantObject)
|
|
|
|
|
} NSDO;
|
|
|
|
|
|
2004-04-19 19:29:15 +00:00
|
|
|
|
@interface Object (NSConformsToProtocolNamed)
|
|
|
|
|
- (BOOL) _conformsToProtocolNamed: (char*)aName;
|
|
|
|
|
@end
|
|
|
|
|
@interface NSObject (NSConformsToProtocolNamed)
|
|
|
|
|
- (BOOL) _conformsToProtocolNamed: (char*)aName;
|
|
|
|
|
@end
|
|
|
|
|
/*
|
|
|
|
|
* Evil hack ... if a remote system wants to know if we conform
|
|
|
|
|
* to a protocol we pretend we have a local protocol with the same name.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
@defs(Protocol)
|
|
|
|
|
} Proto;
|
|
|
|
|
@implementation Object (NSConformsToProtocolNamed)
|
|
|
|
|
- (BOOL) _conformsToProtocolNamed: (char*)aName
|
|
|
|
|
{
|
|
|
|
|
Proto p;
|
|
|
|
|
p.protocol_name = (char*)aName;
|
|
|
|
|
return [self conformsTo: (Protocol*)&p];
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
@implementation NSObject (NSConformsToProtocolNamed)
|
|
|
|
|
- (BOOL) _conformsToProtocolNamed: (char*)aName
|
|
|
|
|
{
|
|
|
|
|
Proto p;
|
|
|
|
|
p.protocol_name = (char*)aName;
|
|
|
|
|
return [self conformsToProtocol: (Protocol*)&p];
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2000-09-12 06:02:01 +00:00
|
|
|
|
@interface NSConnection (DistantObjectHacks)
|
2005-11-06 13:53:40 +00:00
|
|
|
|
- (void) acquireProxyForTarget: (unsigned)target;
|
2003-10-27 13:41:01 +00:00
|
|
|
|
- (NSDistantObject*) retainOrAddLocal: (NSDistantObject*)aProxy
|
|
|
|
|
forObject: (id)anObject;
|
|
|
|
|
- (NSDistantObject*) retainOrAddProxy: (NSDistantObject*)aProxy
|
|
|
|
|
forTarget: (unsigned)aTarget;
|
2000-09-12 06:02:01 +00:00
|
|
|
|
- (void) removeProxy: (id)obj;
|
2003-10-27 13:41:01 +00:00
|
|
|
|
- (void) vendLocal: (NSDistantObject*)aProxy;
|
2000-09-12 06:02:01 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2000-07-04 09:44:05 +00:00
|
|
|
|
/* 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. */
|
2004-09-27 21:32:45 +00:00
|
|
|
|
enum proxyLocation
|
2000-07-04 09:44:05 +00:00
|
|
|
|
{
|
|
|
|
|
PROXY_LOCAL_FOR_RECEIVER = 0,
|
|
|
|
|
PROXY_LOCAL_FOR_SENDER,
|
|
|
|
|
PROXY_REMOTE_FOR_BOTH
|
2004-09-27 21:32:45 +00:00
|
|
|
|
};
|
2000-07-04 09:44:05 +00:00
|
|
|
|
|
1999-01-30 06:29:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The GSDistantObjectPlaceHolder class is simply used as a placeholder
|
|
|
|
|
* for an NSDistantObject so we can manage efficient allocation and
|
|
|
|
|
* initialisation - in most cases when we ask for an NSDistantObject
|
|
|
|
|
* instance, we will get a pre-existing one, so we don't want to go
|
|
|
|
|
* allocating the memory for a new instance unless absolutely necessary.
|
|
|
|
|
*/
|
|
|
|
|
@interface GSDistantObjectPlaceHolder
|
2000-07-02 18:57:05 +00:00
|
|
|
|
+ (id) initWithCoder: (NSCoder*)aCoder;
|
1999-01-30 06:29:08 +00:00
|
|
|
|
+ (id) initWithLocal: (id)anObject connection: (NSConnection*)aConnection;
|
|
|
|
|
+ (id) initWithTarget: (unsigned)target connection: (NSConnection*)aConnection;
|
|
|
|
|
+ (void) autorelease;
|
|
|
|
|
+ (void) release;
|
|
|
|
|
+ (id) retain;
|
2000-09-30 22:08:21 +00:00
|
|
|
|
+ (BOOL) respondsToSelector: (SEL)sel;
|
1999-01-30 06:29:08 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GSDistantObjectPlaceHolder
|
|
|
|
|
|
|
|
|
|
+ (void) autorelease
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) release
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id) retain
|
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
2005-03-07 11:19:34 +00:00
|
|
|
|
if (self == GSClassFromName("GSDistantObjectPlaceHolder"))
|
1999-01-30 06:29:08 +00:00
|
|
|
|
{
|
|
|
|
|
distantObjectClass = [NSDistantObject class];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-30 22:08:21 +00:00
|
|
|
|
+ (BOOL) respondsToSelector: (SEL)sel
|
|
|
|
|
{
|
2004-08-20 17:53:16 +00:00
|
|
|
|
return GSGetMethod(self, sel, NO, YES) != (GSMethod)0;
|
2000-09-30 22:08:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-02 18:57:05 +00:00
|
|
|
|
+ (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
2006-01-11 08:37:16 +00:00
|
|
|
|
uint8_t proxy_tag;
|
2000-07-04 09:44:05 +00:00
|
|
|
|
unsigned target;
|
|
|
|
|
id decoder_connection;
|
2002-12-10 11:30:56 +00:00
|
|
|
|
NSDistantObject *o;
|
2000-07-02 18:57:05 +00:00
|
|
|
|
|
2000-07-04 09:44:05 +00:00
|
|
|
|
/*
|
|
|
|
|
if ([aCoder isKindOfClass: [NSPortCoder class]] == NO)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"NSDistantObject objects only decode with "
|
|
|
|
|
@"NSPortCoder class"];
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
decoder_connection = [(NSPortCoder*)aCoder connection];
|
|
|
|
|
NSAssert(decoder_connection, NSInternalInconsistencyException);
|
|
|
|
|
|
|
|
|
|
/* First get the tag, so we know what values need to be decoded. */
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(typeof(proxy_tag))
|
|
|
|
|
at: &proxy_tag];
|
|
|
|
|
|
|
|
|
|
switch (proxy_tag)
|
|
|
|
|
{
|
|
|
|
|
case PROXY_LOCAL_FOR_RECEIVER:
|
|
|
|
|
/*
|
|
|
|
|
* This was a proxy on the other side of the connection, but
|
|
|
|
|
* here it's local.
|
|
|
|
|
* Lookup the target handle to ensure that it exists here.
|
|
|
|
|
* Return a retained copy of the local target object.
|
|
|
|
|
*/
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(typeof(target))
|
|
|
|
|
at: &target];
|
|
|
|
|
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
NSLog(@"Receiving a proxy for local object 0x%x "
|
2006-01-11 09:32:13 +00:00
|
|
|
|
@"connection 0x%x\n", target, (uintptr_t)decoder_connection);
|
2000-07-04 09:44:05 +00:00
|
|
|
|
|
2002-12-10 11:30:56 +00:00
|
|
|
|
o = [decoder_connection locateLocalTarget: target];
|
|
|
|
|
if (o == nil)
|
2000-07-04 09:44:05 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise: @"ProxyDecodedBadTarget"
|
|
|
|
|
format: @"No local object with given target (0x%x)",
|
|
|
|
|
target];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Local object is 0x%x (0x%x)\n",
|
2006-01-11 09:32:13 +00:00
|
|
|
|
(uintptr_t)o, (uintptr_t)o ? ((NSDO*)o)->_object : 0);
|
2000-07-04 09:44:05 +00:00
|
|
|
|
}
|
2003-10-27 13:41:01 +00:00
|
|
|
|
return RETAIN(((NSDO*)o)->_object);
|
2000-07-04 09:44:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 [NSDistantObject +proxyWithTarget:connection:]; this will
|
|
|
|
|
* return the proxy object we already created for this target, or
|
|
|
|
|
* create a new proxy object if necessary.
|
|
|
|
|
*/
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(typeof(target))
|
|
|
|
|
at: &target];
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
NSLog(@"Receiving a proxy, was local 0x%x connection 0x%x\n",
|
2006-01-11 09:32:13 +00:00
|
|
|
|
target, (uintptr_t)decoder_connection);
|
2003-10-27 13:41:01 +00:00
|
|
|
|
o = [self initWithTarget: target
|
|
|
|
|
connection: decoder_connection];
|
|
|
|
|
return o;
|
2000-07-04 09:44:05 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
* NSPortCoder is connected to, but on a *third* host.
|
|
|
|
|
* This is why I call this a "triangle connection". In addition
|
2000-07-07 10:19:31 +00:00
|
|
|
|
* to decoding the target, we decode the NSPort object that we
|
2000-07-04 09:44:05 +00:00
|
|
|
|
* will use to talk directly to this third host. We send
|
2000-07-07 10:19:31 +00:00
|
|
|
|
* [NSConnection +connectionWithReceivePort:sendPort:]; this
|
2000-07-04 09:44:05 +00:00
|
|
|
|
* will either return the connection already created for this
|
|
|
|
|
* inPort/outPort pair, or create a new connection if necessary.
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
NSConnection *proxy_connection;
|
|
|
|
|
NSPort *proxy_connection_out_port = nil;
|
|
|
|
|
unsigned intermediary;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* There is an object on the intermediary host that is keeping
|
|
|
|
|
* that hosts proxy for the original object retained, thus
|
|
|
|
|
* ensuring that the original is not released. We create a
|
|
|
|
|
* proxy for that intermediate proxy. When we release this
|
|
|
|
|
* proxy, the intermediary will be free to release it's proxy
|
|
|
|
|
* and the original can then be released. Of course, by that
|
|
|
|
|
* time we will have obtained our own proxy for the original
|
|
|
|
|
* object ...
|
|
|
|
|
*/
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(typeof(intermediary))
|
|
|
|
|
at: &intermediary];
|
|
|
|
|
AUTORELEASE([self initWithTarget: intermediary
|
|
|
|
|
connection: decoder_connection]);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now we get the target number and port for the orignal object
|
|
|
|
|
* and (if necessary) get the originating process to retain the
|
|
|
|
|
* object for us.
|
|
|
|
|
*/
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(typeof(target))
|
|
|
|
|
at: &target];
|
|
|
|
|
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id)
|
|
|
|
|
at: &proxy_connection_out_port];
|
|
|
|
|
|
|
|
|
|
NSAssert(proxy_connection_out_port, NSInternalInconsistencyException);
|
|
|
|
|
/*
|
|
|
|
|
# If there already exists a connection for talking to the
|
|
|
|
|
* out port, we use that one rather than creating a new one from
|
2005-02-22 11:22:44 +00:00
|
|
|
|
* our listening port.
|
2000-07-04 09:44:05 +00:00
|
|
|
|
*
|
|
|
|
|
* First we try for a connection from our receive port,
|
|
|
|
|
* Then we try any connection to the send port
|
|
|
|
|
* Finally we resort to creating a new connection - we don't
|
|
|
|
|
* release the newly created connection - it will get released
|
|
|
|
|
* automatically when no proxies are left on it.
|
|
|
|
|
*/
|
|
|
|
|
proxy_connection = [[decoder_connection class]
|
|
|
|
|
connectionWithReceivePort: [decoder_connection receivePort]
|
|
|
|
|
sendPort: proxy_connection_out_port];
|
|
|
|
|
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
NSLog(@"Receiving a triangle-connection proxy 0x%x "
|
2006-01-11 09:32:13 +00:00
|
|
|
|
@"connection 0x%x\n", target, (uintptr_t)proxy_connection);
|
2000-07-04 09:44:05 +00:00
|
|
|
|
|
|
|
|
|
NSAssert(proxy_connection != decoder_connection,
|
|
|
|
|
NSInternalInconsistencyException);
|
|
|
|
|
NSAssert([proxy_connection isValid],
|
|
|
|
|
NSInternalInconsistencyException);
|
|
|
|
|
|
|
|
|
|
/*
|
2003-10-27 13:41:01 +00:00
|
|
|
|
* We may not already have a proxy for the object on the
|
|
|
|
|
* remote system, we must tell the connection to make sure
|
|
|
|
|
* the other end knows we are creating one.
|
2000-07-04 09:44:05 +00:00
|
|
|
|
*/
|
2005-11-06 13:53:40 +00:00
|
|
|
|
[proxy_connection acquireProxyForTarget: target];
|
2000-07-04 09:44:05 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Finally - we get a proxy via a direct connection to the
|
|
|
|
|
* originating server. We have also created a proxy to an
|
|
|
|
|
* intermediate object - but this proxy has not been retained
|
|
|
|
|
* and will therefore go away when the current autorelease
|
|
|
|
|
* pool is destroyed.
|
|
|
|
|
*/
|
2003-10-27 13:41:01 +00:00
|
|
|
|
o = [self initWithTarget: target
|
|
|
|
|
connection: proxy_connection];
|
|
|
|
|
return o;
|
2000-07-04 09:44:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* xxx This should be something different than NSGenericException. */
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Bad proxy tag"];
|
|
|
|
|
}
|
|
|
|
|
/* Not reached. */
|
|
|
|
|
return nil;
|
2000-07-02 18:57:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-30 06:29:08 +00:00
|
|
|
|
+ (id) initWithLocal: (id)anObject connection: (NSConnection*)aConnection
|
|
|
|
|
{
|
|
|
|
|
NSDistantObject *proxy;
|
|
|
|
|
|
|
|
|
|
NSAssert([aConnection isValid], NSInternalInconsistencyException);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If there already is a local proxy for this target/connection
|
|
|
|
|
* combination, don't create a new one, just return the old one.
|
|
|
|
|
*/
|
2003-10-27 13:41:01 +00:00
|
|
|
|
proxy = [aConnection retainOrAddLocal: nil forObject: anObject];
|
|
|
|
|
if (proxy == nil)
|
1999-01-30 06:29:08 +00:00
|
|
|
|
{
|
2003-10-27 13:41:01 +00:00
|
|
|
|
proxy = (NSDistantObject*)NSAllocateObject(distantObjectClass,
|
1999-01-30 06:29:08 +00:00
|
|
|
|
0, NSDefaultMallocZone());
|
2003-10-27 13:41:01 +00:00
|
|
|
|
proxy = [proxy initWithLocal: anObject connection: aConnection];
|
|
|
|
|
}
|
|
|
|
|
return proxy;
|
1999-01-30 06:29:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id) initWithTarget: (unsigned)target connection: (NSConnection*)aConnection
|
|
|
|
|
{
|
|
|
|
|
NSDistantObject *proxy;
|
|
|
|
|
|
|
|
|
|
NSAssert([aConnection isValid], NSInternalInconsistencyException);
|
|
|
|
|
|
|
|
|
|
/*
|
2003-10-27 13:41:01 +00:00
|
|
|
|
* If there already is a local proxy for this target/connection
|
|
|
|
|
* combination, don't create a new one, just return the old one.
|
1999-01-30 06:29:08 +00:00
|
|
|
|
*/
|
2003-10-27 13:41:01 +00:00
|
|
|
|
proxy = [aConnection retainOrAddProxy: nil forTarget: target];
|
|
|
|
|
if (proxy == nil)
|
1999-01-30 06:29:08 +00:00
|
|
|
|
{
|
2003-10-27 13:41:01 +00:00
|
|
|
|
proxy = (NSDistantObject*)NSAllocateObject(distantObjectClass,
|
1999-01-30 06:29:08 +00:00
|
|
|
|
0, NSDefaultMallocZone());
|
2003-10-27 13:41:01 +00:00
|
|
|
|
proxy = [proxy initWithTarget: target connection: aConnection];
|
|
|
|
|
}
|
|
|
|
|
return proxy;
|
1999-01-30 06:29:08 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1998-06-26 20:39:50 +00:00
|
|
|
|
@interface NSDistantObject (Debug)
|
|
|
|
|
+ (void) setDebug: (int)val;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSDistantObject (Debug)
|
|
|
|
|
+ (void) setDebug: (int)val
|
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
debug_proxy = val;
|
1998-06-26 20:39:50 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Instances of this class act as proxies to remote objects using
|
|
|
|
|
* the Distributed Objects system. They also hold references to
|
|
|
|
|
* local objects which are vended to remote processes.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@implementation NSDistantObject
|
|
|
|
|
|
1999-01-30 06:29:08 +00:00
|
|
|
|
+ (void) initialize
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-30 06:29:08 +00:00
|
|
|
|
if (self == [NSDistantObject class])
|
1999-01-24 09:29:13 +00:00
|
|
|
|
{
|
2005-03-07 11:19:34 +00:00
|
|
|
|
placeHolder = GSClassFromName("GSDistantObjectPlaceHolder");
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
1999-01-30 06:29:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
|
|
|
|
{
|
|
|
|
|
return placeHolder;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Creates and returns a proxy associated with aConnection
|
|
|
|
|
* which will hold a reference to the local object anObject.
|
|
|
|
|
*/
|
1999-01-30 06:29:08 +00:00
|
|
|
|
+ (NSDistantObject*) proxyWithLocal: (id)anObject
|
|
|
|
|
connection: (NSConnection*)aConnection
|
|
|
|
|
{
|
2000-07-05 12:23:00 +00:00
|
|
|
|
return AUTORELEASE([placeHolder initWithLocal: anObject
|
|
|
|
|
connection: aConnection]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Creates and returns a proxy associated with aConnection
|
|
|
|
|
* which will provide a link to a remote object whose reference
|
|
|
|
|
* locally is anObject.
|
|
|
|
|
*/
|
1999-01-29 21:29:32 +00:00
|
|
|
|
+ (NSDistantObject*) proxyWithTarget: (unsigned)anObject
|
1997-09-01 21:59:51 +00:00
|
|
|
|
connection: (NSConnection*)aConnection
|
|
|
|
|
{
|
2000-07-05 12:23:00 +00:00
|
|
|
|
return AUTORELEASE([placeHolder initWithTarget: anObject
|
|
|
|
|
connection: aConnection]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the [NSConnection] instance with which the receiver is
|
|
|
|
|
* associated.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (NSConnection*) connectionForProxy
|
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return _connection;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
1999-02-11 08:10:24 +00:00
|
|
|
|
[self gcFinalize];
|
1999-01-24 09:29:13 +00:00
|
|
|
|
[super dealloc];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aRmc
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-30 06:29:08 +00:00
|
|
|
|
unsigned proxy_target;
|
2006-01-11 08:37:16 +00:00
|
|
|
|
uint8_t proxy_tag;
|
1999-01-24 09:29:13 +00:00
|
|
|
|
NSConnection *encoder_connection;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2000-07-02 18:57:05 +00:00
|
|
|
|
/*
|
|
|
|
|
if ([aRmc isKindOfClass: [NSPortCoder class]] == NO)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"NSDistantObject objects only "
|
|
|
|
|
@"encode with NSPortCoder class"];
|
|
|
|
|
}
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
encoder_connection = [(NSPortCoder*)aRmc connection];
|
|
|
|
|
NSAssert(encoder_connection, NSInternalInconsistencyException);
|
|
|
|
|
if (![encoder_connection isValid])
|
|
|
|
|
[NSException
|
1997-09-01 21:59:51 +00:00
|
|
|
|
raise: NSGenericException
|
|
|
|
|
format: @"Trying to encode to an invalid Connection.\n"
|
|
|
|
|
@"You should request NSConnectionDidDieNotification's and\n"
|
|
|
|
|
@"release all references to the proxy's of invalid Connections."];
|
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
proxy_target = _handle;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (encoder_connection == _connection)
|
|
|
|
|
{
|
|
|
|
|
if (_object)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* This proxy is a local to us, remote to other side.
|
|
|
|
|
*/
|
|
|
|
|
proxy_tag = PROXY_LOCAL_FOR_SENDER;
|
|
|
|
|
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
NSLog(@"Sending a proxy, will be remote 0x%x connection 0x%x\n",
|
2006-01-11 09:32:13 +00:00
|
|
|
|
proxy_target, (uintptr_t)_connection);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2000-06-30 11:59:59 +00:00
|
|
|
|
[aRmc encodeValueOfObjCType: @encode(typeof(proxy_tag))
|
|
|
|
|
at: &proxy_tag];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2000-06-30 11:59:59 +00:00
|
|
|
|
[aRmc encodeValueOfObjCType: @encode(typeof(proxy_target))
|
|
|
|
|
at: &proxy_target];
|
2003-10-27 13:41:01 +00:00
|
|
|
|
/*
|
|
|
|
|
* Tell connection this object is being vended.
|
|
|
|
|
*/
|
|
|
|
|
[_connection vendLocal: self];
|
1997-10-01 18:53:50 +00:00
|
|
|
|
}
|
1999-01-24 09:29:13 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* This proxy is a local object on the other side.
|
|
|
|
|
*/
|
|
|
|
|
proxy_tag = PROXY_LOCAL_FOR_RECEIVER;
|
|
|
|
|
|
|
|
|
|
if (debug_proxy)
|
|
|
|
|
NSLog(@"Sending a proxy, will be local 0x%x connection 0x%x\n",
|
2006-01-11 09:32:13 +00:00
|
|
|
|
proxy_target, (uintptr_t)_connection);
|
1997-10-01 18:53:50 +00:00
|
|
|
|
|
2000-06-30 11:59:59 +00:00
|
|
|
|
[aRmc encodeValueOfObjCType: @encode(typeof(proxy_tag))
|
|
|
|
|
at: &proxy_tag];
|
1997-10-01 18:53:50 +00:00
|
|
|
|
|
2000-06-30 11:59:59 +00:00
|
|
|
|
[aRmc encodeValueOfObjCType: @encode(typeof(proxy_target))
|
|
|
|
|
at: &proxy_target];
|
1997-10-01 18:53:50 +00:00
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
1999-01-24 09:29:13 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* This proxy will still be remote on the other side
|
|
|
|
|
*/
|
1999-02-11 08:10:24 +00:00
|
|
|
|
NSPort *proxy_connection_out_port = [_connection sendPort];
|
|
|
|
|
NSDistantObject *localProxy;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-02-11 08:10:24 +00:00
|
|
|
|
NSAssert(proxy_connection_out_port,
|
|
|
|
|
NSInternalInconsistencyException);
|
|
|
|
|
NSAssert([proxy_connection_out_port isValid],
|
|
|
|
|
NSInternalInconsistencyException);
|
|
|
|
|
NSAssert(proxy_connection_out_port != [encoder_connection sendPort],
|
|
|
|
|
NSInternalInconsistencyException);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
proxy_tag = PROXY_REMOTE_FOR_BOTH;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-02-11 08:10:24 +00:00
|
|
|
|
/*
|
2003-10-27 13:41:01 +00:00
|
|
|
|
* Get a proxy to refer to self - we send this to the other
|
|
|
|
|
* side so we will be retained until the other side has
|
|
|
|
|
* obtained a proxy to the original object via a connection
|
|
|
|
|
* to the original vendor.
|
1999-02-11 08:10:24 +00:00
|
|
|
|
*/
|
|
|
|
|
localProxy = [NSDistantObject proxyWithLocal: self
|
|
|
|
|
connection: encoder_connection];
|
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (debug_proxy)
|
|
|
|
|
NSLog(@"Sending triangle-connection proxy 0x%x "
|
1999-02-11 08:10:24 +00:00
|
|
|
|
@"proxy-conn 0x%x to-proxy 0x%x to-conn 0x%x\n",
|
2006-01-11 09:32:13 +00:00
|
|
|
|
localProxy->_handle, (uintptr_t)localProxy->_connection,
|
|
|
|
|
proxy_target, (uintptr_t)_connection);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
/*
|
2003-10-27 13:41:01 +00:00
|
|
|
|
* It's remote here, so we need to tell other side where to form
|
|
|
|
|
* triangle connection to
|
1999-01-24 09:29:13 +00:00
|
|
|
|
*/
|
2000-06-30 11:59:59 +00:00
|
|
|
|
[aRmc encodeValueOfObjCType: @encode(typeof(proxy_tag))
|
|
|
|
|
at: &proxy_tag];
|
1999-01-24 09:29:13 +00:00
|
|
|
|
|
2000-06-30 11:59:59 +00:00
|
|
|
|
[aRmc encodeValueOfObjCType: @encode(typeof(localProxy->_handle))
|
|
|
|
|
at: &localProxy->_handle];
|
1999-02-11 08:10:24 +00:00
|
|
|
|
|
2000-06-30 11:59:59 +00:00
|
|
|
|
[aRmc encodeValueOfObjCType: @encode(typeof(proxy_target))
|
|
|
|
|
at: &proxy_target];
|
1999-01-24 09:29:13 +00:00
|
|
|
|
|
2000-06-30 11:59:59 +00:00
|
|
|
|
[aRmc encodeBycopyObject: proxy_connection_out_port];
|
2003-10-27 13:41:01 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tell connection that localProxy is being vended.
|
|
|
|
|
*/
|
|
|
|
|
[encoder_connection vendLocal: localProxy];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This method needs to be implemented to actually do anything.
|
|
|
|
|
*/
|
|
|
|
|
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
if (debug_proxy)
|
|
|
|
|
NSLog(@"NSDistantObject forwardInvocation: %@\n", anInvocation);
|
|
|
|
|
|
|
|
|
|
if (![_connection isValid])
|
|
|
|
|
[NSException
|
|
|
|
|
raise: NSGenericException
|
|
|
|
|
format: @"Trying to send message to an invalid Proxy.\n"
|
|
|
|
|
@"You should request NSConnectionDidDieNotification's and\n"
|
|
|
|
|
@"release all references to the proxy's of invalid Connections."];
|
|
|
|
|
|
|
|
|
|
[_connection forwardInvocation: anInvocation forProxy: self];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-30 06:29:08 +00:00
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2003-10-27 13:41:01 +00:00
|
|
|
|
DESTROY(self);
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"NSDistantObject decodes from placeholder"];
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Initialises and returns a proxy associated with aConnection
|
|
|
|
|
* which will hold a reference to the local object anObject.
|
|
|
|
|
*/
|
1999-01-24 09:29:13 +00:00
|
|
|
|
- (id) initWithLocal: (id)anObject connection: (NSConnection*)aConnection
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
NSAssert([aConnection isValid], NSInternalInconsistencyException);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2003-10-21 17:05:36 +00:00
|
|
|
|
_object = RETAIN(anObject);
|
2003-10-27 13:41:01 +00:00
|
|
|
|
_handle = 0;
|
2000-07-05 12:23:00 +00:00
|
|
|
|
_connection = RETAIN(aConnection);
|
2003-10-27 13:41:01 +00:00
|
|
|
|
self = [_connection retainOrAddLocal: self forObject: anObject];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (debug_proxy)
|
1999-02-11 08:10:24 +00:00
|
|
|
|
NSLog(@"Created new local=0x%x object 0x%x target 0x%x connection 0x%x\n",
|
2006-01-11 09:32:13 +00:00
|
|
|
|
(uintptr_t)self, (uintptr_t)_object, _handle, (uintptr_t)_connection);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Initialises and returns a proxy associated with aConnection
|
|
|
|
|
* which will provide a link to a remote object whose reference
|
|
|
|
|
* locally is target.
|
|
|
|
|
*/
|
1999-01-29 21:29:32 +00:00
|
|
|
|
- (id) initWithTarget: (unsigned)target connection: (NSConnection*)aConnection
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
NSAssert([aConnection isValid], NSInternalInconsistencyException);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
_object = nil;
|
|
|
|
|
_handle = target;
|
2000-07-05 12:23:00 +00:00
|
|
|
|
_connection = RETAIN(aConnection);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
/*
|
2003-10-27 13:41:01 +00:00
|
|
|
|
* We register this object with the connection using it.
|
|
|
|
|
* Conceivably this could result in self being changed.
|
1999-01-24 09:29:13 +00:00
|
|
|
|
*/
|
2003-10-27 13:41:01 +00:00
|
|
|
|
self = [_connection retainOrAddProxy: self forTarget: target];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (debug_proxy)
|
1999-02-11 08:10:24 +00:00
|
|
|
|
NSLog(@"Created new proxy=0x%x target 0x%x connection 0x%x\n",
|
2006-01-11 09:32:13 +00:00
|
|
|
|
(uintptr_t)self, _handle, (uintptr_t)_connection);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 16:50:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* <p>Returns the method signature describing the arguments and return
|
|
|
|
|
* types of the method in the object referred to by the receiver
|
2005-11-06 13:53:40 +00:00
|
|
|
|
* which implements the aSelector message.
|
2003-07-04 16:50:30 +00:00
|
|
|
|
* </p>
|
|
|
|
|
* <p>This method may need to refer to another process (causing relatively
|
2005-11-06 13:53:40 +00:00
|
|
|
|
* slow network communication) and approximately double the time taken for
|
2003-07-04 16:50:30 +00:00
|
|
|
|
* sending a distributed objects message, so you are advised to use the
|
|
|
|
|
* -setProtocolForProxy: method to avoid this occurring.
|
|
|
|
|
* </p>
|
|
|
|
|
*/
|
1998-09-26 05:07:02 +00:00
|
|
|
|
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
|
|
|
|
|
{
|
2000-05-09 10:16:29 +00:00
|
|
|
|
if (_object != nil)
|
1999-01-24 09:29:13 +00:00
|
|
|
|
{
|
2000-05-21 05:58:17 +00:00
|
|
|
|
return [_object methodSignatureForSelector: aSelector];
|
1998-09-26 05:07:02 +00:00
|
|
|
|
}
|
1999-01-24 09:29:13 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2001-08-10 06:39:29 +00:00
|
|
|
|
/*
|
|
|
|
|
* Evil hack to prevent recursion - if we are asking a remote
|
|
|
|
|
* object for a method signature, we can't ask it for the
|
|
|
|
|
* signature of methodSignatureForSelector:, so we hack in
|
|
|
|
|
* the signature required manually :-(
|
|
|
|
|
*/
|
|
|
|
|
if (sel_eq(aSelector, _cmd))
|
|
|
|
|
{
|
|
|
|
|
static NSMethodSignature *sig = nil;
|
|
|
|
|
|
|
|
|
|
if (sig == nil)
|
|
|
|
|
{
|
|
|
|
|
sig = [NSMethodSignature signatureWithObjCTypes: "@@::"];
|
|
|
|
|
RETAIN(sig);
|
|
|
|
|
}
|
|
|
|
|
return sig;
|
|
|
|
|
}
|
2003-07-04 06:32:14 +00:00
|
|
|
|
/*
|
2003-10-21 17:05:36 +00:00
|
|
|
|
* Simlarly, when we fetch a method signature from the remote end,
|
2003-07-04 06:32:14 +00:00
|
|
|
|
* we get a proxy, and when we build a local signature we need to
|
|
|
|
|
* ask the proxy for its types ... and must avoid recursion again.
|
|
|
|
|
*/
|
|
|
|
|
if (sel_eq(aSelector, @selector(methodType)))
|
|
|
|
|
{
|
|
|
|
|
static NSMethodSignature *sig = nil;
|
|
|
|
|
|
|
|
|
|
if (sig == nil)
|
|
|
|
|
{
|
2003-07-04 10:52:56 +00:00
|
|
|
|
sig = [NSMethodSignature signatureWithObjCTypes: "r*@:"];
|
2003-07-04 06:32:14 +00:00
|
|
|
|
RETAIN(sig);
|
|
|
|
|
}
|
|
|
|
|
return sig;
|
|
|
|
|
}
|
2001-08-10 06:39:29 +00:00
|
|
|
|
|
2000-05-09 10:16:29 +00:00
|
|
|
|
if (_protocol != nil)
|
1999-01-24 09:29:13 +00:00
|
|
|
|
{
|
|
|
|
|
const char *types = 0;
|
1998-09-29 11:32:53 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
struct objc_method_description* mth;
|
1998-09-29 11:32:53 +00:00
|
|
|
|
|
2003-08-15 13:20:50 +00:00
|
|
|
|
/* Older gcc versions may not initialise Protocol objects properly
|
|
|
|
|
* so we have an evil hack which checks for a known bad value of
|
|
|
|
|
* the class pointer, and uses an internal function
|
|
|
|
|
* (implemented in NSObject.m) to examine the protocol contents
|
|
|
|
|
* without sending any ObjectiveC message to it.
|
|
|
|
|
*/
|
2006-01-10 10:29:11 +00:00
|
|
|
|
if ((uintptr_t)GSObjCClass(_protocol) == 0x2)
|
2003-08-15 13:20:50 +00:00
|
|
|
|
{
|
|
|
|
|
extern struct objc_method_description*
|
|
|
|
|
GSDescriptionForInstanceMethod();
|
|
|
|
|
mth = GSDescriptionForInstanceMethod(_protocol, aSelector);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mth = [_protocol descriptionForInstanceMethod: aSelector];
|
|
|
|
|
}
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (mth == 0)
|
|
|
|
|
{
|
2006-01-10 10:29:11 +00:00
|
|
|
|
if ((uintptr_t)GSObjCClass(_protocol) == 0x2)
|
2003-08-15 13:20:50 +00:00
|
|
|
|
{
|
|
|
|
|
extern struct objc_method_description*
|
|
|
|
|
GSDescriptionForClassMethod();
|
|
|
|
|
mth = GSDescriptionForClassMethod(_protocol, aSelector);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mth = [_protocol descriptionForClassMethod: aSelector];
|
|
|
|
|
}
|
1998-09-29 11:32:53 +00:00
|
|
|
|
}
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (mth != 0)
|
|
|
|
|
{
|
|
|
|
|
types = mth->types;
|
1998-09-29 11:32:53 +00:00
|
|
|
|
}
|
2004-08-05 00:03:30 +00:00
|
|
|
|
if (types)
|
|
|
|
|
return [NSMethodSignature signatureWithObjCTypes: types];
|
1998-09-29 11:32:53 +00:00
|
|
|
|
}
|
2004-08-05 00:03:30 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
{
|
2003-07-04 17:34:48 +00:00
|
|
|
|
id m = nil;
|
2004-01-18 12:19:43 +00:00
|
|
|
|
#if defined(USE_FFCALL) || defined(USE_LIBFFI)
|
2001-08-10 06:39:29 +00:00
|
|
|
|
id inv;
|
|
|
|
|
id sig;
|
|
|
|
|
|
|
|
|
|
DO_FORWARD_INVOCATION(methodSignatureForSelector:, aSelector);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#else
|
1999-01-24 09:29:13 +00:00
|
|
|
|
arglist_t args;
|
2000-05-21 05:58:17 +00:00
|
|
|
|
void *retframe;
|
|
|
|
|
|
|
|
|
|
id retframe_id (void *rframe)
|
|
|
|
|
{
|
|
|
|
|
__builtin_return (rframe);
|
|
|
|
|
}
|
1998-09-29 11:32:53 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
/*
|
|
|
|
|
* No protocol - so try forwarding the message.
|
|
|
|
|
*/
|
|
|
|
|
args = __builtin_apply_args();
|
2000-05-21 05:58:17 +00:00
|
|
|
|
retframe = [self forward: _cmd : args];
|
|
|
|
|
m = retframe_id(retframe);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#endif
|
2003-07-04 14:21:05 +00:00
|
|
|
|
if ([m isProxy] == YES)
|
|
|
|
|
{
|
|
|
|
|
const char *types = [m methodType];
|
|
|
|
|
|
|
|
|
|
m = [NSMethodSignature signatureWithObjCTypes: types];
|
|
|
|
|
}
|
|
|
|
|
return m;
|
1998-09-29 11:32:53 +00:00
|
|
|
|
}
|
1998-09-26 05:07:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 16:50:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* <p>A key method for Distributed Objects performance. This sets the
|
|
|
|
|
* a protocol that the distant object referred to by the proxy should
|
|
|
|
|
* conform to. When messages in that protocol are sent to the proxy,
|
|
|
|
|
* the proxy knows that it does not need to ask the remote object for
|
2005-11-06 13:53:40 +00:00
|
|
|
|
* the method signature in order to send the message to it, but can
|
2003-07-04 16:50:30 +00:00
|
|
|
|
* send the message straight away based on the local method signature
|
|
|
|
|
* information obtained from the protocol.
|
|
|
|
|
* </p>
|
|
|
|
|
* <example>
|
|
|
|
|
* if ([anObj isProxy] == YES)
|
|
|
|
|
* {
|
|
|
|
|
* [anObj setProtocolForProxy: @protocol(MyProtocol)];
|
|
|
|
|
* }
|
|
|
|
|
* </example>
|
|
|
|
|
* <p>It is <em>highly recommended</em> that you make use of this facility,
|
|
|
|
|
* but you must beware that versions of the compiler prior to 3.3 suffer a
|
|
|
|
|
* serious bug with respect to the @protocol directive. If the protocol
|
|
|
|
|
* referred to is not declared and implemented in the file where @protocol
|
|
|
|
|
* is used to refer to the protocol by name, a runtime error will occur
|
|
|
|
|
* when you try to use it.
|
|
|
|
|
* </p>
|
2003-07-04 20:22:27 +00:00
|
|
|
|
* <p>Beware, if you don't use this method to set the protocol, the system
|
|
|
|
|
* might well ask the remote process for method signature information, and
|
|
|
|
|
* the remote process might get it <em>wrong</em>. This is because the
|
|
|
|
|
* class of the remote object needs to have been declared to conform to the
|
|
|
|
|
* protocol in order for it to know about any protocol qualifiers (the
|
|
|
|
|
* keywords <code>bycopy, byref, in, out, inout,</code> and
|
|
|
|
|
* <code>oneway</code>). If the author of the server process forgot to do
|
|
|
|
|
* this, the type information returned from that process may not be what
|
|
|
|
|
* you are expecting.
|
|
|
|
|
* </p>
|
|
|
|
|
* The class of the server object should be declared like this ...
|
|
|
|
|
* <example>
|
|
|
|
|
* @interface MyServerClass : NSObject <MyProtocol>
|
|
|
|
|
* ...
|
|
|
|
|
* @end
|
|
|
|
|
* </example>
|
2003-07-04 16:50:30 +00:00
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) setProtocolForProxy: (Protocol*)aProtocol
|
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
_protocol = aProtocol;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2004-06-22 22:40:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* Adds some backwards-compatibility and other methods.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@implementation NSDistantObject(GNUstepExtensions)
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Used by the garbage collection system to tidy up when a proxy is destroyed.
|
|
|
|
|
*/
|
1999-02-11 08:10:24 +00:00
|
|
|
|
- (void) gcFinalize
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-02-11 08:10:24 +00:00
|
|
|
|
if (_connection)
|
|
|
|
|
{
|
|
|
|
|
if (debug_proxy > 3)
|
|
|
|
|
NSLog(@"retain count for connection (0x%x) is now %u\n",
|
2006-01-11 09:32:13 +00:00
|
|
|
|
(uintptr_t)_connection, [_connection retainCount]);
|
1999-02-11 08:10:24 +00:00
|
|
|
|
/*
|
2003-10-21 17:05:36 +00:00
|
|
|
|
* A proxy for local object retains its target - so we release it.
|
1999-02-11 08:10:24 +00:00
|
|
|
|
* For a local object the connection also retains this proxy, so we
|
|
|
|
|
* can't be deallocated unless we are already removed from the
|
2003-10-21 17:05:36 +00:00
|
|
|
|
* connection, and there is no need to remove self from connection.
|
1999-02-11 08:10:24 +00:00
|
|
|
|
*
|
2003-10-21 17:05:36 +00:00
|
|
|
|
* A proxy has a nil local object, and retains it's connection so
|
|
|
|
|
* that the connection will continue to exist as long as there is
|
|
|
|
|
* a something to use it.
|
1999-02-11 08:10:24 +00:00
|
|
|
|
* So we release our reference to the connection here just as soon
|
|
|
|
|
* as we have removed ourself from the connection.
|
|
|
|
|
*/
|
|
|
|
|
if (_object == nil)
|
|
|
|
|
[_connection removeProxy: self];
|
2003-10-21 17:05:36 +00:00
|
|
|
|
else
|
|
|
|
|
DESTROY(_object);
|
2000-07-05 12:23:00 +00:00
|
|
|
|
RELEASE(_connection);
|
1999-02-11 08:10:24 +00:00
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline BOOL class_is_kind_of (Class self, Class aClassObject)
|
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
Class class;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2003-08-24 23:07:41 +00:00
|
|
|
|
for (class = self; class!=Nil; class = GSObjCSuper(class))
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (class==aClassObject)
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* For backward compatibility ... do not use this method.<br />
|
|
|
|
|
* Returns the type information ... the modern way of doing this is
|
|
|
|
|
* with the -methodSignatureForSelector: method.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (const char *) selectorTypeForProxy: (SEL)selector
|
|
|
|
|
{
|
2001-04-24 03:40:04 +00:00
|
|
|
|
#if NeXT_RUNTIME
|
2001-05-31 22:39:16 +00:00
|
|
|
|
/* This isn't what we want, unless the remote machine has
|
|
|
|
|
the same architecture as us. */
|
2001-07-15 03:51:11 +00:00
|
|
|
|
const char *t;
|
|
|
|
|
t = [_connection typeForSelector: selector remoteTarget: _handle];
|
2001-05-31 22:39:16 +00:00
|
|
|
|
return t;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
#else /* NeXT_runtime */
|
|
|
|
|
return sel_get_type (selector);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* For backward compatibility ... do not use this method.<br />
|
|
|
|
|
* Handle old fashioned forwarding to the proxy.
|
|
|
|
|
*/
|
1999-02-11 08:10:24 +00:00
|
|
|
|
- (id) forward: (SEL)aSel :(arglist_t)frame
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (debug_proxy)
|
2003-08-24 23:07:41 +00:00
|
|
|
|
NSLog(@"NSDistantObject forwarding %s\n", GSNameFromSelector(aSel));
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if (![_connection isValid])
|
|
|
|
|
[NSException
|
1997-09-01 21:59:51 +00:00
|
|
|
|
raise: NSGenericException
|
|
|
|
|
format: @"Trying to send message to an invalid Proxy.\n"
|
|
|
|
|
@"You should request NSConnectionDidDieNotification's and\n"
|
|
|
|
|
@"release all references to the proxy's of invalid Connections."];
|
|
|
|
|
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return [_connection forwardForProxy: self
|
|
|
|
|
selector: aSel
|
|
|
|
|
argFrame: frame];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-02-11 08:10:24 +00:00
|
|
|
|
- (Class) classForCoder
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return object_get_class (self);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 20:22:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the class of the receiver.
|
|
|
|
|
*/
|
1999-02-11 08:10:24 +00:00
|
|
|
|
- (Class) classForPortCoder
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return object_get_class (self);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-19 19:29:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* If a protocol has been set for the receiver, this method tests to
|
|
|
|
|
* see that the set protocol conforms to aProtocol. Otherwise, the
|
|
|
|
|
* remote object is checked to see whether it conforms to aProtocol.
|
|
|
|
|
*/
|
2000-10-24 11:58:25 +00:00
|
|
|
|
- (BOOL) conformsToProtocol: (Protocol*)aProtocol
|
|
|
|
|
{
|
2004-04-19 19:29:15 +00:00
|
|
|
|
if (_protocol != nil)
|
2000-10-24 11:58:25 +00:00
|
|
|
|
{
|
2004-04-19 19:29:15 +00:00
|
|
|
|
return [_protocol conformsTo: aProtocol];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return [(id)self _conformsToProtocolNamed: (char*)[aProtocol name]];
|
2000-10-24 11:58:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) respondsToSelector: (SEL)aSelector
|
|
|
|
|
{
|
2004-01-18 12:19:43 +00:00
|
|
|
|
#if defined(USE_FFCALL) || defined(USE_LIBFFI)
|
2003-07-04 17:34:48 +00:00
|
|
|
|
BOOL m = NO;
|
2000-12-08 19:06:00 +00:00
|
|
|
|
id inv, sig;
|
2000-12-21 20:54:02 +00:00
|
|
|
|
DO_FORWARD_INVOCATION(respondsToSelector:, aSelector);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
return m;
|
|
|
|
|
#else
|
2000-10-24 11:58:25 +00:00
|
|
|
|
arglist_t args;
|
|
|
|
|
void *retframe;
|
|
|
|
|
|
|
|
|
|
BOOL retframe_bool (void *rframe)
|
|
|
|
|
{
|
|
|
|
|
__builtin_return (rframe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try forwarding the message.
|
|
|
|
|
*/
|
|
|
|
|
args = __builtin_apply_args();
|
|
|
|
|
retframe = [self forward: _cmd : args];
|
|
|
|
|
return retframe_bool(retframe);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#endif
|
2000-10-24 11:58:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-02-11 08:10:24 +00:00
|
|
|
|
- (id) replacementObjectForCoder: (NSCoder*)aCoder
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-02-11 08:10:24 +00:00
|
|
|
|
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSObject (NSDistantObject)
|
|
|
|
|
- (const char *) selectorTypeForProxy: (SEL)selector
|
|
|
|
|
{
|
|
|
|
|
#if NeXT_runtime
|
|
|
|
|
{
|
2003-06-25 10:26:29 +00:00
|
|
|
|
Method m = GSGetInstanceMethod(isa, selector);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
if (m)
|
|
|
|
|
return m->method_types;
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
return sel_get_type (selector);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation Protocol (DistributedObjectsCoding)
|
|
|
|
|
|
1997-09-29 14:39:53 +00:00
|
|
|
|
- (Class) classForPortCoder
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
return [self class];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-02 18:57:05 +00:00
|
|
|
|
- (id) replacementObjectForPortCoder: (NSPortCoder*)aRmc;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1999-01-24 09:29:13 +00:00
|
|
|
|
if ([aRmc isBycopy])
|
|
|
|
|
return self;
|
|
|
|
|
else
|
|
|
|
|
return [NSDistantObject proxyWithLocal: self
|
|
|
|
|
connection: [aRmc connection]];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|