File: classwx_single_instance_checker.html

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (267 lines) | stat: -rw-r--r-- 21,446 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: wxSingleInstanceChecker Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
 <tbody>
 <tr>
  <td id="projectlogo">
    <a href="http://www.wxwidgets.org/" target="_new">
      <img alt="wxWidgets" src="logo.png"/>
    </a>
  </td>
  <td style="padding-left: 0.5em; text-align: right;">
   <span id="projectnumber">Version: 3.0.2</span>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Categories</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classwx_single_instance_checker-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">wxSingleInstanceChecker Class Reference<div class="ingroups"><a class="el" href="group__group__class__appmanagement.html">Application and Process Management</a></div></div>  </div>
</div><!--header-->
<div class="contents">

<p><code>#include &lt;wx/snglinst.h&gt;</code></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p><a class="el" href="classwx_single_instance_checker.html" title="wxSingleInstanceChecker class allows to check that only a single instance of a program is running...">wxSingleInstanceChecker</a> class allows to check that only a single instance of a program is running. </p>
<p>To do it, you should create an object of this class. As long as this object is alive, calls to <a class="el" href="classwx_single_instance_checker.html#ad3588a5ae39131a129f5b886236f6c40" title="Returns true if another copy of this program is already running and false otherwise.">wxSingleInstanceChecker::IsAnotherRunning</a> from other processes will return <span class="literal">true</span>.</p>
<p>As the object should have the life span as big as possible, it makes sense to create it either as a global or in <a class="el" href="classwx_app_console.html#a99953775a2fd83fa2456e390779afe15" title="This must be provided by the application, and will usually create the application&#39;s main window...">wxApp::OnInit</a>. For example:</p>
<div class="fragment"><div class="line"><span class="keywordtype">bool</span> MyApp::OnInit()</div>
<div class="line">{</div>
<div class="line">    m_checker = <span class="keyword">new</span> <a class="code" href="classwx_single_instance_checker.html#ab5a56ad3ace10afc97d1c1608e40ef0c" title="Default constructor.">wxSingleInstanceChecker</a>;</div>
<div class="line">    <span class="keywordflow">if</span> ( m_checker-&gt;IsAnotherRunning() )</div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="group__group__funcmacro__log.html#ga0dd3c633f990f794e76065c9a7af4c87" title="The functions to use for error messages, i.e.">wxLogError</a>(<a class="code" href="group__group__funcmacro__string.html#ga8a02b8875a521df57263a9e6f090f2d0" title="Macro to be used around all literal strings that should be translated.">_</a>(<span class="stringliteral">&quot;Another program instance is already running, aborting.&quot;</span>));</div>
<div class="line"></div>
<div class="line">        <span class="keyword">delete</span> m_checker; <span class="comment">// OnExit() won&#39;t be called if we return false</span></div>
<div class="line">        m_checker = NULL;</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    ... more initializations ...</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> MyApp::OnExit()</div>
<div class="line">{</div>
<div class="line">    <span class="keyword">delete</span> m_checker;</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><p>Note that by default <a class="el" href="classwx_single_instance_checker.html#a3cfc2177b3271480415c138e2edb5833" title="Calls Create() with default name.">wxSingleInstanceChecker::CreateDefault()</a> is used to create the checker meaning that it will be initialized differently for different users and thus will allow different users to run the application concurrently which is usually the required behaviour. However if only a single instance of a program should be running system-wide, you need to call <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> with a custom name which does <em>not</em> include <a class="el" href="group__group__funcmacro__networkuseros.html#gab1ebfcd4741550d6f7aa6f8a8952f4f3" title="This function returns the &quot;user id&quot; also known as &quot;login name&quot; under Unix (i.e.">wxGetUserId()</a>.</p>
<p>This class is implemented for Win32 and Unix platforms (supporting <code>fcntl()</code> system call, but almost all of modern Unix systems do) only.</p>
<h2></h2>
<div><span class="lib">Library:</span>&#160;&#160;<span class="lib_text"><a class="el" href="page_libs.html#page_libs_wxbase">wxBase</a></span></div><div><span class="category">Category:</span>&#160;&#160;<span class="category_text"><a class="el" href="group__group__class__appmanagement.html">Application and Process Management</a></span></div> </div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:ab5a56ad3ace10afc97d1c1608e40ef0c"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_single_instance_checker.html#ab5a56ad3ace10afc97d1c1608e40ef0c">wxSingleInstanceChecker</a> ()</td></tr>
<tr class="memdesc:ab5a56ad3ace10afc97d1c1608e40ef0c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Default constructor.  <a href="#ab5a56ad3ace10afc97d1c1608e40ef0c"></a><br/></td></tr>
<tr class="separator:ab5a56ad3ace10afc97d1c1608e40ef0c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2abaea6e42eb24d9175a9f23d10aeed7"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_single_instance_checker.html#a2abaea6e42eb24d9175a9f23d10aeed7">wxSingleInstanceChecker</a> (const <a class="el" href="classwx_string.html">wxString</a> &amp;name, const <a class="el" href="classwx_string.html">wxString</a> &amp;path=<a class="el" href="interface_2wx_2string_8h.html#a9a321d587166a30017b608dd2d234033">wxEmptyString</a>)</td></tr>
<tr class="memdesc:a2abaea6e42eb24d9175a9f23d10aeed7"><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructor calling <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a>.  <a href="#a2abaea6e42eb24d9175a9f23d10aeed7"></a><br/></td></tr>
<tr class="separator:a2abaea6e42eb24d9175a9f23d10aeed7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7ed555c3c0ec52becbb84e3702607c0f"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_single_instance_checker.html#a7ed555c3c0ec52becbb84e3702607c0f">~wxSingleInstanceChecker</a> ()</td></tr>
<tr class="memdesc:a7ed555c3c0ec52becbb84e3702607c0f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Destructor frees the associated resources.  <a href="#a7ed555c3c0ec52becbb84e3702607c0f"></a><br/></td></tr>
<tr class="separator:a7ed555c3c0ec52becbb84e3702607c0f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa69725041ea6c0479f65f6b468a42f1e"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e">Create</a> (const <a class="el" href="classwx_string.html">wxString</a> &amp;name, const <a class="el" href="classwx_string.html">wxString</a> &amp;path=<a class="el" href="interface_2wx_2string_8h.html#a9a321d587166a30017b608dd2d234033">wxEmptyString</a>)</td></tr>
<tr class="memdesc:aa69725041ea6c0479f65f6b468a42f1e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize the object if it had been created using the default constructor.  <a href="#aa69725041ea6c0479f65f6b468a42f1e"></a><br/></td></tr>
<tr class="separator:aa69725041ea6c0479f65f6b468a42f1e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3cfc2177b3271480415c138e2edb5833"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_single_instance_checker.html#a3cfc2177b3271480415c138e2edb5833">CreateDefault</a> ()</td></tr>
<tr class="memdesc:a3cfc2177b3271480415c138e2edb5833"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calls <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> with default name.  <a href="#a3cfc2177b3271480415c138e2edb5833"></a><br/></td></tr>
<tr class="separator:a3cfc2177b3271480415c138e2edb5833"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ad3588a5ae39131a129f5b886236f6c40"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classwx_single_instance_checker.html#ad3588a5ae39131a129f5b886236f6c40">IsAnotherRunning</a> () const </td></tr>
<tr class="memdesc:ad3588a5ae39131a129f5b886236f6c40"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns <span class="literal">true</span> if another copy of this program is already running and <span class="literal">false</span> otherwise.  <a href="#ad3588a5ae39131a129f5b886236f6c40"></a><br/></td></tr>
<tr class="separator:ad3588a5ae39131a129f5b886236f6c40"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="ab5a56ad3ace10afc97d1c1608e40ef0c"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">wxSingleInstanceChecker::wxSingleInstanceChecker </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Default constructor. </p>
<p>You may call <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> after using it or directly call <a class="el" href="classwx_single_instance_checker.html#ad3588a5ae39131a129f5b886236f6c40" title="Returns true if another copy of this program is already running and false otherwise.">IsAnotherRunning()</a> in which case <a class="el" href="classwx_single_instance_checker.html#a3cfc2177b3271480415c138e2edb5833" title="Calls Create() with default name.">CreateDefault()</a> will be implicitly used. </p>

</div>
</div>
<a class="anchor" id="a2abaea6e42eb24d9175a9f23d10aeed7"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">wxSingleInstanceChecker::wxSingleInstanceChecker </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="classwx_string.html">wxString</a> &amp;&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classwx_string.html">wxString</a> &amp;&#160;</td>
          <td class="paramname"><em>path</em> = <code><a class="el" href="interface_2wx_2string_8h.html#a9a321d587166a30017b608dd2d234033">wxEmptyString</a></code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Constructor calling <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a>. </p>
<p>This constructor does exactly the same thing as <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> but doesn't allow to check for errors. </p>

</div>
</div>
<a class="anchor" id="a7ed555c3c0ec52becbb84e3702607c0f"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">wxSingleInstanceChecker::~wxSingleInstanceChecker </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Destructor frees the associated resources. </p>
<p>Note that it is not virtual, this class is not meant to be used polymorphically. </p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="aa69725041ea6c0479f65f6b468a42f1e"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool wxSingleInstanceChecker::Create </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="classwx_string.html">wxString</a> &amp;&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classwx_string.html">wxString</a> &amp;&#160;</td>
          <td class="paramname"><em>path</em> = <code><a class="el" href="interface_2wx_2string_8h.html#a9a321d587166a30017b608dd2d234033">wxEmptyString</a></code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize the object if it had been created using the default constructor. </p>
<p>Note that you can't call <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> more than once, so calling it if the non default ctor had been used is an error.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">name</td><td>Must be given and be as unique as possible. It is used as the mutex name under Win32 and the lock file name under Unix. <a class="el" href="classwx_app_console.html#a2bfe9c53c57d61f8b115705796f258eb" title="Returns the application name.">wxApp::GetAppName()</a> and <a class="el" href="group__group__funcmacro__networkuseros.html#gab1ebfcd4741550d6f7aa6f8a8952f4f3" title="This function returns the &quot;user id&quot; also known as &quot;login name&quot; under Unix (i.e.">wxGetUserId()</a> are commonly used to construct this parameter. </td></tr>
    <tr><td class="paramname">path</td><td>The path is optional and is ignored under Win32 and used as the directory to create the lock file in under Unix (default is <a class="el" href="group__group__funcmacro__networkuseros.html#gae426408d7b659be4db51cc8296af5e7a" title="Return the (current) user&#39;s home directory.">wxGetHomeDir()</a>).</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns <span class="literal">false</span> if initialization failed, it doesn't mean that another instance is running &ndash; use <a class="el" href="classwx_single_instance_checker.html#ad3588a5ae39131a129f5b886236f6c40" title="Returns true if another copy of this program is already running and false otherwise.">IsAnotherRunning()</a> to check for it.</dd></dl>
<dl class="section note"><dt>Note</dt><dd>One of possible reasons while <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> may fail on Unix is that the lock file used for checking already exists but was not created by the user. Therefore applications shouldn't treat failure of this function as fatal condition, because doing so would open them to the possibility of a Denial of Service attack. Instead, they should alert the user about the problem and offer to continue execution without checking if another instance is running. </dd></dl>

</div>
</div>
<a class="anchor" id="a3cfc2177b3271480415c138e2edb5833"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool wxSingleInstanceChecker::CreateDefault </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calls <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> with default name. </p>
<p>This method simply calls <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> with a string composed of <a class="el" href="classwx_app_console.html#a2bfe9c53c57d61f8b115705796f258eb" title="Returns the application name.">wxApp::GetAppName()</a> and <a class="el" href="group__group__funcmacro__networkuseros.html#gab1ebfcd4741550d6f7aa6f8a8952f4f3" title="This function returns the &quot;user id&quot; also known as &quot;login name&quot; under Unix (i.e.">wxGetUserId()</a>.</p>
<p>Because this method uses <a class="el" href="classwx_app_console.html#a2bfe9c53c57d61f8b115705796f258eb" title="Returns the application name.">wxApp::GetAppName()</a>, it may only be called after the global application was constructed.</p>
<dl class="section since"><dt>Since</dt><dd>2.9.1 </dd></dl>

</div>
</div>
<a class="anchor" id="ad3588a5ae39131a129f5b886236f6c40"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool wxSingleInstanceChecker::IsAnotherRunning </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Returns <span class="literal">true</span> if another copy of this program is already running and <span class="literal">false</span> otherwise. </p>
<p>Notice that if the object was created using the default constructor <a class="el" href="classwx_single_instance_checker.html#aa69725041ea6c0479f65f6b468a42f1e" title="Initialize the object if it had been created using the default constructor.">Create()</a> hadn't been called before this method, it will call <a class="el" href="classwx_single_instance_checker.html#a3cfc2177b3271480415c138e2edb5833" title="Calls Create() with default name.">CreateDefault()</a> automatically. </p>

</div>
</div>
</div><!-- contents -->

<address class="footer">
	<small>
		Generated on Thu Nov 27 2014 13:46:58 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
	</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>