Update change log and spec for wrt-plugins-tizen_0.4.50
[framework/web/wrt-plugins-tizen.git] / src / DataControl / SqlDataControlConsumer.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <cassert>
19 #include <Commons/Exception.h>
20 #include "DataType.h"
21 #include "SqlDataControlConsumer.h"
22 #include <appsvc/appsvc.h>
23 #include <string>
24 #include <vector>
25 #include <aul/aul.h>
26 #include <sstream>
27 #include <package-manager.h>
28 #include <app.h>
29 // to get package name by appid
30 #include <app_info.h>
31 #include <app_manager.h>
32 // To get ppid
33 #include <unistd.h>
34 #include <security-server.h>
35 #include <sstream>
36 #include "DataControlAsyncCallbackManager.h"
37
38 namespace DeviceAPI {
39 namespace DataControl {
40
41
42 namespace {
43
44 static const char OSP_V_CALLER_TYPE_OSP[] = "osp";
45 static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
46 static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
47 static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
48 static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
49 static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
50 static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
51 static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
52 static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
53 static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
54 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
55 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
56 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
57 static const char BUNDLE_KEY_WINDOW[] = "__APP_SVC_K_WIN_ID__";
58
59
60 #define OSP_K_CALLER_TYPE   "__OSP_CALLER_TYPE__"
61 #define OSP_K_LAUNCH_TYPE   "__OSP_LAUNCH_TYPE__"
62 #define OSP_K_ARG           "__OSP_ARGS__"
63 #define OSP_K_COND          "__OSP_COND_NAME__"
64 #define OSP_K_APPID         "__OSP_APPID__"
65 #define OSP_K_REQUEST_ID    "__OSP_REQUEST_ID__"
66 #define OSP_K_APPCONTROL_PROVIDER   "__OSP_APPCONTROL_PROVIDER__"
67 #define OSP_K_APPCONTROL_OPERATION  "__OSP_APPCONTROL_OPERATION__"
68 #define OSP_K_APPCONTROL_CATEGORY   "__OSP_APPCONTROL_CATEGORY__"
69 #define OSP_K_APPCONTROL_MIME       "__OSP_APPCONTROL_MIME__"
70 #define OSP_K_APPCONTROL_URI        "__OSP_APPCONTROL_URI__"
71 #define OSP_K_DATACONTROL_PROVIDER      "__OSP_DATACONTROL_PROVIDER__"
72 #define OSP_K_DATACONTROL_REQUEST_TYPE  "__OSP_DATACONTROL_REQUEST_TYPE__"
73 #define RESULT_TRUE_FROM_OSP "1"
74 #define RESULT_FALSE_FROM_OSP "0"
75 #define OSP_K_DATACONTROL_PROTOCOL_VERSION  "__OSP_DATACONTROL_PROTOCOL_VERSION__"
76 #define OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE "ver_2.1.0.3"
77
78 #define DATACONTROL_PROTOCOL_DIR_TOP  "/tmp/osp"
79 #define DATACONTROL_PROTOCOL_DIR_MIDDLE  "/tmp/osp/data-control"
80 #define DATACONTROL_PROTOCOL_DIR  "/tmp/osp/data-control/request"
81
82 static std::vector<std::string> getDataArrayFromBundle(bundle *b, std::string key)
83 {
84         std::vector<std::string> result;
85         const char **array;
86         int length = 0;
87         int index = 0;
88         
89         array = appsvc_get_data_array(b, key.c_str(), &length);
90
91         if (array == NULL || length == 0)
92         {
93                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result data fail from datacontrol provider");
94         }
95         
96         for (index = 0; index < length; index++)
97         {
98                 result.push_back(array[index]);
99         }
100
101         return result;
102 }
103
104
105 static void sqldataControlSelectCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
106 {
107         LoggerD("Enter");
108         
109         EventSelectPendingEvent *pendingEvent = NULL;
110         SQLDataControlConsumer *consumer = NULL;
111         EventSelectPtr event;
112         const char *bundleKey = NULL;
113         
114         try 
115         {
116                 if (b == NULL)
117                 {
118                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
119                 }
120                 
121         bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
122
123                 if (bundleKey == NULL)
124                 {
125                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
126                 }
127
128                 pendingEvent = (EventSelectPendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
129                 consumer = (SQLDataControlConsumer*)pendingEvent->getThisObject();
130
131                 if (DataControlAsyncCallbackManagerSingleton::Instance().isSQLDataControlGC((void*)consumer))
132                 {
133                         LoggerD("private object is garbage collected");
134                         delete pendingEvent;
135                         return;
136                 }
137                 event = pendingEvent->getEvent();
138                 
139                 std::vector<std::string> result = getDataArrayFromBundle(b, OSP_K_ARG);
140
141                 for (size_t index = 0; index < result.size(); index++)
142                 {
143                         LoggerD(result[index]);
144                 }
145
146                 if (result.size() < 3)
147                 {
148                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid result from datacontrol provider");
149                 }
150                 
151                 // 0 : result true or false??
152                 if (RESULT_TRUE_FROM_OSP != result[0])
153                 {
154                         // 1 : error msg 
155                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
156                 }
157
158                 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
159                 // 2 : result set file path
160                 event->setResultSetPath(result[2]);
161                 
162         }
163         catch (const WrtDeviceApis::Commons::Exception& ex) 
164         {
165                 LoggerE("Exception: " << ex.GetMessage());
166                 
167                 if (event.Get() == NULL)
168                 {
169                         LoggerD("event removed, invalid cb");
170                         return;
171                 }
172
173                 event->setExceptionCode(ex.getCode());
174                 event->setErrorMsg(ex.GetMessage());            
175         }
176         consumer->handlePendingEvent(event);
177
178         if (pendingEvent)
179         {
180                 delete pendingEvent;
181         }
182
183 }
184
185 static void sqldataControlInsertCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
186 {
187         LoggerD("Enter");
188
189         
190         EventInsertPendingEvent *pendingEvent = NULL;
191         SQLDataControlConsumer *consumer = NULL;
192         EventInsertPtr event;
193         const char *bundleKey = NULL;
194
195         try 
196         {
197                 if (b == NULL)
198                 {
199                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
200                 }
201
202         bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
203
204                 if (bundleKey == NULL)
205                 {
206                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
207                 }
208
209                 pendingEvent = (EventInsertPendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
210                 consumer = (SQLDataControlConsumer*)pendingEvent->getThisObject();
211
212                 if (DataControlAsyncCallbackManagerSingleton::Instance().isSQLDataControlGC((void*)consumer))
213                 {
214                         LoggerD("private object is garbage collected");
215                         delete pendingEvent;
216                         return;
217                 }
218                 
219                 event = pendingEvent->getEvent();
220
221                 std::vector<std::string> result = getDataArrayFromBundle(b, OSP_K_ARG);
222
223                 for (size_t index = 0; index < result.size(); index++)
224                 {
225                         LoggerD(result[index]);
226                 }
227
228                 if (result.size() < 2)
229                 {
230                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid result from datacontrol provider");
231                 }
232                 
233                 // 0 : result true or false??
234                 if (RESULT_TRUE_FROM_OSP != result[0])
235                 {
236                         // 1 : error msg 
237                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
238                 }
239
240                 // 2 : insertrowid
241                 std::stringstream sstr(result[2]);
242                 long insertRowid = 0;
243                 sstr >> insertRowid;
244                 LoggerD(result[2] << insertRowid);
245                 event->setRowId(insertRowid);                   
246                 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
247                 
248         }
249         catch (const WrtDeviceApis::Commons::Exception& ex) 
250         {
251                 LoggerE("Exception: " << ex.GetMessage());
252
253                 if (event.Get() == NULL)
254                 {
255                         LoggerD("event removed, invalid cb");
256                         return;
257                 }
258                         
259                 event->setExceptionCode(ex.getCode());
260                 event->setErrorMsg(ex.GetMessage());            
261         }
262         consumer->handlePendingEvent(event);
263
264         if (pendingEvent)
265         {
266                 delete pendingEvent;
267         }
268
269 }
270
271 static void sqldataControlDeleteCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
272 {
273         LoggerD("Enter");
274
275         EventDeletePendingEvent* pendingEvent = NULL;
276         SQLDataControlConsumer *consumer = NULL;
277         EventDeletePtr event;
278         const char* bundleKey = NULL;
279         
280         try 
281         {
282                 if (b == NULL)
283                 {
284                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
285                 }
286
287         bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
288
289                 if (bundleKey == NULL)
290                 {
291                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
292                 }
293
294                 pendingEvent = (EventDeletePendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
295                 consumer = (SQLDataControlConsumer*)pendingEvent->getThisObject();
296
297                 if (DataControlAsyncCallbackManagerSingleton::Instance().isSQLDataControlGC((void*)consumer))
298                 {
299                         LoggerD("private object is garbage collected");
300                         delete pendingEvent;
301                         return;
302                 }
303
304                 event = pendingEvent->getEvent();
305
306                 std::vector<std::string> result = getDataArrayFromBundle(b, OSP_K_ARG);
307
308                 for (size_t index = 0; index < result.size(); index++)
309                 {
310                         LoggerD(result[index]);
311                 }
312
313                 if (result.size() < 2)
314                 {
315                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid result from datacontrol provider");
316                 }
317                 
318                 // 0 : result true or false??
319                 if (RESULT_TRUE_FROM_OSP != result[0])
320                 {
321                         // 1 : error msg 
322                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
323                 }
324
325                 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
326
327                 
328         }
329         catch (const WrtDeviceApis::Commons::Exception& ex) 
330         {
331                 LoggerE("Exception: " << ex.GetMessage());
332
333                 if (event.Get() == NULL)
334                 {
335                         LoggerD("event removed, invalid cb");
336                         return;
337                 }
338                 
339                 event->setExceptionCode(ex.getCode());
340                 event->setErrorMsg(ex.GetMessage());            
341         }
342         consumer->handlePendingEvent(event);
343
344         if (pendingEvent)
345         {
346                 delete pendingEvent;
347         }
348 }
349
350 static void sqldataControlUpdateCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
351 {
352         LoggerD("Enter");
353
354         EventUpdatePendingEvent* pendingEvent = NULL;
355         SQLDataControlConsumer *consumer = NULL;
356         EventUpdatePtr event;
357         const char *bundleKey = NULL;
358         
359         try 
360         {
361                 if (b == NULL)
362                 {
363                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
364                 }
365
366         bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
367
368                 if (bundleKey == NULL)
369                 {
370                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
371                 }
372
373                 pendingEvent = (EventUpdatePendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);    
374                 consumer = (SQLDataControlConsumer*)pendingEvent->getThisObject();
375
376                 if (DataControlAsyncCallbackManagerSingleton::Instance().isSQLDataControlGC((void*)consumer))
377                 {
378                         LoggerD("private object is garbage collected");
379                         delete pendingEvent;
380                         return;
381                 }
382                 
383                 event = pendingEvent->getEvent();
384
385                 std::vector<std::string> result = getDataArrayFromBundle(b, OSP_K_ARG);
386
387                 for (size_t index = 0; index < result.size(); index++)
388                 {
389                         LoggerD(result[index]);
390                 }
391
392                 if (result.size() < 2)
393                 {
394                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid result from datacontrol provider");
395                 }
396                 
397                 // 0 : result true or false??
398                 if (RESULT_TRUE_FROM_OSP != result[0])
399                 {
400                         // 1 : error msg 
401                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
402                 }
403
404                 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
405                 
406         }
407         catch (const WrtDeviceApis::Commons::Exception& ex) 
408         {
409                 LoggerE("Exception: " << ex.GetMessage());
410
411                 if (event.Get() == NULL)
412                 {
413                         LoggerD("event removed, invalid cb");
414                         return;
415                 }
416                                 
417                 event->setExceptionCode(ex.getCode());
418                 event->setErrorMsg(ex.GetMessage());            
419         }
420         consumer->handlePendingEvent(event);
421
422         if (pendingEvent)
423         {
424                 delete pendingEvent;
425         }
426 }
427
428 static void sqldataControlCommonCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
429 {
430         LoggerD("Enter");
431
432         if (b == NULL)
433         {
434                 LoggerD("Bundle null, Error");
435                 return;         
436         }
437
438         const char *reqType = appsvc_get_data(b, OSP_K_DATACONTROL_REQUEST_TYPE);
439         
440         if (reqType == NULL)
441         {
442                 LoggerD("UnkownRequest");
443                 return;
444         }
445
446         std::istringstream buffer(reqType);
447         int reqTypeInt = 0;
448
449         buffer >> reqTypeInt;
450
451
452         LoggerD(reqTypeInt);
453         
454         switch (reqTypeInt)
455         {
456                 case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
457                         sqldataControlSelectCallback(b, request_code, res, data);
458                         break;
459                 case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
460                         sqldataControlInsertCallback(b, request_code, res, data);
461                         break;
462                 case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
463                         sqldataControlDeleteCallback(b, request_code, res, data);
464                         break;
465                 case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
466                         sqldataControlUpdateCallback(b, request_code, res, data);
467                         break;
468                 default:
469                         LoggerD("Unknown Request");
470         }
471 }
472
473 }
474
475 SQLDataControlConsumer::SQLDataControlConsumer(std::string& provId, std::string& dataId, std::string& type)
476 {
477         LoggerD("Enter");
478
479         m_type = type;
480         m_dataId = dataId;
481         m_providerId = provId;
482         
483         m_appId = getApplicationId(provId);     
484         m_ProviderPkgId = getProviderPkgId(m_appId);
485         security_server_app_give_access(m_ProviderPkgId.c_str(), -1);
486
487         m_currentAppId = getCurrentApplicationId();
488         createResultDir();
489         DataControlAsyncCallbackManagerSingleton::Instance().setSQLDataControlGC((void*)this, false);
490 }
491
492 SQLDataControlConsumer::~SQLDataControlConsumer() 
493 {
494         LoggerD("Enter");
495         DataControlAsyncCallbackManagerSingleton::Instance().setSQLDataControlGC((void*)this, true);
496 }
497
498 DPL::Mutex SQLDataControlConsumer::m_mutex;
499 std::vector<unsigned int> SQLDataControlConsumer::m_currentReqIds;
500
501 std::string SQLDataControlConsumer::getCurrentApplicationId()
502 {
503         char *app_id = NULL;
504         std::string appId = "";
505         int parent_pid = getppid();
506         LoggerD("parent pid : " << parent_pid); 
507         int ret = app_manager_get_app_id(parent_pid, &app_id);  
508
509         if((ret != APP_ERROR_NONE) || (app_id == NULL))
510         {
511                 LoggerE("Can not get app id from current pid (" << ret << ")");
512                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "could not get information about application");
513         }
514         appId = app_id;
515         free(app_id);
516         return appId;           
517 }
518
519 void SQLDataControlConsumer::removeReqId(unsigned int reqId)
520 {
521         bool remove = false;
522         
523         std::vector<unsigned int>::iterator it, found;
524         
525         for (it = m_currentReqIds.begin(); it != m_currentReqIds.end(); ++it)
526         {
527                 if (*it == reqId)
528                 {
529                         found = it;     
530                         remove = true;
531                 }
532         }
533
534         if (remove)
535         {
536                 DPL::Mutex::ScopedLock lock(&m_mutex);
537                 m_currentReqIds.erase(found);
538         }
539 }
540
541 bool SQLDataControlConsumer::checkReqIdUniqueness(unsigned int reqId)
542 {
543         std::string reqIdStr;
544         std::stringstream ssReqId;
545
546         ssReqId << reqId;
547         reqIdStr = ssReqId.str();
548         return DataControlAsyncCallbackManagerSingleton::Instance().checkReqIdUnique(reqIdStr);
549 }
550
551
552 std::string SQLDataControlConsumer::getDataId()
553 {
554         return m_dataId;
555 }
556
557 std::string SQLDataControlConsumer::getProviderId()
558 {
559         return m_providerId;
560 }
561
562 std::string SQLDataControlConsumer::getType()
563 {
564         return m_type;
565 }
566
567 std::string SQLDataControlConsumer::getProviderPkgId(const std::string& appId)
568 {
569         char* pkgId = NULL;
570         app_info_h handle = NULL;
571
572         if (m_ProviderPkgId.length() != 0) 
573         {
574                 return m_ProviderPkgId;
575         }
576         
577         int ret = app_manager_get_app_info(appId.c_str(), &handle);
578
579         if (ret != APP_ERROR_NONE) 
580         {
581                 LoggerD("Fail to get appinfo");
582                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get appId error");
583         }
584
585         ret = app_info_get_package(handle, &pkgId);
586
587         if ((ret != APP_ERROR_NONE) || (pkgId == NULL)) 
588         {
589                 LoggerD("Fail to get pkg_name");
590                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get pkdid error");
591         }
592         m_ProviderPkgId = pkgId;
593         app_info_destroy(handle);
594         free(pkgId);
595         return m_ProviderPkgId; 
596 }
597
598 std::string SQLDataControlConsumer::getApplicationId(const std::string& provId)
599 {
600         std::string appIdStr = "";
601
602         char* appId = NULL;
603         char* access = NULL;
604         const char *passId = provId.c_str();
605         
606         if (m_appId.length() == 0)
607         {
608         
609                 if(     pkgmgr_datacontrol_get_info(passId, OSP_PKGINFO_SQL_TYPE, &appId, &access) < 0)
610                 {
611                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get appId error");
612                 }
613                 
614                 if (appId)
615                 {
616                         appIdStr = appId;
617                         free(appId);
618                 }
619
620                 if (access)
621                 {
622                         free(access);
623                 }
624                 
625                 m_appId = appIdStr;
626
627
628         }
629         return m_appId;
630
631 }
632
633 std::string SQLDataControlConsumer::generateFileName(unsigned int reqId)
634 {
635         std::stringstream ssdata;
636         ssdata.str("");
637         ssdata << reqId;
638         std::string parent = DATACONTROL_PROTOCOL_DIR;
639         std::string filename = parent  + "/" + m_currentAppId + ssdata.str();
640         return filename;
641 }
642
643 void SQLDataControlConsumer::saveArrayToFile(std::string filename, RowData *rowData)
644 {
645         std::fstream insertUpdateFile;
646         std::map<std::string, std::string>::iterator it;
647         int strLength = 0;
648         insertUpdateFile.open(filename.c_str(), std::ios::out | std::ios::binary);
649
650         if (!insertUpdateFile.is_open()) 
651         {
652                 LoggerD("fail open" << filename);
653                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "DataControl IPC Error");
654         }
655
656         for (it = rowData->m_Data.begin(); it != rowData->m_Data.end(); ++it)
657         {
658                 strLength = it->first.size();
659                 insertUpdateFile.write((const char*)&strLength, sizeof(int));
660                 insertUpdateFile.write(it->first.c_str(), strLength);
661
662                 strLength = it->second.size();
663                 insertUpdateFile.write((const char*)&strLength, sizeof(int));
664                 insertUpdateFile.write(it->second.c_str(), strLength);
665         }
666         
667         insertUpdateFile.close();               
668         
669 }
670 void SQLDataControlConsumer::addArrayToBundle(bundle* passData, std::vector<std::string>& array)
671 {
672         size_t arraySize = array.size();
673
674         if (arraySize == 0)
675         {
676                 ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "size = 0");
677         }
678         
679         const char** arr = NULL;
680         arr = (const char**)calloc(sizeof(char*), arraySize);
681
682         if (arr == NULL)
683         {
684                 ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "null");
685         }
686
687         for (size_t index = 0; index < arraySize; index++) 
688         {
689                 arr[index] = array[index].c_str();
690         }
691
692         
693         bundle_add_str_array(passData, OSP_K_ARG, arr, arraySize);
694
695         free(arr);
696         arr = NULL;
697 }
698
699 void SQLDataControlConsumer::handleCommonErrorEvent(void* userData, unsigned int code, std::string msg)
700 {
701         if (userData == NULL)
702         {
703                 LoggerD("userData null");
704                 return;
705         }
706         
707         CommonPendingEvent* pEvent = (CommonPendingEvent*)userData;
708         
709         try 
710         {
711                 if (dynamic_cast<EventInsertPendingEvent*>(pEvent) != NULL)
712                 {
713                         EventInsertPendingEvent* pendingInsertEvent = (EventInsertPendingEvent*)pEvent;
714                         EventInsertPtr insertEvent = pendingInsertEvent->getEvent();
715                         insertEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
716                         insertEvent->setErrorMsg(msg);          
717                 
718                         WrtDeviceApis::Commons::EventRequestReceiver<EventInsert>::ManualAnswer(insertEvent); 
719                 }
720                 else if (dynamic_cast<EventUpdatePendingEvent*>(pEvent) != NULL)
721                 {
722                         EventUpdatePendingEvent* pendingUpdateEvent = (EventUpdatePendingEvent*)pEvent;
723                         EventUpdatePtr updateEvent = pendingUpdateEvent->getEvent();
724                         updateEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
725                         updateEvent->setErrorMsg(msg);          
726                         
727                         WrtDeviceApis::Commons::EventRequestReceiver<EventUpdate>::ManualAnswer(updateEvent); 
728                 }
729                 else if (dynamic_cast<EventSelectPendingEvent*>(pEvent) != NULL)
730                 {
731                         EventSelectPendingEvent* pendingSelectEvent = (EventSelectPendingEvent*)pEvent;
732                         EventSelectPtr selectEvent = pendingSelectEvent->getEvent();
733                         selectEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
734                         selectEvent->setErrorMsg(msg);
735                         
736                         WrtDeviceApis::Commons::EventRequestReceiver<EventSelect>::ManualAnswer(selectEvent); 
737                 }
738                 else if (dynamic_cast<EventDeletePendingEvent*>(pEvent) != NULL)
739                 {
740                         EventDeletePendingEvent* pendingDeleteEvent = (EventDeletePendingEvent*)pEvent;
741                         EventDeletePtr deleteEvent = pendingDeleteEvent->getEvent();
742                         deleteEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
743                         deleteEvent->setErrorMsg(msg);
744                         
745                         WrtDeviceApis::Commons::EventRequestReceiver<EventDelete>::ManualAnswer(deleteEvent); 
746                 }       
747         }
748         catch (const WrtDeviceApis::Commons::Exception& ex) 
749         {
750                 LoggerE("Exception: " << ex.GetMessage());
751         }
752
753 }
754 void SQLDataControlConsumer::handlePendingEvent(const EventInsertPtr& event)
755 {
756         LoggerD("OK");
757         WrtDeviceApis::Commons::EventRequestReceiver<EventInsert>::ManualAnswer(event); 
758         CommonPendingEvent* userData = NULL;
759         
760         try {
761                 userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingSQLOperation();
762
763                 if (userData)
764                 {
765                         SendAppControlLaunchToProvider(userData);
766                 }
767         }
768         catch (const WrtDeviceApis::Commons::Exception& ex) 
769         {
770                 if (event.Get() == NULL)
771                 {
772                         LoggerD("event removed, invalid cb");
773                         return;
774                 }
775                 LoggerE("Exception: " << ex.GetMessage());
776
777                 if (userData)
778                 {
779                         handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
780                 }
781         }
782
783 }
784 void SQLDataControlConsumer::handlePendingEvent(const EventDeletePtr& event)
785 {
786         WrtDeviceApis::Commons::EventRequestReceiver<EventDelete>::ManualAnswer(event); 
787         CommonPendingEvent* userData = NULL;
788
789         try {
790                 userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingSQLOperation();
791
792                 if (userData)
793                 {
794                         SendAppControlLaunchToProvider(userData);
795                 }
796         }
797         catch (const WrtDeviceApis::Commons::Exception& ex) 
798         {
799                 if (event.Get() == NULL)
800                 {
801                         LoggerD("event removed, invalid cb");
802                         return;
803                 }
804                 LoggerE("Exception: " << ex.GetMessage());
805
806                 if (userData)
807                 {
808                         handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
809                 }
810         }
811
812
813 }
814 void SQLDataControlConsumer::handlePendingEvent(const EventSelectPtr& event)
815 {
816         WrtDeviceApis::Commons::EventRequestReceiver<EventSelect>::ManualAnswer(event);
817         CommonPendingEvent* userData = NULL;
818         
819         try {
820                 userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingSQLOperation();
821
822                 if (userData)
823                 {
824                         SendAppControlLaunchToProvider(userData);
825                 }
826         }
827         catch (const WrtDeviceApis::Commons::Exception& ex) 
828         {
829                 if (event.Get() == NULL)
830                 {
831                         LoggerD("event removed, invalid cb");
832                         return;
833                 }
834                 LoggerE("Exception: " << ex.GetMessage());
835
836                 if (userData)
837                 {
838                         handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
839                 }
840
841         }
842         
843
844 }
845
846 void SQLDataControlConsumer::handlePendingEvent(const EventUpdatePtr& event)
847 {
848         WrtDeviceApis::Commons::EventRequestReceiver<EventUpdate>::ManualAnswer(event); 
849         CommonPendingEvent* userData = NULL;
850         
851         try {
852                 userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingSQLOperation();
853
854                 if (userData)
855                 {
856                         SendAppControlLaunchToProvider(userData);
857                 }
858         }
859         catch (const WrtDeviceApis::Commons::Exception& ex) 
860         {
861                 if (event.Get() == NULL)
862                 {
863                         LoggerD("event removed, invalid cb");
864                         return;
865                 }
866                 LoggerE("Exception: " << ex.GetMessage());
867
868                 if (userData)
869                 {
870                         handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
871                 }               
872         }
873
874 }
875
876
877 void SQLDataControlConsumer::insertData(const EventInsertPtr& event)
878 {
879         WrtDeviceApis::Commons::EventRequestReceiver<EventInsert>::PostRequest(event);
880 }
881
882 void SQLDataControlConsumer::deleteData(const EventDeletePtr& event)
883 {
884         WrtDeviceApis::Commons::EventRequestReceiver<EventDelete>::PostRequest(event);
885 }
886
887 void SQLDataControlConsumer::selectData(const EventSelectPtr& event)
888 {
889         WrtDeviceApis::Commons::EventRequestReceiver<EventSelect>::PostRequest(event);
890 }
891
892 void SQLDataControlConsumer::updateData(const EventUpdatePtr& event)
893 {
894         WrtDeviceApis::Commons::EventRequestReceiver<EventUpdate>::PostRequest(event);
895 }
896
897 void SQLDataControlConsumer::createResultDir()
898 {
899     struct stat info;
900     memset(&info, 0, sizeof(struct stat));
901
902     int status = lstat(DATACONTROL_PROTOCOL_DIR_TOP, &info);
903
904         if (status != 0 && errno == ENOENT) 
905         {
906                 if (mkdir(DATACONTROL_PROTOCOL_DIR_TOP, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) 
907                 {
908                         LoggerD("make error");
909                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "result dir could not be created.");
910                 }
911         }
912
913     status = lstat(DATACONTROL_PROTOCOL_DIR_MIDDLE, &info);
914
915         if (status != 0 && errno == ENOENT) 
916         {
917                 if (mkdir(DATACONTROL_PROTOCOL_DIR_MIDDLE, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) 
918                 {
919                         LoggerD("make error");
920                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "result dir could not be created.");
921                 }
922         }
923         
924     status = lstat(DATACONTROL_PROTOCOL_DIR, &info);
925
926         // already exist
927         if (status == 0) 
928         {
929                 LoggerD("already exist");
930         return;
931     } 
932         else if (errno == ENOENT) 
933         {
934                 if (mkdir(DATACONTROL_PROTOCOL_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) 
935                 {
936                         LoggerD("make error");
937                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "result dir could not be created.");
938                 }
939                 return;
940     }
941     ThrowMsg(WrtDeviceApis::Commons::PlatformException, "result dir could be error during checking status");
942 }
943
944 std::string SQLDataControlConsumer::convertIntToString(unsigned int data)
945 {
946         std::stringstream ssbuffer;
947
948         ssbuffer.str("");
949         ssbuffer << data;
950         return ssbuffer.str();
951 }
952
953 void SQLDataControlConsumer::SendAppControlLaunchToProvider(void* event)
954 {
955         LoggerD("OK");
956         bundle* passData = NULL;
957         std::string dataId = getDataId();
958         std::vector<std::string> queryItem;
959         std::stringstream ssBuffer;
960         std::string stringBuffer;
961         CommonPendingEvent* pEvent = (CommonPendingEvent*)(event);
962         std::string ipcFilename;
963         std::string where;
964         unsigned int reqId = 0;
965         unsigned int columnSize = 0;
966
967         try 
968         {
969                 passData = bundle_create();
970                 
971                 if (passData == NULL)
972                 {
973                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "ipc memory allocation fail");
974                 }
975
976                 if (pEvent == NULL)
977                 {
978                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "event null");              
979                 }
980
981                 appsvc_set_operation(passData, APPSVC_OPERATION_DEFAULT);               
982                 appsvc_set_appid(passData, m_appId.c_str());
983
984                 bundle_add(passData, OSP_K_CALLER_TYPE, OSP_V_CALLER_TYPE_OSP);
985                 bundle_add(passData, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
986                 bundle_add(passData, OSP_K_DATACONTROL_PROVIDER, m_providerId.c_str());
987                 bundle_add(passData, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE); // version
988                 bundle_add(passData, AUL_K_CALLER_APPID, m_currentAppId.c_str());
989
990                 if (dynamic_cast<EventInsertPendingEvent*>(pEvent) != NULL)
991                 {
992                         EventInsertPendingEvent* pendingInsertEvent = (EventInsertPendingEvent*)pEvent;
993                         EventInsertPtr insertEvent = pendingInsertEvent->getEvent();
994                         
995                         reqId = insertEvent->getReqId();
996                         columnSize = insertEvent->getColumnSize();
997
998                         stringBuffer = convertIntToString(reqId);
999                         bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());   
1000
1001                         ipcFilename     = generateFileName(reqId);      
1002                         stringBuffer = convertIntToString(columnSize);
1003                         
1004                         queryItem.push_back(dataId); 
1005                         queryItem.push_back(stringBuffer); 
1006                         queryItem.push_back(ipcFilename); 
1007
1008                         stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_SQL_INSERT);
1009                         bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
1010                                 
1011                         addArrayToBundle(passData, queryItem);
1012                 }
1013                 else if (dynamic_cast<EventUpdatePendingEvent*>(pEvent) != NULL)
1014                 {
1015                         EventUpdatePendingEvent* pendingUpdateEvent = (EventUpdatePendingEvent*)pEvent;
1016                         EventUpdatePtr updateEvent = pendingUpdateEvent->getEvent();
1017                         
1018                         reqId = updateEvent->getReqId();
1019                         columnSize = updateEvent->getColumnSize();
1020                         where = updateEvent->getWhere();
1021                         
1022                         stringBuffer = convertIntToString(reqId);
1023                         bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());   
1024
1025                         stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE);
1026                         bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
1027
1028                         ipcFilename     = generateFileName(reqId);      
1029                         stringBuffer = convertIntToString(columnSize);
1030
1031                         queryItem.push_back(dataId); 
1032                         queryItem.push_back(stringBuffer); 
1033                         queryItem.push_back(ipcFilename); 
1034
1035                         if (where.size() == 0)  // where
1036                         {
1037                                 queryItem.push_back("NULL");
1038                         }
1039                         else 
1040                         {
1041                                 queryItem.push_back(where);
1042                         }
1043                 
1044                         addArrayToBundle(passData, queryItem);
1045
1046                 }
1047                 else if (dynamic_cast<EventSelectPendingEvent*>(pEvent) != NULL)
1048                 {
1049                         EventSelectPendingEvent* pendingSelectEvent = (EventSelectPendingEvent*)pEvent;
1050                         EventSelectPtr selectEvent = pendingSelectEvent->getEvent();
1051                         
1052                         reqId = selectEvent->getReqId();
1053                         std::vector<std::string> columns = selectEvent->getColumns();
1054                         columnSize = columns.size();            
1055                         where = selectEvent->getWhere();
1056                         std::string order = selectEvent->getOrder();
1057                         std::string page = selectEvent->getPage();
1058                         std::string numberPerPage = selectEvent->getNumerPerPage();
1059
1060                         stringBuffer = convertIntToString(reqId);
1061                         bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());   
1062
1063                         stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_SQL_QUERY);
1064                         bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
1065
1066                         queryItem.push_back(dataId); 
1067
1068                         if (columnSize == 0)
1069                         {
1070                                 queryItem.push_back("NULL");
1071                         }
1072                         else 
1073                         {
1074                                 stringBuffer = convertIntToString(columnSize);
1075                                 queryItem.push_back(stringBuffer);
1076
1077                                 for (size_t index = 0; index < columnSize; index++)
1078                                 {
1079                                         queryItem.push_back(columns[index]);
1080                                 }
1081                         }
1082
1083                         if (where.size() == 0) 
1084                         {
1085                                 queryItem.push_back("NULL");
1086                         }
1087                         else 
1088                         {
1089                                 queryItem.push_back(where);
1090                         }
1091
1092                         if (order.size() == 0)
1093                         {
1094                                 queryItem.push_back("NULL"); 
1095                         }
1096                         else
1097                         {
1098                                 queryItem.push_back(order);
1099                         }
1100
1101                         if (page.size() == 0) // page
1102                         {
1103                                 queryItem.push_back("1"); 
1104                         }
1105                         else
1106                         {
1107                                 queryItem.push_back(page);
1108                         }
1109
1110                         if (numberPerPage.size() == 0) // numberOfPage
1111                         {
1112                                 queryItem.push_back("20");
1113                         }
1114                         else
1115                         {
1116                                 queryItem.push_back(numberPerPage);
1117                         }
1118
1119                         addArrayToBundle(passData, queryItem);
1120                 }
1121                 else if (dynamic_cast<EventDeletePendingEvent*>(pEvent) != NULL)
1122                 {
1123                         EventDeletePendingEvent* pendingDeleteEvent = (EventDeletePendingEvent*)pEvent;
1124                         EventDeletePtr deleteEvent = pendingDeleteEvent->getEvent();
1125                         reqId = deleteEvent->getReqId();
1126                         stringBuffer = convertIntToString(reqId);
1127                         bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());   
1128
1129                         stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_SQL_DELETE);
1130                         bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
1131
1132                         queryItem.push_back(dataId); // dataid
1133                         where = deleteEvent->getWhere();
1134
1135                         if (where.size() == 0)  // where
1136                         {
1137                                 queryItem.push_back("NULL");
1138                         }
1139                         else 
1140                         {
1141                                 queryItem.push_back(where);
1142                         }
1143                         
1144                         addArrayToBundle(passData, queryItem);
1145                 }
1146                 else 
1147                 {
1148                         // never happen
1149                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "no type request type");            
1150                 }
1151
1152                 int pid = appsvc_run_service(passData, reqId, sqldataControlCommonCallback, (void*)NULL);
1153
1154                 if (pid < 0) 
1155                 {
1156                         ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Launch Error");
1157                 }
1158
1159                 LoggerD("Launch OK : pid(" << pid << "), reqid : (" << reqId << ")");
1160         }
1161         catch (const WrtDeviceApis::Commons::Exception& ex) 
1162         {       
1163                 LoggerE("Exception: " << ex.GetMessage());
1164                 if (passData)
1165                 {
1166                         bundle_free(passData);
1167                         passData = NULL;
1168                 }
1169                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, ex.GetMessage());
1170
1171         }
1172
1173         if (passData)
1174         {
1175                 bundle_free(passData);
1176                 passData = NULL;
1177         }
1178         
1179 }
1180
1181 void SQLDataControlConsumer::OnRequestReceived(const EventInsertPtr& event)
1182 {
1183         LoggerD("Enter");
1184
1185         try 
1186         {
1187                 RowData* rowData = event->getRowData();
1188                 unsigned int reqId = event->getReqId();
1189                 std::string ipcFilename = generateFileName(reqId);
1190                 std::string reqIdStr = convertIntToString(reqId);
1191                 
1192                 if (checkReqIdUniqueness(reqId) == false)
1193                 {
1194                         ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
1195                 }
1196                 
1197                 if (rowData == NULL || rowData->m_Data.size() == 0)
1198                 {
1199                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "No insertion data");
1200                 }
1201                 
1202                 saveArrayToFile(ipcFilename, rowData);          
1203                 delete rowData;
1204                 
1205                 EventInsertPendingEvent* pendingEvent = new EventInsertPendingEvent((void*)this, event);
1206                 
1207                 if (DataControlAsyncCallbackManagerSingleton::Instance().checkDoSQLOperation())
1208                 {
1209                         SendAppControlLaunchToProvider(pendingEvent);
1210                 }
1211                 event->switchToManualAnswer();
1212                 DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(reqIdStr, (void*)pendingEvent);
1213
1214
1215         }       
1216         catch (const WrtDeviceApis::Commons::Exception& ex) 
1217         {
1218                 event->setExceptionCode(ex.getCode());
1219                 event->setErrorMsg(ex.GetMessage());
1220                 LoggerE("Exception: " << ex.GetMessage());
1221                 
1222                 
1223         }
1224 }
1225 void SQLDataControlConsumer::OnRequestReceived(const EventDeletePtr& event)
1226 {
1227         LoggerD("Enter");
1228         bundle* passData = NULL;
1229         
1230         try 
1231         {
1232                 unsigned int reqId = event->getReqId();
1233                 std::string reqIdStr = convertIntToString(reqId);
1234
1235                 if (checkReqIdUniqueness(reqId) == false)
1236                 {
1237                         ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
1238                 }
1239
1240                 EventDeletePendingEvent* pendingEvent = new EventDeletePendingEvent(this, event);
1241                 
1242                 if (DataControlAsyncCallbackManagerSingleton::Instance().checkDoSQLOperation())
1243                 {
1244                         SendAppControlLaunchToProvider(pendingEvent);
1245                 }
1246                 event->switchToManualAnswer();
1247                 DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(reqIdStr, (void*)pendingEvent);
1248         }       
1249         
1250         catch (const WrtDeviceApis::Commons::Exception& ex) 
1251         {
1252                 LoggerE("Exception: " << ex.GetMessage());
1253                 event->setExceptionCode(ex.getCode());
1254                 event->setErrorMsg(ex.GetMessage());
1255         }
1256
1257         if (passData)
1258         {
1259                 bundle_free(passData);
1260                 passData = NULL;
1261         }
1262
1263 }
1264 void SQLDataControlConsumer::OnRequestReceived(const EventSelectPtr& event)
1265 {
1266         try 
1267         {
1268                 unsigned int reqId = event->getReqId();
1269                 std::string reqIdStr = convertIntToString(reqId);
1270
1271                 if (checkReqIdUniqueness(reqId) == false)
1272                 {
1273                         ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
1274                 }
1275                 
1276                 EventSelectPendingEvent* pendingEvent = new EventSelectPendingEvent(this, event);
1277
1278                 if (DataControlAsyncCallbackManagerSingleton::Instance().checkDoSQLOperation())
1279                 {
1280                         SendAppControlLaunchToProvider(pendingEvent);
1281                 }
1282                 
1283                 event->switchToManualAnswer();
1284                 DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(reqIdStr, (void*)pendingEvent);
1285         }
1286         catch (const WrtDeviceApis::Commons::Exception& ex) 
1287         {
1288                 LoggerE("Exception: " << ex.GetMessage());
1289                 event->setExceptionCode(ex.getCode());
1290                 event->setErrorMsg(ex.GetMessage());
1291         }
1292
1293 }
1294
1295 void SQLDataControlConsumer::OnRequestReceived(const EventUpdatePtr& event)
1296 {
1297         LoggerD("Enter");
1298
1299         try 
1300         {
1301                 unsigned int reqId = event->getReqId();
1302                 RowData* rowData = event->getRowData();
1303                 std::string ipcFilename = generateFileName(reqId);
1304                 std::stringstream ssReqId;
1305                 ssReqId << reqId;
1306
1307                 if (checkReqIdUniqueness(reqId) == false)
1308                 {
1309                         ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
1310                 }
1311                 
1312                 if (rowData == NULL || rowData->m_Data.size() == 0)
1313                 {\r                      
1314                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "No update data");
1315                 }
1316
1317                 saveArrayToFile(ipcFilename, rowData);
1318                 delete rowData;
1319
1320                 EventUpdatePendingEvent* pendingEvent = new EventUpdatePendingEvent(this, event);
1321                 
1322                 if (DataControlAsyncCallbackManagerSingleton::Instance().checkDoSQLOperation())
1323                 {
1324                         SendAppControlLaunchToProvider(pendingEvent);
1325                 }
1326                 event->switchToManualAnswer();
1327                 DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(ssReqId.str(), (void*)pendingEvent);
1328
1329         }
1330         catch (const WrtDeviceApis::Commons::Exception& ex) 
1331         {
1332                 LoggerE("Exception: " << ex.GetMessage());
1333                 event->setExceptionCode(ex.getCode());
1334                 event->setErrorMsg(ex.GetMessage());
1335         }
1336
1337 }
1338 }
1339 }
1340
1341