Update change log and spec for wrt-plugins-tizen_0.4.66
[framework/web/wrt-plugins-tizen.git] / src / DataControl / MappedDataControlConsumer.cpp
index cb39fa1..229bc1a 100644 (file)
 #include <sstream>
 #include <iostream>
 #include <package-manager.h>
+#include <security-server.h>
+
 #include "DataControlAsyncCallbackManager.h"
+#include "DataControlCallback.h"
+
+#include "DataType.h"
 
 
 namespace DeviceAPI {
 namespace DataControl {
 
-
-namespace {
-
-static const char OSP_V_CALLER_TYPE_OSP[] = "osp";
-static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
-static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
-static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
-static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
-static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
-static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
-static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
-static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
-static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
-static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
-static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
-static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
-static const char BUNDLE_KEY_WINDOW[] = "__APP_SVC_K_WIN_ID__";
-
-
-#define OSP_K_CALLER_TYPE   "__OSP_CALLER_TYPE__"
-#define OSP_K_LAUNCH_TYPE   "__OSP_LAUNCH_TYPE__"
-#define OSP_K_ARG           "__OSP_ARGS__"
-#define OSP_K_COND          "__OSP_COND_NAME__"
-#define OSP_K_APPID         "__OSP_APPID__"
-#define OSP_K_REQUEST_ID    "__OSP_REQUEST_ID__"
-#define OSP_K_APPCONTROL_PROVIDER   "__OSP_APPCONTROL_PROVIDER__"
-#define OSP_K_APPCONTROL_OPERATION  "__OSP_APPCONTROL_OPERATION__"
-#define OSP_K_APPCONTROL_CATEGORY   "__OSP_APPCONTROL_CATEGORY__"
-#define OSP_K_APPCONTROL_MIME       "__OSP_APPCONTROL_MIME__"
-#define OSP_K_APPCONTROL_URI        "__OSP_APPCONTROL_URI__"
-#define OSP_K_DATACONTROL_PROVIDER      "__OSP_DATACONTROL_PROVIDER__"
-#define OSP_K_DATACONTROL_REQUEST_TYPE  "__OSP_DATACONTROL_REQUEST_TYPE__"
-#define OSP_K_DATACONTROL_PROTOCOL_VERSION  "__OSP_DATACONTROL_PROTOCOL_VERSION__"
-#define OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE "ver_2.1.0.3"
-
-
-#define RESULT_TRUE_FROM_OSP "1"
-#define RESULT_FALSE_FROM_OSP "0"
-
-static std::vector<std::string> getDataArrayFromBundle(bundle *b, std::string key)
-{
-       std::vector<std::string> result;
-       const char **array;
-       int length = 0;
-       int index = 0;
-       
-       array = appsvc_get_data_array(b, key.c_str(), &length);
-
-       if (array == NULL || length == 0)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result data fail from datacontrol provider");
-       }
-       
-       for (index = 0; index < length; index++)
-       {
-               result.push_back(array[index]);
-       }
-
-       return result;
-}
-
-
-
-static void MappedDataControlGetValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
-{
-       LoggerD("Enter");
-       
-       EventGetValuePendingEvent *pendingEvent = NULL;
-       MappedDataControlConsumer *consumer = NULL;
-       EventGetValuePtr event;
-       size_t count = 0;
-       size_t index = 0;
-       std::ifstream getValueStream;
-       std::string getValueFilePath;
-       
-       try 
-       {
-               if (data == NULL)
-               {
-                       LoggerD("data null, can not send result to JS Layer");
-                       return;
-               }
-
-               pendingEvent = (EventGetValuePendingEvent *)data;
-               consumer = (MappedDataControlConsumer*)pendingEvent->getThisObject();
-
-               if (DataControlAsyncCallbackManagerSingleton::Instance().isMappedDataControlGC((void*)consumer))
-               {
-                       LoggerD("private object is garbage collected");
-                       delete pendingEvent;
-                       return;
-               }
-               
-               event = pendingEvent->getEvent();
-
-               if (b == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
-               }
-               std::vector<std::string> result = getDataArrayFromBundle(b, OSP_K_ARG);
-
-               for (index = 0; index < result.size(); index++)
-               {
-                       LoggerD(result[index]);
-               }
-
-               if (result.size() < 2)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid result from datacontrol provider");
-               }
-               
-               // 0 : result true or false??
-               if (RESULT_TRUE_FROM_OSP != result[0])
-               {
-                       // 1 : error msg 
-                       if (result[1].find("E_KEY_NOT_FOUND") != std::string::npos)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, result[1]);
-                       }
-                       else
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
-                       }
-               }
-
-               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
-               // 2 : value count
-               
-               std::istringstream str(result[2]);
-               str >> count;
-
-               // 3 ~ value...
-               if (count > 0)
-               {
-                       getValueFilePath = result[3];
-                       getValueStream.open(getValueFilePath.c_str(), std::ios::binary);
-                       int memorizedSize = 255;
-                       int size = 0;
-                       char *buf =  NULL;
-                       buf = new char[memorizedSize + 1];
-
-                       if (getValueStream.is_open()) 
-                       {
-                               LoggerD("open ok");
-                       }
-                       else
-                       {
-                               LoggerD("fail open" << getValueFilePath);
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get value error");
-                       }
-                       
-                       for (index = 0; index < count; index++)
-                       {
-                               getValueStream.read((char*)&size, sizeof(int)); // read size
-                               //LoggerD(size);
-
-                               if (memorizedSize < size)
-                               {
-                                       memorizedSize = size;
-
-                                       if (buf)
-                                       {
-                                               delete[] buf;
-                                       }
-
-                                       buf = new char[memorizedSize + 1];
-                               }
-
-                               if (buf == NULL)
-                               {
-                                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Out of memory");
-                               }
-                               memset(buf, 0, memorizedSize + 1);
-                               getValueStream.read((char*)buf, size);
-                               buf[size] = '\0';
-                               
-                               //LoggerD(buf);
-                               
-                               event->addResultValue(buf);
-                       }
-
-
-/*                     for (index = 3; index < result.size(); index++)
-                       {
-                               event->addResultValue(result[index]);
-                       }
-*/
-               }
-               
-       }
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LoggerE("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-               event->setErrorMsg(ex.GetMessage());            
-       }
-       getValueStream.close();
-       if (unlink(getValueFilePath.c_str()) != 0) 
-       {
-               LoggerE("Error while removing SelectDataObject.");
-       }
-
-       consumer->handlePendingEvent(event);
-
-       if (pendingEvent)
-       {
-               delete pendingEvent;
-       }
-
-}
-
-static void MappedDataControlAddValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
-{
-       LoggerD("Enter");
-
-       
-       EventAddValuePendingEvent *pendingEvent = NULL;
-       MappedDataControlConsumer *consumer = NULL;
-       EventAddValuePtr event;
-
-       try 
-       {
-               if (data == NULL)
-               {
-                       LoggerD("data null, can not send result to JS Layer");
-                       return;
-               }
-
-               pendingEvent = (EventAddValuePendingEvent *)data;
-               consumer = (MappedDataControlConsumer*)pendingEvent->getThisObject();
-
-               if (DataControlAsyncCallbackManagerSingleton::Instance().isMappedDataControlGC((void*)consumer))
-               {
-                       LoggerD("private object is garbage collected");
-                       delete pendingEvent;
-                       return;
-               }
-               
-               event = pendingEvent->getEvent();
-
-               if (b == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
-               }
-               std::vector<std::string> result = getDataArrayFromBundle(b, OSP_K_ARG);
-
-               for (size_t index = 0; index < result.size(); index++)
-               {
-                       LoggerD(result[index]);
-               }
-
-               if (result.size() < 2)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid result from datacontrol provider");
-               }
-               
-               // 0 : result true or false??
-               if (RESULT_TRUE_FROM_OSP != result[0])
-               {
-                       // 1 : error msg 
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
-               }
-
-               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
-               
-       }
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LoggerE("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-               event->setErrorMsg(ex.GetMessage());            
-       }
-       consumer->handlePendingEvent(event);
-
-       if (pendingEvent)
-       {
-               delete pendingEvent;
-       }
-
-}
-
-static void MappedDataControlRemoveValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
-{
-       LoggerD("Enter");
-
-       if (data == NULL)
-       {
-               LoggerD("Data or Bundle error");
-               return;
-       }
-
-       EventRemoveValuePendingEvent* pendingEvent = NULL;
-       MappedDataControlConsumer *consumer = NULL;
-       EventRemoveValuePtr event;
-       
-       try 
-       {
-               if (data == NULL)
-               {
-                       LoggerD("data null, can not send result to JS Layer");
-                       return;
-               }
-
-               pendingEvent = (EventRemoveValuePendingEvent *)data;
-               consumer = (MappedDataControlConsumer*)pendingEvent->getThisObject();
-               
-               if (DataControlAsyncCallbackManagerSingleton::Instance().isMappedDataControlGC((void*)consumer))
-               {
-                       LoggerD("private object is garbage collected");
-                       delete pendingEvent;
-                       return;
-               }
-               
-               event = pendingEvent->getEvent();
-
-               if (b == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
-               }
-               std::vector<std::string> result = getDataArrayFromBundle(b, OSP_K_ARG);
-
-               for (size_t index = 0; index < result.size(); index++)
-               {
-                       LoggerD(result[index]);
-               }
-
-               if (result.size() < 2)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid result from datacontrol provider");
-               }
-               
-               // 0 : result true or false??
-               if (RESULT_TRUE_FROM_OSP != result[0])
-               {
-                       // 1 : error msg 
-                       if (result[1].find("E_KEY_NOT_FOUND") != std::string::npos)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, result[1]);
-                       }
-                       else
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
-                       }
-               }
-
-               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
-
-               
-       }
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LoggerE("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-               event->setErrorMsg(ex.GetMessage());            
-       }
-       consumer->handlePendingEvent(event);
-
-       if (pendingEvent)
-       {
-               delete pendingEvent;
-       }
-}
-
-static void MappedDataControlUpdateValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
-{
-       LoggerD("Enter");
-
-       EventUpdateValuePendingEvent* pendingEvent = NULL;
-       MappedDataControlConsumer *consumer = NULL;
-       EventUpdateValuePtr event;
-       
-       try 
-       {
-               if (data == NULL)
-               {
-                       LoggerD("data null, can not send result to JS Layer");
-                       return;
-               }
-               
-               pendingEvent = (EventUpdateValuePendingEvent *)data;
-               consumer = (MappedDataControlConsumer*)pendingEvent->getThisObject();
-               
-               if (DataControlAsyncCallbackManagerSingleton::Instance().isMappedDataControlGC((void*)consumer))
-               {
-                       LoggerD("private object is garbage collected");
-                       delete pendingEvent;
-                       return;
-               }
-                               
-               event = pendingEvent->getEvent();
-
-               if (b == NULL)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
-               }
-               std::vector<std::string> result = getDataArrayFromBundle(b, OSP_K_ARG);
-
-               for (size_t index = 0; index < result.size(); index++)
-               {
-                       LoggerD(result[index]);
-               }
-
-               if (result.size() < 2)
-               {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid result from datacontrol provider");
-               }
-               
-               // 0 : result true or false??
-               if (RESULT_TRUE_FROM_OSP != result[0])
-               {
-                       // 1 : error msg 
-                       if (result[1].find("E_KEY_NOT_FOUND") != std::string::npos)
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, result[1]);
-                       }
-                       else
-                       {
-                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, result[1]);
-                       }
-               }
-
-               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
-               
-       }
-       catch (const WrtDeviceApis::Commons::Exception& ex) 
-       {
-               LoggerE("Exception: " << ex.GetMessage());
-               event->setExceptionCode(ex.getCode());
-               event->setErrorMsg(ex.GetMessage());            
-       }
-       consumer->handlePendingEvent(event);
-
-       if (pendingEvent)
-       {
-               delete pendingEvent;
-       }
-
-}
-
-static void MappedDataControlCommonCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
-{
-       LoggerD("Enter");
-
-       if (b == NULL)
-       {
-               LoggerD("Bundle null, Error");
-               return;         
-       }
-       
-
-       const char *reqType = appsvc_get_data(b, OSP_K_DATACONTROL_REQUEST_TYPE);
-       
-       if (reqType == NULL)
-       {
-               LoggerD("UnkownRequest");
-               return;
-       }
-
-       std::istringstream buffer(reqType);
-       int reqTypeInt = 0;
-
-       buffer >> reqTypeInt;
-
-
-       LoggerD(reqTypeInt);
-       
-
-       switch (reqTypeInt)
-       {
-               case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
-                       MappedDataControlGetValueCallback(b, request_code, res, data);
-                       break;
-               case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
-                       MappedDataControlAddValueCallback(b, request_code, res, data);
-                       break;
-               case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
-                       MappedDataControlUpdateValueCallback(b, request_code, res, data);
-                       break;
-               case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
-                       MappedDataControlRemoveValueCallback(b, request_code, res, data);
-                       break;
-               default:
-                       LoggerD("Unknown Request");
-       }
-
-}
-
-}
 MappedDataControlConsumer::MappedDataControlConsumer(std::string& provId, std::string& dataId, std::string& type) 
 {
        LoggerD("Enter");
 
-       m_appId = getApplicationId(provId);
+       
        m_type = type;;
        m_dataId = dataId;
        m_providerId = provId;
-       DataControlAsyncCallbackManagerSingleton::Instance().setMappedDataControlGC((void*)this, false);
+
+       m_appId = getProviderApplicationId(OSP_PKGINFO_MAP_TYPE, provId);
+       m_ProviderPkgId = getProviderPkgId(m_appId);
+       security_server_app_give_access(m_ProviderPkgId.c_str(), -1);
+       
+       m_currentAppId = getCurrentApplicationId();
+
+       DataControlAsyncCallbackManagerSingleton::Instance().setDataControlGC((void*)this, false);
 
 }
 
 MappedDataControlConsumer::~MappedDataControlConsumer() 
 {
        LoggerD("Enter");
-       DataControlAsyncCallbackManagerSingleton::Instance().setMappedDataControlGC((void*)this, true);
+       DataControlAsyncCallbackManagerSingleton::Instance().setDataControlGC((void*)this, true);
        
 }
 
