maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   How to forbid multi-running an application? (https://talk.maemo.org/showthread.php?t=54660)

jarmniku 2010-05-31 10:24

How to forbid multi-running an application?
 
Hi!

I have a computational intensive animation application that I want to run only as a single instance. In other words, if user tries to start the same application again, it should not start. How to do that? Hopefully there is a simple way, though I don't believe so
...

Joorin 2010-05-31 11:35

Re: How to forbid multi-running an application?
 
This is typically done using lock files. The directory /var/run can be used. Or /tmp for lock files that should not survive a reboot.

As far as I know, there are POSIX defined functions to handle this. Depending on your framework, there might be implementations there too.

You could use gconf for ease of use but then you must take into account that it might not be thread safe on the same level as files in the file system.

nicolai 2010-05-31 11:47

Re: How to forbid multi-running an application?
 
Quote:

Originally Posted by Joorin (Post 691523)
This is typically done using lock files. The directory /var/run can be used. Or /tmp for lock files that should not survive a reboot.

Isn't that handled by the osso application framework anyway.

Most builtin applications are running with one single instance
only. For example you can not open multiple instances of the
clock or calculator applications.

nicolai

Joorin 2010-05-31 11:54

Re: How to forbid multi-running an application?
 
Quote:

Originally Posted by nicolai (Post 691544)
Isn't that handled by the osso application framework anyway.

Most builtin applications are running with one single instance
only. For example you can not open multiple instances of the
clock or calculator applications.

nicolai

As far as I know, the osso application framework is a bit more complicated than that with watchdogs keeping track of things and restarting applications and, potentially, rebooting the device to get back to a known state. But I'm sure there is already framework functionality in place to use.

(Just as I wrote later on in my comment...)

jarmniku 2010-05-31 12:15

Re: How to forbid multi-running an application?
 
Okay, so the cows are still not flying. I mean that there is no simple way like a flag in the .desktop file or something. I have to do it the hard way, as usually. Probably a lock file then... Thank you for the hints! :)

fredoll 2010-05-31 12:18

Re: How to forbid multi-running an application?
 
if your app handles DBus request properly, osso should not let it run several times ...

mikkov 2010-05-31 12:24

Re: How to forbid multi-running an application?
 
Yes there is a simple way. Launch application via DBus (use .service file) and register application with osso_init(). Documentation is found for example from the wiki.

qwerty12 2010-05-31 12:25

Re: How to forbid multi-running an application?
 
If you've created an osso_context and have set the X-Osso-Service field in the desktop file correctly, Hildon Desktop will call the "top_application" mehod on an already running instance instead of starting a new one.

jarmniku 2010-05-31 12:28

Re: How to forbid multi-running an application?
 
In fact, lock file isn't very good: if the program is killed before it exits voluntarily, the lock file may not be deleted. That forbids the program to start any more!

Better way would be to examine process list and check if the binary is already running. How to do that, then?

jarmniku 2010-05-31 12:31

Re: How to forbid multi-running an application?
 
Quote:

Originally Posted by qwerty12 (Post 691607)
If you've created an osso_context and have set the X-Osso-Service field in the desktop file correctly, Hildon Desktop will call the "top_application" mehod on an already running instance instead of starting a new one.

Sounds reasonable, but I haven't. Maybe I can do that, any pointers to a simple example?

YoDude 2010-05-31 12:44

Re: How to forbid multi-running an application?
 
Quote:

Originally Posted by qwerty12 (Post 691607)
If you've created an osso_context and have set the X-Osso-Service field in the desktop file correctly, Hildon Desktop will call the "top_application" mehod on an already running instance instead of starting a new one.

This is also a problem with the Sygic Maps program...
Instead of bringing an instance that is running in the background forward and back into full screen when the desktop shortcut is touched, it will open a new instance... Not a good thing.

This also explains why when it is closed from the minimized state, it doesn't save any changes that were made during the running of that instance.

I was hoping that at least the multiple instances problem could be solved by a user hack to the .desktop file.

Venemo 2010-05-31 17:28

Re: How to forbid multi-running an application?
 
Anyone has any ideas about how to do this with Qt?

qwerty12 2010-05-31 18:20

Re: How to forbid multi-running an application?
 
Quote:

Originally Posted by jarmniku (Post 691616)
Sounds reasonable, but I haven't. Maybe I can do that, any pointers to a simple example?

http://vcs.maemo.org/svn/maemoexampl...aemo-examples/ -- look at libosso_* and the Makefile to see where the service file should be installed. The example is a little lengthy for this purpose, but 'twas the best I could find. You need osso_initialize

@Venemo

Grab the FreOffice source. It has the QDBus equiv. to all this.

Venemo 2010-07-26 15:42

Re: How to forbid multi-running an application?
 
Okay, a late post for an old thread: the QtSingleApplication solution from the Qt devs does exactly this.


All times are GMT. The time now is 00:40.

vBulletin® Version 3.8.8