1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #ifndef XQSERVICETHREADDATA_H |
|
23 #define XQSERVICETHREADDATA_H |
|
24 |
|
25 #include "xqservicelog.h" |
|
26 |
|
27 #include <QtCore/qobject.h> |
|
28 |
|
29 #include <QtCore/qshareddata.h> |
|
30 #include <QtCore/qregexp.h> |
|
31 #include <QMap> |
|
32 #include <QVariant> |
|
33 |
|
34 const int CmdRetData = 0xF001 ; |
|
35 const int CmdErrData = 0xF010 ; |
|
36 |
|
37 class XQServiceChannel; |
|
38 class XQServiceIpcClient; |
|
39 class XQServiceRequestCompletedAsync; |
|
40 |
|
41 // Special variant class that can perform QDataStream operations |
|
42 // without the QVariant header information. |
|
43 class XQServiceVariant : public QVariant |
|
44 { |
|
45 public: |
|
46 XQServiceVariant() : QVariant() {} |
|
47 explicit XQServiceVariant(const QVariant& value) |
|
48 : QVariant(value) |
|
49 { |
|
50 XQSERVICE_DEBUG_PRINT("XQServiceVariant::XQServiceVariant"); |
|
51 XQSERVICE_DEBUG_PRINT("value: %s", qPrintable(value.toString())); |
|
52 } |
|
53 |
|
54 void load(QDataStream& stream, int typeOrMetaType) |
|
55 { |
|
56 XQSERVICE_DEBUG_PRINT("XQServiceVariant::load"); |
|
57 clear(); |
|
58 create(typeOrMetaType, 0); |
|
59 d.is_null = false; |
|
60 QMetaType::load(stream, d.type, const_cast<void *>(constData())); |
|
61 } |
|
62 |
|
63 void save(QDataStream& stream) const |
|
64 { |
|
65 XQSERVICE_DEBUG_PRINT("XQServiceVariant::save"); |
|
66 QMetaType::save(stream, d.type, constData()); |
|
67 } |
|
68 }; |
|
69 |
|
70 /*! |
|
71 \class XQServiceChannelPrivate |
|
72 \brief Private implementation of XQServiceChannelPrivate |
|
73 */ |
|
74 class XQServiceChannelPrivate : public QSharedData |
|
75 { |
|
76 public: |
|
77 XQServiceChannelPrivate(XQServiceChannel *obj, const QString& chan, bool isServer) |
|
78 : object(obj), channel(chan), server(isServer) |
|
79 { |
|
80 XQSERVICE_DEBUG_PRINT("XQServiceChannelPrivate::XQServiceChannelPrivate"); |
|
81 } |
|
82 |
|
83 XQServiceChannel *object; |
|
84 QString channel; |
|
85 bool server; |
|
86 }; |
|
87 |
|
88 typedef QExplicitlySharedDataPointer<XQServiceChannelPrivate> XQServiceChannelPrivatePointer; |
|
89 typedef QMap<QString, QList<XQServiceChannelPrivatePointer> > XQServiceClientMap; |
|
90 typedef QMap<QString, XQServiceIpcClient*> XQServiceIpcClientMap; |
|
91 |
|
92 // Thread-specific data for XQService client and server implementations. |
|
93 class XQServiceThreadData |
|
94 { |
|
95 public: |
|
96 XQServiceThreadData() |
|
97 { |
|
98 XQSERVICE_DEBUG_PRINT("XQServiceThreadData::XQServiceThreadData"); |
|
99 m_latestError = 0; |
|
100 } |
|
101 |
|
102 virtual ~XQServiceThreadData(); |
|
103 |
|
104 |
|
105 static XQServiceThreadData *instance(); |
|
106 |
|
107 bool createClientConnection(const QString& channel,bool isServer=false, |
|
108 bool isSync=true, XQServiceRequestCompletedAsync* rc=NULL, |
|
109 const void *userData=NULL); |
|
110 void closeClientConnection(const QString& channel); |
|
111 |
|
112 XQServiceIpcClient *clientConnection(const QString& channel); |
|
113 |
|
114 // Determine if we have a client connection object for this thread. |
|
115 bool hasClientConnection(const QString& ipcConName); |
|
116 QString getIpcConnectioName(const QString& channel); |
|
117 |
|
118 static QVariant deserializeRetData(const QByteArray &retData); |
|
119 static QByteArray serializeRetData(const QVariant &value, int error); |
|
120 |
|
121 int latestError(); |
|
122 |
|
123 void setLatestError(int latestError); |
|
124 // Map client-side channel names to lists of XQServiceChannel objects. |
|
125 XQServiceClientMap clientMap; |
|
126 |
|
127 XQServiceIpcClientMap ipcConnMap; |
|
128 |
|
129 int m_latestError; |
|
130 }; |
|
131 |
|
132 namespace XQService |
|
133 { |
|
134 XQServiceThreadData *serviceThreadData(); |
|
135 } |
|
136 |
|
137 #endif |
|