/* 2003 Jun 14 */ #import #import #import #import #import const int MAX_SEQUENCES = 100; /* Maximal number of simulator sequence numbers */ @class NSAutoreleasePool; int main(int argc, const char **argv) { NSDistributedNotificationCenter *dnc; NSAutoreleasePool *pool; NSUserDefaults *defs; AFSimulator *simulator; NSDictionary *dict; NSConnection *connection; NSString *userIdentifier; NSString *serverName; BOOL isRegistered = NO; int sequence = 0; pool = [NSAutoreleasePool new]; /* Get command line arguments */ defs = [NSUserDefaults standardUserDefaults]; userIdentifier = [defs objectForKey:@"AFUserIdentifier"]; serverName = [defs objectForKey:@"AFServerName"]; if([serverName isEqualtToString:@""]) { serverName = nil; } /* Create simulator */ simulator = [[AFSimulator alloc] init]; /* Register simulator */ connection = RETAIN([NSConnection defaultConnection]); [connection setRootObject:simulator]; if(!serverName) { for(sequence = 0; sequence < MAX_SEQUENCES; sequence++) { serverName = [NSString stringWithFormat:@"AFSimulator%i", sequence]; NSLog(@"Trying to register simulator with name '%@'", serverName); if([connection registerName:serverName]) { isRegistered = YES; break; } } } else { if([connection registerName:serverName]) { isRegistered = YES; } } /* Finish */ if(isRegistered) { NSLog(@"Registered with name '%@'", serverName); dnc = [NSDistributedNotificationCenter defaultCenter]; dict = [NSDictionary dictionaryWithObjectsAndKeys: serverName, @"AFDistantSimulatorName", nil, nil]; [dnc postNotificationName:@"AFDistantSimulatorConnectNotification" object:userIdentifier userInfo:dict]; [[NSRunLoop currentRunLoop] run]; NSLog(@"Terminating simulator server %@", serverName); } else { NSLog(@"Unable to register simulator."); } RELEASE(pool); return 0; }