@@ -558,96 +82,81 @@ std::string MappedDataControlConsumer::getType()
        return m_type;
 }
 
-
-
-
-std::string MappedDataControlConsumer::getApplicationId(const std::string& provId)
+void MappedDataControlConsumer::handleCommonErrorEvent(void* userData, unsigned int code, std::string msg)
 {
-       std::string appIdStr = "";
-
-       char* appId = NULL;
-       char* access = NULL;
-       const char *passId = provId.c_str();
-       
-       if (m_appId.length() == 0)
+       if (userData == NULL)
        {
+               LoggerD("userData null");
+               return;
+       }
+       
+       CommonPendingEvent* pEvent = (CommonPendingEvent*)userData;
        
-               if(     pkgmgr_datacontrol_get_info(passId, OSP_PKGINFO_MAP_TYPE, &appId, &access) < 0)
+       try 
+       {
+               if (dynamic_cast<EventAddValuePendingEvent*>(pEvent) != NULL)
                {
-                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get appId error");
-               }
+                       EventAddValuePendingEvent* pendingAddValueEvent = (EventAddValuePendingEvent*)pEvent;
+                       EventAddValuePtr addValueEvent = pendingAddValueEvent->getEvent();
+                       addValueEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+                       addValueEvent->setErrorMsg(msg);                
                
-
-               if (appId)
+                       WrtDeviceApis::Commons::EventRequestReceiver<EventAddValue>::ManualAnswer(addValueEvent); 
+               }
+               else if (dynamic_cast<EventUpdateValuePendingEvent*>(pEvent) != NULL)
                {
-                       appIdStr = appId;
-                       free(appId);
+                       EventUpdateValuePendingEvent* pendingUpdateValueEvent = (EventUpdateValuePendingEvent*)pEvent;
+                       EventUpdateValuePtr updateValueEvent = pendingUpdateValueEvent->getEvent();
+                       updateValueEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+                       updateValueEvent->setErrorMsg(msg);             
+                       
+                       WrtDeviceApis::Commons::EventRequestReceiver<EventUpdateValue>::ManualAnswer(updateValueEvent); 
                }
-
-               if (access)
+               else if (dynamic_cast<EventGetValuePendingEvent*>(pEvent) != NULL)
                {
-                       free(access);
+                       EventGetValuePendingEvent* pendingGetValueEvent = (EventGetValuePendingEvent*)pEvent;
+                       EventGetValuePtr getValueEvent = pendingGetValueEvent->getEvent();
+                       getValueEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+                       getValueEvent->setErrorMsg(msg);
+                       
+                       WrtDeviceApis::Commons::EventRequestReceiver<EventGetValue>::ManualAnswer(getValueEvent); 
                }
-               
-               m_appId = appIdStr;
-
-
-       }
-       return m_appId;
-
-}
-
-void MappedDataControlConsumer::addArrayToBundle(bundle* passData, std::vector<std::string>& array)
-{
-       size_t arraySize = array.size();
-
-       if (arraySize == 0)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "size = 0");
-       }
-       
-       const char** arr = NULL;
-       arr = (const char**)calloc(sizeof(char*), arraySize);
-
-       if (arr == NULL)
-       {
-               ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "null");
+               else if (dynamic_cast<EventRemoveValuePendingEvent*>(pEvent) != NULL)
+               {
+                       EventRemoveValuePendingEvent* pendingRemoveEvent = (EventRemoveValuePendingEvent*)pEvent;
+                       EventRemoveValuePtr deleteEvent = pendingRemoveEvent->getEvent();
+                       deleteEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+                       deleteEvent->setErrorMsg(msg);
+                       
+                       WrtDeviceApis::Commons::EventRequestReceiver<EventRemoveValue>::ManualAnswer(deleteEvent); 
+               }       
        }
