qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
profilelocker.h
Go to the documentation of this file.
1 /*
2  Copyright © 2015-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 #pragma once
22 
23 #include <QLockFile>
24 #include <memory>
25 
27 {
28 private:
29  ProfileLocker() = delete;
30 
31 public:
32  static bool isLockable(QString profile);
33  static bool lock(QString profile);
34  static void unlock();
35  static bool hasLock();
36  static QString getCurLockName();
37  static void assertLock();
38 
39 private:
40  static QString lockPathFromName(const QString& name);
41  static void deathByBrokenLock();
42 
43 private:
44  static std::unique_ptr<QLockFile> lockfile;
45  static QString curLockName;
46 };
ProfileLocker::unlock
static void unlock()
Releases the lock on the current profile.
Definition: profilelocker.cpp:88
ProfileLocker::getCurLockName
static QString getCurLockName()
Get current locked profile name.
Definition: profilelocker.cpp:145
ProfileLocker
Locks a Tox profile so that multiple instances can not use the same profile. Only one lock can be acq...
Definition: profilelocker.h:26
ProfileLocker::deathByBrokenLock
static void deathByBrokenLock()
Print an error then exit immediately.
Definition: profilelocker.cpp:126
ProfileLocker::lock
static bool lock(QString profile)
Tries to acquire the lock on a profile, will not block.
Definition: profilelocker.cpp:67
ProfileLocker::ProfileLocker
ProfileLocker()=delete
ProfileLocker::assertLock
static void assertLock()
Check that we actually own the lock. In case the file was deleted on disk, restore it....
Definition: profilelocker.cpp:104
ProfileLocker::lockfile
static std::unique_ptr< QLockFile > lockfile
Definition: profilelocker.h:44
ProfileLocker::hasLock
static bool hasLock()
Chacks, that profile locked.
Definition: profilelocker.cpp:136
ProfileLocker::isLockable
static bool isLockable(QString profile)
Checks if a profile is currently locked by another instance. If we own the lock, we consider it locka...
Definition: profilelocker.cpp:52
ProfileLocker::lockPathFromName
static QString lockPathFromName(const QString &name)
Definition: profilelocker.cpp:39
ProfileLocker::curLockName
static QString curLockName
Definition: profilelocker.h:45