]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/snglinst.tex
added ReadType convenience functions (patch 1764160)
[wxWidgets.git] / docs / latex / wx / snglinst.tex
... / ...
CommitLineData
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: snglinst.tex
3%% Purpose: wxSingleInstanceChecker documentation
4%% Author: Vadim Zeitlin
5%% Modified by:
6%% Created: 08.06.01
7%% RCS-ID: $Id$
8%% Copyright: (c) 2001 Vadim Zeitlin
9%% License: wxWindows license
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12\section{\class{wxSingleInstanceChecker}}\label{wxsingleinstancechecker}
13
14wxSingleInstanceChecker class allows to check that only a single instance of a
15program is running. To do it, you should create an object of this class. As
16long as this object is alive, calls to
17\helpref{IsAnotherRunning()}{wxsingleinstancecheckerisanotherrunning} from
18other processes will return {\tt true}.
19
20As the object should have the life span as big as possible, it makes sense to
21create it either as a global or in \helpref{wxApp::OnInit}{wxapponinit}. For
22example:
23
24\begin{verbatim}
25bool MyApp::OnInit()
26{
27 const wxString name = wxString::Format("MyApp-%s", wxGetUserId().c_str());
28 m_checker = new wxSingleInstanceChecker(name);
29 if ( m_checker->IsAnotherRunning() )
30 {
31 wxLogError(_("Another program instance is already running, aborting."));
32
33 return false;
34 }
35
36 ... more initializations ...
37
38 return true;
39}
40
41int MyApp::OnExit()
42{
43 delete m_checker;
44
45 return 0;
46}
47\end{verbatim}
48
49Note using \helpref{wxGetUserId()}{wxgetuserid} to construct the name: this
50allows different user to run the application concurrently which is usually the
51intended goal. If you don't use the user name in the wxSingleInstanceChecker
52name, only one user would be able to run the application at a time.
53
54This class is implemented for Win32 and Unix platforms (supporting {\tt fcntl()}
55system call, but almost all of modern Unix systems do) only.
56
57\wxheading{Derived from}
58
59No base class
60
61\wxheading{Include files}
62
63<wx/snglinst.h>
64
65\wxheading{Library}
66
67\helpref{wxBase}{librarieslist}
68
69\latexignore{\rtfignore{\wxheading{Members}}}
70
71\membersection{wxSingleInstanceChecker::wxSingleInstanceChecker}\label{wxsingleinstancecheckerctor}
72
73\func{}{wxSingleInstanceChecker}{\void}
74
75Default ctor, use \helpref{Create()}{wxsingleinstancecheckercreate} after it.
76
77\membersection{wxSingleInstanceChecker::wxSingleInstanceChecker}\label{wxsingleinstancecheckerwxsingleinstancechecker}
78
79\func{}{wxSingleInstanceChecker}{\param{const wxString\& }{name}, \param{const wxString\& }{path = wxEmptyString}}
80
81Like \helpref{Create()}{wxsingleinstancecheckercreate} but without
82error checking.
83
84\membersection{wxSingleInstanceChecker::Create}\label{wxsingleinstancecheckercreate}
85
86\func{bool}{Create}{\param{const wxString\& }{name}, \param{const wxString\& }{path = wxEmptyString}}
87
88Initialize the object if it had been created using the default constructor.
89Note that you can't call Create() more than once, so calling it if the
90\helpref{non default ctor}{wxsingleinstancecheckerwxsingleinstancechecker}
91had been used is an error.
92
93\wxheading{Parameters}
94
95\docparam{name}{must be given and be as unique as possible. It is used as the
96mutex name under Win32 and the lock file name under Unix.
97\helpref{GetAppName()}{wxappgetappname} and \helpref{wxGetUserId()}{wxgetuserid}
98are commonly used to construct this parameter.}
99
100\docparam{path}{is optional and is ignored under Win32 and used as the directory to
101create the lock file in under Unix (default is
102\helpref{wxGetHomeDir()}{wxgethomedir})}
103
104\wxheading{Return value}
105
106Returns {\tt false} if initialization failed, it doesn't mean that another
107instance is running - use
108\helpref{IsAnotherRunning()}{wxsingleinstancecheckerisanotherrunning} to check
109for it.
110
111\wxheading{Note}
112
113One of possible reasons while Create may fail on Unix is that the lock file
114used for checking already exists but was not created by the user.
115Therefore applications shouldn't treat failure of this function as fatal
116condition, because doing so would open them to the possibility of a Denial of
117Service attack. Instead, they should alert the user about the problem and
118offer to continue execution without checking if another instance is running.
119
120\membersection{wxSingleInstanceChecker::IsAnotherRunning}\label{wxsingleinstancecheckerisanotherrunning}
121
122\constfunc{bool}{IsAnotherRunning}{\void}
123
124Returns {\tt true} if another copy of this program is already running, {\tt
125false} otherwise.
126
127\membersection{wxSingleInstanceChecker::\destruct{wxSingleInstanceChecker}}\label{wxsingleinstancecheckerdtor}
128
129\func{}{\destruct{wxSingleInstanceChecker}}{\void}
130
131Destructor frees the associated resources.
132
133Note that it is not virtual, this class is not meant to be used polymorphically
134