-
-       for (size_t index = 0; index < arraySize; index++) 
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
-               arr[index] = array[index].c_str();
+               LoggerE("Exception: " << ex.GetMessage());
        }
 
-       
-       bundle_add_str_array(passData, OSP_K_ARG, arr, arraySize);
-
-       free(arr);
-       arr = NULL;
-       
 }
 
 
 void MappedDataControlConsumer::handlePendingEvent(const EventAddValuePtr& event)
 {
        WrtDeviceApis::Commons::EventRequestReceiver<EventAddValue>::ManualAnswer(event);       
-       removeReqId(event->getReqId());
 }
+
 void MappedDataControlConsumer::handlePendingEvent(const EventRemoveValuePtr& event)
 {
        WrtDeviceApis::Commons::EventRequestReceiver<EventRemoveValue>::ManualAnswer(event); 
-       removeReqId(event->getReqId());
 }
+
 void MappedDataControlConsumer::handlePendingEvent(const EventGetValuePtr& event)
 {
        WrtDeviceApis::Commons::EventRequestReceiver<EventGetValue>::ManualAnswer(event);
-       removeReqId(event->getReqId());
 }
 
 void MappedDataControlConsumer::handlePendingEvent(const EventUpdateValuePtr& event)
 {
        WrtDeviceApis::Commons::EventRequestReceiver<EventUpdateValue>::ManualAnswer(event); 
-       removeReqId(event->getReqId());
 }
 
 
