mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
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:
parent
96c253eee4
commit
0b2f72a36f
5 changed files with 63 additions and 22 deletions
|
@ -1,7 +1,8 @@
|
||||||
2004-04-25 Richard Frith-Macdonald <rfm@gnu.org>
|
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.
|
non-functional.
|
||||||
|
* Testing/nsconnectiion_server.m: Use NSProtocolChecker as a test.
|
||||||
|
|
||||||
2004-04-23 David Ayers <d.ayers@inode.at>
|
2004-04-23 David Ayers <d.ayers@inode.at>
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,11 @@
|
||||||
#define __NSProtocolChecker_h_GNUSTEP_BASE_INCLUDE
|
#define __NSProtocolChecker_h_GNUSTEP_BASE_INCLUDE
|
||||||
|
|
||||||
#include <Foundation/NSObject.h>
|
#include <Foundation/NSObject.h>
|
||||||
|
#include <Foundation/NSProxy.h>
|
||||||
|
|
||||||
@class Protocol;
|
@class Protocol;
|
||||||
|
|
||||||
@interface NSProtocolChecker : NSObject
|
@interface NSProtocolChecker : NSProxy
|
||||||
{
|
{
|
||||||
Protocol *_myProtocol;
|
Protocol *_myProtocol;
|
||||||
NSObject *_myTarget;
|
NSObject *_myTarget;
|
||||||
|
|
|
@ -61,20 +61,24 @@
|
||||||
*/
|
*/
|
||||||
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
||||||
{
|
{
|
||||||
if (GSObjCIsInstance(_myTarget)
|
if (GSObjCIsInstance(_myTarget))
|
||||||
&& ![_myProtocol descriptionForInstanceMethod: [anInvocation selector]])
|
|
||||||
{
|
{
|
||||||
[NSException raise: NSInvalidArgumentException
|
if (![_myProtocol descriptionForInstanceMethod: [anInvocation selector]])
|
||||||
format: @"<%s -%@> not declared",
|
{
|
||||||
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
[NSException raise: NSInvalidArgumentException
|
||||||
|
format: @"<%s -%@> not declared",
|
||||||
|
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (![_myProtocol descriptionForClassMethod: [anInvocation selector]])
|
else
|
||||||
{
|
{
|
||||||
[NSException raise: NSInvalidArgumentException
|
if (![_myProtocol descriptionForClassMethod: [anInvocation selector]])
|
||||||
format: @"<%s +%@> not declared",
|
{
|
||||||
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
[NSException raise: NSInvalidArgumentException
|
||||||
|
format: @"<%s +%@> not declared",
|
||||||
|
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[anInvocation invokeWithTarget: _myTarget];
|
[anInvocation invokeWithTarget: _myTarget];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,15 +98,25 @@
|
||||||
*/
|
*/
|
||||||
- (id) initWithTarget: (NSObject*)anObject protocol: (Protocol*)aProtocol
|
- (id) initWithTarget: (NSObject*)anObject protocol: (Protocol*)aProtocol
|
||||||
{
|
{
|
||||||
self = [super init];
|
_myProtocol = aProtocol;
|
||||||
if (self != nil)
|
ASSIGN(_myTarget, anObject);
|
||||||
{
|
|
||||||
_myProtocol = aProtocol;
|
|
||||||
ASSIGN(_myTarget, anObject);
|
|
||||||
}
|
|
||||||
return self;
|
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
|
* Returns the protocol object the checker uses to verify whether a
|
||||||
* given message should be forwarded to its delegate.
|
* given message should be forwarded to its delegate.
|
||||||
|
@ -112,6 +126,25 @@
|
||||||
return _myProtocol;
|
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.
|
* Returns the target of the NSProtocolChecker.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <Foundation/NSProcessInfo.h>
|
#include <Foundation/NSProcessInfo.h>
|
||||||
#include <Foundation/NSAutoreleasePool.h>
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
|
#include <Foundation/NSProtocolChecker.h>
|
||||||
|
|
||||||
#define IN_SERVER 1
|
#define IN_SERVER 1
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
@ -460,7 +461,8 @@ usage(const char *program)
|
||||||
int main(int argc, char *argv[], char **env)
|
int main(int argc, char *argv[], char **env)
|
||||||
{
|
{
|
||||||
int i, debug, timeout;
|
int i, debug, timeout;
|
||||||
id l = [[Server alloc] init];
|
id s = [[Server alloc] init];
|
||||||
|
id l;
|
||||||
id o = [[NSObject alloc] init];
|
id o = [[NSObject alloc] init];
|
||||||
NSConnection *c;
|
NSConnection *c;
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
|
@ -469,6 +471,9 @@ int main(int argc, char *argv[], char **env)
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
l = [NSProtocolChecker protocolCheckerWithTarget: s
|
||||||
|
protocol: @protocol(ServerProtocol)];
|
||||||
|
|
||||||
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
|
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
|
||||||
debug = 0;
|
debug = 0;
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
@ -512,13 +517,13 @@ int main(int argc, char *argv[], char **env)
|
||||||
[c registerName: @"test2server"];
|
[c registerName: @"test2server"];
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
addObserver: l
|
addObserver: s
|
||||||
selector: @selector(connectionBecameInvalid:)
|
selector: @selector(connectionBecameInvalid:)
|
||||||
name: NSConnectionDidDieNotification
|
name: NSConnectionDidDieNotification
|
||||||
object: c];
|
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(" list's hash is 0x%x\n", (unsigned)[l hash]);
|
||||||
printf(" object's hash is 0x%x\n", (unsigned)[o hash]);
|
printf(" object's hash is 0x%x\n", (unsigned)[o hash]);
|
||||||
printf("Running...\n");
|
printf("Running...\n");
|
||||||
|
|
|
@ -27,6 +27,7 @@ struct myarray {
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@protocol ServerProtocol
|
@protocol ServerProtocol
|
||||||
|
- (void) addObject: (id)o;
|
||||||
- (BOOL) sendBoolean: (BOOL)b;
|
- (BOOL) sendBoolean: (BOOL)b;
|
||||||
- (void) getBoolean: (BOOL*)bp;
|
- (void) getBoolean: (BOOL*)bp;
|
||||||
- (unsigned char) sendUChar: (unsigned char)uc;
|
- (unsigned char) sendUChar: (unsigned char)uc;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue