2022-10-08 03:28:20 +03:00
|
|
|
/* This file is part of the KDE libraries
|
|
|
|
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KLOCKFILE_H
|
|
|
|
#define KLOCKFILE_H
|
|
|
|
|
2022-10-08 13:57:07 +03:00
|
|
|
#include <kdecore_export.h>
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2017-06-24 08:06:43 +00:00
|
|
|
#include <QString>
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2022-10-08 03:28:20 +03:00
|
|
|
class KLockFilePrivate;
|
|
|
|
|
2014-11-13 01:04:59 +02:00
|
|
|
/**
|
|
|
|
* \class KLockFile klockfile.h <KLockFile>
|
|
|
|
*
|
|
|
|
* The KLockFile class provides NFS safe lockfiles.
|
|
|
|
*
|
2022-10-08 03:28:20 +03:00
|
|
|
* @author Ivailo Monev <xakepa10@gmail.com>
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
2022-10-08 03:28:20 +03:00
|
|
|
class KDECORE_EXPORT KLockFile
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
public:
|
2022-10-08 03:28:20 +03:00
|
|
|
/*!
|
2022-10-08 06:54:40 +03:00
|
|
|
@brief Creates the object, does not attempt to acquire the lock
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
2022-10-08 03:28:20 +03:00
|
|
|
KLockFile(const QString &file);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@brief Destroys the object, releasing the lock if held
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
2022-10-08 03:28:20 +03:00
|
|
|
~KLockFile();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2022-10-08 03:28:20 +03:00
|
|
|
/*!
|
2023-09-09 00:46:42 +03:00
|
|
|
@brief Attempts to acquire the lock
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
2023-09-09 00:46:42 +03:00
|
|
|
bool tryLock();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2022-10-08 03:28:20 +03:00
|
|
|
/*!
|
2023-09-09 00:46:42 +03:00
|
|
|
@brief Acquires the lock
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
2023-09-09 00:46:42 +03:00
|
|
|
void lock();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2022-10-08 03:28:20 +03:00
|
|
|
/*!
|
|
|
|
@brief Returns whether the lock is held or not
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
2022-10-08 03:28:20 +03:00
|
|
|
bool isLocked() const;
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2022-10-08 03:28:20 +03:00
|
|
|
/*!
|
|
|
|
@brief Release the lock
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
2022-10-08 03:28:20 +03:00
|
|
|
void unlock();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
private:
|
2022-10-08 03:28:20 +03:00
|
|
|
Q_DISABLE_COPY(KLockFile);
|
|
|
|
KLockFilePrivate *const d;
|
2014-11-13 01:04:59 +02:00
|
|
|
};
|
|
|
|
|
2023-09-09 00:46:42 +03:00
|
|
|
#endif // KLOCKFILE_H
|