mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Use Array instead of List. Use NotificationDispatcher to hear about
invalid and new connections. Let the user set the registerd name from the command line. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1071 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
10b6ce106e
commit
591e85df32
1 changed files with 33 additions and 21 deletions
|
@ -3,28 +3,27 @@
|
||||||
#include <objects/SocketPort.h>
|
#include <objects/SocketPort.h>
|
||||||
#include <objects/BinaryCStream.h>
|
#include <objects/BinaryCStream.h>
|
||||||
#include <objects/Connection.h>
|
#include <objects/Connection.h>
|
||||||
#include <objc/List.h>
|
|
||||||
#include <objects/String.h>
|
#include <objects/String.h>
|
||||||
|
#include <objects/Notification.h>
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
@implementation Server
|
@implementation Server
|
||||||
- init
|
- init
|
||||||
{
|
{
|
||||||
theList = [[List alloc] init];
|
the_array = [[Array alloc] init];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
- (unsigned) count
|
- (unsigned) count
|
||||||
{
|
{
|
||||||
return [theList count];
|
return [the_array count];
|
||||||
}
|
}
|
||||||
- addObject: o
|
- (void) addObject: o
|
||||||
{
|
{
|
||||||
[theList addObject:o];
|
[the_array addObject:o];
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
- objectAt: (unsigned)i
|
- objectAt: (unsigned)i
|
||||||
{
|
{
|
||||||
return [theList objectAt:i];
|
return [the_array objectAt:i];
|
||||||
}
|
}
|
||||||
- print: (const char *)msg
|
- print: (const char *)msg
|
||||||
{
|
{
|
||||||
|
@ -45,7 +44,7 @@
|
||||||
}
|
}
|
||||||
- callbackNameOn: obj
|
- callbackNameOn: obj
|
||||||
{
|
{
|
||||||
printf(">>callback name is (%s)\n", [obj name]);
|
printf (">>callback name is (%s)\n", object_get_class_name (obj));
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
/* sender must also respond to 'bounce:count:' */
|
/* sender must also respond to 'bounce:count:' */
|
||||||
|
@ -137,7 +136,7 @@
|
||||||
|
|
||||||
- sendBycopy: (bycopy id)o
|
- sendBycopy: (bycopy id)o
|
||||||
{
|
{
|
||||||
printf(">> bycopy class is %s\n", [o name]);
|
printf(">> bycopy class is %s\n", object_get_class_name (o));
|
||||||
[o release];
|
[o release];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -168,17 +167,17 @@
|
||||||
if ([anObj isKindOf:[Connection class]])
|
if ([anObj isKindOf:[Connection class]])
|
||||||
{
|
{
|
||||||
id objList;
|
id objList;
|
||||||
int i, j, count, listCount = [theList count];
|
int i, j, count, listCount = [the_array count];
|
||||||
objList = [anObj proxies];
|
objList = [anObj proxies];
|
||||||
count = [objList count];
|
count = [objList count];
|
||||||
/* This contortion avoids List's calling -isEqual: on the proxy */
|
/* This contortion avoids List's calling -isEqual: on the proxy */
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
for (j = 0; j < [theList count]; j++)
|
for (j = 0; j < [the_array count]; j++)
|
||||||
if ([theList objectAt:j] == [objList objectAtIndex:i])
|
if ([the_array objectAt:j] == [objList objectAtIndex:i])
|
||||||
[theList removeObjectAt:j];
|
[the_array removeObjectAtIndex: j];
|
||||||
[objList release];
|
[objList release];
|
||||||
if (listCount != [theList count])
|
if (listCount != [the_array count])
|
||||||
printf("$$$$$ senderIsInvalid: removed from theList\n");
|
printf("$$$$$ senderIsInvalid: removed from the_array\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -189,13 +188,17 @@
|
||||||
- (Connection*) connection: ancestor didConnect: newConn
|
- (Connection*) connection: ancestor didConnect: newConn
|
||||||
{
|
{
|
||||||
printf("%s\n", sel_get_name(_cmd));
|
printf("%s\n", sel_get_name(_cmd));
|
||||||
[newConn registerForInvalidationNotification:self];
|
[NotificationDispatcher
|
||||||
[newConn setDelegate:self];
|
addObserver: self
|
||||||
|
selector: @selector(connectionBecameInvalid:)
|
||||||
|
name: ConnectionBecameInvalidNotification
|
||||||
|
object: newConn];
|
||||||
|
[newConn setDelegate: self];
|
||||||
return newConn;
|
return newConn;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
int main()
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
id l = [[Server alloc] init];
|
id l = [[Server alloc] init];
|
||||||
id o = [[NSObject alloc] init];
|
id o = [[NSObject alloc] init];
|
||||||
|
@ -207,11 +210,20 @@ int main()
|
||||||
#if NeXT_runtime
|
#if NeXT_runtime
|
||||||
[Proxy setProtocolForProxies:@protocol(AllProxies)];
|
[Proxy setProtocolForProxies:@protocol(AllProxies)];
|
||||||
#endif
|
#endif
|
||||||
c = [Connection newRegisteringAtName:@"test2server" withRootObject:l];
|
if (argc > 1)
|
||||||
[c registerForInvalidationNotification:l];
|
c = [Connection newRegisteringAtName:
|
||||||
|
[NSString stringWithCString: argv[1]]
|
||||||
|
withRootObject:l];
|
||||||
|
else
|
||||||
|
c = [Connection newRegisteringAtName:@"test2server" withRootObject:l];
|
||||||
|
[NotificationDispatcher
|
||||||
|
addObserver: l
|
||||||
|
selector: @selector(connectionBecameInvalid:)
|
||||||
|
name: ConnectionBecameInvalidNotification
|
||||||
|
object: c];
|
||||||
[c setDelegate:l];
|
[c setDelegate:l];
|
||||||
|
|
||||||
[l addObject:o];
|
[l addObject: o];
|
||||||
d = [l returnDouble];
|
d = [l returnDouble];
|
||||||
printf("got double %f\n", d);
|
printf("got double %f\n", d);
|
||||||
printf("list's hash is 0x%x\n", (unsigned)[l hash]);
|
printf("list's hash is 0x%x\n", (unsigned)[l hash]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue