Completed rewrite with some testing.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19181 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2004-04-25 07:40:19 +00:00
parent 55e35306a2
commit 894578ed1b
5 changed files with 63 additions and 22 deletions

View file

@ -1,7 +1,8 @@
2004-04-25 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <d.ayers@inode.at>

View file

@ -25,10 +25,11 @@
#define __NSProtocolChecker_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSObject.h>
#include <Foundation/NSProxy.h>
@class Protocol;
@interface NSProtocolChecker : NSObject
@interface NSProtocolChecker : NSProxy
{
Protocol *_myProtocol;
NSObject *_myTarget;

View file

@ -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.
*/

View file

@ -8,6 +8,7 @@
#include <Foundation/NSProcessInfo.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSException.h>
#include <Foundation/NSProtocolChecker.h>
#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");

View file

@ -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;