diff --git a/ChangeLog b/ChangeLog index 3d27007eb..da5137255 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ 2004-04-25 Richard Frith-Macdonald - * Source/NSProtocolChecker.m: Rewrite ... appeared almost totally + * Source/NSProtocolChecker.m: Major rewrite ... appeared almost totally non-functional. + * Testing/nsconnectiion_server.m: Use NSProtocolChecker as a test. 2004-04-23 David Ayers diff --git a/Headers/Foundation/NSProtocolChecker.h b/Headers/Foundation/NSProtocolChecker.h index cc1a9e9ea..cdb602f30 100644 --- a/Headers/Foundation/NSProtocolChecker.h +++ b/Headers/Foundation/NSProtocolChecker.h @@ -25,10 +25,11 @@ #define __NSProtocolChecker_h_GNUSTEP_BASE_INCLUDE #include +#include @class Protocol; -@interface NSProtocolChecker : NSObject +@interface NSProtocolChecker : NSProxy { Protocol *_myProtocol; NSObject *_myTarget; diff --git a/Source/NSProtocolChecker.m b/Source/NSProtocolChecker.m index 7f6177353..de215e9d5 100644 --- a/Source/NSProtocolChecker.m +++ b/Source/NSProtocolChecker.m @@ -61,20 +61,24 @@ */ - (void) forwardInvocation: (NSInvocation*)anInvocation { - if (GSObjCIsInstance(_myTarget) - && ![_myProtocol descriptionForInstanceMethod: [anInvocation selector]]) + if (GSObjCIsInstance(_myTarget)) { - [NSException raise: NSInvalidArgumentException - format: @"<%s -%@> not declared", - [_myProtocol name], NSStringFromSelector([anInvocation selector])]; + if (![_myProtocol descriptionForInstanceMethod: [anInvocation selector]]) + { + [NSException raise: NSInvalidArgumentException + format: @"<%s -%@> not declared", + [_myProtocol name], NSStringFromSelector([anInvocation selector])]; + } } - else if (![_myProtocol descriptionForClassMethod: [anInvocation selector]]) + else { - [NSException raise: NSInvalidArgumentException - format: @"<%s +%@> not declared", - [_myProtocol name], NSStringFromSelector([anInvocation selector])]; + if (![_myProtocol descriptionForClassMethod: [anInvocation selector]]) + { + [NSException raise: NSInvalidArgumentException + format: @"<%s +%@> not declared", + [_myProtocol name], NSStringFromSelector([anInvocation selector])]; + } } - [anInvocation invokeWithTarget: _myTarget]; } @@ -94,15 +98,25 @@ */ - (id) initWithTarget: (NSObject*)anObject protocol: (Protocol*)aProtocol { - self = [super init]; - if (self != nil) - { - _myProtocol = aProtocol; - ASSIGN(_myTarget, anObject); - } + _myProtocol = aProtocol; + ASSIGN(_myTarget, anObject); return self; } +- (IMP) methodForSelector: (SEL)aSelector +{ + return get_imp(GSObjCClass((id)self), aSelector); +} + +- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector +{ + if (aSelector == _cmd || [self respondsToSelector: aSelector] == YES) + { + return [_myTarget methodSignatureForSelector: aSelector]; + } + return nil; +} + /** * Returns the protocol object the checker uses to verify whether a * given message should be forwarded to its delegate. @@ -112,6 +126,25 @@ return _myProtocol; } +- (BOOL) respondsToSelector: (SEL)aSelector +{ + if (GSObjCIsInstance(_myTarget)) + { + if ([_myProtocol descriptionForInstanceMethod: aSelector]) + { + return YES; + } + } + else + { + if ([_myProtocol descriptionForClassMethod: aSelector]) + { + return YES; + } + } + return NO; +} + /** * Returns the target of the NSProtocolChecker. */ diff --git a/Testing/nsconnection_server.m b/Testing/nsconnection_server.m index 520d391e7..a786cec70 100644 --- a/Testing/nsconnection_server.m +++ b/Testing/nsconnection_server.m @@ -8,6 +8,7 @@ #include #include #include +#include #define IN_SERVER 1 #include "server.h" @@ -460,7 +461,8 @@ usage(const char *program) int main(int argc, char *argv[], char **env) { int i, debug, timeout; - id l = [[Server alloc] init]; + id s = [[Server alloc] init]; + id l; id o = [[NSObject alloc] init]; NSConnection *c; NSAutoreleasePool *arp = [NSAutoreleasePool new]; @@ -469,6 +471,9 @@ int main(int argc, char *argv[], char **env) extern char *optarg; #endif + l = [NSProtocolChecker protocolCheckerWithTarget: s + protocol: @protocol(ServerProtocol)]; + [NSProcessInfo initializeWithArguments: argv count: argc environment: env]; debug = 0; timeout = 0; @@ -512,13 +517,13 @@ int main(int argc, char *argv[], char **env) [c registerName: @"test2server"]; [[NSNotificationCenter defaultCenter] - addObserver: l + addObserver: s selector: @selector(connectionBecameInvalid:) name: NSConnectionDidDieNotification object: c]; - [c setDelegate: l]; + [c setDelegate: s]; - [l addObject: o]; + [s addObject: o]; printf(" list's hash is 0x%x\n", (unsigned)[l hash]); printf(" object's hash is 0x%x\n", (unsigned)[o hash]); printf("Running...\n"); diff --git a/Testing/server.h b/Testing/server.h index ff01426c7..2b57a418e 100644 --- a/Testing/server.h +++ b/Testing/server.h @@ -27,6 +27,7 @@ struct myarray { @end @protocol ServerProtocol +- (void) addObject: (id)o; - (BOOL) sendBoolean: (BOOL)b; - (void) getBoolean: (BOOL*)bp; - (unsigned char) sendUChar: (unsigned char)uc;