On 02/16/13 05:10, Gonzalo Garramuno wrote:
> I would like my application to have only one instance of it running at a
> time. However I am unsure how to implement this.
> If the user opens another instance the contents of what it opened should go
> to the already opened instance.
> As an example, I would put emacs.
>
> How would I go about coding this? Pipes? Sockets? None of the above.
Sniffing around a bit, I believe the terminology to search for is
"single instance application", and SDI (Single Document Interface),
the latter usually using the former.
I'm not sure offhand what the 'right approach' is, esp for a cross
platform app
other than to probably find and use an existing cross platform toolkit
that
handles this for you.
Likely such toolkits use sockets or named pipes.
Microsoft has docs on this (I don't necessarily recommend the technique
they recommend here, but just FYI to show the terminology they use):
http://msdn.microsoft.com/en-us/library/ms996475.aspx#reaworapps1_topic5
Qt has a class to handle this called "QtSingleApplication", ie:
http://doc.qt.digia.com/solutions/4/qtsingleapplication/qtsingleapplication.html#details
..you might want to look at its innards for implementation, as it likely
does what you want cross platform.
From what I can tell, there are cross platform toolkits out there
already
that can implement this for you, but I can't refer to any as I don't
know
which ones to recommend.
Or just roll your own, and create a ~/.yourapp-lock file, and as Kai-Uwe
says, either use that file to write commands, or use a named pipe like
the lp daemon does, or use a socket. The lock file should have a pid in
it
(as KU mentions) and info on how to contact it (socket port#, named pipe
filename etc) or just make the "lock file" the named pipe.
Both unix and windows support named pipes, and although the APIs are
not the same.
Some info here:
http://en.wikipedia.org/wiki/Named_pipe
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk