Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RunGuard Class Reference

Class for checking whether the application is already running. More...

#include <runguard.h>

Public Member Functions

 RunGuard (const QString &key)
 Constructor for a run guard. More...
 
 ~RunGuard ()
 
bool isAnotherRunning ()
 Check whether another instance of the application is running. More...
 
bool tryToRun ()
 Try to run the applicaiton, return false if another instance is running. More...
 
void release ()
 Release the running application. More...
 

Private Member Functions

QString generateKeyHash (const QString &key, const QString &salt)
 Generate hash string for a given keys. More...
 

Private Attributes

const QString key
 Name assigned to the instance. More...
 
const QString memLockKey
 Key labelling the semaphore lock. More...
 
const QString sharedmemKey
 Key labelling the shared memory. More...
 
QSharedMemory sharedMem
 Shared memory labelled by a given key. More...
 
QSystemSemaphore memLock
 Lock used when shared memory is accessed. More...
 

Detailed Description

Class for checking whether the application is already running.

An object of this class can be used to prevent the system from starting serveral instances of the application. There should be no more than one open window of the EPT at a given time.

Internally the instances communicate via a QSharedMemory labelled by a given key. The access to this memory is mutexted by a QSystemSemaphore.

Definition at line 42 of file runguard.h.

Constructor & Destructor Documentation

RunGuard::RunGuard ( const QString &  key)

Constructor for a run guard.

Parameters
key: String naming the run guard (e.g. entropypianotuner_runguard)

Definition at line 39 of file runguard.cpp.

RunGuard::~RunGuard ( )
inline

Definition at line 46 of file runguard.h.

+ Here is the call graph for this function:

Member Function Documentation

QString RunGuard::generateKeyHash ( const QString &  key,
const QString &  salt 
)
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.

Parameters
key: String holding the key
salt: String holding the key extension
Returns
: String containg the hash

Definition at line 64 of file runguard.cpp.

bool RunGuard::isAnotherRunning ( )

Check whether another instance of the application is running.

This function checks first 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.

Returns
Boolean indicating whether another instance of the same application is running.

Definition at line 91 of file runguard.cpp.

void RunGuard::release ( )

Release the running application.

This function detaches the application from the shared memery. It has to be called when the application terminates.

Definition at line 144 of file runguard.cpp.

bool RunGuard::tryToRun ( )

Try to run the applicaiton, return false if another instance is running.

This function tries to create the shared memory and attach itself to it, indicating that this is the running instance of the EPT-

Returns
True if successful, false if another application is running.

Definition at line 122 of file runguard.cpp.

+ Here is the call graph for this function:

Member Data Documentation

const QString RunGuard::key
private

Name assigned to the instance.

Definition at line 55 of file runguard.h.

QSystemSemaphore RunGuard::memLock
private

Lock used when shared memory is accessed.

Definition at line 60 of file runguard.h.

const QString RunGuard::memLockKey
private

Key labelling the semaphore lock.

Definition at line 56 of file runguard.h.

QSharedMemory RunGuard::sharedMem
private

Shared memory labelled by a given key.

Definition at line 59 of file runguard.h.

const QString RunGuard::sharedmemKey
private

Key labelling the shared memory.

Definition at line 57 of file runguard.h.


The documentation for this class was generated from the following files: