Attempt to make conformsToProtocol work for DO

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19155 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-04-19 19:29:15 +00:00
parent 02964e7f8c
commit 24c74732b4
3 changed files with 63 additions and 19 deletions

View file

@ -1,3 +1,11 @@
2004-04-19 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSDistantObject.m: ([-conformsToProtocol:]) rewritten with
various hacks to check locally set protocol (if present) or forward
a request to the remote system to check a protocol by name.
Works round the fact that the gnu runtime protocol code accesses the
ivars of the other protocol directly and so can't work via a proxy.
2004-04-17 01:17 Alexander Malmberg <alexander@malmberg.org>
* Headers/Foundation/NSObject.h, Source/NSObject.m,

View file

@ -54,6 +54,36 @@ typedef struct {
@defs(NSDistantObject)
} NSDO;
@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
@interface NSConnection (DistantObjectHacks)
- (void) aquireProxyForTarget: (unsigned)target;
- (NSDistantObject*) retainOrAddLocal: (NSDistantObject*)aProxy
@ -874,29 +904,21 @@ static inline BOOL class_is_kind_of (Class self, Class aClassObject)
return object_get_class (self);
}
/**
* 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.
*/
- (BOOL) conformsToProtocol: (Protocol*)aProtocol
{
#if defined(USE_FFCALL) || defined(USE_LIBFFI)
BOOL m = NO;
id inv, sig;
DO_FORWARD_INVOCATION(conformsToProtocol:, aProtocol);
return m;
#else
arglist_t args;
void *retframe;
BOOL retframe_bool (void *rframe)
if (_protocol != nil)
{
__builtin_return (rframe);
return [_protocol conformsTo: aProtocol];
}
else
{
return [(id)self _conformsToProtocolNamed: (char*)[aProtocol name]];
}
/*
* Try forwarding the message.
*/
args = __builtin_apply_args();
retframe = [self forward: _cmd : args];
return retframe_bool(retframe);
#endif
}
- (BOOL) respondsToSelector: (SEL)aSelector

View file

@ -238,9 +238,23 @@ int
con_messages (id prx)
{
id obj;
Protocol *pc = @protocol(ClientProtocol);
Protocol *ps = @protocol(ServerProtocol);
obj = [NSObject new];
printf("Conforms to protocol (remote) should be 1: %d\n",
[prx conformsToProtocol: ps]);
printf("Conforms to protocol (remote) should be 0: %d\n",
[prx conformsToProtocol: pc]);
[prx setProtocolForProxy: ps];
printf("Conforms to protocol (local) should be 1: %d\n",
[prx conformsToProtocol: ps]);
printf("Conforms to protocol (local) should be 0: %d\n",
[prx conformsToProtocol: pc]);
printf("Oneway Void message:\n");
[prx shout];
printf(" ok\n");