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.
|
|
|
|
*/
|
2000-08-07 22:00:31 +00:00
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSConnection.h>
|
2009-06-19 15:51:11 +00:00
|
|
|
#include <Foundation/NSPort.h>
|
|
|
|
#include <Foundation/NSPortNameServer.h>
|
2000-08-07 22:00:31 +00:00
|
|
|
#include <Foundation/NSDistantObject.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSNotification.h>
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
#include <Foundation/NSRunLoop.h>
|
|
|
|
#include <Foundation/NSProcessInfo.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
2001-09-20 10:22:09 +00:00
|
|
|
#include <Foundation/NSException.h>
|
2004-04-25 07:40:19 +00:00
|
|
|
#include <Foundation/NSProtocolChecker.h>
|
2003-07-04 09:33:53 +00:00
|
|
|
|
|
|
|
#define IN_SERVER 1
|
2000-08-07 22:00:31 +00:00
|
|
|
#include "server.h"
|
|
|
|
|
2000-09-22 04:20:52 +00:00
|
|
|
#include "wgetopt.h"
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
@implementation Server
|
|
|
|
|
|
|
|
- (NSData*) authenticationDataForComponents: (NSMutableArray*)components
|
|
|
|
{
|
|
|
|
unsigned count = [components count];
|
|
|
|
|
|
|
|
while (count-- > 0)
|
|
|
|
{
|
|
|
|
id obj = [components objectAtIndex: count];
|
|
|
|
|
|
|
|
if ([obj isKindOfClass: [NSData class]] == YES)
|
|
|
|
{
|
|
|
|
NSMutableData *d = [obj mutableCopy];
|
|
|
|
unsigned l = [d length];
|
|
|
|
char *p = (char*)[d mutableBytes];
|
|
|
|
|
|
|
|
while (l-- > 0)
|
|
|
|
p[l] ^= 42;
|
|
|
|
[components replaceObjectAtIndex: count withObject: d];
|
|
|
|
RELEASE(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [NSData data];
|
|
|
|
}
|
|
|
|
|
|
|
|
- init
|
|
|
|
{
|
|
|
|
the_array = [[NSMutableArray alloc] init];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned) count
|
|
|
|
{
|
|
|
|
return [the_array count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addObject: o
|
|
|
|
{
|
|
|
|
[the_array addObject:o];
|
|
|
|
}
|
|
|
|
|
|
|
|
- objectAt: (unsigned)i
|
|
|
|
{
|
|
|
|
if (i < [the_array count])
|
|
|
|
return [the_array objectAtIndex: i];
|
|
|
|
else
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- echoObject: obj
|
|
|
|
{
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2001-09-20 10:22:09 +00:00
|
|
|
- (int) exceptionTest1
|
|
|
|
{
|
|
|
|
[NSException raise: @"Test1" format: @"exception1"];
|
|
|
|
return 111;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) exceptionTest2
|
|
|
|
{
|
|
|
|
[NSException raise: @"Test2" format: @"exception2"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) exceptionTest3
|
|
|
|
{
|
|
|
|
[NSException raise: @"Test3" format: @"exception3"];
|
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- print: (const char *)msg
|
|
|
|
{
|
|
|
|
printf(">>%s<<\n", msg);
|
|
|
|
fflush(stdout);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) sendBoolean: (BOOL)b
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), (int)b, (int)(!b));
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return !b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This causes problems, because the runtime encodes this as "*", a string! */
|
|
|
|
- (void) getBoolean: (BOOL*)bp
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
BOOL rbp = !(*bp);
|
2005-02-22 11:22:44 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
2000-12-08 19:06:00 +00:00
|
|
|
(int)*bp, (int)rbp);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
2000-12-08 19:06:00 +00:00
|
|
|
*bp = rbp;
|
2000-08-07 22:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned char) sendUChar: (unsigned char)num
|
|
|
|
{
|
|
|
|
unsigned char rnum = num + ADD_CONST;
|
2005-02-22 11:22:44 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
2000-12-08 19:06:00 +00:00
|
|
|
(int)num, (int)rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return rnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This causes problems, because the runtime encodes this as "*", a string! */
|
|
|
|
- (void) getUChar: (unsigned char *)num
|
|
|
|
{
|
|
|
|
unsigned char rnum = *num + ADD_CONST;
|
2005-02-22 11:22:44 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
2000-12-08 19:06:00 +00:00
|
|
|
(int)(*num), (int)rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
*num = rnum;
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (char) sendChar: (char)num
|
|
|
|
{
|
|
|
|
char rnum = num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
2000-12-08 19:06:00 +00:00
|
|
|
(int)num, (int)rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return rnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getChar: (char *)num
|
|
|
|
{
|
|
|
|
char rnum = *num + ADD_CONST;
|
2005-02-22 11:22:44 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
2000-12-08 19:06:00 +00:00
|
|
|
(int)(*num), (int)rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
*num = rnum;
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (short) sendShort: (short)num
|
|
|
|
{
|
|
|
|
short rnum = num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %hd, returning %hd\n", GSNameFromSelector(_cmd),
|
2000-12-08 19:06:00 +00:00
|
|
|
num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return rnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getShort: (short *)num
|
|
|
|
{
|
|
|
|
short rnum = *num + ADD_CONST;
|
2005-02-22 11:22:44 +00:00
|
|
|
printf("(%s) got %hd, returning %hd\n", GSNameFromSelector(_cmd),
|
2000-12-08 19:06:00 +00:00
|
|
|
(*num), rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
*num = rnum;
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) sendInt: (int)num
|
|
|
|
{
|
|
|
|
int rnum = num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return rnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getInt: (int *)num
|
|
|
|
{
|
|
|
|
int rnum = *num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), *num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
*num = rnum;
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (long) sendLong: (long)num
|
|
|
|
{
|
|
|
|
long rnum = num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %ld, returning %ld\n", GSNameFromSelector(_cmd), num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return rnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getLong: (long *)num
|
|
|
|
{
|
|
|
|
long rnum = *num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %ld, returning %ld\n", GSNameFromSelector(_cmd), *num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
*num = rnum;
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) sendFloat: (float)num
|
|
|
|
{
|
|
|
|
float rnum = num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %f, returning %f\n", GSNameFromSelector(_cmd), num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return rnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getFloat: (float *)num
|
|
|
|
{
|
|
|
|
float rnum = *num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %f, returning %f\n", GSNameFromSelector(_cmd), *num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
*num = rnum;
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (double) sendDouble: (double)num
|
|
|
|
{
|
|
|
|
double rnum = num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %g, returning %g\n", GSNameFromSelector(_cmd), num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return rnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getDouble: (double *)num
|
|
|
|
{
|
|
|
|
double rnum = *num + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %g, returning %g\n", GSNameFromSelector(_cmd), *num, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
*num = rnum;
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (small_struct) sendSmallStruct: (small_struct)str
|
|
|
|
{
|
|
|
|
char rnum = str.z + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), str.z, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
str.z = rnum;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getSmallStruct: (small_struct *)str
|
|
|
|
{
|
|
|
|
char rnum = str->z + ADD_CONST;
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), str->z, rnum);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
str->z = rnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (foo) sendStruct: (foo)f
|
|
|
|
{
|
2003-04-10 16:28:07 +00:00
|
|
|
foo f2 = {'A', 123.456, 1, "horse", 987654};
|
|
|
|
printf("(%s) got c='%c', d=%g, i=%d, s=%s, l=%lu",
|
2003-08-24 23:07:41 +00:00
|
|
|
GSNameFromSelector(_cmd), f.c, f.d, f.i, f.s, f.l);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
2003-04-10 16:28:07 +00:00
|
|
|
printf(" returning c='%c', d=%g, i=%d, s=%s, l=%lu\n",
|
|
|
|
f2.c, f2.d, f2.i, f2.s, f2.l);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return f2;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getStruct: (foo *)f
|
|
|
|
{
|
2003-04-10 16:28:07 +00:00
|
|
|
foo f2 = {'A', 123.456, 1, "horse", 987654};
|
|
|
|
printf("(%s) got c='%c', d=%g, i=%d, s=%s, l=%lu",
|
2003-08-24 23:07:41 +00:00
|
|
|
GSNameFromSelector(_cmd), f->c, f->d, f->i, f->s, f->l);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
2003-04-10 16:28:07 +00:00
|
|
|
printf(" returning c='%c', d=%g, i=%d, s=%s, l=%lu\n",
|
|
|
|
f2.c, f2.d, f2.i, f2.s, f2.l);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
*f = f2;
|
|
|
|
}
|
|
|
|
|
|
|
|
- sendObject: (id)str
|
|
|
|
{
|
2005-02-22 11:22:44 +00:00
|
|
|
printf ("(%s) got object (%s)\n", GSNameFromSelector(_cmd),
|
2003-08-24 23:07:41 +00:00
|
|
|
GSClassNameFromObject(str));
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getObject: (id *)str
|
|
|
|
{
|
2009-10-04 09:53:19 +00:00
|
|
|
static NSString *ret = @"hello";
|
2005-02-22 11:22:44 +00:00
|
|
|
printf ("(%s) got object (%s)\n", GSNameFromSelector(_cmd),
|
2003-08-24 23:07:41 +00:00
|
|
|
GSClassNameFromObject(*str));
|
2009-10-04 09:53:19 +00:00
|
|
|
*str = ret;
|
|
|
|
printf(" returning (%s)\n", [*str cString]);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (char *) sendString: (char *)str
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf ("(%s) got string (%s)", GSNameFromSelector(_cmd), str);
|
2000-08-07 22:00:31 +00:00
|
|
|
str[0] = 'N';
|
|
|
|
printf(" returning (%s)\n", str);
|
|
|
|
fflush(stdout);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getString: (char **)str
|
|
|
|
{
|
2009-10-04 09:53:19 +00:00
|
|
|
static char *ret = "hello";
|
2003-08-24 23:07:41 +00:00
|
|
|
printf ("(%s) got string (%s)", GSNameFromSelector(_cmd), *str);
|
2009-10-04 09:53:19 +00:00
|
|
|
*str = ret;
|
2000-08-07 22:00:31 +00:00
|
|
|
printf(" returning (%s)\n", *str);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (oneway void) shout
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf ("(%s) got it\n", GSNameFromSelector(_cmd));
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sender must also respond to 'bounce:count:' */
|
|
|
|
- bounce: sender count: (int)c
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf ("(%s) got message %d, bouncing back %d", GSNameFromSelector(_cmd), c, c-1);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
if (--c)
|
|
|
|
[sender bounce:self count:c];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) outputStats:obj
|
|
|
|
{
|
|
|
|
id c = [obj connectionForProxy];
|
|
|
|
id o = [c statistics];
|
|
|
|
id a = [o allKeys];
|
|
|
|
int j;
|
|
|
|
|
|
|
|
printf("------------------------------------------------------------\n");
|
|
|
|
printf("Printing Statistics\n");
|
|
|
|
printf(" Number of connections - %d\n", [[NSConnection allConnections] count]);
|
|
|
|
printf(" This connection -\n");
|
|
|
|
for (j = 0; j < [a count]; j++)
|
|
|
|
{
|
|
|
|
id k = [a objectAtIndex:j];
|
|
|
|
id v = [o objectForKey:k];
|
|
|
|
printf(" %s - %s\n", [k cString], [[v description] cString]);
|
|
|
|
}
|
|
|
|
printf("------------------------------------------------------------\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Doesn't work because GCC generates the wrong encoding: "@0@+8:+12^i+16" */
|
|
|
|
- sendArray: (int[3])a
|
|
|
|
{
|
|
|
|
printf(" >> array %d %d %d\n", a[0], a[1], a[2]);
|
|
|
|
fflush(stdout);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- sendStructArray: (struct myarray)ma
|
|
|
|
{
|
|
|
|
printf(" >>struct array %d %d %d\n", ma.a[0], ma.a[1], ma.a[2]);
|
|
|
|
fflush(stdout);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- sendDouble: (double)d andFloat: (float)f
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("(%s) got double %f, float %f\n", GSNameFromSelector(_cmd), d, f);
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-07-04 09:33:53 +00:00
|
|
|
- quietBycopy: (bycopy id)o
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf(" >> quiet bycopy class is %s\n", GSClassNameFromObject(o));
|
2003-07-04 09:33:53 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- sendBycopy: (bycopy id)o
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf(" >> bycopy class is %s\n", GSClassNameFromObject(o));
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _F_BYREF
|
|
|
|
- sendByref: (byref id)o
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf(" >> byref class is %s\n", GSClassNameFromObject(o));
|
2000-08-07 22:00:31 +00:00
|
|
|
fflush(stdout);
|
|
|
|
return self;
|
|
|
|
}
|
2002-03-20 06:11:36 +00:00
|
|
|
- modifyByref: (byref NSMutableString *)o
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf(" >> byref class is %s\n", GSClassNameFromObject(o));
|
2002-03-20 06:11:36 +00:00
|
|
|
fflush(stdout);
|
|
|
|
[o appendString: @"hello"];
|
|
|
|
return self;
|
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6
|
|
|
|
: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12
|
|
|
|
{
|
|
|
|
printf("manyArgs: got %d %d %d %d %d %d %d %d %d %d %d %d\n",
|
|
|
|
i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12);
|
|
|
|
fflush(stdout);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- connectionBecameInvalid: notification
|
|
|
|
{
|
|
|
|
id anObj = [notification object];
|
2005-11-21 13:15:39 +00:00
|
|
|
if ([anObj isKindOfClass: [NSConnection class]])
|
2000-08-07 22:00:31 +00:00
|
|
|
{
|
|
|
|
int i, count = [the_array count];
|
|
|
|
for (i = count-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
id o = [the_array objectAtIndex: i];
|
|
|
|
if ([o isProxy] && [o connectionForProxy] == anObj)
|
|
|
|
[the_array removeObjectAtIndex: i];
|
|
|
|
}
|
|
|
|
if (count != [the_array count])
|
|
|
|
printf("$$$$$ connectionBecameInvalid: removed from the_array\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self error:"non Connection is invalid"];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSConnection*) connection: ancestor didConnect: newConn
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
printf("%s\n", GSNameFromSelector(_cmd));
|
2000-08-07 22:00:31 +00:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver: self
|
|
|
|
selector: @selector(connectionBecameInvalid:)
|
|
|
|
name: NSConnectionDidDieNotification
|
|
|
|
object: newConn];
|
|
|
|
[newConn setDelegate: self];
|
|
|
|
return newConn;
|
|
|
|
}
|
2003-10-21 14:28:34 +00:00
|
|
|
|
|
|
|
- (oneway void) registerClient: (id<ClientProtocol>)client
|
|
|
|
{
|
|
|
|
ASSIGN(registered_client, client);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (oneway void) unregisterClient: (id<ClientProtocol>)client
|
|
|
|
{
|
|
|
|
DESTROY(registered_client);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) tryClientCallback
|
|
|
|
{
|
|
|
|
return [registered_client callback];
|
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
void
|
|
|
|
usage(const char *program)
|
|
|
|
{
|
|
|
|
printf("Usage: %s [-d -t#] [server_name]\n", program);
|
|
|
|
printf(" -d - Debug connection\n");
|
|
|
|
printf(" -t - Timeout after # seconds\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[], char **env)
|
|
|
|
{
|
|
|
|
int i, debug, timeout;
|
2004-04-25 07:40:19 +00:00
|
|
|
id s = [[Server alloc] init];
|
|
|
|
id l;
|
2000-08-07 22:00:31 +00:00
|
|
|
id o = [[NSObject alloc] init];
|
|
|
|
NSConnection *c;
|
2009-06-19 15:51:11 +00:00
|
|
|
NSPortNameServer *ns;
|
|
|
|
NSPort *port;
|
2000-08-07 22:00:31 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
2010-03-19 12:10:11 +00:00
|
|
|
#if !defined(__MINGW__)
|
2000-08-07 22:00:31 +00:00
|
|
|
extern int optind;
|
|
|
|
extern char *optarg;
|
2000-09-22 04:20:52 +00:00
|
|
|
#endif
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2004-04-25 07:40:19 +00:00
|
|
|
l = [NSProtocolChecker protocolCheckerWithTarget: s
|
|
|
|
protocol: @protocol(ServerProtocol)];
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
|
|
|
|
debug = 0;
|
|
|
|
timeout = 0;
|
2009-06-19 15:51:11 +00:00
|
|
|
while ((i = wgetopt(argc, argv, "hdt:")) != EOF)
|
2005-02-22 11:22:44 +00:00
|
|
|
switch (i)
|
2000-08-07 22:00:31 +00:00
|
|
|
{
|
|
|
|
case 'd':
|
2003-10-27 13:41:01 +00:00
|
|
|
debug++;
|
2000-08-07 22:00:31 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
timeout = atoi(optarg);;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
default:
|
2002-03-25 08:13:46 +00:00
|
|
|
#if 0
|
2000-08-07 22:00:31 +00:00
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
2002-03-25 08:13:46 +00:00
|
|
|
#endif
|
2000-08-07 22:00:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NeXT_runtime
|
|
|
|
[NSDistantObject setProtocolForProxies:@protocol(AllProxies)];
|
|
|
|
#endif
|
|
|
|
|
2003-10-27 13:41:01 +00:00
|
|
|
if (debug > 0)
|
|
|
|
{
|
|
|
|
[NSDistantObject setDebug: debug];
|
|
|
|
[NSConnection setDebug: debug];
|
|
|
|
[NSObject enableDoubleReleaseCheck: YES];
|
|
|
|
}
|
2009-06-19 15:51:11 +00:00
|
|
|
ns = [NSSocketPortNameServer sharedInstance];
|
|
|
|
port = [NSSocketPort port];
|
|
|
|
c = [NSConnection connectionWithReceivePort: port sendPort: port];
|
2000-08-07 22:00:31 +00:00
|
|
|
[c setRootObject: l];
|
|
|
|
|
|
|
|
if (optind < argc)
|
2009-06-19 15:51:11 +00:00
|
|
|
[c registerName: [NSString stringWithUTF8String: argv[optind]]
|
|
|
|
withNameServer: ns];
|
2000-08-07 22:00:31 +00:00
|
|
|
else
|
2009-06-19 15:51:11 +00:00
|
|
|
[c registerName: @"test2server" withNameServer: ns];
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
2004-04-25 07:40:19 +00:00
|
|
|
addObserver: s
|
2000-08-07 22:00:31 +00:00
|
|
|
selector: @selector(connectionBecameInvalid:)
|
|
|
|
name: NSConnectionDidDieNotification
|
|
|
|
object: c];
|
2004-04-25 07:40:19 +00:00
|
|
|
[c setDelegate: s];
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2004-04-25 07:40:19 +00:00
|
|
|
[s addObject: o];
|
2000-08-07 22:00:31 +00:00
|
|
|
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");
|
|
|
|
|
|
|
|
if (timeout)
|
2002-02-26 10:38:50 +00:00
|
|
|
[[NSRunLoop currentRunLoop] runUntilDate:
|
|
|
|
[NSDate dateWithTimeIntervalSinceNow: timeout]];
|
2000-08-07 22:00:31 +00:00
|
|
|
else
|
2002-02-26 10:38:50 +00:00
|
|
|
[[NSRunLoop currentRunLoop] run];
|
2000-08-07 22:00:31 +00:00
|
|
|
printf("Finished\n");
|
|
|
|
|
|
|
|
[arp release];
|
|
|
|
exit(0);
|
|
|
|
}
|