1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtCore module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QSHAREDMEMORY_H |
41 | #define QSHAREDMEMORY_H |
42 | |
43 | #include <QtCore/qglobal.h> |
44 | #ifndef QT_NO_QOBJECT |
45 | # include <QtCore/qobject.h> |
46 | #else |
47 | # include <QtCore/qobjectdefs.h> |
48 | # include <QtCore/qscopedpointer.h> |
49 | # include <QtCore/qstring.h> |
50 | #endif |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | |
54 | #ifndef QT_NO_SHAREDMEMORY |
55 | |
56 | class QSharedMemoryPrivate; |
57 | |
58 | class Q_CORE_EXPORT QSharedMemory |
59 | #ifndef QT_NO_QOBJECT |
60 | : public QObject |
61 | #endif |
62 | { |
63 | #ifndef QT_NO_QOBJECT |
64 | Q_OBJECT |
65 | #endif |
66 | Q_DECLARE_PRIVATE(QSharedMemory) |
67 | |
68 | public: |
69 | enum AccessMode |
70 | { |
71 | ReadOnly, |
72 | ReadWrite |
73 | }; |
74 | |
75 | enum SharedMemoryError |
76 | { |
77 | NoError, |
78 | PermissionDenied, |
79 | InvalidSize, |
80 | KeyError, |
81 | AlreadyExists, |
82 | NotFound, |
83 | LockError, |
84 | OutOfResources, |
85 | UnknownError |
86 | }; |
87 | |
88 | #ifndef QT_NO_QOBJECT |
89 | QSharedMemory(QObject *parent = nullptr); |
90 | QSharedMemory(const QString &key, QObject *parent = nullptr); |
91 | #else |
92 | QSharedMemory(); |
93 | QSharedMemory(const QString &key); |
94 | static QString tr(const char * str) |
95 | { |
96 | return QString::fromLatin1(str); |
97 | } |
98 | #endif |
99 | ~QSharedMemory(); |
100 | |
101 | void setKey(const QString &key); |
102 | QString key() const; |
103 | void setNativeKey(const QString &key); |
104 | QString nativeKey() const; |
105 | |
106 | bool create(int size, AccessMode mode = ReadWrite); |
107 | int size() const; |
108 | |
109 | bool attach(AccessMode mode = ReadWrite); |
110 | bool isAttached() const; |
111 | bool detach(); |
112 | |
113 | void *data(); |
114 | const void* constData() const; |
115 | const void *data() const; |
116 | |
117 | #ifndef QT_NO_SYSTEMSEMAPHORE |
118 | bool lock(); |
119 | bool unlock(); |
120 | #endif |
121 | |
122 | SharedMemoryError error() const; |
123 | QString errorString() const; |
124 | |
125 | private: |
126 | Q_DISABLE_COPY(QSharedMemory) |
127 | #ifdef QT_NO_QOBJECT |
128 | QScopedPointer<QSharedMemoryPrivate> d_ptr; |
129 | #endif |
130 | }; |
131 | |
132 | #endif // QT_NO_SHAREDMEMORY |
133 | |
134 | QT_END_NAMESPACE |
135 | |
136 | #endif // QSHAREDMEMORY_H |
137 | |
138 | |