The FileLocker class provides a simple mechanism to create and manage file locking using a .lck file with lock information. More...
#include <FileLocker.h>
Public Member Functions | |
FileLocker (const QString &lock_extension="lck") | |
Default constructor. | |
virtual bool | isFileLocked (const QString &file_path) const |
Checks if the given file is locked. | |
virtual QString | lastLockDateTime (QString file_path, QString *errorMsg=0) const |
Gets the date and time when a lock was created. | |
virtual QString | lastLockHostName (QString file_path, QString *errorMsg=0) const |
Gets the host name that was used to lock a file. | |
virtual QString | lastLockSummary (QString file_path, const QString &line_break_char="\n", QString *errorMsg=0) const |
Provides a lock summary string for a lock on a file. | |
virtual bool | lockFile (const QString &file_path, QString *errorMsg=0) |
Locks a file. | |
virtual bool | unlockFile (const QString &file_path, QString *errorMsg=0) |
Unlocks a file. |
The FileLocker class provides a simple mechanism to create and manage file locking using a .lck file with lock information.
The .lck file created when locking a file will contain the date and time that the lock was created, as well as the hostname of the computer used to lock the file.
This class was added in Qtilities v1.2.
FileLocker::FileLocker | ( | const QString & | lock_extension = "lck" | ) |
Default constructor.
lock_extension | The file extension to use for lock files. |
|
virtual |
Gets the date and time when a lock was created.
file_path | The path of the file that is locked, not the lock file itself. |
errorMsg | When valid, will be populated with error message if the function fails. |
|
virtual |
Gets the host name that was used to lock a file.
file_path | The path of the file that is locked, not the lock file itself. |
errorMsg | When valid, will be populated with error message if the function fails. |
|
virtual |
Provides a lock summary string for a lock on a file.
file_path | The path of the file that is locked, not the lock file itself. |
line_break_char | The line break characters to use in the summary text. |
errorMsg | When valid, will be populated with error message if the function fails. |
|
virtual |
Locks a file.
This function will create a .lck file with the same name as the file name provided. If the file is already locked, or the .lck file can't be created for some reason, it will return false and set the errorMsg parameter to the reason why the lock failed.
file_path | The path of the file that must be locked. |
errorMsg | When valid, will be populated with error message if the function fails. |
|
virtual |
Unlocks a file.
This function will look for a .lck file with the same name as the file name provided. If the file exists, it means that the file was locked and this function will attempt to lock it. If the .lck file can't be removed for some reason, it will return false and set the errorMsg parameter to the reason why the lock failed.
file_path | The path of the file that must be locked. |
errorMsg | When valid, will be populated with error message if the function fails. |
Qtilities : Reference Documentation | Back to top |
Copyright © 2009-2013, Jaco Naudé
|