2005-07-01 21:00:04 +00:00
|
|
|
/* Test/example program for the base library
|
|
|
|
|
|
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
|
|
|
|
2005-07-15 22:51:23 +00:00
|
|
|
Copying and distribution of this file, with or without modification,
|
|
|
|
are permitted in any medium without royalty provided the copyright
|
|
|
|
notice and this notice are preserved.
|
|
|
|
|
2005-07-01 21:00:04 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
*/
|
2003-04-04 14:15:30 +00:00
|
|
|
#define STRICT_OPENSTEP 1
|
2000-08-07 22:00:31 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
id myServer;
|
|
|
|
|
|
|
|
@interface Tester : NSObject
|
|
|
|
{
|
|
|
|
}
|
|
|
|
+ (void) connectWithPorts: (NSArray*)portArray;
|
|
|
|
+ (void) setServer: (id)anObject;
|
|
|
|
+ (void) startup;
|
|
|
|
- (int) doIt;
|
2005-02-23 16:05:09 +00:00
|
|
|
- (void) testPerform: (id)anObject;
|
2000-08-07 22:00:31 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Tester
|
|
|
|
+ (void) connectWithPorts: (NSArray*)portArray
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
NSConnection *serverConnection;
|
|
|
|
Tester *serverObject;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
serverConnection = [NSConnection
|
|
|
|
connectionWithReceivePort: [portArray objectAtIndex: 0]
|
|
|
|
sendPort: [portArray objectAtIndex: 1]];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
serverObject = [[self alloc] init];
|
2005-02-23 16:05:09 +00:00
|
|
|
[serverObject performSelectorOnMainThread: @selector(testPerform:)
|
|
|
|
withObject: @"84"
|
|
|
|
waitUntilDone: NO];
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
[(id)[serverConnection rootProxy] setServer: serverObject];
|
|
|
|
[serverObject release];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
[[NSRunLoop currentRunLoop] run];
|
|
|
|
[pool release];
|
|
|
|
[NSThread exit];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) setServer: (id)anObject
|
|
|
|
{
|
|
|
|
myServer = [anObject retain];
|
2005-02-22 11:22:44 +00:00
|
|
|
NSLog(@"Got %d", [myServer doIt]);
|
2000-08-07 22:00:31 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) startup
|
|
|
|
{
|
|
|
|
NSPort *port1;
|
|
|
|
NSPort *port2;
|
|
|
|
NSArray *portArray;
|
|
|
|
NSConnection *conn;
|
|
|
|
|
|
|
|
port1 = [NSPort port];
|
|
|
|
port2 = [NSPort port];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
conn = [[NSConnection alloc] initWithReceivePort: port1 sendPort: port2];
|
|
|
|
[conn setRootObject: self];
|
|
|
|
|
|
|
|
/* Ports switched here. */
|
|
|
|
portArray = [NSArray arrayWithObjects: port2, port1, nil];
|
|
|
|
|
|
|
|
[NSThread detachNewThreadSelector: @selector(connectWithPorts:)
|
|
|
|
toTarget: self
|
|
|
|
withObject: portArray];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) doIt
|
|
|
|
{
|
|
|
|
return 42;
|
|
|
|
}
|
2005-02-23 16:05:09 +00:00
|
|
|
|
|
|
|
- (void) testPerform: (id)anObject
|
|
|
|
{
|
|
|
|
NSLog(@"Test perform: %@", anObject);
|
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
int
|
2001-07-30 19:36:39 +00:00
|
|
|
main(int argc, char *argv[], char **env)
|
2000-08-07 22:00:31 +00:00
|
|
|
{
|
2001-07-30 19:36:39 +00:00
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
|
|
|
|
#if LIB_FOUNDATION_LIBRARY || defined(GS_PASS_ARGUMENTS)
|
|
|
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
|
|
|
#endif
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
[Tester startup];
|
|
|
|
[[NSRunLoop currentRunLoop] run];
|
|
|
|
[pool release];
|
|
|
|
return 0;
|
|
|
|
}
|