@@ -673,40 +182,48 @@ void MappedDataControlConsumer::updateValue(const EventUpdateValuePtr& event)
 
 bool MappedDataControlConsumer::checkReqIdUniqueness(unsigned int reqId)
 {
-       size_t index = 0; 
+       std::string reqIdStr;
+       std::stringstream ssReqId;
 
-       for (index = 0; index < m_currentReqIds.size(); index++)
-       {
-               if (m_currentReqIds[index] == reqId)
-                       return false;
-       }
-
-       return true;
+       ssReqId << reqId;
+       reqIdStr = ssReqId.str();
+       return DataControlAsyncCallbackManagerSingleton::Instance().checkReqIdUnique(reqIdStr);
 }
 
-void MappedDataControlConsumer::removeReqId(unsigned int reqId)
+void MappedDataControlConsumer::OnRequestReceived(const EventAddValuePtr& event)
 {
-       bool remove = false;
-       
-       std::vector<unsigned int>::iterator it, found;
-       
-       for (it = m_currentReqIds.begin(); it != m_currentReqIds.end(); ++it)
+       LoggerD("Enter");
+
+       try 
        {
-               if (*it == reqId)
+               unsigned short currentJob = 0;
+               unsigned int reqId = event->getReqId();
+               std::string reqIdStr = convertIntToString(reqId);
+               
+               if (checkReqIdUniqueness(reqId) == false)
                {
-                       found = it;     
-                       remove = true;
+                       ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
                }
-       }
-
-       if (remove)
+               
+               EventAddValuePendingEvent* pendingEvent = new EventAddValuePendingEvent(this, m_dataId, m_appId, m_providerId,  m_currentAppId, event);
+               
+               if (DataControlAsyncCallbackManagerSingleton::Instance().checkRequestIpcOperation())
+               {
+                       SendAppControlLaunchToProvider(pendingEvent, currentJob);
+               }
+               event->switchToManualAnswer();
+               DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(reqIdStr, (void*)pendingEvent);
+       }       
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
-               DPL::Mutex::ScopedLock lock(&m_mutex);
-               m_currentReqIds.erase(found);
+               event->setExceptionCode(ex.getCode());
+               event->setErrorMsg(ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
        }
