1 /* |
|
2 * Copyright (c) 2008 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: IPC request class |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "xqservicelog.h" |
|
23 |
|
24 #include <xqserviceclientinfo.h> |
|
25 #include "xqserviceipcrequest.h" |
|
26 #include "xqserviceipcserversession.h" |
|
27 #include "xqrequestutil.h" |
|
28 |
|
29 namespace QtService |
|
30 { |
|
31 /*! |
|
32 \class ServiceIPCRequest |
|
33 \brief Class to encapsulate a service request |
|
34 */ |
|
35 |
|
36 /*! |
|
37 Constructor. |
|
38 \param aSession Session associated with this request. |
|
39 \param aDataLength Amount of data to be received in this request. |
|
40 \param aRequestOp Operation name. |
|
41 */ |
|
42 ServiceIPCRequest::ServiceIPCRequest(ServiceIPCSession* aSession, |
|
43 qint64 aDataLength, |
|
44 const QString& aRequestOp) : |
|
45 QObject(NULL), |
|
46 iSession(aSession), |
|
47 iClientInfo(NULL), |
|
48 iRequestOp(aRequestOp), |
|
49 iDatalength(aDataLength), |
|
50 iId(-1), |
|
51 iAsync(false) |
|
52 { |
|
53 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::ServiceIPCRequest(1)"); |
|
54 XQSERVICE_DEBUG_PRINT("aDataLength: %d", aDataLength); |
|
55 XQSERVICE_DEBUG_PRINT("aRequestOp: %s", qPrintable(aRequestOp)); |
|
56 } |
|
57 |
|
58 /*! |
|
59 Copy Constructor. |
|
60 \param aRequest Request to be copied. |
|
61 */ |
|
62 ServiceIPCRequest::ServiceIPCRequest(ServiceIPCRequest& aRequest) |
|
63 { |
|
64 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::ServiceIPCRequest(2)"); |
|
65 //session |
|
66 iSession = aRequest.getSession(); |
|
67 |
|
68 //client info |
|
69 iClientInfo = new ClientInfo(); |
|
70 iClientInfo->setName((aRequest.clientInfo())->name()); |
|
71 iClientInfo->setProcessId(aRequest.clientInfo()->processId()); |
|
72 iClientInfo->setVendorId(aRequest.clientInfo()->vendorId()); |
|
73 |
|
74 // request operation |
|
75 iRequestOp = aRequest.getOperation(); |
|
76 |
|
77 //data part |
|
78 iRequestData = aRequest.getData(); |
|
79 iDatalength = iRequestData.length(); |
|
80 |
|
81 // Request options |
|
82 iRequestInfo = aRequest.requestInfo(); |
|
83 |
|
84 } |
|
85 |
|
86 /*! |
|
87 Destructor. |
|
88 */ |
|
89 ServiceIPCRequest::~ServiceIPCRequest() |
|
90 { |
|
91 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::~ServiceIPCRequest"); |
|
92 delete iClientInfo; |
|
93 } |
|
94 |
|
95 /*! |
|
96 Assignment operator. |
|
97 \param aRequest Request to be assigned. |
|
98 \return ServiceIPCRequest assigned request. |
|
99 */ |
|
100 ServiceIPCRequest& ServiceIPCRequest::operator=(ServiceIPCRequest& aRequest) |
|
101 { |
|
102 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::operator="); |
|
103 if (this != &aRequest) { |
|
104 //session |
|
105 iSession = aRequest.getSession(); |
|
106 |
|
107 //client info |
|
108 ClientInfo* info = new ClientInfo(); |
|
109 info->setName((aRequest.clientInfo())->name()); |
|
110 info->setProcessId(aRequest.clientInfo()->processId()); |
|
111 info->setVendorId(aRequest.clientInfo()->vendorId()); |
|
112 delete iClientInfo; |
|
113 iClientInfo = info; |
|
114 |
|
115 // request operation |
|
116 iRequestOp = aRequest.getOperation(); |
|
117 |
|
118 //data part |
|
119 iRequestData = aRequest.getData(); |
|
120 iDatalength = iRequestData.length(); |
|
121 |
|
122 // Request options |
|
123 iRequestInfo = aRequest.requestInfo(); |
|
124 |
|
125 } |
|
126 return *this; |
|
127 } |
|
128 |
|
129 /*! |
|
130 Get the requested operation. |
|
131 \return QString operation ID. |
|
132 */ |
|
133 const QString& ServiceIPCRequest::getOperation() |
|
134 { |
|
135 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::getOperation"); |
|
136 XQSERVICE_DEBUG_PRINT("iRequestOp: %s", qPrintable(iRequestOp)); |
|
137 return iRequestOp; |
|
138 } |
|
139 |
|
140 /*! |
|
141 Get the requested data. |
|
142 \return QByteArray data for this operation. |
|
143 */ |
|
144 const QByteArray& ServiceIPCRequest::getData() |
|
145 { |
|
146 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::getData"); |
|
147 XQSERVICE_DEBUG_PRINT("iRequestData: %s", iRequestData.constData()); |
|
148 return iRequestData; |
|
149 } |
|
150 |
|
151 /*! |
|
152 Write some data to the request. |
|
153 \param aData Data to write to the socket. |
|
154 */ |
|
155 bool ServiceIPCRequest::write(const QByteArray& aData) |
|
156 { |
|
157 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::write"); |
|
158 XQSERVICE_DEBUG_PRINT("aData: %s", aData.constData()); |
|
159 // Do we want to buffer the writes? |
|
160 return iSession->write(aData); |
|
161 } |
|
162 |
|
163 /*! |
|
164 Complete the request. |
|
165 \return true if request completed successfully. |
|
166 */ |
|
167 bool ServiceIPCRequest::completeRequest() |
|
168 { |
|
169 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::completeRequest"); |
|
170 return iSession->completeRequest(); |
|
171 } |
|
172 |
|
173 /*! |
|
174 Append more data when creating the request. |
|
175 \param aMoreData Data to be appended to the request. |
|
176 \return true if iDataLength now equals the full length. |
|
177 */ |
|
178 bool ServiceIPCRequest::addRequestdata(const QByteArray& aMoreData) |
|
179 { |
|
180 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::addRequestdata"); |
|
181 XQSERVICE_DEBUG_PRINT("aMoreData: %s", aMoreData.constData()); |
|
182 iRequestData.append(aMoreData); |
|
183 return (iRequestData.length() == iDatalength); |
|
184 } |
|
185 |
|
186 /*! |
|
187 Sets the client info. Onwership of the object is passed in. |
|
188 \param aClientInfo Client information. |
|
189 */ |
|
190 void ServiceIPCRequest::setClientInfo(ClientInfo *aClientInfo) |
|
191 { |
|
192 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setClientInfo"); |
|
193 delete iClientInfo; |
|
194 iClientInfo = aClientInfo; |
|
195 |
|
196 // Fill in the implicit info generated by the server |
|
197 iRequestInfo.setInfo(XQServiceUtils::InfoSID, iClientInfo->processId()); |
|
198 iRequestInfo.setInfo(XQServiceUtils::InfoVID, iClientInfo->vendorId()); |
|
199 iRequestInfo.setInfo(XQServiceUtils::InfoCap, iClientInfo->capabilities()); |
|
200 |
|
201 } |
|
202 |
|
203 /*! |
|
204 Gets the client info. |
|
205 \return Client Information object, NULL if none is available. |
|
206 */ |
|
207 ClientInfo* ServiceIPCRequest::clientInfo() |
|
208 { |
|
209 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::clientInfo"); |
|
210 return iClientInfo; |
|
211 } |
|
212 |
|
213 /*! |
|
214 Gets the session. |
|
215 \return ServiceIPCSession, NULL if none is available. |
|
216 */ |
|
217 ServiceIPCSession* ServiceIPCRequest::getSession() |
|
218 { |
|
219 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::getSession"); |
|
220 return iSession; |
|
221 } |
|
222 |
|
223 /*! |
|
224 Sets id of the request. |
|
225 \param aId Identifier of the request. |
|
226 */ |
|
227 void ServiceIPCRequest::setId(int aId) |
|
228 { |
|
229 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setId"); |
|
230 XQSERVICE_DEBUG_PRINT("\t aId = %d", aId); |
|
231 iId = aId; |
|
232 } |
|
233 |
|
234 /*! |
|
235 Returns id of the request. |
|
236 \return Id of the request. |
|
237 */ |
|
238 int ServiceIPCRequest::id() const |
|
239 { |
|
240 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::id"); |
|
241 XQSERVICE_DEBUG_PRINT("\t iId = %d", iId); |
|
242 return iId; |
|
243 } |
|
244 |
|
245 /*! |
|
246 Sets asynchcronous flag to true or false. |
|
247 \param aAsync Value of the async flag. |
|
248 */ |
|
249 void ServiceIPCRequest::setAsync(bool aAsync) |
|
250 { |
|
251 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setAsync"); |
|
252 XQSERVICE_DEBUG_PRINT("\t iAsync = %d", aAsync); |
|
253 iAsync = aAsync; |
|
254 } |
|
255 |
|
256 /*! |
|
257 Returns async flag. |
|
258 \return True if the request is asynchronous. False, if synchronous. |
|
259 */ |
|
260 bool ServiceIPCRequest::isAsync() const |
|
261 { |
|
262 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::getAsync"); |
|
263 XQSERVICE_DEBUG_PRINT("\t iAsync = %d", iAsync); |
|
264 return iAsync; |
|
265 } |
|
266 |
|
267 /*! |
|
268 Set request info passed along with the request. |
|
269 \param info Info to be passed with the request. |
|
270 */ |
|
271 void ServiceIPCRequest::setRequestInfo(XQRequestInfo *info) |
|
272 { |
|
273 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setRequestInfo"); |
|
274 if (info) |
|
275 { |
|
276 iRequestInfo = *info; |
|
277 // Restore the overridden id value |
|
278 if (iClientInfo) |
|
279 { |
|
280 // Fill in the implicit info generated by the server |
|
281 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setRequestInfo fill from clientInfo"); |
|
282 iRequestInfo.setInfo(XQServiceUtils::InfoSID, iClientInfo->processId()); |
|
283 iRequestInfo.setInfo(XQServiceUtils::InfoVID, iClientInfo->vendorId()); |
|
284 iRequestInfo.setInfo(XQServiceUtils::InfoCap, iClientInfo->capabilities()); |
|
285 iRequestInfo.setInfo(XQServiceUtils::InfoId, id()); |
|
286 } |
|
287 } |
|
288 } |
|
289 |
|
290 /*! |
|
291 Get info added to the request. |
|
292 \return Info to be passed with the request. |
|
293 */ |
|
294 XQRequestInfo ServiceIPCRequest::requestInfo() const |
|
295 { |
|
296 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::requestInfo"); |
|
297 return iRequestInfo; |
|
298 } |
|
299 |
|
300 /*! |
|
301 Add sharable file to be passed with the request. |
|
302 \param file Sharable file to be added to the request. |
|
303 \param index Currently not used. |
|
304 */ |
|
305 void ServiceIPCRequest::addSharableFile(XQSharableFile *file, int index) |
|
306 { |
|
307 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setSharableFile"); |
|
308 if (file != NULL) |
|
309 iSharableFiles.append(*file); |
|
310 } |
|
311 |
|
312 /*! |
|
313 Get sharable file from request. |
|
314 \param index Index of the sharable file to get. |
|
315 */ |
|
316 XQSharableFile ServiceIPCRequest::sharableFile(int index) const |
|
317 { |
|
318 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setSharableFile"); |
|
319 if (index >= 0 && index < iSharableFiles.size()) |
|
320 { |
|
321 XQSharableFile file = iSharableFiles.at(index); |
|
322 XQSERVICE_DEBUG_PRINT("ServiceIPCRequest::setSharableFile valid=%d", file.isValid()); |
|
323 return file; |
|
324 } |
|
325 return XQSharableFile(); |
|
326 } |
|
327 |
|
328 |
|
329 } |
|
330 // END OF FILE |
|