libs-steptalk/Tools/stenvironment.m
Stefan Urbanek a77d286c2b Added unimplemented ideas of distant conversations and scripting servers
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@18931 72102866-910b-0410-8b05-ffd578937521
2004-03-27 23:23:39 +00:00

129 lines
4 KiB
Objective-C

/**
stexec.m
Script executor
Copyright (c) 2002 Free Software Foundation
Written by: Stefan Urbanek <urbanek@host.sk>
Date: 2000
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import "STEnvironmentProcess.h"
#import <StepTalk/StepTalk.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSException.h>
#import <Foundation/NSConnection.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSDistributedNotificationCenter.h>
#include <stdio.h>
const int MAX_SEQUENCES = 100; /* Maximal number of simulator sequence numbers */
int main(int argc, const char **argv)
{
NSDistributedNotificationCenter *dnc;
STEnvironmentProcess *envprocess;
NSArray *args;
NSAutoreleasePool *pool;
NSUserDefaults *defs;
NSString *envIdentifier;
NSString *ownerIdentifier;
BOOL isRegistered = NO;
int sequence = 0;
NSConnection *connection;
NSDictionary *dict;
NSString *serverName;
pool = [NSAutoreleasePool new];
// [NSAutoreleasePool enableDoubleReleaseCheck:YES];
defs = [NSUserDefaults standardUserDefaults];
ownerIdentifier = [defs objectForKey:@"STEnvironmentOwnerIdentifier"];
envIdentifier = [defs objectForKey:@"STEnvironmentIdentifier"];
envprocess = [[STEnvironmentProcess alloc] init];
/* Register environment */
connection = RETAIN([NSConnection defaultConnection]);
[connection setRootObject:envprocess];
if(!envIdentifier)
{
for(sequence = 0; sequence < MAX_SEQUENCES; sequence++)
{
envIdentifier = [NSString stringWithFormat:@"Unnamed%i", sequence];
serverName = [NSString stringWithFormat:@"STEnvironment:%@", envIdentifier];
NSLog(@"Trying to register environment with name '%@'", envIdentifier);
NS_DURING
if([connection registerName:serverName])
{
isRegistered = YES;
}
NS_HANDLER
NSLog(@"WARNING: GNUstep is broken! Report this to bug-gnustep@gnu.org");
NS_ENDHANDLER
if(isRegistered)
{
break;
}
}
}
else
{
serverName = [NSString stringWithFormat:@"STEnvironment:%@", envIdentifier];
if([connection registerName:serverName])
{
isRegistered = YES;
}
}
/* Finish */
if(isRegistered)
{
NSLog(@"Registered with name '%@'", envIdentifier);
dnc = [NSDistributedNotificationCenter defaultCenter];
dict = [NSDictionary dictionaryWithObjectsAndKeys:
envIdentifier, @"STDistantEnvironmentName",
nil, nil];
[dnc postNotificationName:@"STDistantEnvironmentConnectNotification"
object:ownerIdentifier
userInfo:dict];
[[NSRunLoop currentRunLoop] run];
NSLog(@"Terminating environment process %@", envIdentifier);
}
else
{
NSLog(@"Unable to register environment.");
}
RELEASE(pool);
return 0;
}