Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | QString | - |
8 | QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, | - |
9 | const QString &prefix) | - |
10 | { | - |
11 | if (key.isEmpty()) evaluated: key.isEmpty() yes Evaluation Count:1 | yes Evaluation Count:46 |
| 1-46 |
12 | return QString(); executed: return QString(); Execution Count:1 | 1 |
13 | | - |
14 | QString result = prefix; | - |
15 | | - |
16 | QString part1 = key; | - |
17 | part1.replace(QRegExp(QLatin1String("[^A-Za-z]")), QString()); | - |
18 | result.append(part1); | - |
19 | | - |
20 | QByteArray hex = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Sha1).toHex(); | - |
21 | result.append(QLatin1String(hex)); | - |
22 | | - |
23 | | - |
24 | | - |
25 | return QDir::tempPath() + QLatin1Char('/') + result; executed: return QDir::tempPath() + QLatin1Char('/') + result; Execution Count:46 | 46 |
26 | | - |
27 | } | - |
28 | QSharedMemory::QSharedMemory(QObject *parent) | - |
29 | : QObject(*new QSharedMemoryPrivate, parent) | - |
30 | { | - |
31 | } executed: } Execution Count:1 | 1 |
32 | QSharedMemory::QSharedMemory(const QString &key, QObject *parent) | - |
33 | : QObject(*new QSharedMemoryPrivate, parent) | - |
34 | { | - |
35 | setKey(key); | - |
36 | } | 0 |
37 | QSharedMemory::~QSharedMemory() | - |
38 | { | - |
39 | setKey(QString()); | - |
40 | } executed: } Execution Count:1 | 1 |
41 | void QSharedMemory::setKey(const QString &key) | - |
42 | { | - |
43 | QSharedMemoryPrivate * const d = d_func(); | - |
44 | if (key == d->key && d->makePlatformSafeKey(key) == d->nativeKey) partially evaluated: key == d->key yes Evaluation Count:1 | no Evaluation Count:0 |
partially evaluated: d->makePlatformSafeKey(key) == d->nativeKey yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
45 | return; executed: return; Execution Count:1 | 1 |
46 | | - |
47 | if (isAttached()) never evaluated: isAttached() | 0 |
48 | detach(); never executed: detach(); | 0 |
49 | d->cleanHandle(); | - |
50 | d->key = key; | - |
51 | d->nativeKey = d->makePlatformSafeKey(key); | - |
52 | } | 0 |
53 | void QSharedMemory::setNativeKey(const QString &key) | - |
54 | { | - |
55 | QSharedMemoryPrivate * const d = d_func(); | - |
56 | if (key == d->nativeKey && d->key.isNull()) never evaluated: key == d->nativeKey never evaluated: d->key.isNull() | 0 |
57 | return; | 0 |
58 | | - |
59 | if (isAttached()) never evaluated: isAttached() | 0 |
60 | detach(); never executed: detach(); | 0 |
61 | d->cleanHandle(); | - |
62 | d->key = QString(); | - |
63 | d->nativeKey = key; | - |
64 | } | 0 |
65 | | - |
66 | bool QSharedMemoryPrivate::initKey() | - |
67 | { | - |
68 | if (!cleanHandle()) never evaluated: !cleanHandle() | 0 |
69 | return false; never executed: return false; | 0 |
70 | | - |
71 | systemSemaphore.setKey(QString(), 1); | - |
72 | systemSemaphore.setKey(key, 1); | - |
73 | if (systemSemaphore.error() != QSystemSemaphore::NoError) { never evaluated: systemSemaphore.error() != QSystemSemaphore::NoError | 0 |
74 | QString function = QLatin1String("QSharedMemoryPrivate::initKey"); | - |
75 | errorString = QSharedMemory::tr("%1: unable to set key on lock").arg(function); | - |
76 | switch(systemSemaphore.error()) { | - |
77 | case QSystemSemaphore::PermissionDenied: | - |
78 | error = QSharedMemory::PermissionDenied; | - |
79 | break; | 0 |
80 | case QSystemSemaphore::KeyError: | - |
81 | error = QSharedMemory::KeyError; | - |
82 | break; | 0 |
83 | case QSystemSemaphore::AlreadyExists: | - |
84 | error = QSharedMemory::AlreadyExists; | - |
85 | break; | 0 |
86 | case QSystemSemaphore::NotFound: | - |
87 | error = QSharedMemory::NotFound; | - |
88 | break; | 0 |
89 | case QSystemSemaphore::OutOfResources: | - |
90 | error = QSharedMemory::OutOfResources; | - |
91 | break; | 0 |
92 | case QSystemSemaphore::UnknownError: | - |
93 | default: | - |
94 | error = QSharedMemory::UnknownError; | - |
95 | break; | 0 |
96 | } | - |
97 | return false; never executed: return false; | 0 |
98 | } | - |
99 | | - |
100 | errorString = QString(); | - |
101 | error = QSharedMemory::NoError; | - |
102 | return true; never executed: return true; | 0 |
103 | } | - |
104 | QString QSharedMemory::key() const | - |
105 | { | - |
106 | const QSharedMemoryPrivate * const d = d_func(); | - |
107 | return d->key; never executed: return d->key; | 0 |
108 | } | - |
109 | QString QSharedMemory::nativeKey() const | - |
110 | { | - |
111 | const QSharedMemoryPrivate * const d = d_func(); | - |
112 | return d->nativeKey; never executed: return d->nativeKey; | 0 |
113 | } | - |
114 | bool QSharedMemory::create(int size, AccessMode mode) | - |
115 | { | - |
116 | QSharedMemoryPrivate * const d = d_func(); | - |
117 | | - |
118 | if (!d->initKey()) never evaluated: !d->initKey() | 0 |
119 | return false; never executed: return false; | 0 |
120 | | - |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
125 | d->systemSemaphore.setKey(d->key, 1, QSystemSemaphore::Create); | - |
126 | | - |
127 | | - |
128 | | - |
129 | QString function = QLatin1String("QSharedMemory::create"); | - |
130 | | - |
131 | QSharedMemoryLocker lock(this); | - |
132 | if (!d->key.isNull() && !d->tryLocker(&lock, function)) never evaluated: !d->key.isNull() never evaluated: !d->tryLocker(&lock, function) | 0 |
133 | return false; never executed: return false; | 0 |
134 | | - |
135 | | - |
136 | if (size <= 0) { never evaluated: size <= 0 | 0 |
137 | d->error = QSharedMemory::InvalidSize; | - |
138 | d->errorString = | - |
139 | QSharedMemory::tr("%1: create size is less then 0").arg(function); | - |
140 | return false; never executed: return false; | 0 |
141 | } | - |
142 | | - |
143 | if (!d->create(size)) never evaluated: !d->create(size) | 0 |
144 | return false; never executed: return false; | 0 |
145 | | - |
146 | return d->attach(mode); never executed: return d->attach(mode); | 0 |
147 | } | - |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | int QSharedMemory::size() const | - |
156 | { | - |
157 | const QSharedMemoryPrivate * const d = d_func(); | - |
158 | return d->size; never executed: return d->size; | 0 |
159 | } | - |
160 | bool QSharedMemory::attach(AccessMode mode) | - |
161 | { | - |
162 | QSharedMemoryPrivate * const d = d_func(); | - |
163 | | - |
164 | if (isAttached() || !d->initKey()) never evaluated: isAttached() never evaluated: !d->initKey() | 0 |
165 | return false; never executed: return false; | 0 |
166 | | - |
167 | QSharedMemoryLocker lock(this); | - |
168 | if (!d->key.isNull() && !d->tryLocker(&lock, QLatin1String("QSharedMemory::attach"))) never evaluated: !d->key.isNull() never evaluated: !d->tryLocker(&lock, QLatin1String("QSharedMemory::attach")) | 0 |
169 | return false; never executed: return false; | 0 |
170 | | - |
171 | | - |
172 | if (isAttached() || !d->handle()) never evaluated: isAttached() never evaluated: !d->handle() | 0 |
173 | return false; never executed: return false; | 0 |
174 | | - |
175 | return d->attach(mode); never executed: return d->attach(mode); | 0 |
176 | } | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | bool QSharedMemory::isAttached() const | - |
185 | { | - |
186 | const QSharedMemoryPrivate * const d = d_func(); | - |
187 | return (0 != d->memory); never executed: return (0 != d->memory); | 0 |
188 | } | - |
189 | bool QSharedMemory::detach() | - |
190 | { | - |
191 | QSharedMemoryPrivate * const d = d_func(); | - |
192 | if (!isAttached()) never evaluated: !isAttached() | 0 |
193 | return false; never executed: return false; | 0 |
194 | | - |
195 | | - |
196 | QSharedMemoryLocker lock(this); | - |
197 | if (!d->key.isNull() && !d->tryLocker(&lock, QLatin1String("QSharedMemory::detach"))) never evaluated: !d->key.isNull() never evaluated: !d->tryLocker(&lock, QLatin1String("QSharedMemory::detach")) | 0 |
198 | return false; never executed: return false; | 0 |
199 | | - |
200 | | - |
201 | return d->detach(); never executed: return d->detach(); | 0 |
202 | } | - |
203 | void *QSharedMemory::data() | - |
204 | { | - |
205 | QSharedMemoryPrivate * const d = d_func(); | - |
206 | return d->memory; never executed: return d->memory; | 0 |
207 | } | - |
208 | const void* QSharedMemory::constData() const | - |
209 | { | - |
210 | const QSharedMemoryPrivate * const d = d_func(); | - |
211 | return d->memory; never executed: return d->memory; | 0 |
212 | } | - |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | const void *QSharedMemory::data() const | - |
218 | { | - |
219 | const QSharedMemoryPrivate * const d = d_func(); | - |
220 | return d->memory; never executed: return d->memory; | 0 |
221 | } | - |
222 | bool QSharedMemory::lock() | - |
223 | { | - |
224 | QSharedMemoryPrivate * const d = d_func(); | - |
225 | if (d->lockedByMe) { never evaluated: d->lockedByMe | 0 |
226 | QMessageLogger("kernel/qsharedmemory.cpp", 509, __PRETTY_FUNCTION__).warning("QSharedMemory::lock: already locked"); | - |
227 | return true; never executed: return true; | 0 |
228 | } | - |
229 | if (d->systemSemaphore.acquire()) { never evaluated: d->systemSemaphore.acquire() | 0 |
230 | d->lockedByMe = true; | - |
231 | return true; never executed: return true; | 0 |
232 | } | - |
233 | QString function = QLatin1String("QSharedMemory::lock"); | - |
234 | d->errorString = QSharedMemory::tr("%1: unable to lock").arg(function); | - |
235 | d->error = QSharedMemory::LockError; | - |
236 | return false; never executed: return false; | 0 |
237 | } | - |
238 | bool QSharedMemory::unlock() | - |
239 | { | - |
240 | QSharedMemoryPrivate * const d = d_func(); | - |
241 | if (!d->lockedByMe) never evaluated: !d->lockedByMe | 0 |
242 | return false; never executed: return false; | 0 |
243 | d->lockedByMe = false; | - |
244 | if (d->systemSemaphore.release()) never evaluated: d->systemSemaphore.release() | 0 |
245 | return true; never executed: return true; | 0 |
246 | QString function = QLatin1String("QSharedMemory::unlock"); | - |
247 | d->errorString = QSharedMemory::tr("%1: unable to unlock").arg(function); | - |
248 | d->error = QSharedMemory::LockError; | - |
249 | return false; never executed: return false; | 0 |
250 | } | - |
251 | QSharedMemory::SharedMemoryError QSharedMemory::error() const | - |
252 | { | - |
253 | const QSharedMemoryPrivate * const d = d_func(); | - |
254 | return d->error; never executed: return d->error; | 0 |
255 | } | - |
256 | QString QSharedMemory::errorString() const | - |
257 | { | - |
258 | const QSharedMemoryPrivate * const d = d_func(); | - |
259 | return d->errorString; never executed: return d->errorString; | 0 |
260 | } | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | | - |
| | |