qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
Static Public Member Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
ProfileLocker Class Reference

Locks a Tox profile so that multiple instances can not use the same profile. Only one lock can be acquired at the same time, which means that there is little need for manually unlocking. The current lock will expire if you exit or acquire a new one. More...

#include <profilelocker.h>

Collaboration diagram for ProfileLocker:
Collaboration graph

Static Public Member Functions

static bool isLockable (QString profile)
 Checks if a profile is currently locked by another instance. If we own the lock, we consider it lockable. There is no guarantee that the result will still be valid by the time it is returned, this is provided on a best effort basis. More...
 
static bool lock (QString profile)
 Tries to acquire the lock on a profile, will not block. More...
 
static void unlock ()
 Releases the lock on the current profile. More...
 
static bool hasLock ()
 Chacks, that profile locked. More...
 
static QString getCurLockName ()
 Get current locked profile name. More...
 
static void assertLock ()
 Check that we actually own the lock. In case the file was deleted on disk, restore it. If we can't get a lock, exit qTox immediately. If we never had a lock in the first place, exit immediately. More...
 

Private Member Functions

 ProfileLocker ()=delete
 

Static Private Member Functions

static QString lockPathFromName (const QString &name)
 
static void deathByBrokenLock ()
 Print an error then exit immediately. More...
 

Static Private Attributes

static std::unique_ptr< QLockFile > lockfile
 
static QString curLockName
 

Detailed Description

Locks a Tox profile so that multiple instances can not use the same profile. Only one lock can be acquired at the same time, which means that there is little need for manually unlocking. The current lock will expire if you exit or acquire a new one.

Definition at line 26 of file profilelocker.h.

Constructor & Destructor Documentation

◆ ProfileLocker()

ProfileLocker::ProfileLocker ( )
privatedelete

Member Function Documentation

◆ assertLock()

void ProfileLocker::assertLock ( )
static

Check that we actually own the lock. In case the file was deleted on disk, restore it. If we can't get a lock, exit qTox immediately. If we never had a lock in the first place, exit immediately.

Definition at line 104 of file profilelocker.cpp.

Here is the caller graph for this function:

◆ deathByBrokenLock()

void ProfileLocker::deathByBrokenLock ( )
staticprivate

Print an error then exit immediately.

Definition at line 126 of file profilelocker.cpp.

◆ getCurLockName()

QString ProfileLocker::getCurLockName ( )
static

Get current locked profile name.

Returns
Return the name of the currently loaded profile, a null string if there is none.

Definition at line 145 of file profilelocker.cpp.

Here is the caller graph for this function:

◆ hasLock()

bool ProfileLocker::hasLock ( )
static

Chacks, that profile locked.

Returns
Returns true if we're currently holding a lock.

Definition at line 136 of file profilelocker.cpp.

Here is the caller graph for this function:

◆ isLockable()

bool ProfileLocker::isLockable ( QString  profile)
static

Checks if a profile is currently locked by another instance. If we own the lock, we consider it lockable. There is no guarantee that the result will still be valid by the time it is returned, this is provided on a best effort basis.

Parameters
profileProfile name to check.
Returns
True, if profile locked, false otherwise.

Definition at line 52 of file profilelocker.cpp.

Here is the caller graph for this function:

◆ lock()

bool ProfileLocker::lock ( QString  profile)
static

Tries to acquire the lock on a profile, will not block.

Parameters
profileProfile to lock.
Returns
Returns true if we already own the lock.

Definition at line 67 of file profilelocker.cpp.

Here is the caller graph for this function:

◆ lockPathFromName()

QString ProfileLocker::lockPathFromName ( const QString &  name)
staticprivate

Definition at line 39 of file profilelocker.cpp.

Here is the call graph for this function:

◆ unlock()

void ProfileLocker::unlock ( )
static

Releases the lock on the current profile.

Definition at line 88 of file profilelocker.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ curLockName

QString ProfileLocker::curLockName
staticprivate

Definition at line 45 of file profilelocker.h.

◆ lockfile

unique_ptr< QLockFile > ProfileLocker::lockfile
staticprivate

Definition at line 44 of file profilelocker.h.


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