Just Intonation
Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
|
Class for checking whether the application is already running. More...
#include <runguard.h>
Public Member Functions | |
RunGuard (const QString &mKey) | |
Constructor for a runguard. More... | |
~RunGuard () | |
RunGuard destructor. More... | |
bool | anotherInstanceIsRunning (bool showMessage=true) |
Check whether another instance of the application is running. More... | |
Private Member Functions | |
QString | generateKeyHash (const QString &mKey, const QString &salt) |
Generate hash string for a given keys. More... | |
void | release () |
Release the running application. More... | |
Private Attributes | |
const QString | mKey |
Name assigned to the instance. More... | |
const QString | mMemLockKey |
Key labelling the semaphore lock. More... | |
const QString | mSharedMemKey |
Key labelling the shared memory. More... | |
QSharedMemory | mSharedMem |
Shared memory labelled by a given key. More... | |
QSystemSemaphore | mMemLock |
Lock used when shared memory is accessed. More... | |
Class for checking whether the application is already running.
Creating an instance of this class prevents the system from starting serveral instances of the application.
Internally the instances communicate via a QSharedMemory labelled by a given key. The access to this memory is mutexted by a QSystemSemaphore.
This mechanism is not needed on tablets and smartphones, where the operating system itself makes sure that only one instance can be started. Therefore, the essential code of this class is only compiled if the Q_OS_DESKTOP label is set in the case of a desktop application.
The runguard is based on a similar one developed by Christoph Wick in the Entropy Piano Tuner.
Definition at line 52 of file runguard.h.
RunGuard::RunGuard | ( | const QString & | key | ) |
Constructor for a runguard.
The constructor creates a flag in the shared memory indicating that the application is running. This allows other instances to detect an already running application.
key | : String naming the run guard (e.g. myapp_runguard) |
Definition at line 48 of file runguard.cpp.
RunGuard::~RunGuard | ( | ) |
RunGuard destructor.
The destructor releases the blocking label. Since the destructor is is called at the end of the main() function, this ensures that the label is automatically removed as soon as the application stops.
Definition at line 80 of file runguard.cpp.
bool RunGuard::anotherInstanceIsRunning | ( | bool | showMessage = true | ) |
Check whether another instance of the application is running.
This function first checks whether the own instance is already running. Then it checks whether another application has already created the shared memory, indicating that another instance of the same applicaiton is running.
Definition at line 148 of file runguard.cpp.
|
private |
Generate hash string for a given keys.
This function converts a key (entropypianotuner_runguard) and a second key extenstion (e.g._memLockKey) into a hash string.
key | : String holding the key |
salt | : String holding the key extension |
Definition at line 121 of file runguard.cpp.
|
private |
Release the running application.
This function detaches the application from the shared memory, removing the blocking label. It has to be called when the application terminates.
Definition at line 99 of file runguard.cpp.
|
private |
Name assigned to the instance.
Definition at line 65 of file runguard.h.
|
private |
Lock used when shared memory is accessed.
Definition at line 69 of file runguard.h.
|
private |
Key labelling the semaphore lock.
Definition at line 66 of file runguard.h.
|
private |
Shared memory labelled by a given key.
Definition at line 68 of file runguard.h.
|
private |
Key labelling the shared memory.
Definition at line 67 of file runguard.h.