Re: Setting up an auxiliary task for use with Distributed Objects
Re: Setting up an auxiliary task for use with Distributed Objects
- Subject: Re: Setting up an auxiliary task for use with Distributed Objects
- From: Ken Thomases <email@hidden>
- Date: Thu, 16 Apr 2009 19:11:13 -0500
On Apr 16, 2009, at 4:01 AM, Oleg Krupnov wrote:
2) How do I quit the aux task? [NSTask terminate] does not work,
invalidating the connection does not work...
First, your MyVendedObject class should expose a method for the client
to request that the server terminate.
Then, you can change your code...
MyVendedObject* vendedObj = [[[MyVendedObject alloc] init]
autorelease];
NSConnection* connection = [NSConnection defaultConnection];
[connection setRootObject:vendedObj];
if ([connection registerName:@"MyAuxTask"])
{
Replace this line:
[[NSRunLoop currentRunLoop] run];
with something like:
while ([vendedObj shouldKeepRunning])
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:
[NSDate distantFuture]];
}
1) I need to block the main task until the aux task is ready to work.
How do I do it? Sleep/poll connection/repeat doesn't seem a good
approach, is there any better way?
Have you considered reversing the roles of the two processes, in terms
of which is the "server" and which the "client"?
You can have the main task register a connection under a known name.
It will vend an object with which the auxiliary task will register.
It will start the auxiliary task. The auxiliary task will obtain the
vended object from the main task using the known name. The auxiliary
task will create a worker object. It will pass that worker object to
the main task in a check-in message. It will then run the run loop in
the manner illustrated above. The main task will passively receive a
reference (proxy) for the auxiliary task's worker object. It can then
invoke methods of that object just as it would in the design you were
working with.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden