25
|
1 |
/**
|
|
2 |
* Copyright (c) 2010 Sasken Communication Technologies Ltd.
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html"
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
* Nalina Hariharan
|
|
14 |
*
|
|
15 |
* Description:
|
|
16 |
* Private implementation of events related services
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
#include <qdebug.h>
|
|
21 |
#include <smfcontact.h>
|
|
22 |
|
|
23 |
#include "smfeventsfetcher.h"
|
|
24 |
#include "smfeventsfetcher_p.h"
|
|
25 |
#ifdef Q_OS_SYMBIAN
|
|
26 |
#include "smfclientsymbian.h"
|
|
27 |
#else
|
|
28 |
#include "smfclientqt.h"
|
|
29 |
#endif
|
|
30 |
|
|
31 |
|
|
32 |
SmfEventsFetcherPrivate::SmfEventsFetcherPrivate(SmfEventsFetcher* aEventFetcher)
|
|
33 |
:m_eventFetcher(aEventFetcher)
|
|
34 |
{
|
|
35 |
#ifdef Q_OS_SYMBIAN
|
|
36 |
//private impl for symbian
|
|
37 |
m_SmfClientPrivate = CSmfClientSymbian::NewL(this);
|
|
38 |
#else
|
|
39 |
//TODO:- Use private impl for other platforms or else Qt impl
|
|
40 |
#endif
|
|
41 |
}
|
|
42 |
|
|
43 |
SmfEventsFetcherPrivate::~SmfEventsFetcherPrivate()
|
|
44 |
{
|
|
45 |
if(m_SmfClientPrivate)
|
|
46 |
{
|
|
47 |
delete m_SmfClientPrivate;
|
|
48 |
m_SmfClientPrivate = NULL;
|
|
49 |
}
|
|
50 |
}
|
|
51 |
|
|
52 |
SmfError SmfEventsFetcherPrivate::events(SmfLocation venue, int pageNum, int perPage)
|
|
53 |
{
|
|
54 |
SmfError err = SmfNoError;
|
|
55 |
//We need to pass Opcode and SmfProvider serialized into bytearray
|
|
56 |
SmfProvider* m_baseProvider = m_eventFetcher->getProvider();
|
|
57 |
m_serializedDataToServer.clear();
|
|
58 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
59 |
write<<*(m_baseProvider);
|
|
60 |
|
|
61 |
QByteArray dataToPlugins;
|
|
62 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
|
63 |
m_argFlag = 1;
|
|
64 |
streamToPlugin<<m_argFlag;
|
|
65 |
streamToPlugin<<venue;
|
|
66 |
streamToPlugin<<m_argFlag;
|
|
67 |
streamToPlugin<<pageNum;
|
|
68 |
streamToPlugin<<m_argFlag;
|
|
69 |
streamToPlugin<<perPage;
|
|
70 |
|
|
71 |
write<<dataToPlugins;
|
|
72 |
|
|
73 |
QString intfName(eventFetcherInterface);
|
|
74 |
//TODO:-revisit all the maxalloc
|
|
75 |
int maxalloc = 1000;
|
|
76 |
|
|
77 |
//call private impl's send method
|
|
78 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
79 |
SmfEventsGetEvents, maxalloc);
|
|
80 |
return err;
|
|
81 |
}
|
|
82 |
|
|
83 |
SmfError SmfEventsFetcherPrivate::venues(SmfLocation location, int pageNum, int perPage)
|
|
84 |
{
|
|
85 |
SmfError err = SmfNoError;
|
|
86 |
//We need to pass Opcode and SmfProvider serialized into bytearray
|
|
87 |
SmfProvider* m_baseProvider = m_eventFetcher->getProvider();
|
|
88 |
m_serializedDataToServer.clear();
|
|
89 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
90 |
write<<*(m_baseProvider);
|
|
91 |
|
|
92 |
QByteArray dataToPlugins;
|
|
93 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
|
94 |
m_argFlag = 1;
|
|
95 |
streamToPlugin<<m_argFlag;
|
|
96 |
streamToPlugin<<location;
|
|
97 |
streamToPlugin<<m_argFlag;
|
|
98 |
streamToPlugin<<pageNum;
|
|
99 |
streamToPlugin<<m_argFlag;
|
|
100 |
streamToPlugin<<perPage;
|
|
101 |
|
|
102 |
write<<dataToPlugins;
|
|
103 |
|
|
104 |
QString intfName(eventFetcherInterface);
|
|
105 |
//TODO:-revisit all the maxalloc
|
|
106 |
int maxalloc = 1000;
|
|
107 |
|
|
108 |
//call private impl's send method
|
|
109 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
110 |
SmfEventsGetVenues, maxalloc);
|
|
111 |
return err;
|
|
112 |
}
|
|
113 |
|
|
114 |
SmfError SmfEventsFetcherPrivate::attendees(SmfEvent event, int pageNum, int perPage )
|
|
115 |
{
|
|
116 |
SmfError err = SmfNoError;
|
|
117 |
//We need to pass Opcode and SmfProvider serialized into bytearray
|
|
118 |
SmfProvider* m_baseProvider = m_eventFetcher->getProvider();
|
|
119 |
m_serializedDataToServer.clear();
|
|
120 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
121 |
write<<*(m_baseProvider);
|
|
122 |
|
|
123 |
QByteArray dataToPlugins;
|
|
124 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
|
125 |
m_argFlag = 1;
|
|
126 |
streamToPlugin<<m_argFlag;
|
|
127 |
streamToPlugin<<event;
|
|
128 |
streamToPlugin<<m_argFlag;
|
|
129 |
streamToPlugin<<pageNum;
|
|
130 |
streamToPlugin<<m_argFlag;
|
|
131 |
streamToPlugin<<perPage;
|
|
132 |
|
|
133 |
write<<dataToPlugins;
|
|
134 |
|
|
135 |
QString intfName(eventFetcherInterface);
|
|
136 |
//TODO:-revisit all the maxalloc
|
|
137 |
int maxalloc = 1000;
|
|
138 |
|
|
139 |
//call private impl's send method
|
|
140 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
141 |
SmfEventsGetEventAttendees, maxalloc);
|
|
142 |
return err;
|
|
143 |
}
|
|
144 |
|
|
145 |
SmfError SmfEventsFetcherPrivate::postEvents(SmfEventList events)
|
|
146 |
{
|
|
147 |
SmfError err = SmfNoError;
|
|
148 |
//We need to pass Opcode and SmfProvider serialized into bytearray
|
|
149 |
SmfProvider* m_baseProvider = m_eventFetcher->getProvider();
|
|
150 |
m_serializedDataToServer.clear();
|
|
151 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
152 |
write<<*(m_baseProvider);
|
|
153 |
|
|
154 |
QByteArray dataToPlugins;
|
|
155 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
|
156 |
m_argFlag = 1;
|
|
157 |
streamToPlugin<<m_argFlag;
|
|
158 |
streamToPlugin<<events;
|
|
159 |
|
|
160 |
write<<dataToPlugins;
|
|
161 |
|
|
162 |
QString intfName(eventFetcherInterface);
|
|
163 |
//TODO:-revisit all the maxalloc
|
|
164 |
int maxalloc = 1000;
|
|
165 |
|
|
166 |
//call private impl's send method
|
|
167 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
168 |
SmfEventsPostEvents, maxalloc);
|
|
169 |
return err;
|
|
170 |
}
|
|
171 |
|
|
172 |
SmfError SmfEventsFetcherPrivate::customRequest ( const int& operationId, QByteArray* customData )
|
|
173 |
{
|
|
174 |
SmfError err = SmfNoError;
|
|
175 |
//We need to pass Opcode and SmfProvider serialized into bytearray
|
|
176 |
SmfProvider* m_baseProvider = m_eventFetcher->getProvider();
|
|
177 |
m_serializedDataToServer.clear();
|
|
178 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
179 |
write<<*m_baseProvider;
|
|
180 |
|
|
181 |
QByteArray dataToPlugins;
|
|
182 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
|
183 |
|
|
184 |
m_argFlag = 1;
|
|
185 |
streamToPlugin<<m_argFlag;
|
|
186 |
streamToPlugin<<operationId;
|
|
187 |
if(customData)
|
|
188 |
{
|
|
189 |
streamToPlugin<<m_argFlag;
|
|
190 |
streamToPlugin<<*customData;
|
|
191 |
}
|
|
192 |
else
|
|
193 |
{
|
|
194 |
m_argFlag = 0;
|
|
195 |
streamToPlugin<<m_argFlag;
|
|
196 |
}
|
|
197 |
|
|
198 |
write<<dataToPlugins;
|
|
199 |
|
|
200 |
QString intfName(eventFetcherInterface);
|
|
201 |
//TODO:-revisit all the maxalloc
|
|
202 |
int maxalloc = 1000;
|
|
203 |
|
|
204 |
//call private impl's send method
|
|
205 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
206 |
SmfEventsCustomRequest, maxalloc);
|
|
207 |
return err;
|
|
208 |
}
|
|
209 |
|
|
210 |
SmfError SmfEventsFetcherPrivate::cancelRequest()
|
|
211 |
{
|
|
212 |
qDebug()<<"Inside SmfEventsFetcherPrivate::cancelRequest()";
|
|
213 |
QByteArray notused;
|
|
214 |
QByteArray retData = m_SmfClientPrivate->sendSyncRequest(notused,SmfCancelRequest,1000, notused);
|
|
215 |
|
|
216 |
//De-serialize it into SmfError
|
|
217 |
QDataStream reader(&retData,QIODevice::ReadOnly);
|
|
218 |
int val;
|
|
219 |
reader>>val;
|
|
220 |
SmfError error = (SmfError) val;
|
|
221 |
return error;
|
|
222 |
}
|
|
223 |
|
|
224 |
void SmfEventsFetcherPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode,SmfError error)
|
|
225 |
{
|
|
226 |
//note:- "result" is serialized and we need to de-serialize it as per opcode
|
|
227 |
//Order of serialization Error value followed by data
|
|
228 |
|
|
229 |
QDataStream reader(&result,QIODevice::ReadOnly);
|
|
230 |
|
|
231 |
//Now de-serialize it based on opcode
|
|
232 |
switch(opcode)
|
|
233 |
{
|
|
234 |
case SmfEventsGetEvents:
|
|
235 |
{
|
|
236 |
SmfEventList* m_events = new SmfEventList;
|
|
237 |
reader>>*(m_events);
|
|
238 |
|
|
239 |
// ToDo :-
|
|
240 |
SmfResultPage page;
|
|
241 |
|
|
242 |
m_eventFetcher->eventsAvailable(m_events,error,page);
|
|
243 |
break;
|
|
244 |
}
|
|
245 |
|
|
246 |
case SmfEventsGetVenues:
|
|
247 |
{
|
|
248 |
SmfLocationList* m_venues = new SmfLocationList;
|
|
249 |
reader>>*(m_venues);
|
|
250 |
|
|
251 |
//ToDo :-
|
|
252 |
SmfResultPage page;
|
|
253 |
|
|
254 |
m_eventFetcher->venuesAvailable(m_venues,error,page);
|
|
255 |
break;
|
|
256 |
}
|
|
257 |
|
|
258 |
case SmfEventsGetEventAttendees:
|
|
259 |
{
|
|
260 |
SmfContactList* m_list = new SmfContactList;
|
|
261 |
reader>>*(m_list);
|
|
262 |
|
|
263 |
//ToDo :-
|
|
264 |
SmfResultPage page;
|
|
265 |
|
|
266 |
m_eventFetcher->attendeesAvailable(m_list,error,page);
|
|
267 |
break;
|
|
268 |
}
|
|
269 |
|
|
270 |
case SmfEventsPostEvents:
|
|
271 |
m_eventFetcher->eventsUpdated(error);
|
|
272 |
break;
|
|
273 |
|
|
274 |
case SmfEventsCustomRequest:
|
|
275 |
{
|
|
276 |
int operationId;
|
|
277 |
QByteArray *data = new QByteArray;
|
|
278 |
reader>>operationId;
|
|
279 |
reader>>*data;
|
|
280 |
qDebug()<<"operationId = "<<operationId;
|
|
281 |
qDebug()<<"data size = "<<data->size();
|
|
282 |
emit m_eventFetcher->customDataAvailable(operationId, data);
|
|
283 |
break;
|
|
284 |
}
|
|
285 |
|
|
286 |
default:
|
|
287 |
Q_ASSERT_X(1,"SmfEventsFetcherPrivate::resultsAvailable","unknown opcode");
|
|
288 |
}
|
|
289 |
}
|