Home › Forums › Syphon › Syphon Development – Developer › getting list of servers › Reply To: getting list of servers
Hi, I opened an issue about this:
http://code.google.com/p/syphon-implementations/issues/detail?id=26
and did some coding. I started by adding the following native method to JSyphon:
JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonServerList_getList(JNIEnv * env, jobject jobj)
{
jobject serverlist = nil;
JNF_COCOA_ENTER(env);
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSLog(@”Getting list of servers”);
NSArray *servers = [[SyphonServerDirectory sharedDirectory] servers];
NSMutableArray *output = [NSMutableArray arrayWithCapacity:[servers count]];
NSLog(@”Number of servers %i”, [servers count]);
for (NSDictionary *description in servers)
{
NSLog(@”Adding server = %@”, description);
NSDictionary *simple = [NSDictionary dictionaryWithObjectsAndKeys:[description objectForKey:SyphonServerDescriptionNameKey], @”Name”, [description objectForKey:SyphonServerDescriptionAppNameKey], @”App Name”, nil];
[output addObject:simple];
}
JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
[JNFDefaultCoercions addMapCoercionTo:coecer];
serverlist = [coecer coerceNSObject:servers withEnv:env];
[pool drain];
JNF_COCOA_EXIT(env);
return serverlist;
}
I can run it from Java, but gives 0 as the server count, even though I have several servers running already, which I can connect to with the Client object.
What am I missing here? In the QC server list plugin I also see some additional initialization, in particular:
[[SyphonServerDirectory sharedDirectory] addObserver:self forKeyPath:@”servers” options:0 context:nil];
Do I need to do something similar, or there is it a way to query the SyphonServerDirectory only one time in order to get the list of available servers at the moment of the query?