-}
 
+}
 
+#if 0
 void MappedDataControlConsumer::OnRequestReceived(const EventAddValuePtr& event)
 {
        LoggerD("Enter");
@@ -762,8 +279,8 @@ void MappedDataControlConsumer::OnRequestReceived(const EventAddValuePtr& event)
 
                // FIXEME
                // reqid sholud be known
-               EventAddValuePendingEvent* pendingEvent = new EventAddValuePendingEvent((void*)this, event);
-               int pid = appsvc_run_service(passData, reqId, MappedDataControlCommonCallback, (void*)pendingEvent);
+               EventAddValuePendingEvent* pendingEvent = new EventAddValuePendingEvent((void*)this, dataId, m_appId, m_providerId,  "", event);
+               int pid = appsvc_run_service(passData, reqId, dataControlCommonCallback, (void*)pendingEvent);
 
                if (pid < 0) 
                {
@@ -773,7 +290,6 @@ void MappedDataControlConsumer::OnRequestReceived(const EventAddValuePtr& event)
                event->switchToManualAnswer();
 
                DPL::Mutex::ScopedLock lock(&m_mutex);
-               m_currentReqIds.push_back(reqId);
        }       
        catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
@@ -791,10 +307,43 @@ void MappedDataControlConsumer::OnRequestReceived(const EventAddValuePtr& event)
        }
 
 }
