Remove redundant classes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2861 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 1998-07-21 17:56:48 +00:00
parent 130dfd071f
commit 3246db28c8
41 changed files with 189 additions and 3485 deletions

View file

@ -36,27 +36,16 @@ include ../config.mak
TEST_TOOL_NAME = \
dictionary \
stdio-stream \
textcoding \
first-server \
first-client \
second-server \
second-client
textcoding
# The Objective-C source files to be compiled
dictionary_OBJC_FILES = dictionary.m
stdio-stream_OBJC_FILES = stdio-stream.m
textcoding_OBJC_FILES = textcoding.m
first-server_OBJC_FILES = first-server.m
first-client_OBJC_FILES = first-client.m
second-server_OBJC_FILES = second-server.m
second-client_OBJC_FILES = second-client.m
SRCS = $(TEST_TOOL_NAME:=.m)
HDRS = \
first-server.h \
second-server.h \
second-client.h
HDRS =
DIST_FILES = $(SRCS) $(HDRS) GNUmakefile Makefile.postamble Makefile.preamble \
custom-zone.m

View file

@ -1,39 +0,0 @@
#include <gnustep/base/Connection.h>
#include <gnustep/base/Proxy.h>
#include "first-server.h"
#include <Foundation/NSString.h>
int main(int argc, char *argv[])
{
id s;
if (argc > 2)
{
printf("Looking for connection named `firstserver' on host `%s'...\n",
argv[2]);
s = [Connection rootProxyAtName:@"firstserver"
onHost:[NSString stringWithCString:argv[2]]];
}
else
{
printf("Looking for connection named `firstserver' on localhost...\n");
s = [Connection rootProxyAtName:@"firstserver"];
}
printf("Found connection named `firstserver'\n");
printf("Saying hello to the server\n");
if (argc > 1)
[s sayHiTo:argv[1]];
else
[s sayHiTo:"out there"];
printf("Shutting down my connection to the server\n");
[[s connectionForProxy] invalidate];
/* Although this isn't strictly necessary. The server will recognize
that we are gone, and handle it, if we just exit (or if we crash). */
exit(0);
}

View file

@ -1,13 +0,0 @@
#ifndef _first_server_h
#define _first_server_h
#include <Foundation/NSObject.h>
@interface FirstServer : NSObject
- sayHiTo: (char *)name;
@end
#endif /* _first_server_h */

View file

@ -1,77 +0,0 @@
#include <gnustep/base/Connection.h>
#include "first-server.h"
#include <Foundation/NSString.h>
#include <Foundation/NSRunLoop.h>
#include <sys/file.h>
@interface MyIo: NSObject <FdListening,FdSpeaking>
{
id runLoop;
id mode;
char c;
}
- initForRunLoop: r andMode: m;
- (void) readyForReadingOnFileDescriptor: (int)fd;
- (void) readyForWritingOnFileDescriptor: (int)fd;
@end
@implementation MyIo
- initForRunLoop: r andMode: m
{
runLoop = r;
mode = m;
return self;
}
- (void) readyForReadingOnFileDescriptor: (int)fd
{
if (read(fd, &c, 1) == 1) {
[runLoop addWriteDescriptor: 1 object: self forMode: mode];
[runLoop removeReadDescriptor: fd forMode: mode];
}
}
- (void) readyForWritingOnFileDescriptor: (int)fd
{
if (write(fd, &c, 1) == 1) {
[runLoop addReadDescriptor: 0 object: self forMode: mode];
[runLoop removeWriteDescriptor: fd forMode: mode];
}
}
@end
@implementation FirstServer
- sayHiTo: (char *)name
{
printf("Hello, %s.\n", name);
return self;
}
@end
int main()
{
id s, c;
MyIo* myIo;
NSString* m;
id r;
r = [NSRunLoop currentInstance];
m = [NSRunLoop currentMode];
myIo = [[MyIo alloc] initForRunLoop: r andMode: m];
[r addReadDescriptor: 0 object: myIo forMode: m];
/* Create our server object */
s = [[FirstServer alloc] init];
/* Register a connection that provides the server object to the network */
printf("Registering a connection for the server using name `firstserver'\n");
c = [Connection newRegisteringAtName:@"firstserver"
withRootObject:s];
/* Run the connection */
printf("Running the connection... (until you interrupt with control-C)\n");
[c runConnection]; /* This runs until interrupt. */
exit(0);
}

View file

@ -1,30 +0,0 @@
#ifndef second_client_h
#define second_client_h
#include <gnustep/base/Connection.h>
#include <gnustep/base/Proxy.h>
#include "second-server.h"
@interface AppellationObject : NSObject
{
const char *appellation;
}
@end
@implementation AppellationObject
- setAppellation: (const char *)n
{
appellation = n;
return self;
}
- (const char *) appellation
{
return appellation;
}
@end
#endif

View file

