digiKam
filereadwritelock.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2012-01-29
7  * Description : Intra-process file i/o lock
8  *
9  * Copyright (C) 2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_FILE_READ_WRITE_LOCK_H
25 #define DIGIKAM_FILE_READ_WRITE_LOCK_H
26 
27 // Qt includes
28 
29 #include <QString>
30 #include <QTemporaryFile>
31 
32 // Local includes
33 
34 #include "digikam_export.h"
35 
36 namespace Digikam
37 {
38 
39 class FileReadWriteLockPriv;
40 
41 class DIGIKAM_EXPORT FileReadWriteLockKey
42 {
43 public:
44 
45  explicit FileReadWriteLockKey(const QString& filePath);
47 
48  void lockForRead();
49  void lockForWrite();
50  bool tryLockForRead();
51  bool tryLockForRead(int timeout);
52  bool tryLockForWrite();
53  bool tryLockForWrite(int timeout);
54  void unlock();
55 
56 private:
57 
58  FileReadWriteLockPriv* d;
59 };
60 
61 // ----------------------------------------------------------------------
62 
63 class DIGIKAM_EXPORT FileReadLocker
64 {
65 public:
66 
67  explicit FileReadLocker(const QString& filePath);
68  ~FileReadLocker();
69 
70 private:
71 
72  FileReadWriteLockPriv* d;
73 };
74 
75 // ----------------------------------------------------------------------
76 
77 class DIGIKAM_EXPORT FileWriteLocker
78 {
79 public:
80 
81  explicit FileWriteLocker(const QString& filePath);
82  ~FileWriteLocker();
83 
84 private:
85 
86  FileReadWriteLockPriv* d;
87 };
88 
89 // ----------------------------------------------------------------------
90 
91 class DIGIKAM_EXPORT SafeTemporaryFile : public QTemporaryFile
92 {
93  Q_OBJECT
94 
95 public:
96 
97  explicit SafeTemporaryFile(const QString& templ);
99 
100  bool open();
101 
102  QString safeFilePath() const;
103 
104 protected:
105 
106  bool open(QIODevice::OpenMode) override;
107 
108 private:
109 
110  // Disable
111  SafeTemporaryFile(QObject*) = delete;
112 
113  QString m_templ;
114 };
115 
116 } // namespace Digikam
117 
118 #endif // DIGIKAM_FILE_READ_WRITE_LOCK_H
Definition: filereadwritelock.h:64
Definition: filereadwritelock.h:42
Definition: filereadwritelock.h:78
Definition: filereadwritelock.h:92
Definition: datefolderview.cpp:43