1 /** |
1 /** |
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the "Eclipse Public License v1.0" |
5 * under the terms of the "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html" |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html" |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
10 * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * Manasij Roy, Nalina Hariharan |
13 * Manasij Roy, Nalina Hariharan |
14 */ |
14 * |
|
15 * Description: |
|
16 * SMF Server component which handles the client requests and delegates |
|
17 * them properly to the appropriate component |
|
18 * |
|
19 */ |
|
20 |
|
21 #include <QDebug> |
|
22 #include <qglobal.h> |
|
23 #include <smfcontact.h> |
|
24 #include <smfgroup.h> |
|
25 #include <smfpost.h> |
|
26 #include <smflocation.h> |
|
27 #include <smfpicture.h> |
|
28 #include <smfcomment.h> |
|
29 #include <smfcredmgrclient.h> |
|
30 #include <smfrelationmgr.h> |
15 |
31 |
16 #include "smfserver.h" |
32 #include "smfserver.h" |
17 #include "smfpluginmanager.h" |
33 #include "smfpluginmanager.h" |
18 #include "smftransportmanager.h" |
34 #include "smftransportmanager.h" |
19 #include "dsm.h" |
35 #include "dsm.h" |
20 #include "smfclientglobal.h" |
|
21 #include <smfprovider.h> |
|
22 #include <smfpost.h> |
|
23 #include <smflocation.h> |
|
24 #include <smfcontact.h> |
|
25 #include <smfpicture.h> |
|
26 #include <smfcomment.h> |
|
27 #include <SmfCredMgrClient.h> |
|
28 #include <smfrelationmgr.h> |
|
29 #include <smfclientglobal.h> |
|
30 #include <QImage> |
|
31 #include <QUrl> |
|
32 #include <smfgroup.h> |
|
33 #include <QTextStream> |
|
34 #include <QFile> |
|
35 |
|
36 #ifdef Q_OS_SYMBIAN |
36 #ifdef Q_OS_SYMBIAN |
37 #include "smfserversymbian_p.h" |
37 #include "smfserversymbian_p.h" |
38 #else |
38 #else |
39 #include "smfserverqt_p.h" |
39 #include "smfserverqt_p.h" |
40 #include "smfserverqtsession.h" |
40 #include "smfserverqtsession.h" |
41 #endif |
41 #endif |
|
42 |
42 |
43 |
43 SmfServer::SmfServer(QObject* parent) |
44 SmfServer::SmfServer(QObject* parent) |
44 : QObject(parent) |
45 : QObject(parent) |
45 { |
46 { |
|
47 m_transportManager = NULL; |
|
48 m_pluginManager = NULL; |
|
49 m_credentialMngr = NULL; |
46 } |
50 } |
47 |
51 |
48 SmfServer::~SmfServer() |
52 SmfServer::~SmfServer() |
49 { |
53 { |
|
54 qDebug()<<"Inside Smfserver::~SmfServer()"; |
|
55 if(m_transportManager) |
|
56 delete m_transportManager; |
|
57 if(m_pluginManager) |
|
58 delete m_pluginManager; |
|
59 if(m_credentialMngr) |
|
60 delete m_credentialMngr; |
50 if(m_SmfServerPrivate) |
61 if(m_SmfServerPrivate) |
51 { |
62 { |
52 delete m_SmfServerPrivate; |
63 delete m_SmfServerPrivate; |
53 m_SmfServerPrivate = NULL; |
64 m_SmfServerPrivate = NULL; |
54 } |
65 } |
55 |
66 } |
56 } |
|
57 |
67 |
58 bool SmfServer::startServer() |
68 bool SmfServer::startServer() |
59 { |
69 { |
|
70 qDebug()<<"Inside SmfServer::startServer()"; |
|
71 |
60 bool success = false; |
72 bool success = false; |
|
73 |
61 //Initialize all the component handles |
74 //Initialize all the component handles |
62 |
|
63 SmfTransportInitializeResult networkStatus = prepareTransport(); |
75 SmfTransportInitializeResult networkStatus = prepareTransport(); |
64 qDebug()<<("Before m_pluginManager construction"); |
76 |
|
77 qDebug()<<"Before m_pluginManager construction"; |
65 m_pluginManager = SmfPluginManager::getInstance(this); |
78 m_pluginManager = SmfPluginManager::getInstance(this); |
66 qDebug()<<("After m_pluginManager construction"); |
79 qDebug()<<"After m_pluginManager construction"; |
|
80 |
67 // m_dataStoreManager = new SmfDataStoreManager(); |
81 // m_dataStoreManager = new SmfDataStoreManager(); |
|
82 |
|
83 #ifdef Q_OS_SYMBIAN |
68 //Initialize private implementation |
84 //Initialize private implementation |
69 #ifdef Q_OS_SYMBIAN |
|
70 TRAPD(err, m_SmfServerPrivate = SmfServerSymbian::NewL(CActive::EPriorityStandard,this)); |
85 TRAPD(err, m_SmfServerPrivate = SmfServerSymbian::NewL(CActive::EPriorityStandard,this)); |
71 QString log("SmfServer::startServer="); |
86 qDebug()<<"SmfServerSymbian::NewL() = "<<err; |
72 int errorQ = err ; |
87 |
73 log += errorQ; |
|
74 qDebug()<<(log); |
|
75 if( KErrNone != err ) |
88 if( KErrNone != err ) |
76 { |
|
77 return success; |
89 return success; |
78 } |
90 |
79 TInt error = m_SmfServerPrivate->Start( KSmfServerName ); |
91 TInt error = m_SmfServerPrivate->Start( KSmfServerName ); |
|
92 qDebug()<<"m_SmfServerPrivate->Start = "<<error; |
|
93 |
80 RSemaphore semaphore; |
94 RSemaphore semaphore; |
81 User::LeaveIfError( semaphore.OpenGlobal( KSmfServerSemaphoreName ) ); |
95 User::LeaveIfError( semaphore.OpenGlobal( KSmfServerSemaphoreName ) ); |
|
96 |
82 // Semaphore opened ok |
97 // Semaphore opened ok |
83 semaphore.Signal(); |
98 semaphore.Signal(); |
84 semaphore.Close(); |
99 semaphore.Close(); |
85 errorQ = error ; |
100 |
86 log.clear(); |
|
87 log = QString("m_SmfServerPrivate->Start="); |
|
88 log += QString::number(error); |
|
89 qDebug()<<(log); |
|
90 if( KErrNone == error ) |
101 if( KErrNone == error ) |
91 { |
102 { |
92 success = true; |
103 success = true; |
93 } |
104 } |
94 else |
105 else |
95 { |
106 { |
96 //error |
107 //error |
97 return success; |
108 return success; |
98 } |
109 } |
99 #else |
110 #else |
100 m_SmfServerPrivate = new SmfServerQt(this); |
111 // For non-symbian platforms |
|
112 m_SmfServerPrivate = new SmfServerQt(this); |
101 success = m_SmfServerPrivate->start(); |
113 success = m_SmfServerPrivate->start(); |
102 if (!success) |
114 if (!success) |
103 { |
115 { |
104 return success; |
116 return success; |
105 } |
117 } |
106 #endif |
118 #endif |
107 |
119 |
108 m_credentialMngr = new SmfCredMgrClient(); |
120 m_credentialMngr = new SmfCredMgrClient(); |
109 return success; |
121 return success; |
110 } |
122 } |
|
123 |
111 //Note:- Almost all the following APIs are called by private impl via the handle |
124 //Note:- Almost all the following APIs are called by private impl via the handle |
112 /** |
125 /** |
113 * This API is called by the private impl when client is authorized |
126 * This API is called by the private impl when client is authorized |
114 * @param interfaceID Interface id, provided by the private impl (it gets it from client) |
127 * @param interfaceID Interface id, provided by the private impl (it gets it from client) |
115 * @param pluginIDMap Map of plugins who implement this interface and corresponding provider, |
128 * @param pluginIDMap Map of plugins who implement this interface and corresponding provider, |
116 * this is returned to the private impl |
129 * this is returned to the private impl |
117 * It calls PM to get the list. Note:- PM may return SmfProviderBase which is superset of SmfProvider. |
130 * It calls PM to get the list. Note:- PM may return SmfProviderBase which is superset of SmfProvider. |
118 * TODO:- session should store this map for future ref? |
131 * TODO:- session should store this map for future ref? |
119 */ |
132 */ |
120 void SmfServer::getPlugins(SmfInterfaceID interfaceID, QMap<SmfPluginID,SmfProvider>& pluginIDMap) |
133 void SmfServer::getPlugins(const SmfInterfaceID& interfaceID, QMap<SmfPluginID,SmfProvider>& pluginIDMap) |
121 { |
134 { |
122 pluginIDMap.clear(); |
135 qDebug()<<"Inside SmfServer::getPlugins()"; |
123 m_pluginManager->getPlugins(interfaceID,pluginIDMap); |
136 m_pluginManager->getPlugins(interfaceID,pluginIDMap); |
124 } |
137 } |
125 |
138 |
126 SmfPluginID SmfServer::getPlugin(SmfInterfaceID interfaceID,SmfProvider provider) |
139 SmfPluginID SmfServer::getPlugin(const SmfInterfaceID& interfaceID,SmfProvider provider) |
127 { |
140 { |
128 //TODO:- do it properly as per PM implementation |
141 qDebug()<<"Inside SmfServer::getPlugin()"; |
129 //return PM->getplugin(interfaceID,provider); |
|
130 //TODO:- PM is not yet ready |
|
131 SmfPluginID id; |
142 SmfPluginID id; |
132 m_pluginManager->getPluginId(interfaceID,provider, id); |
143 m_pluginManager->getPluginId(interfaceID,provider, id); |
133 return id; |
144 return id; |
134 //testing purpose only |
145 } |
135 } |
146 |
136 /** |
147 /** |
137 * This API is called by the private impl to get a list of authorized plugins from CM |
148 * This API is called by the private impl to get a list of authorized plugins from CM |
138 * @param list List of plugins to be filtered |
149 * @param list List of plugins to be filtered |
139 * @param authList List of authorised plugins filled by CM |
150 * @param authList List of authorised plugins filled by CM |
140 * this is returned to the private impl |
151 * this is returned to the private impl |
141 * It calls CMclient to get the list synchronously |
152 * It calls CMclient to get the list synchronously |
142 * TODO:- session should store this for future ref? |
153 * TODO:- session should store this for future ref? |
143 */ |
154 */ |
144 void SmfServer::getAuthorizedPlugins(QList<SmfPluginID>& list,QList<SmfPluginID>& authList) |
155 void SmfServer::getAuthorizedPlugins(QList<SmfPluginID>& list,QList<SmfPluginID>& authList) |
145 { |
156 { |
146 //TODO:-Uncomment the following once authorization flow of plugin is implemented |
157 qDebug()<<"Inside SmfServer::getAuthorizedPlugins()"; |
147 /* authList.clear(); |
158 authList.clear(); |
148 for(int i=0;i<list.count();i++) |
159 for(int i=0;i<list.count();i++) |
149 { |
160 { |
150 bool isAuthorized = m_credentialMngr->CheckPluginAuthentication(list[i]); |
161 bool isAuthorized = m_credentialMngr->CheckPluginAuthentication(list[i]); |
151 if(isAuthorized) |
162 if(isAuthorized) |
152 { |
|
153 authList.append(list[i]); |
163 authList.append(list[i]); |
154 } |
164 } |
155 }*/ |
165 } |
156 authList = list; |
166 |
157 } |
|
158 SmfTransportInitializeResult SmfServer::prepareTransport() |
167 SmfTransportInitializeResult SmfServer::prepareTransport() |
159 { |
168 { |
160 qDebug()<<("Before SmfTransportManager::getInstance"); |
169 qDebug()<<"Inside SmfServer::prepareTransport()"; |
161 m_transportManager = SmfTransportManager::getInstance(); |
170 m_transportManager = SmfTransportManager::getInstance(); |
162 qDebug()<<("Before m_transportManager->initializeTransport"); |
171 |
163 //checking the network status |
172 //checking the network status |
164 SmfTransportInitializeResult networkStatus = m_transportManager->initializeTransport(); |
173 SmfTransportInitializeResult networkStatus = m_transportManager->initializeTransport(); |
165 qDebug()<<("m_transportManager->initializeTransport return = ")<<networkStatus; |
174 qDebug()<<"m_transportManager->initializeTransport() return = "<<networkStatus; |
166 return networkStatus; |
175 return networkStatus; |
167 } |
176 } |
168 void SmfServer::sendToPluginManager(int requestID,SmfPluginID pluginID,SmfInterfaceID interfaceID,SmfRequestTypeID requestTypeID,QByteArray dataForPlugin ,int pageno,int perpage) |
177 |
169 { |
178 void SmfServer::sendToPluginManager ( int requestID, SmfPluginID pluginID, |
170 qDebug()<<("SmfServer::delegateToPluginManager"); |
179 SmfInterfaceID interfaceID, SmfRequestTypeID requestTypeID, |
171 qDebug()<<(QString::number(requestID)); |
180 QByteArray dataForPlugin ) |
172 qDebug()<<(pluginID); |
181 { |
173 qDebug()<<(interfaceID); |
182 qDebug()<<"Inside SmfServer::sendToPluginManager()"; |
174 qDebug()<<(QString::number(requestTypeID)); |
183 qDebug()<<"Request ID = "<<requestID; |
|
184 qDebug()<<"PluginID = "<<pluginID; |
|
185 qDebug()<<"Interface = "<<interfaceID; |
|
186 qDebug()<<"RequestType = "<<requestTypeID; |
|
187 |
175 //TODO:-PM should take page info too |
188 //TODO:-PM should take page info too |
176 m_pluginManager->createRequest(requestID,pluginID,requestTypeID,dataForPlugin); |
189 SmfError err = m_pluginManager->createRequest(requestID,pluginID,requestTypeID,dataForPlugin); |
177 } |
190 qDebug()<<"m_pluginManager->createRequest() = "<<err; |
178 SmfError SmfServer::sendToDSM(QByteArray qtdataForDSM,SmfRequestTypeID opcode,QByteArray& qtdataFromDSM) |
191 } |
179 { |
192 |
|
193 /** |
|
194 * Request the Plugin manager to get the data. |
|
195 * @param requestID Corresponds to a client's session |
|
196 * @param pluginID Plugin for which the request is intended |
|
197 * @param interfaceID Interface name |
|
198 * @param dataForPlugin Data to be sent for this request |
|
199 */ |
|
200 SmfError SmfServer::sendToPluginManager ( SmfPluginID pluginID, |
|
201 SmfInterfaceID interfaceID, SmfRequestTypeID requestTypeID, |
|
202 QByteArray dataForPlugin, QByteArray &outputData) |
|
203 { |
|
204 qDebug()<<"Inside SmfServer::sendToPluginManager() for sync req"; |
|
205 qDebug()<<"PluginID = "<<pluginID; |
|
206 qDebug()<<"Interface = "<<interfaceID; |
|
207 qDebug()<<"RequestType = "<<requestTypeID; |
|
208 |
|
209 //TODO:-PM should take page info too |
|
210 SmfError err = m_pluginManager->createSyncRequest(pluginID,requestTypeID,dataForPlugin, outputData); |
|
211 qDebug()<<"m_pluginManager->createSyncRequest() = "<<err; |
|
212 return err; |
|
213 } |
|
214 |
|
215 SmfError SmfServer::sendToDSM ( QByteArray qtdataForDSM, SmfRequestTypeID opcode, |
|
216 QByteArray& qtdataFromDSM ) |
|
217 { |
|
218 qDebug()<<"Inside SmfServer::sendToDSM()"; |
|
219 |
180 DataStoreManager* dsm = DataStoreManager::getDataStoreManager(); |
220 DataStoreManager* dsm = DataStoreManager::getDataStoreManager(); |
|
221 |
181 //Note:- deserialization and formation of user profile and social profile are done by server |
222 //Note:- deserialization and formation of user profile and social profile are done by server |
182 QDataStream readStream(&qtdataForDSM,QIODevice::ReadOnly); |
223 QDataStream readStream(&qtdataForDSM,QIODevice::ReadOnly); |
183 QDataStream writeStream(&qtdataFromDSM,QIODevice::ReadOnly); |
224 QDataStream writeStream(&qtdataFromDSM,QIODevice::ReadOnly); |
|
225 quint8 flag = 0; |
184 switch(opcode) |
226 switch(opcode) |
185 { |
227 { |
186 case SmfRelationCreate: |
228 case SmfRelationCreate: |
187 { |
229 { |
188 //read the incoming data |
230 //read the incoming data |
189 SmfProvider provider; |
231 SmfProvider provider; |
190 SmfContact contact; |
232 SmfContact contact; |
191 readStream>>provider; |
233 readStream>>flag; |
192 readStream>>contact; |
234 if(flag) |
|
235 readStream>>provider; |
|
236 readStream>>flag; |
|
237 if(flag) |
|
238 readStream>>contact; |
193 |
239 |
194 SmfRelationId relnId = dsm->create(&provider,&contact); |
240 SmfRelationId relnId = dsm->create(&provider,&contact); |
195 writeStream<<relnId; |
241 writeStream<<relnId; |
196 } |
242 } |
197 break; |
243 break; |
249 { |
342 { |
250 QList<SmfRelationId> relnIdList = dsm->getAllRelations(); |
343 QList<SmfRelationId> relnIdList = dsm->getAllRelations(); |
251 writeStream<<relnIdList; |
344 writeStream<<relnIdList; |
252 } |
345 } |
253 break; |
346 break; |
|
347 case SmfRelationDeleteRelation: |
|
348 { |
|
349 SmfRelationId relnId; |
|
350 readStream>>relnId; |
|
351 SmfError err = dsm->deleteRelation(relnId); |
|
352 int errInt = err; |
|
353 writeStream<<errInt; |
|
354 break; |
|
355 } |
254 default: |
356 default: |
255 break; |
357 break; |
256 } |
358 } |
257 return SmfNoError; |
359 return SmfNoError; |
258 } |
360 } |
|
361 |
259 /** |
362 /** |
260 * This slot is invoked when CM finishes the authorization of the client. |
363 * This slot is invoked when CM finishes the authorization of the client. |
261 * @param authID As it contains the session ptr, sever directly invokes the session's API to notify success |
364 * @param authID As it contains the session ptr, sever directly invokes the session's API to notify success |
262 */ |
365 */ |
263 void SmfServer::clientAuthorizationFinished(bool success,SmfClientAuthID authID ) |
366 void SmfServer::clientAuthorizationFinished(bool success,SmfClientAuthID authID ) |
264 { |
367 { |
|
368 qDebug()<<"Inside SmfServer::clientAuthorizationFinished()"; |
265 //TODO:- implement this api in session class |
369 //TODO:- implement this api in session class |
266 //note:- in case success is false client completes the request with SmfErrClientAuthFailed |
370 //note:- in case success is false client completes the request with SmfErrClientAuthFailed |
267 //TODO:- define set of smf wide error after consulting with other module owners |
371 //TODO:- define set of smf wide error after consulting with other module owners |
268 authID.session->clientathorizationFinished(success); |
372 authID.session->clientAuthorizationFinished(success); |
269 } |
373 } |
|
374 |
270 /** |
375 /** |
271 * This API is called by PM once its done with request and parsing |
376 * This API is called by PM once its done with request and parsing |
272 * @param requestID The request id which is completed |
377 * @param requestID The request id which is completed |
273 * @param parsedData Serialized data(as per request type) filled by PM |
378 * @param parsedData Serialized data(as per request type) filled by PM |
274 * @param error Error occured |
379 * @param error Error occured |
275 * TODO:- should use smf wide global errors instead |
380 * TODO:- should use smf wide global errors instead |
276 */ |
381 */ |
277 void SmfServer::resultsAvailable(int requestID,QByteArray* parsedData,SmfError error) |
382 void SmfServer::resultsAvailable ( int requestID, QByteArray* parsedData, SmfError error ) |
278 { |
383 { |
279 qDebug()<<("SmfServer::resultsAvailable"); |
384 qDebug()<<"Inside SmfServer::resultsAvailable()"; |
280 qDebug()<<("requestID="); |
385 qDebug()<<"requestID = "<<requestID; |
281 qDebug()<<(QString::number(requestID)); |
386 qDebug()<<"parsedData->size() = "<<parsedData->size(); |
282 qDebug()<<("parsedData->size()="); |
387 qDebug()<<"Error = "<<error; |
283 qDebug()<<(QString::number(parsedData->size())); |
388 |
284 qDebug()<<("Error="); |
|
285 qDebug()<<(QString::number(error)); |
|
286 //Serialize error followed by actual data |
389 //Serialize error followed by actual data |
287 QByteArray dataWithError; |
390 QByteArray dataWithError; |
288 QDataStream writer(&dataWithError,QIODevice::WriteOnly); |
391 QDataStream writer(&dataWithError,QIODevice::WriteOnly); |
289 writer<<error; |
392 writer<<error; |
290 if(parsedData->size()) |
393 if(parsedData->size()) |
291 { |
394 { |
292 writer<<*(parsedData); |
395 writer<<*(parsedData); |
293 } |
396 } |
|
397 |
294 //find out the appropriate session and request id and service that |
398 //find out the appropriate session and request id and service that |
295 m_SmfServerPrivate->findAndServiceclient(requestID,&dataWithError,error); |
399 m_SmfServerPrivate->findAndServiceclient(requestID,&dataWithError,error); |
296 } |
400 } |
297 /** |
401 |
298 * Seems reduntant |
|
299 */ |
|
300 void SmfServer::serviceClient(QByteArray* parsedData) |
|
301 { |
|
302 Q_UNUSED(parsedData) |
|
303 } |
|
304 /** |
402 /** |
305 * This is called when CMclient notifies client expiry. |
403 * This is called when CMclient notifies client expiry. |
306 * @param type notification type, set of enums for future expansion |
404 * @param type notification type, set of enums for future expansion |
307 * @param id Plugin Id for which the authentication has expired |
405 * @param id Plugin Id for which the authentication has expired |
308 */ |
406 */ |