author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qsystemsemaphore.h" |
|
43 |
#include "qsystemsemaphore_p.h" |
|
44 |
#include "qcoreapplication.h" |
|
45 |
#include <qdebug.h> |
|
46 |
||
47 |
#include <qcore_symbian_p.h> |
|
48 |
#include <e32cmn.h> |
|
49 |
QT_BEGIN_NAMESPACE |
|
50 |
||
51 |
#ifndef QT_NO_SYSTEMSEMAPHORE |
|
52 |
||
53 |
QSystemSemaphorePrivate::QSystemSemaphorePrivate() : |
|
54 |
error(QSystemSemaphore::NoError) |
|
55 |
{ |
|
56 |
} |
|
57 |
||
58 |
void QSystemSemaphorePrivate::setErrorString(const QString &function, int err) |
|
59 |
{ |
|
60 |
if (err == KErrNone){ |
|
61 |
return; |
|
62 |
} |
|
63 |
switch(err){ |
|
64 |
case KErrAlreadyExists: |
|
65 |
errorString = QCoreApplication::tr("%1: already exists", "QSystemSemaphore").arg(function); |
|
66 |
error = QSystemSemaphore::AlreadyExists; |
|
67 |
break; |
|
68 |
case KErrNotFound: |
|
69 |
errorString = QCoreApplication::tr("%1: does not exist", "QSystemSemaphore").arg(function); |
|
70 |
error = QSystemSemaphore::NotFound; |
|
71 |
break; |
|
72 |
case KErrNoMemory: |
|
73 |
case KErrInUse: |
|
74 |
errorString = QCoreApplication::tr("%1: out of resources", "QSystemSemaphore").arg(function); |
|
75 |
error = QSystemSemaphore::OutOfResources; |
|
76 |
break; |
|
77 |
default: |
|
78 |
errorString = QCoreApplication::tr("%1: unknown error %2", "QSystemSemaphore").arg(function).arg(err); |
|
79 |
error = QSystemSemaphore::UnknownError; |
|
80 |
} |
|
81 |
||
82 |
#if defined QSYSTEMSEMAPHORE_DEBUG |
|
83 |
qDebug() << errorString << "key" << key; |
|
84 |
#endif |
|
85 |
} |
|
86 |
||
87 |
int QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode) |
|
88 |
{ |
|
89 |
// don't allow making handles on empty keys |
|
90 |
if (key.isEmpty()) |
|
91 |
return 0; |
|
92 |
QString safeName = makeKeyFileName(); |
|
93 |
TPtrC name(qt_QString2TPtrC(safeName)); |
|
94 |
int err; |
|
95 |
err = semaphore.OpenGlobal(name,EOwnerProcess); |
|
96 |
if (err == KErrNotFound){ |
|
97 |
err = semaphore.CreateGlobal(name,initialValue, EOwnerProcess); |
|
98 |
} |
|
99 |
if (err){ |
|
100 |
setErrorString(QLatin1String("QSystemSemaphore::handle"),err); |
|
101 |
return 0; |
|
102 |
} |
|
103 |
return semaphore.Handle(); |
|
104 |
} |
|
105 |
||
106 |
void QSystemSemaphorePrivate::cleanHandle() |
|
107 |
{ |
|
108 |
semaphore.Close(); |
|
109 |
} |
|
110 |
||
111 |
bool QSystemSemaphorePrivate::modifySemaphore(int count) |
|
112 |
{ |
|
113 |
if (0 == handle()) |
|
114 |
return false; |
|
115 |
||
116 |
if (count > 0) { |
|
117 |
semaphore.Signal(count); |
|
118 |
} else { |
|
119 |
semaphore.Wait(); |
|
120 |
} |
|
121 |
return true; |
|
122 |
} |
|
123 |
||
124 |
#endif //QT_NO_SYSTEMSEMAPHORE |
|
125 |
||
126 |
QT_END_NAMESPACE |