42 { |
45 { |
43 } |
46 } |
44 |
47 |
45 SmfServer::~SmfServer() |
48 SmfServer::~SmfServer() |
46 { |
49 { |
47 delete m_SmfServerPrivate; |
50 if(m_SmfServerPrivate) |
|
51 { |
|
52 delete m_SmfServerPrivate; |
|
53 m_SmfServerPrivate = NULL; |
|
54 } |
|
55 |
48 } |
56 } |
49 |
57 |
50 bool SmfServer::startServer() |
58 bool SmfServer::startServer() |
51 { |
59 { |
52 bool success = false; |
60 bool success = false; |
53 //Initialize all the component handles |
61 //Initialize all the component handles |
54 writeLog("Not doing SmfTransportManager::getInstance"); |
62 |
55 //m_transportManager = SmfTransportManager::getInstance(); |
63 SmfTransportInitializeResult networkStatus = prepareTransport(); |
56 writeLog("Not doing m_transportManager->initializeTransport"); |
64 qDebug()<<("Before m_pluginManager construction"); |
57 //checking the network status, no need to proceed if not permitted |
65 m_pluginManager = SmfPluginManager::getInstance(this); |
58 //SmfTransportInitializeResult networkStatus = m_transportManager->initializeTransport(); |
66 qDebug()<<("After m_pluginManager construction"); |
59 writeLog("Before networkStatus"); |
67 // m_dataStoreManager = new SmfDataStoreManager(); |
60 //TODO:-check this |
68 //Initialize private implementation |
61 if(1/*networkStatus == SmfTransportInitNoError*/) |
69 #ifdef Q_OS_SYMBIAN |
62 { |
70 TRAPD(err, m_SmfServerPrivate = SmfServerSymbian::NewL(CActive::EPriorityStandard,this)); |
63 writeLog("Before m_pluginManager construction"); |
71 QString log("SmfServer::startServer="); |
64 m_pluginManager = SmfPluginManager::getInstance(this); |
72 int errorQ = err ; |
65 writeLog("After m_pluginManager construction"); |
73 log += errorQ; |
66 // m_dataStoreManager = new SmfDataStoreManager(); |
74 qDebug()<<(log); |
67 //Initialize private implementation |
75 if( KErrNone != err ) |
68 #ifdef Q_OS_SYMBIAN |
76 { |
69 TRAPD(err, m_SmfServerPrivate = SmfServerSymbian::NewL(CActive::EPriorityStandard,this)); |
77 return success; |
70 QString log("SmfServer::startServer="); |
78 } |
71 int errorQ = err ; |
79 TInt error = m_SmfServerPrivate->Start( KSmfServerName ); |
72 log += errorQ; |
80 RSemaphore semaphore; |
73 writeLog(log); |
81 User::LeaveIfError( semaphore.OpenGlobal( KSmfServerSemaphoreName ) ); |
74 if( KErrNone != err ) |
82 // Semaphore opened ok |
75 { |
83 semaphore.Signal(); |
76 return success; |
84 semaphore.Close(); |
77 } |
85 errorQ = error ; |
78 TInt error = m_SmfServerPrivate->Start( KSmfServerName ); |
86 log.clear(); |
79 errorQ = error ; |
87 log = QString("m_SmfServerPrivate->Start="); |
80 log.clear(); |
88 log += QString::number(error); |
81 log = QString("m_SmfServerPrivate->Start="); |
89 qDebug()<<(log); |
82 log += QString::number(error); |
90 if( KErrNone == error ) |
83 writeLog(log); |
91 { |
84 if( KErrNone == error ) |
92 success = true; |
85 { |
93 } |
86 success = true; |
94 else |
87 } |
95 { |
88 else |
96 //error |
89 { |
97 return success; |
90 //error |
98 } |
91 return success; |
99 #else |
92 } |
100 m_SmfServerPrivate = new SmfServerQt(this); |
93 #else |
101 success = m_SmfServerPrivate->start(); |
94 m_SmfServerPrivate = new SmfServerQt(this); |
102 if (!success) |
95 success = m_SmfServerPrivate->start(); |
103 { |
96 if (!success) |
104 return success; |
97 { |
105 } |
98 return success; |
106 #endif |
99 } |
107 |
100 #endif |
108 m_credentialMngr = new SmfCredMgrClient(); |
101 //request CM server for auth expiry info, note:- we should resend the request everytime we get expiry |
|
102 //notification |
|
103 //TODO:- Do it after CM implementation |
|
104 //CMclient->requestAuthExpiryNotify(); |
|
105 //connect(CMClient,SIGNAL(authExpiryNotify(NotificationType,SmfPluginID),this,SLOT(NotificationType,SmfPluginID)); |
|
106 } |
|
107 return success; |
109 return success; |
108 } |
110 } |
109 //Note:- Almost all the following APIs are called by private impl via the handle |
111 //Note:- Almost all the following APIs are called by private impl via the handle |
110 /** |
|
111 * This called first once a session is created by the private impl |
|
112 * @param clientID some unique client process ID, SID for symbian platform |
|
113 * TODO:-How to get the pid for rest of the platforms? |
|
114 * @return true if client is already athorized, else false |
|
115 * |
|
116 */ |
|
117 bool SmfServer::isClientAuthorized(SmfClientAuthID clientID) |
|
118 { |
|
119 //TODO:- once CM is complete do it properly |
|
120 Q_UNUSED(clientID); |
|
121 return true; |
|
122 } |
|
123 /** |
|
124 * This API is called by the private impl when isClientAuthorized returns false |
|
125 * @param clientID client Id (SID for symbian platform), provided by the private impl |
|
126 * Note:- The session(and in turn the client) will be blocked untill authorization completes. |
|
127 */ |
|
128 void SmfServer::authorizeClient(SmfClientAuthID clientID) |
|
129 { |
|
130 //TODO:- once CM is complete, do it properly |
|
131 //CMclient->authorizeClient(clientID) |
|
132 //connect(CMClient,SIGNAL(clientAuthorizationFinished(bool,SmfClientAuthID)),this,SLOT(clientAuthorizationFinished(bool,SmfClientAuthID))); |
|
133 Q_UNUSED(clientID); |
|
134 } |
|
135 /** |
112 /** |
136 * This API is called by the private impl when client is authorized |
113 * This API is called by the private impl when client is authorized |
137 * @param interfaceID Interface id, provided by the private impl (it gets it from client) |
114 * @param interfaceID Interface id, provided by the private impl (it gets it from client) |
138 * @param pluginIDMap Map of plugins who implement this interface and corresponding provider, |
115 * @param pluginIDMap Map of plugins who implement this interface and corresponding provider, |
139 * this is returned to the private impl |
116 * this is returned to the private impl |
164 * It calls CMclient to get the list synchronously |
141 * It calls CMclient to get the list synchronously |
165 * TODO:- session should store this for future ref? |
142 * TODO:- session should store this for future ref? |
166 */ |
143 */ |
167 void SmfServer::getAuthorizedPlugins(QList<SmfPluginID>& list,QList<SmfPluginID>& authList) |
144 void SmfServer::getAuthorizedPlugins(QList<SmfPluginID>& list,QList<SmfPluginID>& authList) |
168 { |
145 { |
169 //TODO:- do it properly as per CMclient implementation |
146 //TODO:-Uncomment the following once authorization flow of plugin is implemented |
170 //CMclient->getAuthorizedPlugins(list,authList); |
147 /* authList.clear(); |
171 //testing purpose only |
148 for(int i=0;i<list.count();i++) |
172 #ifdef NO_OTHER_MODULES |
149 { |
|
150 bool isAuthorized = m_credentialMngr->CheckPluginAuthentication(list[i]); |
|
151 if(isAuthorized) |
|
152 { |
|
153 authList.append(list[i]); |
|
154 } |
|
155 }*/ |
173 authList = list; |
156 authList = list; |
174 #endif |
157 } |
175 } |
158 SmfTransportInitializeResult SmfServer::prepareTransport() |
176 /** |
159 { |
177 * This API is called by the private impl to request the PM to do the actual request/parsing asynchronously |
160 qDebug()<<("Before SmfTransportManager::getInstance"); |
178 * Note:- the sever private impl (SmfServerSymbian for symbian platform) maintains a map of session ptr and some randomely |
161 m_transportManager = SmfTransportManager::getInstance(); |
179 * generated number.For the time being we are allowing only one outstanding request per session, so no need to store |
162 qDebug()<<("Before m_transportManager->initializeTransport"); |
180 * both session and msg ptr, but in future we may need to. |
163 //checking the network status |
181 * @param requestID Request id (corresponds to the key of the mapmaintained by SmfServerSymbian). |
164 SmfTransportInitializeResult networkStatus = m_transportManager->initializeTransport(); |
182 * @param pluginID PluginID, provided by the session |
165 qDebug()<<("m_transportManager->initializeTransport return = ")<<networkStatus; |
183 * @param interfaceID InterfaceID provided by session |
166 return networkStatus; |
184 * @requestTypeID Request Opcode, provided by session |
167 } |
185 */ |
168 void SmfServer::sendToPluginManager(int requestID,SmfPluginID pluginID,SmfInterfaceID interfaceID,SmfRequestTypeID requestTypeID,QByteArray dataForPlugin ,int pageno,int perpage) |
186 void SmfServer::getRequestedData(int requestID,SmfPluginID pluginID,SmfInterfaceID interfaceID, SmfRequestTypeID requestTypeID,QByteArray dataForPlugin) |
169 { |
187 { |
170 qDebug()<<("SmfServer::delegateToPluginManager"); |
188 //TODO:- cross check the params with PM owner |
171 qDebug()<<(QString::number(requestID)); |
189 //PM->getData(requestID,pluginID,interfaceID,requestTypeID); |
172 qDebug()<<(pluginID); |
190 m_SmfServerPrivate->writeLog("SmfServer::getRequestedData"); |
173 qDebug()<<(interfaceID); |
191 m_SmfServerPrivate->writeLog(QString::number(requestID)); |
174 qDebug()<<(QString::number(requestTypeID)); |
192 m_SmfServerPrivate->writeLog(pluginID); |
175 //TODO:-PM should take page info too |
193 m_SmfServerPrivate->writeLog(interfaceID); |
176 m_pluginManager->createRequest(requestID,pluginID,requestTypeID,dataForPlugin); |
194 m_SmfServerPrivate->writeLog(QString::number(requestTypeID)); |
177 } |
195 bool defaultCase = false; |
178 SmfError SmfServer::sendToDSM(QByteArray qtdataForDSM,SmfRequestTypeID opcode,QByteArray& qtdataFromDSM) |
196 //serializedInfo contains base provider info+ other data depending on requestTypeID |
179 { |
197 QDataStream reader(&dataForPlugin,QIODevice::ReadOnly); |
180 DataStoreManager* dsm = DataStoreManager::getDataStoreManager(); |
198 QByteArray dataTobeSent; |
181 //Note:- deserialization and formation of user profile and social profile are done by server |
199 switch(requestTypeID) |
182 QDataStream readStream(&qtdataForDSM,QIODevice::ReadOnly); |
200 { |
183 QDataStream writeStream(&qtdataFromDSM,QIODevice::ReadOnly); |
201 case SmfContactPost: |
184 switch(opcode) |
202 { |
185 { |
203 SmfProvider provider; |
186 case SmfRelationCreate: |
204 SmfPost post; |
187 { |
205 SmfLocation loc; |
188 //read the incoming data |
206 reader>>provider; |
189 SmfProvider provider; |
207 reader>>post; |
190 SmfContact contact; |
208 reader>>loc; |
191 readStream>>provider; |
209 //now form the serialized bytearray with only SmfPost and SmfPlace |
192 readStream>>contact; |
210 QDataStream writer(&dataTobeSent,QIODevice::WriteOnly); |
193 |
211 writer<<post; |
194 SmfRelationId relnId = dsm->create(&provider,&contact); |
212 writer<<loc; |
195 writeStream<<relnId; |
213 } |
196 } |
214 break; |
197 break; |
215 case SmfContactUpdatePost: |
198 case SmfRelationAssociate: |
216 { |
199 { |
217 SmfProvider provider; |
200 SmfRelationId relnId; |
218 SmfPost post; |
201 SmfContact contact; |
219 reader>>provider; |
202 SmfProvider provider; |
220 reader>>post; |
203 readStream>>relnId; |
221 //now form the serialized bytearray with only SmfPost |
204 readStream>>contact; |
222 QDataStream writer(&dataTobeSent,QIODevice::WriteOnly); |
205 readStream>>provider; |
223 writer<<post; |
206 |
224 } |
207 SmfError err = dsm->associate(relnId,&contact,&provider); |
225 break; |
208 int errInt = err; |
226 case SmfContactPostDirected: |
209 writeStream<<errInt; |
227 { |
210 } |
228 SmfProvider provider; |
211 break; |
229 SmfPost post; |
212 case SmfRelationSearchById: |
230 SmfContact contact; |
213 { |
231 SmfLocation place; |
214 SmfRelationId relnId; |
232 reader>>provider; |
215 readStream>>relnId; |
233 reader>>post; |
216 |
234 reader>>contact; |
217 SmfRelationItem* relnItem = dsm->searchById(relnId); |
235 reader>>place; |
218 writeStream<<*(relnItem); |
236 QDataStream writer(&dataTobeSent,QIODevice::WriteOnly); |
219 } |
237 writer<<post; |
220 break; |
238 writer<<contact; |
221 case SmfRelationCount: |
239 writer<<place; |
222 { |
240 } |
223 SmfRelationId relationId; |
241 break; |
224 readStream>>relationId; |
242 case SmfContactSharePost: |
225 int cnt = dsm->count(relationId); |
243 { |
226 writeStream<<cnt; |
244 SmfProvider provider; |
227 } |
245 SmfPost post; |
228 break; |
246 SmfContact contact; |
229 case SmfRelationGet: |
247 bool edited; |
230 { |
248 reader>>provider; |
231 SmfRelationId relationId; |
249 reader>>post; |
232 quint32 index; |
250 reader>>contact; |
233 readStream>>relationId; |
251 reader>>edited; |
234 readStream>>index; |
252 //now form the serialized bytearray with only SmfPost |
235 SmfRelationItem* relnItem = dsm->getContact(relationId,index); |
253 QDataStream writer(&dataTobeSent,QIODevice::WriteOnly); |
236 writeStream<<relnItem; |
254 writer<<post; |
237 } |
255 writer<<contact; |
238 break; |
256 writer<<edited; |
239 case SmfRelationGetAll: |
257 } |
240 { |
258 break; |
241 SmfRelationId relationId; |
259 case SmfPictureDescription: |
242 readStream>>relationId; |
260 case SmfPictureUpload: |
243 |
261 { |
244 QList<SmfRelationItem> relnIditemList = dsm->getAll(relationId); |
262 SmfProvider provider; |
245 writeStream<<relnIditemList; |
263 SmfPicture picture; |
246 } |
264 reader>>provider; |
247 break; |
265 reader>>picture; |
248 case SmfRelationGetAllRelations: |
266 //now form the serialized bytearray with only SmfPicture |
249 { |
267 QDataStream writer(&dataTobeSent,QIODevice::WriteOnly); |
250 QList<SmfRelationId> relnIdList = dsm->getAllRelations(); |
268 writer<<picture; |
251 writeStream<<relnIdList; |
269 } |
252 } |
270 break; |
253 break; |
271 case SmfPictureMultiUpload: |
254 default: |
272 { |
255 break; |
273 SmfProvider provider; |
256 } |
274 SmfPictureList pictureList; |
257 return SmfNoError; |
275 reader>>provider; |
|
276 reader>>pictureList; |
|
277 //now form the serialized bytearray with only SmfPicture |
|
278 QDataStream writer(&dataTobeSent,QIODevice::WriteOnly); |
|
279 writer<<pictureList; |
|
280 } |
|
281 break; |
|
282 case SmfPicturePostComment: |
|
283 { |
|
284 SmfProvider provider; |
|
285 SmfPicture picture; |
|
286 SmfComment comment; |
|
287 reader>>provider; |
|
288 reader>>picture; |
|
289 reader>>comment; |
|
290 //now form the serialized bytearray with only SmfPicture |
|
291 QDataStream writer(&dataTobeSent,QIODevice::WriteOnly); |
|
292 writer<<picture; |
|
293 writer<<comment; |
|
294 } |
|
295 break; |
|
296 default: |
|
297 defaultCase = true; |
|
298 break; |
|
299 } |
|
300 //When xtra info to be sent to plugin manager |
|
301 if(!defaultCase) |
|
302 { |
|
303 m_pluginManager->createRequest(requestID,pluginID,requestTypeID,dataTobeSent); |
|
304 } |
|
305 //when plugin manager needs to xtra info |
|
306 else |
|
307 { |
|
308 QByteArray arr; |
|
309 m_pluginManager->createRequest(requestID,pluginID,requestTypeID,arr); |
|
310 } |
|
311 } |
258 } |
312 /** |
259 /** |
313 * This slot is invoked when CM finishes the authorization of the client. |
260 * This slot is invoked when CM finishes the authorization of the client. |
314 * @param authID As it contains the session ptr, sever directly invokes the session's API to notify success |
261 * @param authID As it contains the session ptr, sever directly invokes the session's API to notify success |
315 */ |
262 */ |
316 void SmfServer::clientAuthorizationFinished(bool success,SmfClientAuthID authID ) |
263 void SmfServer::clientAuthorizationFinished(bool success,SmfClientAuthID authID ) |
317 { |
264 { |
318 //TODO:- implement this api in session class |
265 //TODO:- implement this api in session class |
319 //note:- in case success is false client completes the request with SmfErrClientAuthFailed |
266 //note:- in case success is false client completes the request with SmfErrClientAuthFailed |
320 //TODO:- define set of smf wide error after consulting with other module owners |
267 //TODO:- define set of smf wide error after consulting with other module owners |
321 authID.session->clientAuthorizationFinished(success); |
268 authID.session->clientathorizationFinished(success); |
322 } |
269 } |
323 /** |
270 /** |
324 * This API is called by PM once its done with request and parsing |
271 * This API is called by PM once its done with request and parsing |
325 * @param requestID The request id which is completed |
272 * @param requestID The request id which is completed |
326 * @param parsedData Serialized data(as per request type) filled by PM |
273 * @param parsedData Serialized data(as per request type) filled by PM |
327 * @param error Error occured |
274 * @param error Error occured |
328 * TODO:- should use smf wide global errors instead |
275 * TODO:- should use smf wide global errors instead |
329 */ |
276 */ |
330 void SmfServer::resultsAvailable(int requestID,QByteArray* parsedData,SmfError error) |
277 void SmfServer::resultsAvailable(int requestID,QByteArray* parsedData,SmfError error) |
331 { |
278 { |
332 m_SmfServerPrivate->writeLog("SmfServer::resultsAvailable"); |
279 qDebug()<<("SmfServer::resultsAvailable"); |
333 m_SmfServerPrivate->writeLog("requestID="); |
280 qDebug()<<("requestID="); |
334 m_SmfServerPrivate->writeLog(QString::number(requestID)); |
281 qDebug()<<(QString::number(requestID)); |
335 m_SmfServerPrivate->writeLog("parsedData->size()="); |
282 qDebug()<<("parsedData->size()="); |
336 m_SmfServerPrivate->writeLog(QString::number(parsedData->size())); |
283 qDebug()<<(QString::number(parsedData->size())); |
337 m_SmfServerPrivate->writeLog("Error="); |
284 qDebug()<<("Error="); |
338 m_SmfServerPrivate->writeLog(QString::number(error)); |
285 qDebug()<<(QString::number(error)); |
339 //Serialize error followed by actual data |
286 //Serialize error followed by actual data |
340 QByteArray dataWithError; |
287 QByteArray dataWithError; |
341 QDataStream writer(&dataWithError,QIODevice::WriteOnly); |
288 QDataStream writer(&dataWithError,QIODevice::WriteOnly); |
342 writer<<error; |
289 writer<<error; |
343 writer<<*(parsedData); |
290 if(parsedData->size()) |
|
291 { |
|
292 writer<<*(parsedData); |
|
293 } |
344 //find out the appropriate session and request id and service that |
294 //find out the appropriate session and request id and service that |
345 m_SmfServerPrivate->findAndServiceclient(requestID,&dataWithError,error); |
295 m_SmfServerPrivate->findAndServiceclient(requestID,&dataWithError,error); |
346 } |
296 } |
347 /** |
297 /** |
348 * Seems reduntant in symbian as client is served with RMessage2::Complete() |
298 * Seems reduntant |
349 */ |
299 */ |
350 void SmfServer::serviceClient(QByteArray* parsedData) |
300 void SmfServer::serviceClient(QByteArray* parsedData) |
351 { |
301 { |
352 Q_UNUSED(parsedData); |
302 Q_UNUSED(parsedData) |
353 } |
303 } |
354 /** |
|
355 * Used by PM to get a list of tokens |
|
356 * TODO:- cross check the params |
|
357 */ |
|
358 void SmfServer::getAuthenticationKeys(int pluginID,QStringList& keys,QStringList& urls) |
|
359 { |
|
360 //SMF-CM communication will be via CM client |
|
361 //TODO:- do it properly as per CM client impl |
|
362 //CMclient->getKeys(pluginID,keys,urls); |
|
363 Q_UNUSED(pluginID); |
|
364 Q_UNUSED(keys); |
|
365 Q_UNUSED(urls); |
|
366 } |
|
367 |
|
368 /** |
304 /** |
369 * This is called when CMclient notifies client expiry. |
305 * This is called when CMclient notifies client expiry. |
370 * @param type notification type, set of enums for future expansion |
306 * @param type notification type, set of enums for future expansion |
371 * @param id Plugin Id for which the authentication has expired |
307 * @param id Plugin Id for which the authentication has expired |
372 */ |
308 */ |
373 void SmfServer::authenticationKeysExpired(NotificationType type,SmfPluginID id) |
309 void SmfServer::authenticationKeysExpired(NotificationType type,SmfPluginID id) |
374 { |
310 { |
|
311 Q_UNUSED(type) |
|
312 Q_UNUSED(id) |
375 //resend the notify request |
313 //resend the notify request |
376 //CMclient->requestAuthExpiryNotify(); |
314 //CMclient->requestAuthExpiryNotify(); |
377 Q_UNUSED(type); |
315 } |
378 Q_UNUSED(id); |
316 /*void SmfServer::writeLog(QString log) const |
379 } |
|
380 |
|
381 void SmfServer::writeLog(QString log) const |
|
382 { |
317 { |
383 #ifdef WRITE_LOG |
318 #ifdef WRITE_LOG |
384 QFile file("c:\\data\\SmfServerLogs.txt"); |
319 QFile file("c:\\data\\SmfServerLogs.txt"); |
385 if (!file.open(QIODevice::Append | QIODevice::Text)) |
320 if (!file.open(QIODevice::Append | QIODevice::Text)) |
386 ; |
321 ; |
387 QTextStream out(&file); |
322 QTextStream out(&file); |
388 out << log << "\n"; |
323 out << log << "\n"; |
389 file.close(); |
324 file.close(); |
390 #else |
325 #else |
391 Q_UNUSED(log); |
326 Q_UNUSED(log) |
392 #endif |
327 #endif |
393 } |
328 }*/ |
|
329 //#ifdef CLIENT_SERVER_TEST |
|
330 dummyPM::dummyPM(SmfServer* server,QObject* parent) |
|
331 : m_server(server),QObject(parent) |
|
332 { |
|
333 m_timer = new QTimer(this); |
|
334 connect(m_timer, SIGNAL(timeout()), this, SLOT(responseAvailable())); |
|
335 } |
|
336 SmfError dummyPM::createRequest ( const quint32& aSessionID, |
|
337 const QString& aPluginID, |
|
338 const SmfRequestTypeID& aOperation, |
|
339 QByteArray& aInputData ) |
|
340 { |
|
341 qDebug()<<QString::number(aSessionID); |
|
342 qDebug()<<aPluginID; |
|
343 qDebug()<<QString::number(aOperation); |
|
344 qDebug()<<QString::number(aInputData.size()); |
|
345 m_timer->start(1000); |
|
346 } |
|
347 void dummyPM::responseAvailable() |
|
348 { |
|
349 |
|
350 } |
|
351 //#endif |