+#endif
 
 void MappedDataControlConsumer::OnRequestReceived(const EventRemoveValuePtr& event)
 {
        LoggerD("Enter");
+
+       try 
+       {
+               unsigned short currentJob = 0;
+               unsigned int reqId = event->getReqId();
+               std::string reqIdStr = convertIntToString(reqId);
+               
+               if (checkReqIdUniqueness(reqId) == false)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+               }
+               
+               EventRemoveValuePendingEvent* pendingEvent = new EventRemoveValuePendingEvent(this, m_dataId, m_appId, m_providerId,  m_currentAppId, event);
+               
+               if (DataControlAsyncCallbackManagerSingleton::Instance().checkRequestIpcOperation())
+               {
+                       SendAppControlLaunchToProvider(pendingEvent, currentJob);
+               }
+               event->switchToManualAnswer();
+               DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(reqIdStr, (void*)pendingEvent);
+       }       
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               event->setExceptionCode(ex.getCode());
+               event->setErrorMsg(ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
+       }
+}
+#if 0
+void MappedDataControlConsumer::OnRequestReceived(const EventRemoveValuePtr& event)
+{
+       LoggerD("Enter");
        bundle* passData = NULL;
        
        try 
@@ -843,9 +392,9 @@ void MappedDataControlConsumer::OnRequestReceived(const EventRemoveValuePtr& eve
                
 
                addArrayToBundle(passData, queryItem);
-               EventRemoveValuePendingEvent* pendingEvent = new EventRemoveValuePendingEvent(this, event);
+               EventRemoveValuePendingEvent* pendingEvent = new EventRemoveValuePendingEvent(this, dataId, m_appId, m_providerId,  "", event);
 
-               int pid = appsvc_run_service(passData, reqId, MappedDataControlCommonCallback, (void*)pendingEvent);
+               int pid = appsvc_run_service(passData, reqId, dataControlCommonCallback, (void*)pendingEvent);
 
                if (pid < 0) 
                {
@@ -855,7 +404,6 @@ void MappedDataControlConsumer::OnRequestReceived(const EventRemoveValuePtr& eve
                event->switchToManualAnswer();
 
                DPL::Mutex::ScopedLock lock(&m_mutex);
-               m_currentReqIds.push_back(reqId);
        }       
        catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
@@ -871,9 +419,43 @@ void MappedDataControlConsumer::OnRequestReceived(const EventRemoveValuePtr& eve
        }
 
 }
+#endif
+
+void MappedDataControlConsumer::OnRequestReceived(const EventGetValuePtr& event)
+{
+       LoggerD("Enter");
+
+       try 
+       {
+               unsigned short currentJob = 0;
+               unsigned int reqId = event->getReqId();
+               std::string reqIdStr = convertIntToString(reqId);
+               
+               if (checkReqIdUniqueness(reqId) == false)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+               }
+               
+               EventGetValuePendingEvent* pendingEvent = new EventGetValuePendingEvent(this, m_dataId, m_appId, m_providerId,  m_currentAppId, event);
+               
+               if (DataControlAsyncCallbackManagerSingleton::Instance().checkRequestIpcOperation())
+               {
+                       SendAppControlLaunchToProvider(pendingEvent, currentJob);
+               }
+               event->switchToManualAnswer();
+               DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(reqIdStr, (void*)pendingEvent);
+       }       
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               event->setExceptionCode(ex.getCode());
+               event->setErrorMsg(ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
+       }
 
+}
 
 
+#if 0
 void MappedDataControlConsumer::OnRequestReceived(const EventGetValuePtr& event)
 {
        LoggerD("Enter");
@@ -926,9 +508,9 @@ void MappedDataControlConsumer::OnRequestReceived(const EventGetValuePtr& event)
                queryItem.push_back("1");
                
                addArrayToBundle(passData, queryItem);
-               EventGetValuePendingEvent* pendingEvent = new EventGetValuePendingEvent(this, event);
+               EventGetValuePendingEvent* pendingEvent = new EventGetValuePendingEvent(this, dataId, m_appId, m_providerId,  "", event);
                
-               int pid = appsvc_run_service(passData, reqId, MappedDataControlCommonCallback, (void*)pendingEvent);
+               int pid = appsvc_run_service(passData, reqId, dataControlCommonCallback, (void*)pendingEvent);
 
                if (pid < 0) 
                {
@@ -938,7 +520,6 @@ void MappedDataControlConsumer::OnRequestReceived(const EventGetValuePtr& event)
                event->switchToManualAnswer();
 
                DPL::Mutex::ScopedLock lock(&m_mutex);          
-               m_currentReqIds.push_back(reqId);
        }       
        catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
@@ -954,10 +535,44 @@ void MappedDataControlConsumer::OnRequestReceived(const EventGetValuePtr& event)
        }
                
 }      
