-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathnsconnection.m
111 lines (85 loc) · 2.29 KB
/
nsconnection.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Test/example program for the base library
Copyright (C) 2005 Free Software Foundation, Inc.
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.
This file is part of the GNUstep Base Library.
*/
#include <Foundation/Foundation.h>
id myServer;
@interface Tester : NSObject
{
}
+ (void) connectWithPorts: (NSArray*)portArray;
+ (void) setServer: (id)anObject;
+ (void) startup;
- (int) doIt;
- (void) testPerform: (id)anObject;
@end
@implementation Tester
+ (void) connectWithPorts: (NSArray*)portArray
{
NSAutoreleasePool *pool;
NSConnection *serverConnection;
Tester *serverObject;
pool = [[NSAutoreleasePool alloc] init];
serverConnection = [NSConnection
connectionWithReceivePort: [portArray objectAtIndex: 0]
sendPort: [portArray objectAtIndex: 1]];
serverObject = [[self alloc] init];
[serverObject performSelectorOnMainThread: @selector(testPerform:)
withObject: @"84"
waitUntilDone: NO];
[(id)[serverConnection rootProxy] setServer: serverObject];
[serverObject release];
[[NSRunLoop currentRunLoop] run];
[pool release];
[NSThread exit];
return;
}
+ (void) setServer: (id)anObject
{
myServer = [anObject retain];
NSLog(@"Got %d", [myServer doIt]);
exit(0);
}
+ (void) startup
{
NSPort *port1;
NSPort *port2;
NSArray *portArray;
NSConnection *conn;
port1 = [NSPort port];
port2 = [NSPort port];
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;
}
- (void) testPerform: (id)anObject
{
NSLog(@"Test perform: %@", anObject);
}
@end
int
main(int argc, char *argv[], char **env)
{
NSAutoreleasePool *pool;
#if LIB_FOUNDATION_LIBRARY || defined(GS_PASS_ARGUMENTS)
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
#endif
pool = [[NSAutoreleasePool alloc] init];
[NSConnection setDebug: YES];
[Tester startup];
[[NSRunLoop currentRunLoop] run];
[pool release];
return 0;
}