Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /* |
---|---|
2 | This file is part of the KDE libraries |
3 | Copyright (c) 2004 Waldo Bastian <bastian@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License version 2 as published by the Free Software Foundation. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef KLOCKFILE_H |
21 | #define KLOCKFILE_H |
22 | |
23 | #include <kdecore_export.h> |
24 | #include <ksharedptr.h> |
25 | #include <kglobal.h> |
26 | |
27 | class QString; |
28 | |
29 | /** |
30 | * \class KLockFile klockfile.h <KLockFile> |
31 | * |
32 | * The KLockFile class provides NFS safe lockfiles. |
33 | * |
34 | * @author Waldo Bastian <bastian@kde.org> |
35 | */ |
36 | class KDECORE_EXPORT KLockFile : public KShared |
37 | { |
38 | public: |
39 | typedef KSharedPtr<KLockFile> Ptr; |
40 | |
41 | explicit KLockFile(const QString &file, const KComponentData &componentName = KGlobal::mainComponent()); |
42 | |
43 | /** |
44 | * Destroys the object, releasing the lock if held |
45 | **/ |
46 | ~KLockFile(); |
47 | |
48 | /** |
49 | * Possible return values of the lock function. |
50 | */ |
51 | enum LockResult { |
52 | /** |
53 | * Lock was acquired successfully |
54 | */ |
55 | LockOK = 0, |
56 | |
57 | /** |
58 | * The lock could not be acquired because it is held by another process |
59 | */ |
60 | LockFail, |
61 | |
62 | /** |
63 | * The lock could not be acquired due to an error |
64 | */ |
65 | LockError, |
66 | |
67 | /** |
68 | * A stale lock has been detected |
69 | */ |
70 | LockStale |
71 | }; |
72 | |
73 | enum LockFlag { |
74 | /** |
75 | * Return immediately, do not wait for the lock to become available |
76 | */ |
77 | NoBlockFlag = 1, |
78 | |
79 | /** |
80 | * Automatically remove a lock when a lock is detected that is stale |
81 | * for more than staleTime() seconds, or if the process that created it |
82 | * is not running anymore. |
83 | */ |
84 | ForceFlag = 2 |
85 | }; |
86 | Q_DECLARE_FLAGS(LockFlags, LockFlag) |
87 | |
88 | /** |
89 | * Attempt to acquire the lock |
90 | * |
91 | * @param flags A set of @ref LockFlag values OR'ed together. |
92 | */ |
93 | LockResult lock(LockFlags flags=LockFlags()); |
94 | |
95 | /** |
96 | * Returns whether the lock is held or not |
97 | */ |
98 | bool isLocked() const; |
99 | |
100 | /** |
101 | * Release the lock |
102 | */ |
103 | void unlock(); |
104 | |
105 | /** |
106 | * Return the time in seconds after which a lock is considered stale |
107 | * The default is 30. |
108 | */ |
109 | int staleTime() const; |
110 | |
111 | /** |
112 | * Set the time in seconds after which a lock is considered stale |
113 | */ |
114 | void setStaleTime(int _staleTime); |
115 | |
116 | /** |
117 | * Returns the pid, hostname and appname of the process holding |
118 | * the lock after the lock functon has returned with LockStale. |
119 | * @returns false if the pid and hostname could not be determined |
120 | */ |
121 | bool getLockInfo(int &pid, QString &hostname, QString &appname); |
122 | |
123 | private: |
124 | class Private; |
125 | Private *const d; |
126 | }; |
127 | |
128 | Q_DECLARE_OPERATORS_FOR_FLAGS(KLockFile::LockFlags) |
129 | |
130 | #endif |
131 |
Warning: That file was not part of the compilation database. It may have many parsing errors.