@ -1,95 +0,0 @@
#include "second-client.h"
#include <Foundation/NSString.h>
#include <gnustep/base/Notification.h>
#include <gnustep/base/Invocation.h>
#include <Foundation/NSRunLoop.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSException.h>
id announce_new_connection (id notification)
{
#if 0
id connection = [notification object];
printf ("Created Connection 0x%x to %@\n",
(unsigned)connection, [[connection outPort] description]);
#endif
return nil;
}
int main(int argc, char *argv[])
{
static id server;
id a1;
id remote_array;
char namebuf[16];
printf("Looking up server object on localhost with name `secondserver'\n");
if (argc > 1)
server = [Connection rootProxyAtName:
[NSString stringWithCString: argv[1]]];
else
server = [Connection rootProxyAtName: @"secondserver"];
printf("Found server.\n");
[NotificationDispatcher
addInvocation: [[ObjectFunctionInvocation alloc]
initWithObjectFunction: announce_new_connection]
name: ConnectionWasCreatedNotification
object: nil];
/* Create an AppellationObject */
a1 = [[AppellationObject alloc] init];
sprintf(namebuf, "%d", (int)getpid());
[a1 setAppellation: namebuf];
printf("This client has appellation %s\n", [a1 appellation]);
/* Let the server know about object a1. */
[server addRemoteObject: a1];
/* Get the server's array of all other AppellationObject's */
remote_array = [server array];
/* Print all the appellations; this will involve making connections
to the other clients of the server. */
{
int i, count;
const char *s;
id a2; /* appellation object from server's list */
count = [remote_array count];
for (i = 0; i < count; i++)
{
a2 = [remote_array objectAtIndex: i];
s = [a2 appellation];
printf(">>>Server knows about client with appellation %s<<<\n", s);
if ([a2 isProxy])
(*objc_free)((void*)s);
}
}
/* Cause an exception in the server, and watch it return to us. */
NS_DURING
{
[remote_array objectAtIndex: 99];
}
NS_HANDLER
{
printf("Exceptions are working; caught exception:\n"
"NAME: %s\n"
"REASON: %s\n",
[[localException name] cStringNoCopy],
[[localException reason] cStringNoCopy]);
[localException release];
}
NS_ENDHANDLER
/* Run, exiting as soon as there are 30 minutes with no requests */
[NSRunLoop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 30 * 60]];
/* Clean up, to let the server know we're going away; (although
this isn't strictly necessary because the remote port will
detect that the connection has been severed). */
[[server connectionForProxy] invalidate];
exit(0);
}

View file

@ -1,18 +0,0 @@
#ifndef second_server_h
#define second_server_h
#include <Foundation/NSObject.h>
#include <gnustep/base/Array.h>
@interface SecondServer : NSObject
{
Array *array;
}
- init;
- addRemoteObject: o;
- array;
@end
#endif

View file

@ -1,154 +0,0 @@
#include "second-server.h"
#include "second-client.h"
#include <gnustep/base/Connection.h>
#include <gnustep/base/TcpPort.h>
#include <Foundation/NSString.h>
#include <gnustep/base/Notification.h>
#include <gnustep/base/Invocation.h>
/* This function will be called by an Invocation object that will be
registered to fire every time an InPort accepts a new client. */
id announce_new_port (id notification)
{
id in_port = [notification object];
id out_port = [notification userInfo];
printf ("{%s}\n\tconnected to\n\t{%s}\n",
[[out_port description] cStringNoCopy],
[[in_port description] cStringNoCopy]);
printf ("Now servicing %d connection(s).\n",
[in_port numberOfConnectedOutPorts]);
return nil;
}
/* This function will be called by an Invocation object that will be
registered to fire every time an InPort client disconnects. */
id announce_broken_port (id notification)
{
id in_port = [notification object];
id out_port = [notification userInfo];
printf ("{%s}\n\tdisconnected from\n\t{%s}\n",
[[out_port description] cStringNoCopy],
[[in_port description] cStringNoCopy]);
printf ("Now servicing %d connection(s).\n",
[in_port numberOfConnectedOutPorts]);
return nil;
}
/* The implementation of the object that will be registered with D.O.
as the server. */
@implementation SecondServer
- init
{
[super init];
array = [[Array alloc] init];
return self;
}
- addRemoteObject: o
{
const char *s;
[array addObject:o];
/* This next line is a callback */
s = [o appellation];
printf("Added remote object with appellation %s\n", s);
return self;
}
- array
{
return array;
}
- (Connection*) connection: ancestor didConnect: newConn
{
printf(">>>>New connection 0x%x created\n", (unsigned)newConn);
[NotificationDispatcher
addObserver: self
selector: @selector(connectionBecameInvalid:)
name: ConnectionBecameInvalidNotification
object: newConn];
[newConn setDelegate: self];
return newConn;
}
- connectionBecameInvalid: notification
{
id connection = [notification object];
if ([connection isKindOf: [Connection class]])
{
int arrayCount = [array count];
int i;
printf(">>> Connection 0x%x invalidated\n", (unsigned)connection);
/* Remember to avoid calling -isEqual: on the proxies of the
invalidated Connection. */
for (i = arrayCount-1; i >= 0; i--)
{
id o = [array objectAtIndex: i];
if ([o isProxy]
&& [o connectionForProxy] == connection)
{
printf(">>> Removing proxy 0x%x\n", (unsigned)o);
[array removeObjectAtIndex: i];
}
}
}
else
{
[self error:"non-Connection sent invalidation"];
}
return self;
}
@end
int main(int argc, char *argv[])
{
id s;
id c;
[NSObject enableDoubleReleaseCheck: YES];
s = [[SecondServer alloc] init];
[NotificationDispatcher
addInvocation: [[ObjectFunctionInvocation alloc]
initWithObjectFunction: announce_broken_port]
name: InPortClientBecameInvalidNotification
object: nil];
[NotificationDispatcher
addInvocation: [[ObjectFunctionInvocation alloc]
initWithObjectFunction: announce_new_port]
name: InPortAcceptedClientNotification
object: nil];
if (argc > 1)
{
c = [Connection newRegisteringAtName:
[NSString stringWithCString: argv[1]]
withRootObject:s];
printf("Regsitered server object on localhost with "
"name `%s'\n", argv[1]);
}
else
{
c = [Connection newRegisteringAtName: @"secondserver" withRootObject: s];
printf("Regsitered server object on localhost with "
"name `secondserver'\n");
}
[c setDelegate:s];
[NotificationDispatcher
addObserver: s
selector: @selector(connectionBecameInvalid:)
name: ConnectionBecameInvalidNotification
object: c];
[c runConnection];
exit(0);
}