|
From: | Richard Frith-Macdonald |
Subject: | Re: Detecting running application |
Date: | Thu, 11 May 2006 11:39:52 +0100 |
On 11 May 2006, at 09:14, Chris B. Vetter wrote:
Hi, I'm looking for a way to detect whether a *bundle* is already loaded. Point is, I'm working on a bundle that can either be loaded automatically by adding it to GSAppKitUserBundles() OR implicitly from an application through NSBundle -- but only once. If the bundle detects another copy already loaded, it is supposed to quietly "exit." I remember that back in the old days of GNUstep, when you launched an application twice, you got an alert that the application is already running. So I figured 'registering' the bundle with gdomap(? I think that was how it was done back then) would do the trick. However, I just launched SystemPreferences twice and no alert.. Uhm? Does anyone on the list have an idea how I could solve my problem? The easiest would probably be an entry to the user defaults that the bundle already loaded. However if the application unexpectedly quits, the entry wouldn't be removed. So that's not an option.
I'm not sure what you are after here ... you start by talking about bundles and give the impression that you are concerned about handling things within a single application, but then talk about registering with gdomap, implying that you only want one copy of the bundle loaded across all applications.
Assuming that you are only concerned about a single application ...1. if the issue is to prevent the system trying to re-load dynamic libraries it has already loaded within an app ... current SVN code of NSBundle should do that anyway. Alternatively, you could register for NSBundleDidLoadNotification and add each loaded bundle to an NSMutableSet so that those bundles are never deallocated and therefore can't be re-created.
2. if you want to make sure a bundle is never created twice in the same app, whether it's a bunlde containing code or not, the thing to do is make sure that bundles are never deallocated (since NSBundle already ensures that only one copy of a bundle exists at a time). You could do that by overriding the -dealloc method in a category.
If you are concerned about multiple applications you really have a problem ... you need to synchronize with bundle creation between apps. I think that means clever category based overriding of -initWithPath: so that you perform the synchronisation before calling the original initialiser of the bundle. I guess your apps could use [NSPortNameServer-registerPort:forName:] using the bundle path as the port name, and refuse to initialise the bundle if the path is in use as the name of another port. Alternatively, you could write your own synchronisation mechanism.
[Prev in Thread] | Current Thread | [Next in Thread] |