| 8f427b2 by axis at 2009-04-24 |
1 |
/**************************************************************************** |
|
2 |
** |
| 89c08c0 by Jason McDonald at 2012-01-11 |
3 |
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). |
| 04e3b30 by Jason McDonald at 2009-09-09 |
4 |
** All rights reserved. |
| da8dc76 by axis at 2009-08-06 |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 8f427b2 by axis at 2009-04-24 |
6 |
** |
| bec7a9c by Jason McDonald at 2009-10-06 |
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
| 8f427b2 by axis at 2009-04-24 |
8 |
** |
| a014c07 by axis at 2009-06-03 |
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** GNU Lesser General Public License Usage |
| 1eea52e by Jyri Tahtela at 2011-05-13 |
11 |
** This file may be used under the terms of the GNU Lesser General Public |
|
12 |
** License version 2.1 as published by the Free Software Foundation and |
|
13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
|
14 |
** file. Please review the following information to ensure the GNU Lesser |
|
15 |
** General Public License version 2.1 requirements will be met: |
|
16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| a014c07 by axis at 2009-06-03 |
17 |
** |
| 04e3b30 by Jason McDonald at 2009-09-09 |
18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 1eea52e by Jyri Tahtela at 2011-05-13 |
19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 04e3b30 by Jason McDonald at 2009-09-09 |
20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| a014c07 by axis at 2009-06-03 |
21 |
** |
| 1eea52e by Jyri Tahtela at 2011-05-13 |
22 |
** GNU General Public License Usage |
|
23 |
** Alternatively, this file may be used under the terms of the GNU General |
|
24 |
** Public License version 3.0 as published by the Free Software Foundation |
|
25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
|
26 |
** file. Please review the following information to ensure the GNU General |
|
27 |
** Public License version 3.0 requirements will be met: |
|
28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 115a995 by Jason McDonald at 2009-08-31 |
29 |
** |
| 1eea52e by Jyri Tahtela at 2011-05-13 |
30 |
** Other Usage |
|
31 |
** Alternatively, this file may be used in accordance with the terms and |
|
32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 115a995 by Jason McDonald at 2009-08-31 |
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
| a014c07 by axis at 2009-06-03 |
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
| 8f427b2 by axis at 2009-04-24 |
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
|
|
42 |
#ifndef QCORE_SYMBIAN_P_H |
|
43 |
#define QCORE_SYMBIAN_P_H |
|
44 |
|
|
45 |
// |
|
46 |
// W A R N I N G |
|
47 |
// ------------- |
|
48 |
// |
|
49 |
// This file is not part of the Qt API. It exists for the convenience |
|
50 |
// of other Qt classes. This header file may change from version to |
|
51 |
// version without notice, or even be removed. |
|
52 |
// |
|
53 |
// We mean it. |
|
54 |
// |
|
55 |
|
|
56 |
#include <e32std.h> |
|
57 |
#include <QtCore/qglobal.h> |
| 5c7c126 by Shane Kearns at 2010-12-01 |
58 |
#include <QtCore/qmutex.h> |
| 8f427b2 by axis at 2009-04-24 |
59 |
#include <qstring.h> |
|
60 |
#include <qrect.h> |
|
61 |
#include <qhash.h> |
| 4846920 by Shane Kearns at 2011-06-27 |
62 |
#include <qscopedpointer.h> |
| 6dade01 by Shane Kearns at 2009-08-24 |
63 |
#include <f32file.h> |
| 5c7c126 by Shane Kearns at 2010-12-01 |
64 |
#include <es_sock.h> |
| 8f427b2 by axis at 2009-04-24 |
65 |
|
| 4542e8d by Miikka Heikkinen at 2010-03-19 |
66 |
#define QT_LSTRING2(x) L##x |
|
67 |
#define QT_LSTRING(x) QT_LSTRING2(x) |
|
68 |
|
|
69 |
#if defined(QT_LIBINFIX) |
|
70 |
# define QT_LIBINFIX_UNICODE QT_LSTRING(QT_LIBINFIX) |
|
71 |
#else |
|
72 |
# define QT_LIBINFIX_UNICODE L"" |
|
73 |
#endif |
|
74 |
|
| 8f427b2 by axis at 2009-04-24 |
75 |
QT_BEGIN_HEADER |
|
76 |
|
|
77 |
QT_BEGIN_NAMESPACE |
|
78 |
|
| 7604f80 by Robert Griebl at 2009-06-10 |
79 |
Q_CORE_EXPORT HBufC* qt_QString2HBufC(const QString& aString); |
| 8f427b2 by axis at 2009-04-24 |
80 |
|
| 41a83e1 by Harald Fernengel at 2009-08-03 |
81 |
Q_CORE_EXPORT QString qt_TDesC2QString(const TDesC& aDescriptor); |
|
82 |
inline QString qt_TDes2QString(const TDes& aDescriptor) { return qt_TDesC2QString(aDescriptor); } |
| 8f427b2 by axis at 2009-04-24 |
83 |
|
|
84 |
static inline QSize qt_TSize2QSize(const TSize& ts) |
|
85 |
{ |
|
86 |
return QSize(ts.iWidth, ts.iHeight); |
|
87 |
} |
|
88 |
|
|
89 |
static inline TSize qt_QSize2TSize(const QSize& qs) |
|
90 |
{ |
|
91 |
return TSize(qs.width(), qs.height()); |
|
92 |
} |
|
93 |
|
|
94 |
static inline QRect qt_TRect2QRect(const TRect& tr) |
|
95 |
{ |
|
96 |
return QRect(tr.iTl.iX, tr.iTl.iY, tr.Width(), tr.Height()); |
|
97 |
} |
|
98 |
|
|
99 |
static inline TRect qt_QRect2TRect(const QRect& qr) |
|
100 |
{ |
|
101 |
return TRect(TPoint(qr.left(), qr.top()), TSize(qr.width(), qr.height())); |
|
102 |
} |
|
103 |
|
|
104 |
// Returned TPtrC is valid as long as the given parameter is valid and unmodified |
|
105 |
static inline TPtrC qt_QString2TPtrC( const QString& string ) |
|
106 |
{ |
| 7604f80 by Robert Griebl at 2009-06-10 |
107 |
return TPtrC16(static_cast<const TUint16*>(string.utf16()), string.length()); |
| 8f427b2 by axis at 2009-04-24 |
108 |
} |
|
109 |
|
| 0286550 by axis at 2009-08-21 |
110 |
/*! |
|
111 |
\internal |
|
112 |
This class is a wrapper around the Symbian HBufC descriptor class. |
|
113 |
It makes sure that the heap allocated HBufC class is freed when it is |
|
114 |
destroyed. |
|
115 |
*/ |
| 8f427b2 by axis at 2009-04-24 |
116 |
class Q_CORE_EXPORT QHBufC |
|
117 |
{ |
|
118 |
public: |
|
119 |
QHBufC(); |
|
120 |
QHBufC(const QHBufC &src); |
|
121 |
QHBufC(HBufC *src); |
|
122 |
QHBufC(const QString &src); |
|
123 |
~QHBufC(); |
|
124 |
|
|
125 |
inline operator HBufC *() { return m_hBufC; } |
|
126 |
inline operator const HBufC *() const { return m_hBufC; } |
|
127 |
inline HBufC *data() { return m_hBufC; } |
|
128 |
inline const HBufC *data() const { return m_hBufC; } |
|
129 |
inline HBufC & operator*() { return *m_hBufC; } |
|
130 |
inline const HBufC & operator*() const { return *m_hBufC; } |
|
131 |
inline HBufC * operator->() { return m_hBufC; } |
|
132 |
inline const HBufC * operator->() const { return m_hBufC; } |
|
133 |
|
|
134 |
inline bool operator==(const QHBufC ¶m) const { return data() == param.data(); } |
|
135 |
inline bool operator!=(const QHBufC ¶m) const { return data() != param.data(); } |
|
136 |
|
|
137 |
private: |
|
138 |
HBufC *m_hBufC; |
|
139 |
}; |
|
140 |
|
|
141 |
inline uint qHash(TUid uid) |
|
142 |
{ |
|
143 |
return qHash(uid.iUid); |
|
144 |
} |
|
145 |
|
| 6dade01 by Shane Kearns at 2009-08-24 |
146 |
Q_CORE_EXPORT RFs& qt_s60GetRFs(); |
| 5c7c126 by Shane Kearns at 2010-12-01 |
147 |
Q_CORE_EXPORT RSocketServ& qt_symbianGetSocketServer(); |
| 6dade01 by Shane Kearns at 2009-08-24 |
148 |
|
| b9ea054 by axis at 2009-08-25 |
149 |
// Defined in qlocale_symbian.cpp. |
|
150 |
Q_CORE_EXPORT QByteArray qt_symbianLocaleName(int code); |
|
151 |
|
| f29b95c by mread at 2011-02-10 |
152 |
template <typename R> |
|
153 |
struct QScopedPointerRCloser |
|
154 |
{ |
|
155 |
static inline void cleanup(R *rPointer) |
|
156 |
{ |
|
157 |
// Enforce a complete type. |
|
158 |
// If you get a compile error here, read the section on forward declared |
|
159 |
// classes in the QScopedPointer documentation. |
|
160 |
typedef char IsIncompleteType[ sizeof(R) ? 1 : -1 ]; |
|
161 |
(void) sizeof(IsIncompleteType); |
|
162 |
|
|
163 |
if (rPointer) |
|
164 |
rPointer->Close(); |
|
165 |
} |
|
166 |
}; |
|
167 |
|
| de55502 by Shane Kearns at 2010-12-06 |
168 |
//Wrapper for RSocket so it can be used as a key in QHash or QMap |
|
169 |
class QHashableSocket : public RSocket |
|
170 |
{ |
|
171 |
public: |
|
172 |
bool operator==(const QHashableSocket &other) const |
|
173 |
{ |
|
174 |
return SubSessionHandle() == other.SubSessionHandle() |
|
175 |
&& Session().Handle() == other.Session().Handle(); |
|
176 |
} |
|
177 |
bool operator<(const QHashableSocket &other) const |
|
178 |
{ |
| 8adba78 by Shane Kearns at 2010-12-07 |
179 |
if (Session().Handle() == other.Session().Handle()) |
| de55502 by Shane Kearns at 2010-12-06 |
180 |
return SubSessionHandle() < other.SubSessionHandle(); |
|
181 |
return Session().Handle() < other.Session().Handle(); |
|
182 |
} |
|
183 |
}; |
|
184 |
|
|
185 |
uint qHash(const RSubSessionBase& key); |
|
186 |
|
| 5c7c126 by Shane Kearns at 2010-12-01 |
187 |
/*! |
|
188 |
\internal |
|
189 |
This class exists in QtCore for the benefit of QSocketNotifier, which uses integer |
|
190 |
file descriptors in its public API. |
|
191 |
So we need a way to map between int and RSocket. |
|
192 |
Additionally, it is used to host the global RSocketServ session |
|
193 |
*/ |
|
194 |
class Q_CORE_EXPORT QSymbianSocketManager |
|
195 |
{ |
|
196 |
public: |
|
197 |
QSymbianSocketManager(); |
|
198 |
~QSymbianSocketManager(); |
|
199 |
|
|
200 |
/*! |
|
201 |
\internal |
|
202 |
\return handle to the socket server |
|
203 |
*/ |
|
204 |
RSocketServ& getSocketServer(); |
|
205 |
/*! |
|
206 |
\internal |
|
207 |
Adds a symbian socket to the global map |
|
208 |
\param an open socket |
|
209 |
\return pseudo file descriptor, -1 if out of resources |
|
210 |
*/ |
| de55502 by Shane Kearns at 2010-12-06 |
211 |
int addSocket(const RSocket &sock); |
| 5c7c126 by Shane Kearns at 2010-12-01 |
212 |
/*! |
|
213 |
\internal |
|
214 |
Removes a symbian socket from the global map |
|
215 |
\param an open socket |
|
216 |
\return true if the socket was in the map |
|
217 |
*/ |
| de55502 by Shane Kearns at 2010-12-06 |
218 |
bool removeSocket(const RSocket &sock); |
| 5c7c126 by Shane Kearns at 2010-12-01 |
219 |
/*! |
|
220 |
\internal |
|
221 |
Get pseudo file descriptor for a socket |
|
222 |
\param an open socket |
|
223 |
\return integer handle, or -1 if not in map |
|
224 |
*/ |
| de55502 by Shane Kearns at 2010-12-06 |
225 |
int lookupSocket(const RSocket &sock) const; |
| 5c7c126 by Shane Kearns at 2010-12-01 |
226 |
/*! |
|
227 |
\internal |
|
228 |
Get socket for a pseudo file descriptor |
|
229 |
\param an open socket fd |
| de55502 by Shane Kearns at 2010-12-06 |
230 |
\param sock (out) socket handle |
|
231 |
\return true on success or false if not in map |
| 5c7c126 by Shane Kearns at 2010-12-01 |
232 |
*/ |
| de55502 by Shane Kearns at 2010-12-06 |
233 |
bool lookupSocket(int fd, RSocket& sock) const; |
| 5c7c126 by Shane Kearns at 2010-12-01 |
234 |
|
|
235 |
/*! |
|
236 |
\internal |
| 8adba78 by Shane Kearns at 2010-12-07 |
237 |
Set the default connection to use for new sockets |
|
238 |
\param an open connection |
|
239 |
*/ |
|
240 |
void setDefaultConnection(RConnection* con); |
|
241 |
/*! |
|
242 |
\internal |
|
243 |
Get the default connection to use for new sockets |
|
244 |
\return the connection, or null pointer if there is none set |
|
245 |
*/ |
|
246 |
RConnection *defaultConnection() const; |
|
247 |
|
|
248 |
/*! |
|
249 |
\internal |
| 916076b by Shane Kearns at 2011-11-30 |
250 |
Add an opened connection to the active list |
|
251 |
\param an open connection |
|
252 |
*/ |
|
253 |
void addActiveConnection(TUint32 identifier); |
|
254 |
|
|
255 |
/*! |
|
256 |
\internal |
|
257 |
Remove a connection from the active list |
|
258 |
\param a closed connection |
|
259 |
*/ |
|
260 |
void removeActiveConnection(TUint32 identifier); |
|
261 |
|
|
262 |
/*! |
|
263 |
\internal |
|
264 |
Add an opened connection to the active list |
|
265 |
\param an open connection |
|
266 |
*/ |
|
267 |
QList<TUint32> activeConnections() const; |
|
268 |
|
|
269 |
/*! |
|
270 |
\internal |
| 5c7c126 by Shane Kearns at 2010-12-01 |
271 |
Gets a reference to the singleton socket manager |
|
272 |
*/ |
|
273 |
static QSymbianSocketManager& instance(); |
|
274 |
private: |
|
275 |
int allocateSocket(); |
|
276 |
|
|
277 |
const static int max_sockets = 0x20000; //covers all TCP and UDP ports, probably run out of memory first |
|
278 |
const static int socket_offset = 0x40000000; //hacky way of separating sockets from file descriptors |
|
279 |
int iNextSocket; |
| de55502 by Shane Kearns at 2010-12-06 |
280 |
QHash<QHashableSocket, int> socketMap; |
|
281 |
QHash<int, RSocket> reverseSocketMap; |
| 916076b by Shane Kearns at 2011-11-30 |
282 |
QHash<TUint32, int> activeConnectionsMap; |
| 5c7c126 by Shane Kearns at 2010-12-01 |
283 |
mutable QMutex iMutex; |
|
284 |
RSocketServ iSocketServ; |
| 8adba78 by Shane Kearns at 2010-12-07 |
285 |
RConnection *iDefaultConnection; |
| 5c7c126 by Shane Kearns at 2010-12-01 |
286 |
}; |
|
287 |
|
| 4846920 by Shane Kearns at 2011-06-27 |
288 |
template <typename T> class QScopedPointerResourceCloser |
|
289 |
{ |
|
290 |
public: |
|
291 |
static inline void cleanup(T* pointer) |
|
292 |
{ |
|
293 |
if (pointer) |
|
294 |
pointer->Close(); |
|
295 |
} |
|
296 |
}; |
|
297 |
|
|
298 |
/*typical use: |
|
299 |
RFile file; |
|
300 |
file.Open(...); |
|
301 |
QScopedResource<RFile> ptr(file); |
|
302 |
container.append(file); //this may throw std::bad_alloc, in which case file.Close() is called by destructor |
|
303 |
ptr.take(); //if we reach this line, ownership is transferred to the container |
|
304 |
*/ |
|
305 |
template <typename T> class QScopedResource : public QScopedPointer<T, QScopedPointerResourceCloser<T> > |
|
306 |
{ |
|
307 |
public: |
|
308 |
inline QScopedResource(T& resource) : QScopedPointer<T, QScopedPointerResourceCloser<T> >(&resource) {} |
|
309 |
}; |
|
310 |
|
| 8f427b2 by axis at 2009-04-24 |
311 |
QT_END_NAMESPACE |
|
312 |
|
|
313 |
QT_END_HEADER |
|
314 |
|
|
315 |
#endif //QCORE_SYMBIAN_P_H |