+#endif
 
 void MappedDataControlConsumer::OnRequestReceived(const EventUpdateValuePtr& event)
 {
        LoggerD("Enter");
+
+       try 
+       {
+               unsigned short currentJob = 0;
+               unsigned int reqId = event->getReqId();
+               std::string reqIdStr = convertIntToString(reqId);
+               
+               if (checkReqIdUniqueness(reqId) == false)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+               }
+               
+               EventUpdateValuePendingEvent* pendingEvent = new EventUpdateValuePendingEvent(this, m_dataId, m_appId, m_providerId,  m_currentAppId, event);
+               
+               if (DataControlAsyncCallbackManagerSingleton::Instance().checkRequestIpcOperation())
+               {
+                       SendAppControlLaunchToProvider(pendingEvent, currentJob);
+               }
+               event->switchToManualAnswer();
+               DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(reqIdStr, (void*)pendingEvent);
+       }       
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               event->setExceptionCode(ex.getCode());
+               event->setErrorMsg(ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
+       }
+}
+
+#if 0
+void MappedDataControlConsumer::OnRequestReceived(const EventUpdateValuePtr& event)
+{
+       LoggerD("Enter");
        bundle* passData = NULL;
        
        try 
@@ -1008,9 +623,9 @@ void MappedDataControlConsumer::OnRequestReceived(const EventUpdateValuePtr& eve
                queryItem.push_back(newValue);
 
                addArrayToBundle(passData, queryItem);
-               EventUpdateValuePendingEvent* pendingEvent = new EventUpdateValuePendingEvent(this, event);
+               EventUpdateValuePendingEvent* pendingEvent = new EventUpdateValuePendingEvent(this, dataId, m_appId, m_providerId,  "",  event);
 
-               int pid = appsvc_run_service(passData, reqId, MappedDataControlCommonCallback, (void*)pendingEvent);
+               int pid = appsvc_run_service(passData, reqId, dataControlCommonCallback, (void*)pendingEvent);
 
                if (pid < 0) 
                {
@@ -1020,7 +635,6 @@ void MappedDataControlConsumer::OnRequestReceived(const EventUpdateValuePtr& eve
                event->switchToManualAnswer();
 
                DPL::Mutex::ScopedLock lock(&m_mutex);          
-               m_currentReqIds.push_back(reqId);
        }       
        catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
@@ -1037,7 +651,7 @@ void MappedDataControlConsumer::OnRequestReceived(const EventUpdateValuePtr& eve
 
 
 }
-
+#endif
 
 
 }