dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
runguard.h
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  *
27  * Additional note on redistribution: The copyright and license notices above
28  * must be maintained in each individual source file that is a derivative work
29  * of this source file; otherwise redistribution is prohibited.
30  */
31 
32 #ifndef RUNGUARD_H
33 #define RUNGUARD_H
34 
35 #include "runguard_global.h"
36 
37 #include <QObject>
38 #include <QSharedMemory>
39 #include <QSystemSemaphore>
40 
41 
42 class RUNGUARD_EXPORT RunGuard
43 {
44 
45 public:
51  static RunGuard &instance(const QString &key);
52 
57  bool tryToRun();
62  quint64 secondaryAttempts();
63 
64 private:
65  const QString key;
66  const QString memLockKey;
67  const QString sharedmemKey;
68 
69  QSharedMemory sharedMem;
70  QSystemSemaphore memLock;
71 
72  RunGuard(const QString &key = QString());
73  ~RunGuard();
74 
75  bool isAnotherRunning();
76  void release();
77 
78  Q_DISABLE_COPY(RunGuard)
79 };
80 
81 #endif // RUNGUARD_H
82