Mercurial > hg > syntilista
annotate src/runguard.h @ 243:975eeb71576f rel-0_9_3
Bump version.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 08 May 2018 00:43:46 +0300 |
parents | 37d5f4329449 |
children |
rev | line source |
---|---|
228
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 // Taken and modified from https://stackoverflow.com/questions/5006547/qt-best-practice-for-a-single-instance-app-protection |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 #ifndef RUNGUARD_H |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 #define RUNGUARD_H |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #include <QObject> |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #include <QSharedMemory> |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include <QSystemSemaphore> |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 class RunGuard |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 { |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 public: |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 RunGuard(const QString &key); |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 ~RunGuard(); |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 bool isAnotherRunning(); |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 bool tryToRun(); |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 void release(); |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 private: |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 const QString key; |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 const QString memLockKey; |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 const QString sharedmemKey; |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 QSharedMemory sharedMem; |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 QSystemSemaphore memLock; |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 Q_DISABLE_COPY(RunGuard) |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 }; |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 #endif // RUNGUARD_H |