All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions
Qtilities::Core::FileLocker Class Reference

The FileLocker class provides a simple mechanism to create and manage file locking using a .lck file with lock information. More...

#include <FileLocker.h>

List of all members.

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.

Detailed Description

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.


Constructor & Destructor Documentation

FileLocker::FileLocker ( const QString &  lock_extension = "lck")

Default constructor.

Parameters:
lock_extensionThe file extension to use for lock files.

Member Function Documentation

QString FileLocker::lastLockDateTime ( QString  file_path,
QString *  errorMsg = 0 
) const
virtual

Gets the date and time when a lock was created.

Parameters:
file_pathThe path of the file that is locked, not the lock file itself.
errorMsgWhen valid, will be populated with error message if the function fails.
Returns:
The last lock date and time.
QString FileLocker::lastLockHostName ( QString  file_path,
QString *  errorMsg = 0 
) const
virtual

Gets the host name that was used to lock a file.

Parameters:
file_pathThe path of the file that is locked, not the lock file itself.
errorMsgWhen valid, will be populated with error message if the function fails.
Returns:
The last lock host name.
QString FileLocker::lastLockSummary ( QString  file_path,
const QString &  line_break_char = "\n",
QString *  errorMsg = 0 
) const
virtual

Provides a lock summary string for a lock on a file.

Parameters:
file_pathThe path of the file that is locked, not the lock file itself.
line_break_charThe line break characters to use in the summary text.
errorMsgWhen valid, will be populated with error message if the function fails.
Returns:
The last lock summary.
bool FileLocker::lockFile ( const QString &  file_path,
QString *  errorMsg = 0 
)
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.

Parameters:
file_pathThe path of the file that must be locked.
errorMsgWhen valid, will be populated with error message if the function fails.
Returns:
True if successfull, false otherwise.
bool FileLocker::unlockFile ( const QString &  file_path,
QString *  errorMsg = 0 
)
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.

Parameters:
file_pathThe path of the file that must be locked.
errorMsgWhen valid, will be populated with error message if the function fails.
Returns:
True if successfull, false otherwise.


Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé