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