Just Intonation  Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
runguard.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * JustIntonation is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //============================================================================
21 // RunGuard, preventing multiple instances of the application
22 //============================================================================
23 
24 #ifndef RUNGUARD_HPP
25 #define RUNGUARD_HPP
26 
27 #include <QObject>
28 #include <QSharedMemory>
29 #include <QSystemSemaphore>
30 
35 
51 
52 class RunGuard : public QObject
53 {
54  Q_OBJECT
55 public:
56  RunGuard (const QString &mKey);
57  ~RunGuard();
58 
59  bool anotherInstanceIsRunning (bool showMessage=true); // Is another instance running?
60 
61 private:
62  QString generateKeyHash (const QString& mKey, const QString& salt);
63  void release();
64 
65  const QString mKey;
66  const QString mMemLockKey;
67  const QString mSharedMemKey;
68  QSharedMemory mSharedMem;
69  QSystemSemaphore mMemLock;
70 };
71 
72 #endif // RUNGUARD_HPP
73 
RunGuard(const QString &mKey)
Constructor for a runguard.
Definition: runguard.cpp:48
const QString mKey
Name assigned to the instance.
Definition: runguard.h:65
const QString mMemLockKey
Key labelling the semaphore lock.
Definition: runguard.h:66
QString generateKeyHash(const QString &mKey, const QString &salt)
Generate hash string for a given keys.
Definition: runguard.cpp:121
void release()
Release the running application.
Definition: runguard.cpp:99
QSharedMemory mSharedMem
Shared memory labelled by a given key.
Definition: runguard.h:68
Class for checking whether the application is already running.
Definition: runguard.h:52
~RunGuard()
RunGuard destructor.
Definition: runguard.cpp:80
bool anotherInstanceIsRunning(bool showMessage=true)
Check whether another instance of the application is running.
Definition: runguard.cpp:148
QSystemSemaphore mMemLock
Lock used when shared memory is accessed.
Definition: runguard.h:69
const QString mSharedMemKey
Key labelling the shared memory.
Definition: runguard.h:67