18
|
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 |
* Manasij Roy, Nalina Hariharan
|
|
14 |
*
|
|
15 |
* Description:
|
|
16 |
* Private Implementation of SmfActivityFetcher
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
#include <QDebug>
|
|
21 |
|
|
22 |
#include "smfactivityfetcher.h"
|
|
23 |
#include "smfactivityfetcher_p.h"
|
|
24 |
#ifdef Q_OS_SYMBIAN
|
|
25 |
#include "smfclientsymbian.h"
|
|
26 |
#else
|
|
27 |
#include "smfclientqt.h"
|
|
28 |
#endif
|
|
29 |
|
|
30 |
|
|
31 |
SmfActivityFetcherPrivate::SmfActivityFetcherPrivate(SmfActivityFetcher *activityFetcher)
|
|
32 |
:m_activityFetcher(activityFetcher)
|
|
33 |
{
|
|
34 |
#ifdef Q_OS_SYMBIAN
|
|
35 |
//private impl for symbian
|
|
36 |
m_SmfClientPrivate = CSmfClientSymbian::NewL(this);
|
|
37 |
#else
|
|
38 |
//TODO:- Qt private impl
|
|
39 |
#endif
|
|
40 |
}
|
|
41 |
|
|
42 |
SmfActivityFetcherPrivate::~SmfActivityFetcherPrivate()
|
|
43 |
{
|
|
44 |
if(m_SmfClientPrivate)
|
|
45 |
{
|
|
46 |
delete m_SmfClientPrivate;
|
|
47 |
m_SmfClientPrivate = NULL;
|
|
48 |
}
|
|
49 |
}
|
|
50 |
|
25
|
51 |
SmfError SmfActivityFetcherPrivate::selfActivities(int pageNum, int perPage)
|
18
|
52 |
{
|
26
|
53 |
if((pageNum<0 && perPage >0) || (pageNum>0 && perPage <0) || (pageNum ==0 && perPage ==0)
|
|
54 |
|| (pageNum > 100 && perPage >0) || (pageNum > 0 && perPage > 30) || (isalpha(pageNum)&& isalpha(perPage)))
|
|
55 |
|
|
56 |
{
|
|
57 |
|
|
58 |
qDebug()<<"Invalid Arguments, Check for Negative Values, Large Values, Junk Values";
|
|
59 |
SmfError error = SmfInvalidDataInArguement;
|
|
60 |
return error;
|
|
61 |
}
|
25
|
62 |
SmfError err = SmfNoError;
|
18
|
63 |
SmfProvider* m_baseProvider = m_activityFetcher->getProvider();
|
|
64 |
//serialize start
|
|
65 |
m_serializedDataToServer.clear();
|
|
66 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
67 |
//SmfProvider
|
|
68 |
write<<*m_baseProvider;
|
25
|
69 |
|
|
70 |
QByteArray dataToPlugins;
|
|
71 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
18
|
72 |
m_argFlag = 1;
|
25
|
73 |
streamToPlugin<<m_argFlag;
|
|
74 |
streamToPlugin<<pageNum;
|
|
75 |
streamToPlugin<<m_argFlag;
|
|
76 |
streamToPlugin<<perPage;
|
|
77 |
|
|
78 |
write<<dataToPlugins;
|
18
|
79 |
//serialize end
|
|
80 |
|
|
81 |
QString intfName(activityFetcherInterface);
|
|
82 |
int max = MaxSmfActivityEntrySize*perPage;
|
|
83 |
|
|
84 |
//call private impl's send method
|
|
85 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
86 |
SmfActivitySelfActivity, max);
|
25
|
87 |
return err;
|
18
|
88 |
}
|
|
89 |
|
25
|
90 |
SmfError SmfActivityFetcherPrivate::friendsActivities(const SmfContact & aFriend, int pageNum, int perPage)
|
18
|
91 |
{
|
26
|
92 |
|
|
93 |
if((pageNum<0 && perPage >0) || (pageNum>0 && perPage <0) || (pageNum ==0 && perPage ==0)
|
|
94 |
|| (pageNum > 100 && perPage >0) || (pageNum > 0 && perPage > 30) || (isalpha(pageNum)&& isalpha(perPage)))
|
|
95 |
|
|
96 |
{
|
|
97 |
|
|
98 |
qDebug()<<"Invalid Arguments, Check for Negative Values, Large Values, Junk Values";
|
|
99 |
SmfError error = SmfInvalidDataInArguement;
|
|
100 |
return error;
|
|
101 |
}
|
25
|
102 |
SmfError err = SmfNoError;
|
18
|
103 |
SmfProvider* m_baseProvider = m_activityFetcher->getProvider();
|
|
104 |
//serialize start
|
|
105 |
m_serializedDataToServer.clear();
|
|
106 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
107 |
//SmfProvider
|
|
108 |
write<<*m_baseProvider;
|
25
|
109 |
|
|
110 |
QByteArray dataToPlugins;
|
|
111 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
18
|
112 |
m_argFlag = 1;
|
25
|
113 |
streamToPlugin<<m_argFlag;
|
|
114 |
streamToPlugin<<aFriend;
|
|
115 |
streamToPlugin<<m_argFlag;
|
|
116 |
streamToPlugin<<pageNum;
|
|
117 |
streamToPlugin<<m_argFlag;
|
|
118 |
streamToPlugin<<perPage;
|
18
|
119 |
|
25
|
120 |
write<<dataToPlugins;
|
|
121 |
|
18
|
122 |
QString intfName(activityFetcherInterface);
|
|
123 |
int max = MaxSmfActivityEntrySize*perPage;
|
|
124 |
|
|
125 |
//call private impl's send method
|
|
126 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
127 |
SmfActivityFriendsActivities, max);
|
25
|
128 |
return err;
|
18
|
129 |
}
|
|
130 |
|
25
|
131 |
SmfError SmfActivityFetcherPrivate::filtered(QList<SmfActivityObjectType> filters, int pageNum, int perPage)
|
18
|
132 |
{
|
26
|
133 |
|
|
134 |
if((pageNum<0 && perPage >0) || (pageNum>0 && perPage <0) || (pageNum ==0 && perPage ==0)
|
|
135 |
|| (pageNum > 100 && perPage >0) || (pageNum > 0 && perPage > 30) || (isalpha(pageNum)&& isalpha(perPage)))
|
|
136 |
|
|
137 |
{
|
|
138 |
|
|
139 |
qDebug()<<"Invalid Arguments, Check for Negative Values, Large Values, Junk Values";
|
|
140 |
SmfError error = SmfInvalidDataInArguement;
|
|
141 |
return error;
|
|
142 |
}
|
25
|
143 |
SmfError err = SmfNoError;
|
18
|
144 |
SmfProvider* m_baseProvider = m_activityFetcher->getProvider();
|
|
145 |
|
|
146 |
//serialize start
|
|
147 |
m_serializedDataToServer.clear();
|
|
148 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
149 |
//SmfProvider
|
|
150 |
write<<*m_baseProvider;
|
25
|
151 |
|
|
152 |
QByteArray dataToPlugins;
|
|
153 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
18
|
154 |
m_argFlag = 1;
|
25
|
155 |
streamToPlugin<<m_argFlag;
|
|
156 |
streamToPlugin<<filters;
|
|
157 |
streamToPlugin<<m_argFlag;
|
|
158 |
streamToPlugin<<pageNum;
|
|
159 |
streamToPlugin<<m_argFlag;
|
|
160 |
streamToPlugin<<perPage;
|
|
161 |
|
|
162 |
write<<dataToPlugins;
|
18
|
163 |
|
|
164 |
QString intfName(activityFetcherInterface);
|
|
165 |
int max = MaxSmfActivityEntrySize*perPage;
|
|
166 |
|
|
167 |
//call private impl's send method
|
|
168 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
169 |
SmfActivityFiltered, max);
|
25
|
170 |
return err;
|
18
|
171 |
}
|
|
172 |
|
25
|
173 |
SmfError SmfActivityFetcherPrivate::customRequest ( const int& operationId, QByteArray* customData )
|
18
|
174 |
{
|
25
|
175 |
SmfError err = SmfNoError;
|
18
|
176 |
SmfProvider* m_baseProvider = m_activityFetcher->getProvider();
|
|
177 |
|
|
178 |
//serialize start
|
|
179 |
m_serializedDataToServer.clear();
|
|
180 |
QDataStream write(&m_serializedDataToServer,QIODevice::WriteOnly);
|
|
181 |
write<<*m_baseProvider;
|
25
|
182 |
|
|
183 |
QByteArray dataToPlugins;
|
|
184 |
QDataStream streamToPlugin(&dataToPlugins, QIODevice::WriteOnly);
|
18
|
185 |
m_argFlag = 1;
|
25
|
186 |
streamToPlugin<<m_argFlag;
|
|
187 |
streamToPlugin<<operationId;
|
18
|
188 |
if(customData)
|
|
189 |
{
|
25
|
190 |
streamToPlugin<<m_argFlag;
|
|
191 |
streamToPlugin<<*customData;
|
18
|
192 |
}
|
|
193 |
else
|
|
194 |
{
|
|
195 |
m_argFlag = 0;
|
25
|
196 |
streamToPlugin<<m_argFlag;
|
18
|
197 |
}
|
|
198 |
|
25
|
199 |
write<<dataToPlugins;
|
|
200 |
|
18
|
201 |
QString intfName(activityFetcherInterface);
|
|
202 |
//ToDo:- How much size to allocate for custom data? keeping MaxSmfActivityEntrySize for now
|
|
203 |
int maxAllocation = MaxSmfActivityEntrySize;
|
|
204 |
|
|
205 |
//call private impl's send method
|
|
206 |
m_SmfClientPrivate->sendRequest(m_serializedDataToServer, intfName,
|
|
207 |
SmfActivityCustomRequest, maxAllocation);
|
25
|
208 |
return err;
|
18
|
209 |
}
|
|
210 |
|
25
|
211 |
SmfError SmfActivityFetcherPrivate::cancelRequest()
|
|
212 |
{
|
|
213 |
qDebug()<<"Inside SmfActivityFetcherPrivate::cancelRequest()";
|
|
214 |
QByteArray notused;
|
|
215 |
QByteArray retData = m_SmfClientPrivate->sendSyncRequest(notused,SmfCancelRequest,1000, notused);
|
|
216 |
|
|
217 |
//De-serialize it into SmfError
|
|
218 |
QDataStream reader(&retData,QIODevice::ReadOnly);
|
|
219 |
int val;
|
|
220 |
reader>>val;
|
|
221 |
SmfError error = (SmfError) val;
|
|
222 |
return error;
|
|
223 |
}
|
|
224 |
|
|
225 |
|
18
|
226 |
void SmfActivityFetcherPrivate::resultsAvailable(QByteArray result,SmfRequestTypeID opcode, SmfError error)
|
|
227 |
{
|
|
228 |
qDebug()<<"SmfActivityFetcherPrivate::resultsAvailable";
|
|
229 |
qDebug()<<"opcode = "<<opcode;
|
|
230 |
|
|
231 |
QDataStream reader(&result,QIODevice::ReadOnly);
|
|
232 |
|
|
233 |
//Now de-serialize it based on opcode
|
|
234 |
switch(opcode)
|
|
235 |
{
|
|
236 |
case SmfActivitySelfActivity:
|
|
237 |
case SmfActivityFriendsActivities:
|
|
238 |
case SmfActivityFiltered:
|
|
239 |
{
|
|
240 |
SmfActivityEntryList* m_entries = new SmfActivityEntryList;
|
|
241 |
reader>>*m_entries;
|
|
242 |
qDebug()<<"m_entries.count = "<<m_entries->count();
|
|
243 |
|
|
244 |
//ToDo:- not incorporating paging now
|
|
245 |
SmfResultPage page;
|
|
246 |
|
|
247 |
emit m_activityFetcher->resultsAvailable(m_entries,error,page);
|
|
248 |
}
|
|
249 |
break;
|
|
250 |
|
|
251 |
case SmfActivityCustomRequest:
|
|
252 |
{
|
|
253 |
int operationId;
|
|
254 |
QByteArray *data = new QByteArray;
|
|
255 |
reader>>operationId;
|
|
256 |
reader>>*data;
|
|
257 |
|
|
258 |
qDebug()<<"operationId = "<<operationId;
|
|
259 |
qDebug()<<"data size = "<<data->size();
|
|
260 |
emit m_activityFetcher->customDataAvailable(operationId, data);
|
|
261 |
}
|
|
262 |
break;
|
|
263 |
default:
|
|
264 |
Q_ASSERT_X(1,"Activity Private Unknown opcode","default case");
|
|
265 |
}
|
|
266 |
}
|