[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper way of connecting to apps

From: Richard Frith-Macdonald
Subject: Re: Proper way of connecting to apps
Date: Sun, 22 Jun 2003 08:58:21 +0100

On Sunday, June 22, 2003, at 01:14 am, Stefan Urbanek wrote:


At first, thank you for your answer. Thing is, that I know all you have suggested me, but this does not solve the problem i am pointing at. I'll put something together here, instead of under-writing it.

1. is it somewhere explicitly stated, that using NSConnection is the official way how to get remote application object? I know, that with current implementation I can do that.

It's probably mentioned in the documentation somewhere (certainly was in the original NeXT documentation) ... but its hardly the point really ... the API provides a single (excellent) mechanism for inter-process messaging and therefore does not really need to state explicitly that it should be used in each case you can think of.

2. I think that using same namespace for application objects and distant object registered with NSConnection is not good. Another name server should be used for applications ... or betyter solutions is: same with separated namespace and interface for applications.

I see no justification for having two namespaces. You seem to be saying you want one namespace for applications to talk to each other, and one for NSConnection objects to talk to each other. To me, that seems to be starting from the assumption that applications should not communicate using NSConnection. That assumption needs a *lot* of justification, especially since the whole point of NSConnection is to allow applications to communicate, and since this is the mechanism that all existing applications use and that OpenStep/MacOS-X applications use.

3. [NSWorkspace -launchApplication:] does not work correctly. The method returns immediately after executing application binary, i would expect it to wait until successfull application launch, so i can connect to it immediately and start communicating with it. Now I have to create a loop where I check whether application is running.

That might be a bug as you suggest... how does OpenStep/MacOS-X do it? I thought it counted 'launch' as meaning that that it had started the new task rather than as meaning that the application had completed all its startup. It's very simple to change this of course, but we need to be sure what the correct behavior is.

4. Following code is not making using application services attractive in any way:

[NSWorkspace launchApplication:name]

myApp = [NSConnection rootProxyForConnectionWithRegisteredName:name host:nil];
[NSRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];

MOREOVER, this code does not work correctly if i do not have application installed and i want to use its services (from other application). I can wait for application to be connected forever. Therefore this code is missing check for application presence, which should be done somehow with NSWorkspace.

If you are talking about application 'services', there is a different API for that NSPerformService() ... which does all this for you. I think however, you are talking about general sending of messages to an application? In the context of a potentially long and complex conversation between two applications, the overhead of launching another application and checking that it has started up seems relatively unimportant (also I think this is a rare case ... more normally you want two apps to talk to each other if they are running, rather than starting each other up).

Ho would you explain that anyone who would like to use application services has to write this long piece of code

If they just want application services, they would use NSPerformService()

Well ... if there is a bug in the launching code, the issue does not arise, because you would just call the launch method.

If the launching code already does the same thing as MacOS-X, I'd say that the normal case is ...

otherApp = [NSConnection rootProxyForConnectionWithRegisteredName:name host:nil];
if (otherApp == nil)
// Do nothing ... other app is not running

and a more sophisticated model is to monitor the notifications to check when the application launches...

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self selector: @selector(notified:) name: nil object: nil];
if ([ws launchApplication: anAppName] == NO) ...// Exceptional case
- (void) notificed: (NSNotification*)n
/// start conversation

(that has to be changed when application registration changes)?

I don't expect us to gratuitously break OpenStep/MacOS-X compatibility and change this.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]