QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RunGuard.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QString>
4#include <QtCore/QLockFile>
5
7{
8public:
9 explicit RunGuard(const QString &key);
10 ~RunGuard();
11
12 // Returns true if another instance holds the lock.
13 bool isAnotherRunning();
14
15 // Attempts to acquire the single-instance lock.
16 bool tryToRun();
17
18 // Releases the lock if held.
19 void release();
20
21 // Optional: returns true if this instance currently holds the lock.
22 bool isLocked() const { return _lockFile.isLocked(); }
23
24private:
25 static QString generateKeyHash(const QString &key, const QString &salt);
26 static QString lockDir();
27
28 const QString _key;
29 const QString _lockFilePath;
30 QLockFile _lockFile;
31
32 Q_DISABLE_COPY(RunGuard)
33};
~RunGuard()
Definition RunGuard.cc:16
void release()
Definition RunGuard.cc:55
bool isLocked() const
Definition RunGuard.h:22
bool tryToRun()
Definition RunGuard.cc:50
bool isAnotherRunning()
Definition RunGuard.cc:21