summaryrefslogtreecommitdiff
path: root/mobile_src/DataControl
diff options
context:
space:
mode:
authorSehong Na <sehong.na@samsung.com>2014-05-31 13:20:25 +0900
committerSehong Na <sehong.na@samsung.com>2014-05-31 13:20:25 +0900
commit59c401dcb6127a3ca74995bd3b3a7864a95fc418 (patch)
tree1d621db3eb1506f2fa42f1c38e143b90e1c3984f /mobile_src/DataControl
downloadwrt-plugins-tizen-tizen_2.3.tar.gz
wrt-plugins-tizen-tizen_2.3.tar.bz2
wrt-plugins-tizen-tizen_2.3.zip
Diffstat (limited to 'mobile_src/DataControl')
-rwxr-xr-xmobile_src/DataControl/CMakeLists.txt61
-rwxr-xr-xmobile_src/DataControl/DataControlAsyncCallbackManager.cpp24
-rwxr-xr-xmobile_src/DataControl/DataControlAsyncCallbackManager.h240
-rw-r--r--mobile_src/DataControl/DataControlCallback.cpp1382
-rwxr-xr-xmobile_src/DataControl/DataControlCallback.h61
-rw-r--r--mobile_src/DataControl/DataControlConverter.cpp210
-rwxr-xr-xmobile_src/DataControl/DataControlConverter.h50
-rwxr-xr-xmobile_src/DataControl/DataControlErrorObject.h58
-rwxr-xr-xmobile_src/DataControl/DataControlFactory.cpp58
-rwxr-xr-xmobile_src/DataControl/DataControlFactory.h52
-rw-r--r--mobile_src/DataControl/DataControlListener.cpp317
-rwxr-xr-xmobile_src/DataControl/DataControlListener.h90
-rwxr-xr-xmobile_src/DataControl/DataControlPendingEvent.h207
-rw-r--r--mobile_src/DataControl/DataType.h95
-rw-r--r--mobile_src/DataControl/EventAddValue.h58
-rw-r--r--mobile_src/DataControl/EventDelete.h55
-rw-r--r--mobile_src/DataControl/EventGetValue.h59
-rw-r--r--mobile_src/DataControl/EventInsert.h60
-rw-r--r--mobile_src/DataControl/EventRemoveValue.h56
-rw-r--r--mobile_src/DataControl/EventSelect.h80
-rw-r--r--mobile_src/DataControl/EventUpdate.h61
-rw-r--r--mobile_src/DataControl/EventUpdateValue.h61
-rwxr-xr-xmobile_src/DataControl/IMappedDataControlConsumer.cpp41
-rwxr-xr-xmobile_src/DataControl/IMappedDataControlConsumer.h69
-rwxr-xr-xmobile_src/DataControl/ISelectDataObject.cpp34
-rwxr-xr-xmobile_src/DataControl/ISelectDataObject.h48
-rwxr-xr-xmobile_src/DataControl/ISqlDataControlConsumer.cpp40
-rwxr-xr-xmobile_src/DataControl/ISqlDataControlConsumer.h69
-rw-r--r--mobile_src/DataControl/JSDataControlManager.cpp229
-rwxr-xr-xmobile_src/DataControl/JSDataControlManager.h59
-rw-r--r--mobile_src/DataControl/JSMappedDataControlConsumer.cpp659
-rwxr-xr-xmobile_src/DataControl/JSMappedDataControlConsumer.h82
-rw-r--r--mobile_src/DataControl/JSSQLDataControlConsumer.cpp681
-rwxr-xr-xmobile_src/DataControl/JSSQLDataControlConsumer.h82
-rw-r--r--mobile_src/DataControl/JSSelectObjectArrayValues.cpp392
-rwxr-xr-xmobile_src/DataControl/JSSelectObjectArrayValues.h177
-rw-r--r--mobile_src/DataControl/MappedDataControlConsumer.cpp660
-rwxr-xr-xmobile_src/DataControl/MappedDataControlConsumer.h90
-rw-r--r--mobile_src/DataControl/RowData.h66
-rw-r--r--mobile_src/DataControl/SelectDataObject.cpp279
-rwxr-xr-xmobile_src/DataControl/SelectDataObject.h69
-rw-r--r--mobile_src/DataControl/SqlDataControlConsumer.cpp542
-rwxr-xr-xmobile_src/DataControl/SqlDataControlConsumer.h86
-rwxr-xr-xmobile_src/DataControl/config.xml12
-rwxr-xr-xmobile_src/DataControl/plugin_config.cpp82
-rwxr-xr-xmobile_src/DataControl/plugin_config.h38
-rw-r--r--mobile_src/DataControl/plugin_initializer.cpp87
47 files changed, 8068 insertions, 0 deletions
diff --git a/mobile_src/DataControl/CMakeLists.txt b/mobile_src/DataControl/CMakeLists.txt
new file mode 100755
index 0000000..8d982a5
--- /dev/null
+++ b/mobile_src/DataControl/CMakeLists.txt
@@ -0,0 +1,61 @@
+SET(TARGET_NAME ${datacontrol_target})
+SET(DESTINATION_NAME ${datacontrol_dest})
+SET(TARGET_IMPL_NAME ${datacontrol_impl})
+
+PKG_CHECK_MODULES(platform_pkgs_datacontrol REQUIRED capi-appfw-application capi-appfw-app-manager appsvc pkgmgr)
+
+INCLUDE_DIRECTORIES(
+ ${platform_pkgs_datacontrol_INCLUDE_DIRS}
+ ${INCLUDE_COMMON}
+)
+
+SET(CMAKE_INSTALL_RPATH
+ ${CMAKE_INSTALL_RPATH}
+ ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${tizen_dest}
+ ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME}
+)
+
+SET(SRCS_IMPL
+ DataControlFactory.cpp
+ IMappedDataControlConsumer.cpp
+ ISqlDataControlConsumer.cpp
+ ISelectDataObject.cpp
+ DataControlCallback.cpp
+ MappedDataControlConsumer.cpp
+ SelectDataObject.cpp
+ SqlDataControlConsumer.cpp
+ SelectDataObject.cpp
+ DataControlConverter.cpp
+ DataControlListener.cpp
+ JSDataControlManager.cpp
+ JSSQLDataControlConsumer.cpp
+ JSMappedDataControlConsumer.cpp
+ JSSelectObjectArrayValues.cpp
+ DataControlAsyncCallbackManager.cpp
+)
+
+ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+
+TARGET_LINK_LIBRARIES(${TARGET_IMPL_NAME}
+ ${LIBS_COMMON}
+ ${tizen_impl}
+ ${platform_pkgs_datacontrol_LIBRARIES}
+)
+
+SET(SRCS
+ plugin_config.cpp
+ plugin_initializer.cpp
+)
+
+ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ ${TARGET_IMPL_NAME}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
+INSTALL(
+ DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/datacontrol
+ FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE
+)
diff --git a/mobile_src/DataControl/DataControlAsyncCallbackManager.cpp b/mobile_src/DataControl/DataControlAsyncCallbackManager.cpp
new file mode 100755
index 0000000..f31172c
--- /dev/null
+++ b/mobile_src/DataControl/DataControlAsyncCallbackManager.cpp
@@ -0,0 +1,24 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include "DataControlAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+
+
+IMPLEMENT_SINGLETON(DeviceAPI::DataControl::DataControlAsyncCallbackManager)
diff --git a/mobile_src/DataControl/DataControlAsyncCallbackManager.h b/mobile_src/DataControl/DataControlAsyncCallbackManager.h
new file mode 100755
index 0000000..0cb5e78
--- /dev/null
+++ b/mobile_src/DataControl/DataControlAsyncCallbackManager.h
@@ -0,0 +1,240 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef _TIZEN_DATACONTROL_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_DATACONTROL_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <AsyncCallbackManager.h>
+#include <dpl/mutex.h>
+#include "DataControlPendingEvent.h"
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class DataControlAsyncCallbackManager : public DeviceAPI::Common::AsyncCallbackManager
+{
+public:
+ DataControlAsyncCallbackManager()
+ {
+ }
+
+ virtual ~DataControlAsyncCallbackManager()
+ {
+ cleanupUserData();
+ }
+
+ bool isDataControlGC(void* address)
+ {
+ LoggerD(address);
+
+ if (m_dataControlGCMap.find(address) == m_dataControlGCMap.end())
+ {
+ return true;
+ }
+
+ return m_dataControlGCMap[address];
+ }
+
+ void setDataControlGC(void* address, bool gc)
+ {
+ LoggerD(address);
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ if (gc && m_dataControlGCMap.find(address) != m_dataControlGCMap.end())
+ {
+ m_dataControlGCMap.erase(address);
+ }
+ m_dataControlGCMap[address] = gc;
+ }
+
+
+ bool checkRequestIpcOperation()
+ {
+// return m_callbackUserDataMap.empty();
+ // limitation 128
+ if (m_callbackUserDataMap.size() < 128)
+ return true;
+ else
+ return false;
+ }
+
+ void* getRemainingIpcOperation()
+ {
+ LoggerD("OK");
+ void *retPtr = NULL;
+
+ if (m_callbackUserDataMap.empty() == false)
+ {
+ std::string key = m_reqIdVector[0];
+ retPtr = m_callbackUserDataMap[key];
+ }
+ return retPtr;
+ }
+
+ bool checkReqIdUnique(std::string key)
+ {
+ if (m_callbackUserDataMap.find(key) == m_callbackUserDataMap.end())
+ {
+ return true;
+ }
+ return false;
+ }
+
+
+ void addSQLUserData(std::string key, void* data)
+ {
+ if (m_callbackUserDataMap.find(key) != m_callbackUserDataMap.end())
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "same id exist");
+ }
+
+ m_reqIdVector.push_back(key);
+
+ LoggerD("Add OK ReqId : " << key);
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ m_callbackUserDataMap[key] = data;
+ }
+
+ void* removeSQLUserData(std::string key)
+ {
+ size_t index = 0;
+ if (m_callbackUserDataMap.find(key) == m_callbackUserDataMap.end())
+ {
+ LoggerD("Fail ReqId : " << key);
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "there is no key");
+ }
+
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ void* data = m_callbackUserDataMap[key];
+
+ // LoggerD(key << " : " << std::hex << data);
+
+ m_callbackUserDataMap.erase(key);
+
+ for (index = 0; index < m_reqIdVector.size(); index++)
+ {
+ if (m_reqIdVector[index] == key)
+ {
+ m_reqIdVector.erase(m_reqIdVector.begin() + index);
+ break;
+ }
+ }
+
+
+ return data;
+ }
+
+ friend class DPL::Singleton<DataControlAsyncCallbackManager>;
+
+private:
+ void cleanupUserData()
+ {
+ for (std::map<std::string, void*>::iterator it = m_callbackUserDataMap.begin();
+ it != m_callbackUserDataMap.end(); ++it)
+ {
+ CommonPendingEvent *event = (CommonPendingEvent*)it->second;
+
+ EventInsertPendingEvent *insertEvent = dynamic_cast<EventInsertPendingEvent*>(event);
+
+ if (insertEvent)
+ {
+ LoggerD("free insert");
+ delete insertEvent;
+ continue;
+ }
+
+
+ EventSelectPendingEvent *selectEvent = dynamic_cast<EventSelectPendingEvent*>(event);
+
+ if (selectEvent)
+ {
+ LoggerD("free select");
+ delete selectEvent;
+ continue;
+ }
+
+ EventUpdatePendingEvent *updateEvent = dynamic_cast<EventUpdatePendingEvent*>(event);
+
+ if (updateEvent)
+ {
+ LoggerD("free update");
+ delete updateEvent;
+ continue;
+ }
+
+ EventDeletePendingEvent *deleteEvent = dynamic_cast<EventDeletePendingEvent*>(event);
+
+ if (deleteEvent)
+ {
+ LoggerD("free delete");
+ delete deleteEvent;
+ }
+
+ EventAddValuePendingEvent *addValueEvent = dynamic_cast<EventAddValuePendingEvent*>(event);
+
+ if (addValueEvent)
+ {
+ LoggerD("free addValue");
+ delete addValueEvent;
+ continue;
+ }
+
+
+ EventGetValuePendingEvent *getValueEvent = dynamic_cast<EventGetValuePendingEvent*>(event);
+
+ if (getValueEvent)
+ {
+ LoggerD("free getValue");
+ delete getValueEvent;
+ continue;
+ }
+
+ EventUpdateValuePendingEvent *updateValueEvent = dynamic_cast<EventUpdateValuePendingEvent*>(event);
+
+ if (updateValueEvent)
+ {
+ LoggerD("free updateValue");
+ delete updateValueEvent;
+ continue;
+ }
+
+ EventRemoveValuePendingEvent *removeValueEvent = dynamic_cast<EventRemoveValuePendingEvent*>(event);
+
+ if (removeValueEvent)
+ {
+ LoggerD("free removeValue");
+ delete removeValueEvent;
+ }
+ }
+ }
+ DPL::Mutex m_mutex;
+ std::map<void*, bool> m_dataControlGCMap;
+ std::map<std::string, void*> m_callbackUserDataMap;
+ std::vector<std::string> m_reqIdVector;
+
+};
+
+typedef DPL::Singleton<DataControlAsyncCallbackManager> DataControlAsyncCallbackManagerSingleton;
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/DataControlCallback.cpp b/mobile_src/DataControl/DataControlCallback.cpp
new file mode 100644
index 0000000..6f3ce02
--- /dev/null
+++ b/mobile_src/DataControl/DataControlCallback.cpp
@@ -0,0 +1,1382 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include <Commons/Exception.h>
+#include <Logger.h>
+#include <app.h>
+#include <app_info.h>
+#include <app_manager.h>
+#include <package-manager.h>
+#include <aul/aul.h>
+#include <unistd.h>
+#include "DataControlCallback.h"
+#include "SqlDataControlConsumer.h"
+#include "MappedDataControlConsumer.h"
+#include "DataType.h"
+#include "DataControlAsyncCallbackManager.h"
+
+#include "EventDelete.h"
+#include "EventInsert.h"
+#include "EventSelect.h"
+#include "EventUpdate.h"
+#include "EventRemoveValue.h"
+#include "EventAddValue.h"
+#include "EventGetValue.h"
+#include "EventUpdateValue.h"
+
+
+using namespace WrtDeviceApis::Commons;
+
+namespace DeviceAPI {
+namespace DataControl {
+
+// utils for common usage
+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;
+}
+
+std::string getProviderApplicationId(const std::string type, const std::string& provId)
+{
+ std::string appIdStr = "";
+
+ char* appId = NULL;
+ char* access = NULL;
+ const char *passId = provId.c_str();
+
+ if( pkgmgr_datacontrol_get_info(passId, type.c_str(), &appId, &access) < 0)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get appId error");
+ }
+
+ if (appId)
+ {
+ appIdStr = appId;
+ free(appId);
+ }
+
+ if (access)
+ {
+ free(access);
+ }
+
+ return appIdStr;
+}
+
+std::string getCurrentApplicationId()
+{
+ char *app_id = NULL;
+ std::string appId = "";
+ int parent_pid = getpid();
+
+ int ret = app_manager_get_app_id(parent_pid, &app_id);
+
+ if((ret != APP_ERROR_NONE) || (app_id == NULL))
+ {
+ LoggerE("Can not get app id from current pid (" << ret << ")");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "could not get information about application");
+ }
+
+ appId = app_id;
+ free(app_id);
+ return appId;
+}
+
+std::string getProviderPkgId(const std::string& appId)
+{
+ char* pkgId = NULL;
+ std::string pkgIdStr = "";
+ app_info_h handle = NULL;
+
+ int ret = app_manager_get_app_info(appId.c_str(), &handle);
+
+ if (ret != APP_ERROR_NONE)
+ {
+ LoggerD("Fail to get appinfo");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get appId error");
+ }
+
+ ret = app_info_get_package(handle, &pkgId);
+
+ if ((ret != APP_ERROR_NONE) || (pkgId == NULL))
+ {
+ LoggerD("Fail to get pkg_name");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get pkdid error");
+ }
+ pkgIdStr = pkgId;
+ app_info_destroy(handle);
+ free(pkgId);
+ return pkgIdStr;
+}
+
+std::string convertIntToString(unsigned int data)
+{
+ std::stringstream ssbuffer;
+
+ ssbuffer.str("");
+ ssbuffer << data;
+ return ssbuffer.str();
+}
+
+std::string generateFileName(unsigned int reqId, const std::string currentAppId)
+{
+ std::stringstream ssdata;
+ ssdata.str("");
+ ssdata << reqId;
+ std::string parent = DATACONTROL_PROTOCOL_DIR;
+ std::string filename = parent + "/" + currentAppId + ssdata.str();
+ return filename;
+}
+
+void 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");
+ }
+
+ for (size_t index = 0; index < arraySize; index++)
+ {
+ arr[index] = array[index].c_str();
+ }
+
+
+ bundle_add_str_array(passData, OSP_K_ARG, arr, arraySize);
+
+ free(arr);
+ arr = NULL;
+
+}
+void handleRemainingPendingEvent()
+{
+ CommonPendingEvent* userData = NULL;
+ unsigned short currentJob = 0;
+ SQLDataControlConsumer *sqlConsumer = NULL;
+ MappedDataControlConsumer *mapConsumer = NULL;
+
+ try
+ {
+ userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingIpcOperation();
+
+ if (userData)
+ {
+ SendAppControlLaunchToProvider(userData, currentJob);
+ }
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ if (userData)
+ {
+ switch(currentJob)
+ {
+ case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
+ case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
+ case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
+ case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
+ {
+ sqlConsumer = (SQLDataControlConsumer *)userData->getThisObject();
+ sqlConsumer->handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
+ }
+ break;
+ case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
+ case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
+ case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
+ case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
+ {
+ mapConsumer = (MappedDataControlConsumer *)userData->getThisObject();
+ mapConsumer->handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
+
+ }
+ break;
+ default:
+ LoggerD("Unknown Request");
+ }
+ }
+ }
+}
+
+
+void SendAppControlLaunchToProvider(void* event, unsigned short& currentJob)
+{
+ LoggerD("OK");
+ bundle* passData = NULL;
+ std::vector<std::string> queryItem;
+ std::stringstream ssBuffer;
+ std::string stringBuffer;
+ CommonPendingEvent* pEvent = (CommonPendingEvent*)(event);
+ std::string ipcFilename;
+ std::string where;
+ unsigned int reqId = 0;
+ unsigned int columnSize = 0;
+ currentJob = _DATACONTROL_REQUEST_TYPE_UNDEFINED;
+
+ try
+ {
+ passData = bundle_create();
+
+ if (passData == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "ipc memory allocation fail");
+ }
+
+ if (pEvent == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "event null");
+ }
+
+ appsvc_set_operation(passData, APPSVC_OPERATION_DEFAULT);
+ appsvc_set_appid(passData, pEvent->getProviderAppId().c_str());
+
+ bundle_add(passData, OSP_K_CALLER_TYPE, OSP_V_CALLER_TYPE_OSP);
+ bundle_add(passData, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
+ bundle_add(passData, OSP_K_DATACONTROL_PROVIDER, pEvent->getProviderId().c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE); // version
+ bundle_add(passData, AUL_K_CALLER_APPID, pEvent->getCurrentAppId().c_str());
+
+ if (dynamic_cast<EventInsertPendingEvent*>(pEvent) != NULL)
+ {
+
+ currentJob = _DATACONTROL_REQUEST_TYPE_SQL_INSERT;
+
+ EventInsertPendingEvent* pendingInsertEvent = (EventInsertPendingEvent*)pEvent;
+ EventInsertPtr insertEvent = pendingInsertEvent->getEvent();
+
+ reqId = insertEvent->getReqId();
+ columnSize = insertEvent->getColumnSize();
+
+ stringBuffer = convertIntToString(reqId);
+ bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());
+
+ ipcFilename = generateFileName(reqId, pendingInsertEvent->getCurrentAppId().c_str());
+ stringBuffer = convertIntToString(columnSize);
+
+ queryItem.push_back(pendingInsertEvent->getDataId());
+ queryItem.push_back(stringBuffer);
+ queryItem.push_back(ipcFilename);
+
+ stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_SQL_INSERT);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
+
+ addArrayToBundle(passData, queryItem);
+ }
+ else if (dynamic_cast<EventUpdatePendingEvent*>(pEvent) != NULL)
+ {
+
+ currentJob = _DATACONTROL_REQUEST_TYPE_SQL_UPDATE;
+
+ EventUpdatePendingEvent* pendingUpdateEvent = (EventUpdatePendingEvent*)pEvent;
+ EventUpdatePtr updateEvent = pendingUpdateEvent->getEvent();
+
+ reqId = updateEvent->getReqId();
+ columnSize = updateEvent->getColumnSize();
+ where = updateEvent->getWhere();
+
+ stringBuffer = convertIntToString(reqId);
+ bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());
+
+ stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
+
+ ipcFilename = generateFileName(reqId, pendingUpdateEvent->getCurrentAppId().c_str());
+ stringBuffer = convertIntToString(columnSize);
+
+ queryItem.push_back(pendingUpdateEvent->getDataId());
+ queryItem.push_back(stringBuffer);
+ queryItem.push_back(ipcFilename);
+
+ if (where.size() == 0) // where
+ {
+ queryItem.push_back("NULL");
+ }
+ else
+ {
+ queryItem.push_back(where);
+ }
+
+ addArrayToBundle(passData, queryItem);
+
+ }
+ else if (dynamic_cast<EventSelectPendingEvent*>(pEvent) != NULL)
+ {
+
+ currentJob = _DATACONTROL_REQUEST_TYPE_SQL_QUERY;
+
+ EventSelectPendingEvent* pendingSelectEvent = (EventSelectPendingEvent*)pEvent;
+ EventSelectPtr selectEvent = pendingSelectEvent->getEvent();
+
+ reqId = selectEvent->getReqId();
+ std::vector<std::string> columns = selectEvent->getColumns();
+ columnSize = columns.size();
+ where = selectEvent->getWhere();
+ std::string order = selectEvent->getOrder();
+ std::string page = selectEvent->getPage();
+ std::string numberPerPage = selectEvent->getNumerPerPage();
+
+ stringBuffer = convertIntToString(reqId);
+ bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());
+
+ stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_SQL_QUERY);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
+
+ queryItem.push_back(pendingSelectEvent->getDataId());
+
+ if (columnSize == 0)
+ {
+ queryItem.push_back("NULL");
+ }
+ else
+ {
+ stringBuffer = convertIntToString(columnSize);
+ queryItem.push_back(stringBuffer);
+
+ for (size_t index = 0; index < columnSize; index++)
+ {
+ queryItem.push_back(columns[index]);
+ }
+ }
+
+ if (where.size() == 0)
+ {
+ queryItem.push_back("NULL");
+ }
+ else
+ {
+ queryItem.push_back(where);
+ }
+
+ if (order.size() == 0)
+ {
+ queryItem.push_back("NULL");
+ }
+ else
+ {
+ queryItem.push_back(order);
+ }
+
+ if (page.size() == 0) // page
+ {
+ queryItem.push_back("1");
+ }
+ else
+ {
+ queryItem.push_back(page);
+ }
+
+ if (numberPerPage.size() == 0) // numberOfPage
+ {
+ queryItem.push_back("20");
+ }
+ else
+ {
+ queryItem.push_back(numberPerPage);
+ }
+
+ addArrayToBundle(passData, queryItem);
+ }
+ else if (dynamic_cast<EventDeletePendingEvent*>(pEvent) != NULL)
+ {
+ currentJob = _DATACONTROL_REQUEST_TYPE_SQL_DELETE;
+
+ EventDeletePendingEvent* pendingDeleteEvent = (EventDeletePendingEvent*)pEvent;
+ EventDeletePtr deleteEvent = pendingDeleteEvent->getEvent();
+ reqId = deleteEvent->getReqId();
+ stringBuffer = convertIntToString(reqId);
+ bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());
+
+ stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_SQL_DELETE);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
+
+ queryItem.push_back(pendingDeleteEvent->getDataId()); // dataid
+ where = deleteEvent->getWhere();
+
+ if (where.size() == 0) // where
+ {
+ queryItem.push_back("NULL");
+ }
+ else
+ {
+ queryItem.push_back(where);
+ }
+
+ addArrayToBundle(passData, queryItem);
+ }
+ else if (dynamic_cast<EventAddValuePendingEvent*>(pEvent) != NULL)
+ {
+
+ currentJob = _DATACONTROL_REQUEST_TYPE_MAP_INSERT;
+
+ EventAddValuePendingEvent* pendingAddValueEvent = (EventAddValuePendingEvent*)pEvent;
+ EventAddValuePtr addValueEvent = pendingAddValueEvent->getEvent();
+ reqId = addValueEvent->getReqId();
+ stringBuffer = convertIntToString(reqId);
+ bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());
+
+ stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_MAP_INSERT);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
+
+ queryItem.push_back(pendingAddValueEvent->getDataId());
+ queryItem.push_back(addValueEvent->getKey());
+ queryItem.push_back(addValueEvent->getValue());
+
+ addArrayToBundle(passData, queryItem);
+ }
+ else if (dynamic_cast<EventUpdateValuePendingEvent*>(pEvent) != NULL)
+ {
+
+ currentJob = _DATACONTROL_REQUEST_TYPE_MAP_UPDATE;
+
+ EventUpdateValuePendingEvent* pendingUpdateValueEvent = (EventUpdateValuePendingEvent*)pEvent;
+ EventUpdateValuePtr updateValueEvent = pendingUpdateValueEvent->getEvent();
+ reqId = updateValueEvent->getReqId();
+ stringBuffer = convertIntToString(reqId);
+ bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());
+
+ stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_MAP_UPDATE);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
+
+ queryItem.push_back(pendingUpdateValueEvent->getDataId());
+ queryItem.push_back(updateValueEvent->getKey());
+ queryItem.push_back(updateValueEvent->getOldValue());
+ queryItem.push_back(updateValueEvent->getNewValue());
+
+
+ addArrayToBundle(passData, queryItem);
+ }
+ else if (dynamic_cast<EventGetValuePendingEvent*>(pEvent) != NULL)
+ {
+
+ currentJob = _DATACONTROL_REQUEST_TYPE_MAP_QUERY;
+
+ EventGetValuePendingEvent* pendingGetValueEvent = (EventGetValuePendingEvent*)pEvent;
+ EventGetValuePtr getValueEvent = pendingGetValueEvent->getEvent();
+ reqId = getValueEvent->getReqId();
+ stringBuffer = convertIntToString(reqId);
+ bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());
+
+ stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_MAP_QUERY);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
+
+ queryItem.push_back(pendingGetValueEvent->getDataId());
+ queryItem.push_back(getValueEvent->getKey());
+ queryItem.push_back("1");
+ queryItem.push_back("100"); //default num per a page // consider this in 3.0 as a spec
+
+ addArrayToBundle(passData, queryItem);
+
+ }
+ else if (dynamic_cast<EventRemoveValuePendingEvent*>(pEvent) != NULL)
+ {
+
+ currentJob = _DATACONTROL_REQUEST_TYPE_MAP_DELETE;
+
+ EventRemoveValuePendingEvent* pendingRemoveValueEvent = (EventRemoveValuePendingEvent*)pEvent;
+ EventRemoveValuePtr removeValueEvent = pendingRemoveValueEvent->getEvent();
+ reqId = removeValueEvent->getReqId();
+ stringBuffer = convertIntToString(reqId);
+ bundle_add(passData, OSP_K_REQUEST_ID, stringBuffer.c_str());
+
+ stringBuffer = convertIntToString(_DATACONTROL_REQUEST_TYPE_MAP_DELETE);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, stringBuffer.c_str());
+
+ queryItem.push_back(pendingRemoveValueEvent->getDataId());
+ queryItem.push_back(removeValueEvent->getKey());
+ queryItem.push_back(removeValueEvent->getValue());
+
+ addArrayToBundle(passData, queryItem);
+ }
+ else
+ {
+ // never happen
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "no type request type");
+ }
+
+ int pid = 0;
+
+ for (int index = 0; index < 3; index++)
+ {
+ pid = appsvc_run_service(passData, reqId, dataControlCommonCallback, (void*)NULL);
+
+ if (pid >= 0)
+ break;
+
+ usleep(300 * 1000);
+ LoggerD("Launch Retry" << (index + 1));
+ }
+
+
+ if (pid < 0)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Launch Error");
+ }
+
+ LoggerD("Launch OK : pid(" << pid << "), reqid : (" << reqId << ")");
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ if (passData)
+ {
+ bundle_free(passData);
+ passData = NULL;
+ }
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, ex.GetMessage());
+
+ }
+
+ if (passData)
+ {
+ bundle_free(passData);
+ passData = NULL;
+ }
+
+}
+
+
+// callbacks for sqldatacontrol
+void sqldataControlSelectCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
+{
+ LoggerD("Enter");
+
+ EventSelectPendingEvent *pendingEvent = NULL;
+ SQLDataControlConsumer *consumer = NULL;
+ EventSelectPtr event;
+ const char *bundleKey = NULL;
+
+ try
+ {
+ if (b == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
+ }
+
+ bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
+
+ if (bundleKey == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
+ }
+
+ pendingEvent = (EventSelectPendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
+ consumer = (SQLDataControlConsumer*)pendingEvent->getThisObject();
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().isDataControlGC((void*)consumer))
+ {
+ LoggerD("private object is garbage collected");
+ delete pendingEvent;
+ return;
+ }
+ event = pendingEvent->getEvent();
+
+ 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() < 3)
+ {
+ 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);
+ // 2 : result set file path
+ event->setResultSetPath(result[2]);
+
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+ consumer->handlePendingEvent(event);
+
+ if (pendingEvent)
+ {
+ delete pendingEvent;
+ }
+
+}
+
+void sqldataControlInsertCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
+{
+ LoggerD("Enter");
+
+
+ EventInsertPendingEvent *pendingEvent = NULL;
+ SQLDataControlConsumer *consumer = NULL;
+ EventInsertPtr event;
+ const char *bundleKey = NULL;
+
+ try
+ {
+ if (b == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
+ }
+
+ bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
+
+ if (bundleKey == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
+ }
+
+ pendingEvent = (EventInsertPendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
+ consumer = (SQLDataControlConsumer*)pendingEvent->getThisObject();
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().isDataControlGC((void*)consumer))
+ {
+ LoggerD("private object is garbage collected");
+ delete pendingEvent;
+ return;
+ }
+
+ event = pendingEvent->getEvent();
+
+ 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]);
+ }
+
+ // 2 : insertrowid
+ std::stringstream sstr(result[2]);
+ long insertRowid = 0;
+ sstr >> insertRowid;
+ LoggerD(result[2] << insertRowid);
+ event->setRowId(insertRowid);
+ event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
+
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+ consumer->handlePendingEvent(event);
+
+ if (pendingEvent)
+ {
+ delete pendingEvent;
+ }
+
+}
+
+void sqldataControlDeleteCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
+{
+ LoggerD("Enter");
+
+ EventDeletePendingEvent* pendingEvent = NULL;
+ SQLDataControlConsumer *consumer = NULL;
+ EventDeletePtr event;
+ const char* bundleKey = NULL;
+
+ try
+ {
+ if (b == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
+ }
+
+ bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
+
+ if (bundleKey == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
+ }
+
+ pendingEvent = (EventDeletePendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
+ consumer = (SQLDataControlConsumer*)pendingEvent->getThisObject();
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().isDataControlGC((void*)consumer))
+ {
+ LoggerD("private object is garbage collected");
+ delete pendingEvent;
+ return;
+ }
+
+ event = pendingEvent->getEvent();
+
+ 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());
+
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+ consumer->handlePendingEvent(event);
+
+ if (pendingEvent)
+ {
+ delete pendingEvent;
+ }
+}
+
+void sqldataControlUpdateCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
+{
+ LoggerD("Enter");
+
+ EventUpdatePendingEvent* pendingEvent = NULL;
+ SQLDataControlConsumer *consumer = NULL;
+ EventUpdatePtr event;
+ const char *bundleKey = NULL;
+
+ try
+ {
+ if (b == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
+ }
+
+ bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
+
+ if (bundleKey == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
+ }
+
+ pendingEvent = (EventUpdatePendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
+ consumer = (SQLDataControlConsumer*)pendingEvent->getThisObject();
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().isDataControlGC((void*)consumer))
+ {
+ LoggerD("private object is garbage collected");
+ delete pendingEvent;
+ return;
+ }
+
+ event = pendingEvent->getEvent();
+
+ 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());
+
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+ consumer->handlePendingEvent(event);
+
+ if (pendingEvent)
+ {
+ delete pendingEvent;
+ }
+}
+
+void dataControlCommonCallback(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_SQL_QUERY:
+ sqldataControlSelectCallback(b, request_code, res, data);
+ break;
+ case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
+ sqldataControlInsertCallback(b, request_code, res, data);
+ break;
+ case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
+ sqldataControlDeleteCallback(b, request_code, res, data);
+ break;
+ case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
+ sqldataControlUpdateCallback(b, request_code, res, data);
+ break;
+ 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");
+ }
+}
+
+// callbacks for mapped datacontrol
+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;
+ const char *bundleKey = NULL;
+
+ try
+ {
+ if (b == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
+ }
+
+ bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
+
+ if (bundleKey == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
+ }
+
+ pendingEvent = (EventGetValuePendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
+ consumer = (MappedDataControlConsumer*)pendingEvent->getThisObject();
+
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().isDataControlGC((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';
+
+ event->addResultValue(buf);
+ }
+
+ }
+
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+
+ 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;
+ }
+ handleRemainingPendingEvent();
+}
+
+void MappedDataControlAddValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
+{
+ LoggerD("Enter");
+
+
+ EventAddValuePendingEvent *pendingEvent = NULL;
+ MappedDataControlConsumer *consumer = NULL;
+ EventAddValuePtr event;
+ const char *bundleKey = NULL;
+
+ try
+ {
+ if (b == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
+ }
+
+ bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
+
+ if (bundleKey == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
+ }
+
+ pendingEvent = (EventAddValuePendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
+ consumer = (MappedDataControlConsumer*)pendingEvent->getThisObject();
+
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().isDataControlGC((void*)consumer))
+ {
+ LoggerD("private object is garbage collected");
+ delete pendingEvent;
+ return;
+ }
+
+ event = pendingEvent->getEvent();
+
+ 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());
+
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+
+ LoggerE("Exception: " << ex.GetMessage());
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+ consumer->handlePendingEvent(event);
+
+ if (pendingEvent)
+ {
+ delete pendingEvent;
+ }
+ handleRemainingPendingEvent();
+
+}
+
+void MappedDataControlRemoveValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
+{
+ LoggerD("Enter");
+
+ EventRemoveValuePendingEvent* pendingEvent = NULL;
+ MappedDataControlConsumer *consumer = NULL;
+ EventRemoveValuePtr event;
+ const char *bundleKey = NULL;
+
+ try
+ {
+ if (b == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
+ }
+
+ bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
+
+ if (bundleKey == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
+ }
+
+ pendingEvent = (EventRemoveValuePendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
+ consumer = (MappedDataControlConsumer*)pendingEvent->getThisObject();
+
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().isDataControlGC((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());
+
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+ consumer->handlePendingEvent(event);
+
+ if (pendingEvent)
+ {
+ delete pendingEvent;
+ }
+ handleRemainingPendingEvent();
+}
+
+void MappedDataControlUpdateValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data)
+{
+ LoggerD("Enter");
+
+ EventUpdateValuePendingEvent* pendingEvent = NULL;
+ MappedDataControlConsumer *consumer = NULL;
+ EventUpdateValuePtr event;
+ const char *bundleKey = NULL;
+
+ try
+ {
+ if (b == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get result fail from datacontrol provider");
+ }
+
+ bundleKey = appsvc_get_data(b, OSP_K_REQUEST_ID);
+
+ if (bundleKey == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Get key fail from datacontrol provider");
+ }
+
+ pendingEvent = (EventUpdateValuePendingEvent *)DataControlAsyncCallbackManagerSingleton::Instance().removeSQLUserData(bundleKey);
+ consumer = (MappedDataControlConsumer*)pendingEvent->getThisObject();
+
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().isDataControlGC((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());
+
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+
+
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+ consumer->handlePendingEvent(event);
+
+ if (pendingEvent)
+ {
+ delete pendingEvent;
+ }
+ handleRemainingPendingEvent();
+}
+
+}
+}
+
diff --git a/mobile_src/DataControl/DataControlCallback.h b/mobile_src/DataControl/DataControlCallback.h
new file mode 100755
index 0000000..97f93b8
--- /dev/null
+++ b/mobile_src/DataControl/DataControlCallback.h
@@ -0,0 +1,61 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_TIZEN_DATACONTROL_CALLBACK_H_
+#define TIZENAPIS_TIZEN_DATACONTROL_CALLBACK_H_
+
+#include <map>
+#include <vector>
+#include <string>
+#include <app.h>
+#include <appsvc/appsvc.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+// utils for common usage
+std::vector<std::string> getDataArrayFromBundle(bundle *b, std::string key);
+std::string getProviderApplicationId(const std::string type, const std::string& provId);
+std::string getCurrentApplicationId();
+std::string getProviderPkgId(const std::string& appId);
+void SendAppControlLaunchToProvider(void* event, unsigned short& currentJob);
+void handleRemainingPendingEvent();
+std::string convertIntToString(unsigned int data);
+void addArrayToBundle(bundle* passData, std::vector<std::string>& array);
+std::string generateFileName(unsigned int reqId, const std::string currentAppId);
+
+void dataControlCommonCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+
+// callbacks for sqldatacontrol
+void sqldataControlSelectCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+void sqldataControlInsertCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+void sqldataControlDeleteCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+void sqldataControlUpdateCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+// callbacks for mapped datacontrol
+void MappedDataControlGetValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+void MappedDataControlAddValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+void MappedDataControlRemoveValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+void MappedDataControlUpdateValueCallback(bundle* b, int request_code, appsvc_result_val res, void* data);
+
+
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/DataControlConverter.cpp b/mobile_src/DataControl/DataControlConverter.cpp
new file mode 100644
index 0000000..556f115
--- /dev/null
+++ b/mobile_src/DataControl/DataControlConverter.cpp
@@ -0,0 +1,210 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include "DataControlConverter.h"
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include "DataType.h"
+#include <pcrecpp.h>
+#include <JSUtil.h>
+#include <Logger.h>
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace DataControl {
+
+DataControlConverter::DataControlConverter(JSContextRef context) :
+ Converter(context)
+{
+}
+
+DataControlConverter::~DataControlConverter()
+{
+}
+
+unsigned long DataControlConverter::toULong(const JSValueRef& arg)
+{
+ return JSUtil::JSValueToULong(m_context, arg);
+}
+
+std::string DataControlConverter::toString(int arg)
+{
+ std::stringstream ss;
+ if (!(ss << arg)) {
+ ThrowMsg(WrtDeviceApis::Commons::ConversionException,
+ "Could not convert to string.");
+ }
+ return ss.str();
+}
+
+
+std::string DataControlConverter::toString(const JSValueRef& arg)
+{
+ std::string result;
+
+ JSValueRef exception = NULL;
+ JSStringRef str = JSValueToStringCopy(m_context, arg, &exception);
+ if (exception != NULL) {
+ ThrowMsg(ConversionException, "Conversion Exception");
+ }
+ size_t jsSize = JSStringGetMaximumUTF8CStringSize(str);
+ {
+ char buffer[jsSize];
+ JSStringGetUTF8CString(str, buffer, jsSize);
+ result = buffer;
+ }
+ JSStringRelease(str);
+ return result;
+}
+
+std::string DataControlConverter::toString(const JSStringRef& arg)
+{
+ return Converter::toString(arg);
+}
+
+JSValueRef DataControlConverter::toFunctionOrNull(const JSValueRef& arg)
+{
+ if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg))
+ {
+ LoggerD("null.");
+
+ return NULL;
+ }
+ else if (JSValueIsObject(m_context, arg) == false)
+ {
+ LoggerD("undefined, not object");
+ ThrowMsg(ConversionException, "Not a function nor JS null.");
+ }
+ else if (Validator(m_context).isCallback(arg))
+ {
+ LoggerD("Function OK");
+ return arg;
+ }
+
+ ThrowMsg(ConversionException, "Not a function nor JS null.");
+ return NULL;
+}
+
+JSValueRef DataControlConverter::toFunction(const JSValueRef& arg)
+{
+ if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg)
+ || !JSValueIsObject(m_context, arg))
+ {
+ ThrowMsg(ConversionException, "JS null passed as function.");
+ }
+ else if (Validator(m_context).isCallback(arg))
+ {
+ LoggerD("Function OK");
+ return arg;
+ }
+
+ ThrowMsg(ConversionException, "Not a function nor JS null.");
+ return NULL;
+}
+
+void DataControlConverter::checkRowDataSize(const RowData* data, const std::string& where)
+{
+ unsigned long dataSize = 0;
+
+ if (data == NULL)
+ {
+ ThrowMsg(InvalidArgumentException, "No data to handle");
+ }
+
+ std::map<std::string, std::string>::const_iterator it;
+
+ for (it = data->m_Data.begin(); it != data->m_Data.end(); ++it)
+ {
+ dataSize += (unsigned long)it->first.size();
+ dataSize += (unsigned long)it->second.size();
+ }
+ dataSize += where.size();
+
+ if (dataSize > ROW_DATA_MAX)
+ {
+ ThrowMsg(InvalidArgumentException, "Data is too big");
+ }
+}
+
+RowData* DataControlConverter::toRowDataPtr(const JSValueRef& arg)
+{
+ if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg)
+ || !JSValueIsObject(m_context, arg))
+ {
+ ThrowMsg(ConversionException, "undefined or null or not a object");
+ }
+
+ const ScopedJSStringRef keys(JSStringCreateWithUTF8CString(ROW_DATA_COLUMNS));
+ const ScopedJSStringRef values(JSStringCreateWithUTF8CString(ROW_DATA_VALUES));
+
+ JSObjectRef dictObject = toJSObjectRef(arg);
+
+ JSValueRef keysProperty = JSObjectGetProperty(m_context, dictObject, keys.get(), NULL);
+ JSValueRef valuesProperty = JSObjectGetProperty(m_context, dictObject, values.get(), NULL);
+
+ if (JSValueIsUndefined(m_context, keysProperty) || JSValueIsUndefined(m_context, valuesProperty))
+ {
+ ThrowMsg(ConversionException, "property missing");
+ }
+
+ std::vector<std::string> keysArray = toVectorOfStrings(keysProperty);
+ std::vector<std::string> valuesArray = toVectorOfStrings(valuesProperty);
+
+ RowData* rowdata = new RowData(keysArray, valuesArray);
+
+ return rowdata;
+}
+
+JSValueRef DataControlConverter::toJSRowData(const RowDataPtr & arg)
+{
+ JSObjectRef jsRowData = JSObjectMake(m_context, NULL, NULL);
+
+ ScopedJSStringRef jsColumns(JSStringCreateWithUTF8CString("columns"));
+ ScopedJSStringRef jsValues(JSStringCreateWithUTF8CString("values"));
+
+
+ std::map<std::string, std::string>::iterator it;
+ std::vector<string> keyArray, valueArray;
+
+ for (it = arg->m_Data.begin(); it != arg->m_Data.end(); ++it)
+ {
+ keyArray.push_back((*it).first);
+ valueArray.push_back((*it).second);
+ }
+
+ JSValueRef arrayColumns = toJSValueRef(keyArray);
+ JSValueRef arrayValues = toJSValueRef(valueArray);
+
+ JSObjectSetProperty(m_context, jsRowData, jsColumns.get(), arrayColumns, kJSPropertyAttributeNone, NULL);
+ JSObjectSetProperty(m_context, jsRowData, jsValues.get(), arrayValues, kJSPropertyAttributeNone, NULL);
+
+ return jsRowData;
+}
+
+
+
+}
+}
+
diff --git a/mobile_src/DataControl/DataControlConverter.h b/mobile_src/DataControl/DataControlConverter.h
new file mode 100755
index 0000000..5e9545c
--- /dev/null
+++ b/mobile_src/DataControl/DataControlConverter.h
@@ -0,0 +1,50 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <CommonsJavaScript/Converter.h>
+#include "RowData.h"
+
+#ifndef TIZENAPIS_TIZEN_DATACONTROL_CONVERTER_H_
+#define TIZENAPIS_TIZEN_DATACONTROL_CONVERTER_H_
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class DataControlConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+ public:
+ using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+
+ explicit DataControlConverter(JSContextRef context);
+ virtual ~DataControlConverter();
+
+ JSValueRef toFunctionOrNull(const JSValueRef& arg);
+ JSValueRef toFunction(const JSValueRef& arg);
+ RowData* toRowDataPtr(const JSValueRef& arg);
+ JSValueRef toJSRowData(const RowDataPtr & arg);
+ std::string toString(const JSValueRef& arg);
+ std::string toString(int arg);
+ std::string toString(const JSStringRef& arg);
+ unsigned long toULong(const JSValueRef& arg);
+ void checkRowDataSize(const RowData* data, const std::string& where);
+};
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/DataControlErrorObject.h b/mobile_src/DataControl/DataControlErrorObject.h
new file mode 100755
index 0000000..75d5b59
--- /dev/null
+++ b/mobile_src/DataControl/DataControlErrorObject.h
@@ -0,0 +1,58 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_DATACONTROL_ERROROBJECT_H_
+#define TIZENAPIS_API_DATACONTROL_ERROROBJECT_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+#include <Commons/Exception.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+
+class DataControlError
+{
+private :
+ std::string m_errorCode;
+ std::string m_errorMsg;
+ unsigned int m_reqId;
+public:
+
+ DataControlError(unsigned int id, std::string code, std::string msg )
+ {
+ m_reqId = id;
+ m_errorMsg = msg;
+ m_errorCode = code;
+ }
+
+ std::string getErrorMsg() { return m_errorMsg;}
+ unsigned int getReqId() { return m_reqId;}
+ std::string getErrorCode() { return m_errorCode;}
+
+ ~DataControlError() { }
+
+};
+
+typedef DPL::SharedPtr<DataControlError> DataControlErrorPtr;
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/DataControlFactory.cpp b/mobile_src/DataControl/DataControlFactory.cpp
new file mode 100755
index 0000000..af54e14
--- /dev/null
+++ b/mobile_src/DataControl/DataControlFactory.cpp
@@ -0,0 +1,58 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include "DataControlFactory.h"
+#include "SqlDataControlConsumer.h"
+#include "MappedDataControlConsumer.h"
+#include "SelectDataObject.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+
+ISQLDataControlConsumerPtr DataControlFactory::getSQLDataControlConsumer(std::string& provId, std::string& dataId, std::string& type)
+{
+ return ISQLDataControlConsumerPtr(new SQLDataControlConsumer(provId, dataId, type));
+}
+IMappedDataControlConsumerPtr DataControlFactory::getMappedDataControlConsumer(std::string& provId, std::string& dataId, std::string& type)
+{
+ return IMappedDataControlConsumerPtr(new MappedDataControlConsumer(provId, dataId, type));
+}
+
+ISelectDataObjectPtr DataControlFactory::getSelectDataObject()
+{
+ return ISelectDataObjectPtr(new SelectDataObject());
+}
+
+
+DataControlFactory& DataControlFactory::getInstance()
+{
+ static DataControlFactory theInstance;
+ return theInstance;
+}
+
+DataControlFactory::DataControlFactory()
+{
+}
+
+DataControlFactory::~DataControlFactory()
+{
+}
+
+}
+}
diff --git a/mobile_src/DataControl/DataControlFactory.h b/mobile_src/DataControl/DataControlFactory.h
new file mode 100755
index 0000000..3f84c4e
--- /dev/null
+++ b/mobile_src/DataControl/DataControlFactory.h
@@ -0,0 +1,52 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+
+#ifndef TIZENAPIS_API_DATACONTROL_FACTORY_H_
+#define TIZENAPIS_API_DATACONTROL_FACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include "ISqlDataControlConsumer.h"
+#include "IMappedDataControlConsumer.h"
+#include "ISelectDataObject.h"
+
+
+#include <string>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class DataControlFactory : DPL::Noncopyable
+{
+public:
+ ISQLDataControlConsumerPtr getSQLDataControlConsumer(std::string& provId, std::string& dataId, std::string& type);
+ IMappedDataControlConsumerPtr getMappedDataControlConsumer(std::string& provId, std::string& dataId, std::string& type) ;
+ ISelectDataObjectPtr getSelectDataObject();
+
+ static DataControlFactory& getInstance();
+
+protected:
+ DataControlFactory();
+ ~DataControlFactory();
+};
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/DataControlListener.cpp b/mobile_src/DataControl/DataControlListener.cpp
new file mode 100644
index 0000000..d0eb7f6
--- /dev/null
+++ b/mobile_src/DataControl/DataControlListener.cpp
@@ -0,0 +1,317 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/Utils.h>
+#include "DataControlListener.h"
+#include "DataControlConverter.h"
+#include "DataControlAsyncCallbackManager.h"
+#include "JSSelectObjectArrayValues.h"
+#include <CommonsJavaScript/JSUtils.h>
+#include <JSWebAPIErrorFactory.h>
+#include <Logger.h>
+
+using namespace DeviceAPI::Common;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace DeviceAPI {
+namespace DataControl {
+
+DataControlListener::DataControlListener() :
+ EventInsertAnswerReceiver(ThreadEnum::NULL_THREAD),
+ EventDeleteAnswerReceiver(ThreadEnum::NULL_THREAD),
+ EventSelectAnswerReceiver(ThreadEnum::NULL_THREAD),
+ EventUpdateAnswerReceiver(ThreadEnum::NULL_THREAD),
+ EventAddValueAnswerReceiver(ThreadEnum::NULL_THREAD),
+ EventRemoveValueAnswerReceiver(ThreadEnum::NULL_THREAD),
+ EventGetValueAnswerReceiver(ThreadEnum::NULL_THREAD),
+ EventUpdateValueAnswerReceiver(ThreadEnum::NULL_THREAD)
+
+ //,
+// EventGetIndexedRowAnswerReceiver(ThreadEnum::NULL_THREAD)
+{
+ LoggerD("entered");
+}
+
+
+
+DataControlListener::~DataControlListener()
+{
+ LoggerD("entered");
+}
+
+
+DataControlListener& DataControlListener::getInstance()
+{
+ static DataControlListener instance;
+ return instance;
+}
+
+void DataControlListener::MakeErrorJSCallBack(JSCallbackManagerPtr cbm, JSContextRef globalContext,
+ unsigned int error, unsigned int reqid, std::string errorMsg)
+{
+ LoggerD("Enter");
+ JSValueRef err[2];
+ DataControlConverter converter(globalContext);
+
+ switch (error)
+ {
+ case ExceptionCodes::SecurityException:
+ if (errorMsg.size() == 0)
+ errorMsg = "permission denied error";
+
+ err[0] = converter.toJSValueRef(reqid);
+ err[1] = JSWebAPIErrorFactory::makeErrorObject(globalContext,
+ JSWebAPIErrorFactory::SECURITY_ERROR, errorMsg);
+
+ break;
+ case ExceptionCodes::UnsupportedException:
+ if (errorMsg.size() == 0)
+ errorMsg = "unsupport error";
+
+ err[0] = converter.toJSValueRef(reqid);
+ err[1] = JSWebAPIErrorFactory::makeErrorObject(globalContext,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, errorMsg);
+
+ break;
+ case ExceptionCodes::NotFoundException:
+ if (errorMsg.size() == 0)
+ errorMsg = "not found error";
+
+ err[0] = converter.toJSValueRef(reqid);
+ err[1] = JSWebAPIErrorFactory::makeErrorObject(globalContext,
+ JSWebAPIErrorFactory::NOT_FOUND_ERROR, errorMsg);
+
+ break;
+ case ExceptionCodes::AlreadyInUseException:
+ if (errorMsg.size() == 0)
+ errorMsg = "service not available";
+
+ err[0] = converter.toJSValueRef(reqid);
+ err[1] = JSWebAPIErrorFactory::makeErrorObject(globalContext,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, errorMsg);
+
+ break;
+ case ExceptionCodes::EventCancelledException:
+
+ LoggerD("Enter - Event was cancled, callback will be silently discarded");
+ return;
+ case ExceptionCodes::UnknownException:
+ default:
+ if (errorMsg.size() == 0)
+ errorMsg = "unknown error";
+
+ err[0] = converter.toJSValueRef(reqid);
+ err[1] = JSWebAPIErrorFactory::makeErrorObject(globalContext,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, errorMsg);
+
+ break;
+ }
+ cbm->callOnError(err, 2);
+}
+
+
+void DataControlListener::OnAnswerReceived(const EventInsertPtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+ DataControlConverter converter(globalContext);
+ DataControlAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+ JSValueRef successArray[2];
+ int insertRowId = event->getInsertRowId();
+ LoggerD(event->getInsertRowId());
+ successArray[0] = converter.toJSValueRef(event->getReqId());
+ successArray[1] = converter.toJSValueRef(insertRowId);
+
+ callbackManager->callOnSuccess(successArray, 2);
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, (unsigned int)event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+}
+void DataControlListener::OnAnswerReceived(const EventDeletePtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+ DataControlConverter converter(globalContext);
+ DataControlAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+ JSValueRef reqid = converter.toJSValueRef(event->getReqId());
+ callbackManager->callOnSuccess(reqid);
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, (unsigned int)event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+
+}
+void DataControlListener::OnAnswerReceived(const EventSelectPtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+ DataControlConverter converter(globalContext);
+ DataControlAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+ std::string path = event->getResultSetPath();
+
+ JSValueRef successArray[2];
+ successArray[0] = JSSelectObjectArrayValues::createJSObject(globalContext, path);
+ successArray[1] = converter.toJSValueRef(event->getReqId());
+ LoggerD(event->getReqId());
+ callbackManager->callOnSuccess(successArray, 2);
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, (unsigned int)event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+
+}
+void DataControlListener::OnAnswerReceived(const EventUpdatePtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+ DataControlConverter converter(globalContext);
+ DataControlAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+ JSValueRef reqid = converter.toJSValueRef(event->getReqId());
+ callbackManager->callOnSuccess(reqid);
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, (unsigned int)event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+
+}
+
+void DataControlListener::OnAnswerReceived(const EventAddValuePtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+ DataControlConverter converter(globalContext);
+ DataControlAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+ JSValueRef reqid = converter.toJSValueRef(event->getReqId());
+ callbackManager->callOnSuccess(reqid);
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, (unsigned int)event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+
+}
+
+void DataControlListener::OnAnswerReceived(const EventRemoveValuePtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+ DataControlConverter converter(globalContext);
+ DataControlAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+ JSValueRef reqid = converter.toJSValueRef(event->getReqId());
+ callbackManager->callOnSuccess(reqid);
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, (unsigned int)event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+
+}
+
+void DataControlListener::OnAnswerReceived(const EventGetValuePtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+ DataControlConverter converter(globalContext);
+ DataControlAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+ std::vector<std::string> result = event->getResultValues();
+
+ JSValueRef successArray[2];
+ successArray[0] = converter.toJSValueRef(result);
+ successArray[1] = converter.toJSValueRef(event->getReqId());
+ LoggerD(event->getReqId());
+ callbackManager->callOnSuccess(successArray, 2);
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, (unsigned int)event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+
+}
+
+void DataControlListener::OnAnswerReceived(const EventUpdateValuePtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+ DataControlConverter converter(globalContext);
+ DataControlAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+ JSValueRef reqid = converter.toJSValueRef(event->getReqId());
+ callbackManager->callOnSuccess(reqid);
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, (unsigned int)event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+
+}
+
+
+/*
+void DataControlListener::OnAnswerReceived(const EventGetIndexedRowPtr& event)
+{
+ JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+ JSContextRef globalContext = callbackManager->getContext();
+
+ if (event->getExceptionCode() == ExceptionCodes::None)
+ {
+
+ }
+ else
+ {
+ MakeErrorJSCallBack(callbackManager, globalContext, event->getExceptionCode(), event->getReqId(), event->getErrorMsg());
+ }
+
+}*/
+
+
+
+}
+}
diff --git a/mobile_src/DataControl/DataControlListener.h b/mobile_src/DataControl/DataControlListener.h
new file mode 100755
index 0000000..0b97c96
--- /dev/null
+++ b/mobile_src/DataControl/DataControlListener.h
@@ -0,0 +1,90 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef TIZENAPIS_TIZEN_DATACONTROL_LISTENER_H_
+#define TIZENAPIS_TIZEN_DATACONTROL_LISTENER_H_
+
+#include <map>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include "ISqlDataControlConsumer.h"
+#include "IMappedDataControlConsumer.h"
+#include "ISelectDataObject.h"
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventInsert>
+ EventInsertAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventDelete>
+ EventDeleteAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventSelect>
+ EventSelectAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventUpdate>
+ EventUpdateAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventAddValue>
+ EventAddValueAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventRemoveValue>
+ EventRemoveValueAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventGetValue>
+ EventGetValueAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventUpdateValue>
+ EventUpdateValueAnswerReceiver;
+
+class DataControlListener :
+ public EventInsertAnswerReceiver,
+ public EventDeleteAnswerReceiver,
+ public EventSelectAnswerReceiver,
+ public EventUpdateAnswerReceiver,
+ public EventAddValueAnswerReceiver,
+ public EventRemoveValueAnswerReceiver,
+ public EventGetValueAnswerReceiver,
+ public EventUpdateValueAnswerReceiver
+{
+
+private:
+ DataControlListener();
+ void MakeErrorJSCallBack(WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr cbm, JSContextRef globalContext,
+ unsigned int error, unsigned int reqid, std::string errorMsg);
+public:
+ static DataControlListener& getInstance();
+
+ virtual ~DataControlListener();
+protected:
+
+ virtual void OnAnswerReceived(const EventInsertPtr& event);
+ virtual void OnAnswerReceived(const EventDeletePtr& event);
+ virtual void OnAnswerReceived(const EventSelectPtr& event);
+ virtual void OnAnswerReceived(const EventUpdatePtr& event);
+ virtual void OnAnswerReceived(const EventAddValuePtr& event);
+ virtual void OnAnswerReceived(const EventRemoveValuePtr& event);
+ virtual void OnAnswerReceived(const EventGetValuePtr& event);
+ virtual void OnAnswerReceived(const EventUpdateValuePtr& event);
+
+// virtual void OnAnswerReceived(const EventGetIndexedRowPtr& event);
+
+
+};
+
+typedef DPL::SharedPtr<DataControlListener> DataControlListenerPtr;
+
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/DataControlPendingEvent.h b/mobile_src/DataControl/DataControlPendingEvent.h
new file mode 100755
index 0000000..f9e9c9e
--- /dev/null
+++ b/mobile_src/DataControl/DataControlPendingEvent.h
@@ -0,0 +1,207 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_TIZEN_DATACONTROL_PENDING_EVENT_H_
+#define TIZENAPIS_TIZEN_DATACONTROL_PENDING_EVENT_H_
+
+#include "EventRemoveValue.h"
+#include "EventAddValue.h"
+#include "EventGetValue.h"
+#include "EventUpdateValue.h"
+#include "EventDelete.h"
+#include "EventInsert.h"
+#include "EventSelect.h"
+#include "EventUpdate.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class CommonPendingEvent
+{
+public:
+ CommonPendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId, std::string cAppId) :
+ m_dataId(dataId), m_providerAppId(pAppId),
+ m_providerId(proivderId), m_currentAppId(cAppId), m_thisObject(thisObject) {}
+ virtual ~CommonPendingEvent() {}
+ void* getThisObject() const { return m_thisObject; }
+ std::string getDataId() const { return m_dataId;}
+ std::string getProviderId() const { return m_providerId;}
+ std::string getProviderAppId() const { return m_providerAppId;}
+ std::string getCurrentAppId() const { return m_currentAppId;}
+
+protected:
+ std::string m_dataId;
+ std::string m_providerAppId;
+ std::string m_providerId;
+ std::string m_currentAppId;
+ void *m_thisObject;
+};
+
+class EventInsertPendingEvent : public CommonPendingEvent
+{
+public:
+ EventInsertPendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId,
+ std::string cAppId, const EventInsertPtr &event) :
+ CommonPendingEvent(thisObject, dataId, pAppId, proivderId, cAppId), m_event(event)
+ {
+ }
+
+ virtual ~EventInsertPendingEvent()
+ {
+ }
+ EventInsertPtr getEvent() const { return m_event; }
+private:
+ EventInsertPtr m_event;
+};
+
+class EventDeletePendingEvent : public CommonPendingEvent
+{
+public:
+ EventDeletePendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId,
+ std::string cAppId, const EventDeletePtr &event) :
+ CommonPendingEvent(thisObject, dataId, pAppId, proivderId, cAppId), m_event(event)
+ {
+ }
+
+ virtual ~EventDeletePendingEvent()
+ {
+ }
+ EventDeletePtr getEvent() const { return m_event; }
+private:
+ EventDeletePtr m_event;
+};
+
+class EventUpdatePendingEvent : public CommonPendingEvent
+{
+public:
+ EventUpdatePendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId,
+ std::string cAppId, const EventUpdatePtr &event) :
+ CommonPendingEvent(thisObject, dataId, pAppId, proivderId, cAppId), m_event(event)
+ {
+ }
+
+ virtual ~EventUpdatePendingEvent()
+ {
+ }
+ EventUpdatePtr getEvent() const { return m_event; }
+private:
+ EventUpdatePtr m_event;
+};
+
+class EventSelectPendingEvent : public CommonPendingEvent
+{
+public:
+ EventSelectPendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId,
+ std::string cAppId, const EventSelectPtr &event) :
+ CommonPendingEvent(thisObject, dataId, pAppId, proivderId, cAppId), m_event(event)
+ {
+ }
+
+ virtual ~EventSelectPendingEvent()
+ {
+ }
+ EventSelectPtr getEvent() const { return m_event; }
+private:
+ EventSelectPtr m_event;
+};
+
+
+class EventAddValuePendingEvent : public CommonPendingEvent
+{
+public:
+ EventAddValuePendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId,
+ std::string cAppId, const EventAddValuePtr &event) :
+ CommonPendingEvent(thisObject, dataId, pAppId, proivderId, cAppId), m_event(event)
+ {
+ }
+
+ virtual ~EventAddValuePendingEvent()
+ {
+ }
+ EventAddValuePtr getEvent() const { return m_event; }
+private:
+ EventAddValuePtr m_event;
+};
+
+class EventRemoveValuePendingEvent : public CommonPendingEvent
+{
+public:
+ EventRemoveValuePendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId,
+ std::string cAppId, const EventRemoveValuePtr &event) :
+ CommonPendingEvent(thisObject, dataId, pAppId, proivderId, cAppId), m_event(event)
+ {
+ }
+
+ virtual ~EventRemoveValuePendingEvent()
+ {
+ }
+ void* getThisObject() const { return m_thisObject; }
+ EventRemoveValuePtr getEvent() const { return m_event; }
+private:
+ EventRemoveValuePtr m_event;
+};
+
+class EventUpdateValuePendingEvent: public CommonPendingEvent
+{
+public:
+ EventUpdateValuePendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId,
+ std::string cAppId, const EventUpdateValuePtr &event) :
+ CommonPendingEvent(thisObject, dataId, pAppId, proivderId, cAppId), m_event(event)
+ {
+ }
+
+ virtual ~EventUpdateValuePendingEvent()
+ {
+ }
+ EventUpdateValuePtr getEvent() const { return m_event; }
+private:
+ EventUpdateValuePtr m_event;
+};
+
+class EventGetValuePendingEvent : public CommonPendingEvent
+{
+public:
+ EventGetValuePendingEvent(void *thisObject, std::string dataId,
+ std::string pAppId, std::string proivderId,
+ std::string cAppId, const EventGetValuePtr &event) :
+ CommonPendingEvent(thisObject, dataId, pAppId, proivderId, cAppId), m_event(event)
+ {
+ }
+
+ virtual ~EventGetValuePendingEvent()
+ {
+ }
+ EventGetValuePtr getEvent() const { return m_event; }
+private:
+ void *m_thisObject;
+ EventGetValuePtr m_event;
+};
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/DataType.h b/mobile_src/DataControl/DataType.h
new file mode 100644
index 0000000..b1239b1
--- /dev/null
+++ b/mobile_src/DataControl/DataType.h
@@ -0,0 +1,95 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_DATA_CONTROL_TYPE_H_
+#define TIZENAPIS_API_DATA_CONTROL_TYPE_H_
+
+#define MAP_DATA_CONTROL "MAP"
+#define SQL_DATA_CONTROL "SQL"
+
+#define ROW_DATA_COLUMNS "columns"
+#define ROW_DATA_VALUES "values"
+
+#define OSP_PKGINFO_SQL_TYPE "Sql"
+#define OSP_PKGINFO_MAP_TYPE "Map"
+
+#define PROTOCOL_DATA_MAX 16 * 1024
+#define ROW_DATA_MAX 1024 * 1024
+
+#define OSP_V_CALLER_TYPE_OSP "osp"
+#define OSP_V_LAUNCH_TYPE_LAUNCH "launch"
+#define OSP_V_LAUNCH_TYPE_APPCONTROL "appcontrol"
+#define OSP_V_LAUNCH_TYPE_DATACONTROL "datacontrol"
+#define OSP_V_LAUNCH_TYPE_CONDTION "condition"
+#define OSP_V_REQUEST_TYPE_SQL_QUERY "sql_query"
+#define OSP_V_REQUEST_TYPE_SQL_INSERT "sql_insert"
+#define OSP_V_REQUEST_TYPE_SQL_UPDATE "sql_update"
+#define OSP_V_REQUEST_TYPE_SQL_DELETE "sql_delete"
+#define OSP_V_REQUEST_TYPE_MAP_QEURY "map_query"
+#define OSP_V_REQUEST_TYPE_MAP_INSERT "map_insert"
+#define OSP_V_REQUEST_TYPE_MAP_UPDATE "map_update"
+#define OSP_V_REQUEST_TYPE_MAP_DELETE "map_delete"
+
+#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 RESULT_TRUE_FROM_OSP "1"
+#define RESULT_FALSE_FROM_OSP "0"
+#define OSP_K_DATACONTROL_PROTOCOL_VERSION "__OSP_DATACONTROL_PROTOCOL_VERSION__"
+#define OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE "ver_2.1.0.3"
+
+#define DATACONTROL_PROTOCOL_DIR_TOP "/tmp/osp"
+#define DATACONTROL_PROTOCOL_DIR_MIDDLE "/tmp/osp/data-control"
+#define DATACONTROL_PROTOCOL_DIR "/tmp/osp/data-control/request"
+
+enum _DataControlRequestType
+{
+ _DATACONTROL_REQUEST_TYPE_UNDEFINED = 0,
+ _DATACONTROL_REQUEST_TYPE_SQL_QUERY,
+ _DATACONTROL_REQUEST_TYPE_SQL_INSERT,
+ _DATACONTROL_REQUEST_TYPE_SQL_UPDATE,
+ _DATACONTROL_REQUEST_TYPE_SQL_DELETE,
+ _DATACONTROL_REQUEST_TYPE_MAP_QUERY,
+ _DATACONTROL_REQUEST_TYPE_MAP_INSERT,
+ _DATACONTROL_REQUEST_TYPE_MAP_UPDATE,
+ _DATACONTROL_REQUEST_TYPE_MAP_DELETE
+};
+
+enum DbColumnType
+{
+ DB_COLUMNTYPE_INT = 0, /**< The column type is 4bytes integer */
+ DB_COLUMNTYPE_INT64, /**< The column type is 8bytes integer */
+ DB_COLUMNTYPE_DOUBLE, /**< The column type is double */
+ DB_COLUMNTYPE_TEXT, /**< The column type is text */
+ DB_COLUMNTYPE_BLOB, /**< The column type is blob */
+ DB_COLUMNTYPE_NULL, /**< The column type is null */
+ DB_COLUMNTYPE_UNDEFINED
+};
+
+
+#endif
diff --git a/mobile_src/DataControl/EventAddValue.h b/mobile_src/DataControl/EventAddValue.h
new file mode 100644
index 0000000..2f2a709
--- /dev/null
+++ b/mobile_src/DataControl/EventAddValue.h
@@ -0,0 +1,58 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_EVENT_ADD_VALUE_H_
+#define TIZENAPIS_API_EVENT_ADD_VALUE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class EventAddValue : public WrtDeviceApis::Commons::IEvent<EventAddValue>
+{
+private :
+ unsigned int m_reqId;
+ std::string m_errorMsg;
+ std::string m_key;
+ std::string m_value;
+
+public:
+ unsigned int getReqId() { return m_reqId; }
+ std::string getErrorMsg() { return m_errorMsg; }
+ std::string getKey() { return m_key;}
+ std::string getValue() { return m_value;}
+
+ void setReqId(const unsigned int & reqId) { m_reqId = reqId;}
+ void setErrorMsg(const std::string &msg) { m_errorMsg = msg; }
+ void setKey(const std::string &key) {m_key = key;}
+ void setValue(const std::string &value) { m_value = value;}
+
+ EventAddValue() { LoggerD("entered"); }
+ ~EventAddValue() { }
+};
+
+typedef DPL::SharedPtr<EventAddValue> EventAddValuePtr;
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/EventDelete.h b/mobile_src/DataControl/EventDelete.h
new file mode 100644
index 0000000..08db100
--- /dev/null
+++ b/mobile_src/DataControl/EventDelete.h
@@ -0,0 +1,55 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_EVENT_DELETE_H_
+#define TIZENAPIS_API_EVENT_DELETE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class EventDelete : public WrtDeviceApis::Commons::IEvent<EventDelete>
+{
+private :
+ std::string m_where;
+ unsigned int m_reqId;
+ std::string m_errorMsg;
+
+public:
+ unsigned int getReqId() { return m_reqId;}
+ std::string getWhere() { return m_where; }
+ std::string getErrorMsg() { return m_errorMsg;}
+
+ void setReqId(const unsigned int & reqId) { m_reqId = reqId;}
+ void setWhere(const std::string& where) { m_where = where; }
+ void setErrorMsg(const std::string& errorMsg) { m_errorMsg = errorMsg;}
+
+ EventDelete() { LoggerD("entered"); }
+ ~EventDelete() { }
+};
+
+typedef DPL::SharedPtr<EventDelete> EventDeletePtr;
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/EventGetValue.h b/mobile_src/DataControl/EventGetValue.h
new file mode 100644
index 0000000..bf51f0e
--- /dev/null
+++ b/mobile_src/DataControl/EventGetValue.h
@@ -0,0 +1,59 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_EVENT_GET_VALUE_H_
+#define TIZENAPIS_API_EVENT_GET_VALUE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <vector>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class EventGetValue : public WrtDeviceApis::Commons::IEvent<EventGetValue>
+{
+private :
+ unsigned int m_reqId;
+ std::string m_errorMsg;
+ std::string m_key;
+ std::vector<std::string> m_result;
+public:
+ unsigned int getReqId() { return m_reqId; }
+ std::string getErrorMsg() { return m_errorMsg; }
+ std::string getKey() { return m_key;}
+ std::vector<std::string> getResultValues() { return m_result;}
+
+ void setReqId(const unsigned int & reqId) { m_reqId = reqId;}
+ void setKey(const std::string &key) { m_key = key;}
+ void setErrorMsg(const std::string &msg) { m_errorMsg = msg; }
+ void addResultValue(const std::string &value) { m_result.push_back(value);}
+
+
+ EventGetValue() { LoggerD("entered"); }
+ ~EventGetValue() { }
+};
+
+typedef DPL::SharedPtr<EventGetValue> EventGetValuePtr;
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/EventInsert.h b/mobile_src/DataControl/EventInsert.h
new file mode 100644
index 0000000..281b016
--- /dev/null
+++ b/mobile_src/DataControl/EventInsert.h
@@ -0,0 +1,60 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_EVENT_INSERT_H_
+#define TIZENAPIS_API_EVENT_INSERT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "RowData.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class EventInsert : public WrtDeviceApis::Commons::IEvent<EventInsert>
+{
+private :
+ std::string m_dataId;
+ unsigned int m_reqId;
+ std::string m_errorMsg;
+ RowData* m_rowData;
+ long m_insertRowId;
+ unsigned int m_columnSize;
+public:
+ unsigned int getReqId() { return m_reqId; }
+ RowData* getRowData() { return m_rowData; }
+ std::string getErrorMsg() { return m_errorMsg; }
+ long getInsertRowId() { return m_insertRowId;}
+ unsigned int getColumnSize() { return m_columnSize;}
+
+ void setReqId(const unsigned int & reqId) { m_reqId = reqId;}
+ void setRowData(RowData* rowData) { m_rowData = rowData;}
+ void setErrorMsg(const std::string &msg) { m_errorMsg = msg; }
+ void setRowId(const long &id) { m_insertRowId = id;}
+ void setColumnSize(unsigned int& columnSize) { m_columnSize = columnSize;}
+ EventInsert() { LoggerD("entered"); m_insertRowId = -1; m_columnSize = 0;}
+ ~EventInsert() { }
+};
+
+typedef DPL::SharedPtr<EventInsert> EventInsertPtr;
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/EventRemoveValue.h b/mobile_src/DataControl/EventRemoveValue.h
new file mode 100644
index 0000000..2bdee43
--- /dev/null
+++ b/mobile_src/DataControl/EventRemoveValue.h
@@ -0,0 +1,56 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_EVENT_REMOVE_VALUE_H_
+#define TIZENAPIS_API_EVENT_REMOVE_VALUE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class EventRemoveValue : public WrtDeviceApis::Commons::IEvent<EventRemoveValue>
+{
+private :
+ unsigned int m_reqId;
+ std::string m_errorMsg;
+ std::map<std::string, std::string> m_map;
+ std::string m_key;
+ std::string m_value;
+public:
+ unsigned int getReqId() { return m_reqId; }
+ std::string getErrorMsg() { return m_errorMsg; }
+ void setReqId(const unsigned int & reqId) { m_reqId = reqId;}
+ std::string getKey() { return m_key;}
+ std::string getValue() { return m_value;}
+ void setKey(const std::string &key) { m_key = key;}
+ void setValue(const std::string &value) { m_value = value;}
+ void setErrorMsg(const std::string &msg) { m_errorMsg = msg; }
+
+ EventRemoveValue() { LoggerD("entered"); }
+ ~EventRemoveValue() { }
+};
+
+typedef DPL::SharedPtr<EventRemoveValue> EventRemoveValuePtr;
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/EventSelect.h b/mobile_src/DataControl/EventSelect.h
new file mode 100644
index 0000000..43bbcc5
--- /dev/null
+++ b/mobile_src/DataControl/EventSelect.h
@@ -0,0 +1,80 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_EVENT_SELECT_H_
+#define TIZENAPIS_API_EVENT_SELECT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "RowData.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class EventSelect : public WrtDeviceApis::Commons::IEvent<EventSelect>
+{
+private :
+ std::vector<std::string> m_columns;
+
+ unsigned int m_reqId;
+ std::string m_where;
+ std::string m_order;
+ std::string m_page;
+ std::string m_numberPerPage;
+ std::string m_resultSetPath;
+ std::string m_errorMsg;
+
+public:
+ EventSelect() {
+ LoggerD("entered");
+ m_reqId = 0;
+ m_where = "";
+ m_order = "";
+ m_page = "";
+ m_numberPerPage = "";
+ m_resultSetPath = "";
+ m_errorMsg = "";
+
+ }
+ ~EventSelect() {
+ }
+
+ unsigned int getReqId() { return m_reqId; }
+ std::string getWhere() { return m_where; }
+ std::string getPage() { return m_page; }
+ std::string getOrder() { return m_order; }
+ std::string getNumerPerPage() { return m_numberPerPage; }
+ std::vector<std::string> getColumns() { return m_columns;}
+ std::string getResultSetPath() { return m_resultSetPath;}
+ std::string getErrorMsg() { return m_errorMsg; }
+ void setReqId(const unsigned int & reqId) { m_reqId = reqId;}
+ void setWhere(const std::string& where) { m_where = where; }
+ void setOrder(const std::string& order) { m_order = order; }
+ void setPage(const std::string& page) { m_page = page;}
+ void setNumberPerPage(const std::string &number) { m_numberPerPage = number;}
+ void setColumns(const std::vector<std::string>& columns) { m_columns = columns;}
+ void setResultSetPath(const std::string& path) { m_resultSetPath = path;}
+ void setErrorMsg(const std::string& msg) { m_errorMsg = msg; }
+};
+
+typedef DPL::SharedPtr<EventSelect> EventSelectPtr;
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/EventUpdate.h b/mobile_src/DataControl/EventUpdate.h
new file mode 100644
index 0000000..7556ba4
--- /dev/null
+++ b/mobile_src/DataControl/EventUpdate.h
@@ -0,0 +1,61 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_EVENT_UPDATE_H_
+#define TIZENAPIS_API_EVENT_UPDATE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "RowData.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class EventUpdate : public WrtDeviceApis::Commons::IEvent<EventUpdate>
+{
+private :
+ std::string m_where;
+ unsigned int m_reqId;
+ unsigned int m_columnSize;
+ RowData* m_rowData;
+ std::string m_errorMsg;
+
+public:
+ unsigned int getReqId() { return m_reqId;}
+ unsigned int getColumnSize() { return m_columnSize;}
+ std::string getWhere() { return m_where; }
+ RowData* getRowData() { return m_rowData; }
+ std::string getErrorMsg() { return m_errorMsg;}
+
+ void setReqId(const unsigned int & reqId) { m_reqId = reqId;}
+ void setRowData(RowData* rowData) { m_rowData = rowData;}
+ void setWhere(const std::string& where) { m_where = where; }
+ void setErrorMsg(const std::string& errorMsg) { m_errorMsg = errorMsg;}
+ void setColumnSize(unsigned int& columnSize) { m_columnSize = columnSize; }
+
+ EventUpdate() { LoggerD("entered"); }
+ ~EventUpdate() { }
+};
+
+typedef DPL::SharedPtr<EventUpdate> EventUpdatePtr;
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/EventUpdateValue.h b/mobile_src/DataControl/EventUpdateValue.h
new file mode 100644
index 0000000..c418861
--- /dev/null
+++ b/mobile_src/DataControl/EventUpdateValue.h
@@ -0,0 +1,61 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_EVENT_UPDATE_VALUE_H_
+#define TIZENAPIS_API_EVENT_UPDATE_VALUE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class EventUpdateValue : public WrtDeviceApis::Commons::IEvent<EventUpdateValue>
+{
+private :
+ unsigned int m_reqId;
+ std::string m_errorMsg;
+ std::string m_key;
+ std::string m_oldValue;
+ std::string m_newValue;
+public:
+ unsigned int getReqId() { return m_reqId; }
+ std::string getErrorMsg() { return m_errorMsg; }
+ std::string getKey() { return m_key;}
+ std::string getOldValue() { return m_oldValue;}
+ std::string getNewValue() { return m_newValue;}
+
+ void setReqId(const unsigned int& reqId) { m_reqId = reqId;}
+ void setErrorMsg(const std::string& msg) { m_errorMsg = msg; }
+ void setKey(const std::string& key) { m_key = key;}
+ void setOldValue(const std::string& value) { m_oldValue = value;}
+ void setNewValue(const std::string& value) { m_newValue = value;}
+
+ EventUpdateValue() { LoggerD("entered"); }
+ ~EventUpdateValue() { }
+};
+
+typedef DPL::SharedPtr<EventUpdateValue> EventUpdateValuePtr;
+
+}
+}
+
+#endif
+
+
diff --git a/mobile_src/DataControl/IMappedDataControlConsumer.cpp b/mobile_src/DataControl/IMappedDataControlConsumer.cpp
new file mode 100755
index 0000000..6098a95
--- /dev/null
+++ b/mobile_src/DataControl/IMappedDataControlConsumer.cpp
@@ -0,0 +1,41 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include "IMappedDataControlConsumer.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+using namespace WrtDeviceApis::Commons;
+
+IMappedDataControlConsumer::IMappedDataControlConsumer() :
+ EventRequestReceiver<EventAddValue>(ThreadEnum::NULL_THREAD),
+ EventRequestReceiver<EventRemoveValue>(ThreadEnum::NULL_THREAD),
+ EventRequestReceiver<EventGetValue>(ThreadEnum::NULL_THREAD),
+ EventRequestReceiver<EventUpdateValue>(ThreadEnum::NULL_THREAD)
+{
+}
+
+
+
+IMappedDataControlConsumer::~IMappedDataControlConsumer() {
+}
+
+}
+}
+
diff --git a/mobile_src/DataControl/IMappedDataControlConsumer.h b/mobile_src/DataControl/IMappedDataControlConsumer.h
new file mode 100755
index 0000000..957e0da
--- /dev/null
+++ b/mobile_src/DataControl/IMappedDataControlConsumer.h
@@ -0,0 +1,69 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_IMAPPED_DATACONTROL_CONSUMER_H_
+#define TIZENAPIS_API_IMAPPED_DATACONTROL_CONSUMER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include "EventRemoveValue.h"
+#include "EventAddValue.h"
+#include "EventGetValue.h"
+#include "EventUpdateValue.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+
+class IMappedDataControlConsumer :
+ public WrtDeviceApis::Commons::EventRequestReceiver<EventAddValue>,
+ public WrtDeviceApis::Commons::EventRequestReceiver<EventRemoveValue>,
+ public WrtDeviceApis::Commons::EventRequestReceiver<EventGetValue>,
+ public WrtDeviceApis::Commons::EventRequestReceiver<EventUpdateValue>
+{
+public:
+ virtual ~IMappedDataControlConsumer();
+
+ virtual void addValue(const EventAddValuePtr& event) = 0;
+ virtual void removeValue(const EventRemoveValuePtr& event) = 0;
+ virtual void getValue(const EventGetValuePtr& event) = 0;
+ virtual void updateValue(const EventUpdateValuePtr& event) = 0;
+
+ virtual std::string getType() = 0;
+ virtual std::string getDataId() = 0;
+ virtual std::string getProviderId() = 0;
+
+
+
+protected:
+ IMappedDataControlConsumer();
+
+ virtual void OnRequestReceived(const EventAddValuePtr& event) = 0;
+ virtual void OnRequestReceived(const EventRemoveValuePtr& event) = 0;
+ virtual void OnRequestReceived(const EventGetValuePtr& event) = 0;
+ virtual void OnRequestReceived(const EventUpdateValuePtr& event) = 0;
+
+};
+
+typedef DPL::SharedPtr<IMappedDataControlConsumer> IMappedDataControlConsumerPtr;
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/ISelectDataObject.cpp b/mobile_src/DataControl/ISelectDataObject.cpp
new file mode 100755
index 0000000..1007308
--- /dev/null
+++ b/mobile_src/DataControl/ISelectDataObject.cpp
@@ -0,0 +1,34 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include "ISelectDataObject.h"
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+using namespace WrtDeviceApis::Commons;
+ISelectDataObject::ISelectDataObject()
+{
+}
+
+ISelectDataObject::~ISelectDataObject() {
+}
+
+}
+}
diff --git a/mobile_src/DataControl/ISelectDataObject.h b/mobile_src/DataControl/ISelectDataObject.h
new file mode 100755
index 0000000..07b5750
--- /dev/null
+++ b/mobile_src/DataControl/ISelectDataObject.h
@@ -0,0 +1,48 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_ISELECT_DATA_OBJECT_H_
+#define TIZENAPIS_API_ISELECT_DATA_OBJECT_H_
+
+#include <dpl/shared_ptr.h>
+#include <fstream>
+#include "RowData.h"
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+
+class ISelectDataObject
+{
+public:
+ virtual ~ISelectDataObject();
+ virtual RowDataPtr getIndexedRow(const int fetchIndex) = 0;
+ virtual int getRowNumber() = 0;
+ virtual void setResultSetPath(const std::string& path) = 0;
+ virtual void openResultPath(const std::string& filepath) = 0;
+protected:
+ ISelectDataObject();
+};
+
+typedef DPL::SharedPtr<ISelectDataObject> ISelectDataObjectPtr;
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/ISqlDataControlConsumer.cpp b/mobile_src/DataControl/ISqlDataControlConsumer.cpp
new file mode 100755
index 0000000..58cf108
--- /dev/null
+++ b/mobile_src/DataControl/ISqlDataControlConsumer.cpp
@@ -0,0 +1,40 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include "ISqlDataControlConsumer.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+using namespace WrtDeviceApis::Commons;
+
+ISQLDataControlConsumer::ISQLDataControlConsumer() :
+ EventRequestReceiver<EventInsert>(ThreadEnum::NULL_THREAD),
+ EventRequestReceiver<EventDelete>(ThreadEnum::NULL_THREAD),
+ EventRequestReceiver<EventSelect>(ThreadEnum::NULL_THREAD),
+ EventRequestReceiver<EventUpdate>(ThreadEnum::NULL_THREAD)
+{
+}
+
+
+
+ISQLDataControlConsumer::~ISQLDataControlConsumer() {
+}
+
+}
+}
diff --git a/mobile_src/DataControl/ISqlDataControlConsumer.h b/mobile_src/DataControl/ISqlDataControlConsumer.h
new file mode 100755
index 0000000..4811054
--- /dev/null
+++ b/mobile_src/DataControl/ISqlDataControlConsumer.h
@@ -0,0 +1,69 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_ISQL_DATACONTROL_CONSUMER_H_
+#define TIZENAPIS_API_ISQL_DATACONTROL_CONSUMER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include "EventDelete.h"
+#include "EventInsert.h"
+#include "EventSelect.h"
+#include "EventUpdate.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+
+class ISQLDataControlConsumer :
+ public WrtDeviceApis::Commons::EventRequestReceiver<EventInsert>,
+ public WrtDeviceApis::Commons::EventRequestReceiver<EventDelete>,
+ public WrtDeviceApis::Commons::EventRequestReceiver<EventSelect>,
+ public WrtDeviceApis::Commons::EventRequestReceiver<EventUpdate>
+{
+public:
+ virtual ~ISQLDataControlConsumer();
+
+ virtual void insertData(const EventInsertPtr& event) = 0;
+ virtual void deleteData(const EventDeletePtr& event) = 0;
+ virtual void selectData(const EventSelectPtr& emitter) = 0;
+ virtual void updateData(const EventUpdatePtr& event) = 0;
+
+ virtual std::string getType() = 0;
+ virtual std::string getDataId() = 0;
+ virtual std::string getProviderId() = 0;
+
+
+
+protected:
+ ISQLDataControlConsumer();
+
+ virtual void OnRequestReceived(const EventInsertPtr& event) = 0;
+ virtual void OnRequestReceived(const EventDeletePtr& event) = 0;
+ virtual void OnRequestReceived(const EventSelectPtr& event) = 0;
+ virtual void OnRequestReceived(const EventUpdatePtr& event) = 0;
+
+};
+
+typedef DPL::SharedPtr<ISQLDataControlConsumer> ISQLDataControlConsumerPtr;
+
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/JSDataControlManager.cpp b/mobile_src/DataControl/JSDataControlManager.cpp
new file mode 100644
index 0000000..557b5c9
--- /dev/null
+++ b/mobile_src/DataControl/JSDataControlManager.cpp
@@ -0,0 +1,229 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <JSWebAPIErrorFactory.h>
+#include <SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include <TimeTracer.h>
+#include "DataType.h"
+#include "JSDataControlManager.h"
+#include "JSMappedDataControlConsumer.h"
+#include "JSSQLDataControlConsumer.h"
+#include "DataControlListener.h"
+#include "plugin_config.h"
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DeviceAPI::Common;
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+JSClassRef JSDataControlManager::m_jsClassRef = NULL;
+
+JSClassDefinition JSDataControlManager::m_classInfo =
+{
+ 0,
+ kJSClassAttributeNone,
+ "DataControlManager",
+ NULL,
+ NULL,
+ m_function,
+ initialize,
+ finalize,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ hasInstance,
+ NULL
+};
+
+JSStaticFunction JSDataControlManager::m_function[] =
+{
+ { "getDataControlConsumer", getDataControlConsumer, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+const JSClassRef JSDataControlManager::getClassRef()
+{
+ if (!m_jsClassRef)
+ {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSDataControlManager::getClassInfo()
+{
+ return &m_classInfo;
+}
+
+
+void JSDataControlManager::initialize(JSContextRef context, JSObjectRef object)
+{
+ JSDataControlManagerPriv *priv = static_cast<JSDataControlManagerPriv*>(JSObjectGetPrivate(object));
+ LoggerD("JSDataControlManager::initialize");
+
+ if (priv != NULL)
+ {
+ LoggerE("already exist");
+ }
+ else
+ {
+ priv = new JSDataControlManagerPriv(context);
+ LoggerD("OK creation");
+ if(!JSObjectSetPrivate(object, static_cast<void*>(priv)))
+ {
+ LoggerE("Object can't store private data.");
+ delete priv;
+ }
+ }
+
+}
+
+void JSDataControlManager::finalize(JSObjectRef object)
+{
+ LoggerD("JSDataControlManager::Finalrize");
+
+
+ JSDataControlManagerPriv *priv = static_cast<JSDataControlManagerPriv*>(JSObjectGetPrivate(object));
+
+ if (priv != NULL)
+ {
+ delete priv;
+ }
+}
+
+bool JSDataControlManager::hasInstance(JSContextRef context, JSObjectRef constructor,
+ JSValueRef possibleInstance, JSValueRef* exception)
+{
+ return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+JSValueRef JSDataControlManager::getDataControlConsumer (
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toString(0, false);
+ validator.toString(1, false);
+ validator.toString(2, false);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ JSValueRef reserveArguments[3];
+ JSDataControlManagerPriv *priv = static_cast<JSDataControlManagerPriv*>(JSObjectGetPrivate(thisObject));
+
+ Try
+ {
+ for (size_t index = 0; index < 3; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(context);
+ }
+
+
+ Converter converter(context);
+ std::string providerId = converter.toString(reserveArguments[0]);
+ std::string dataId = converter.toString(reserveArguments[1]);
+ std::string type = converter.toString(reserveArguments[2]);
+
+
+ if (type == SQL_DATA_CONTROL)
+ {
+ return JSSQLDataControlConsumer::createJSObject(
+ priv->getContext(), providerId, dataId, type);
+ }
+ else if (type == MAP_DATA_CONTROL)
+ {
+ return JSMappedDataControlConsumer::createJSObject(
+ priv->getContext(), providerId, dataId, type);
+ }
+ else
+ {
+ Throw(WrtDeviceApis::Commons::ConversionException);
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ }
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+}
+
+
+}
+}
diff --git a/mobile_src/DataControl/JSDataControlManager.h b/mobile_src/DataControl/JSDataControlManager.h
new file mode 100755
index 0000000..3bc13ca
--- /dev/null
+++ b/mobile_src/DataControl/JSDataControlManager.h
@@ -0,0 +1,59 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_TIZEN_JS_DATACONTROL_MANAGER_H_
+#define TIZENAPIS_TIZEN_JS_DATACONTROL_MANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<void>::Type JSDataControlManagerPriv;
+
+
+class JSDataControlManager {
+public:
+ static const JSClassDefinition* getClassInfo();
+ static const JSClassRef getClassRef();
+private:
+ static void initialize(JSContextRef context, JSObjectRef object);
+ static void finalize(JSObjectRef object);
+ static bool hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
+
+ static JSValueRef getDataControlConsumer (
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+
+ static JSClassDefinition m_classInfo;
+ static JSStaticFunction m_function[];
+ static JSClassRef m_jsClassRef;
+
+};
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/JSMappedDataControlConsumer.cpp b/mobile_src/DataControl/JSMappedDataControlConsumer.cpp
new file mode 100644
index 0000000..4bf3573
--- /dev/null
+++ b/mobile_src/DataControl/JSMappedDataControlConsumer.cpp
@@ -0,0 +1,659 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <JSWebAPIErrorFactory.h>
+#include <SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include <TimeTracer.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+#include "DataType.h"
+#include "DataControlFactory.h"
+#include "JSMappedDataControlConsumer.h"
+#include "DataControlAsyncCallbackManager.h"
+#include "DataControlListener.h"
+#include "DataControlConverter.h"
+#include "plugin_config.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+using namespace DeviceAPI::Common;
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+JSClassRef JSMappedDataControlConsumer::m_jsClassRef = NULL;
+
+JSClassDefinition JSMappedDataControlConsumer::m_classInfo =
+{
+ 0,
+ kJSClassAttributeNone,
+ "MappedDataControlConsumer",
+ NULL,
+ m_property,
+ m_function,
+ initialize,
+ finalize,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ hasInstance,
+ NULL
+};
+
+JSStaticValue JSMappedDataControlConsumer::m_property[] = {
+ { "type", getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { "providerId", getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { "dataId", getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSMappedDataControlConsumer::m_function[] =
+{
+ { "addValue", JSMappedDataControlConsumer::addValue, kJSPropertyAttributeNone },
+ { "updateValue", JSMappedDataControlConsumer::updateValue, kJSPropertyAttributeNone },
+ { "removeValue", JSMappedDataControlConsumer::removeValue, kJSPropertyAttributeNone },
+ { "getValue", JSMappedDataControlConsumer::getValue, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+const JSClassRef JSMappedDataControlConsumer::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSMappedDataControlConsumer::getClassInfo()
+{
+ return &m_classInfo;
+}
+
+void JSMappedDataControlConsumer::initialize(JSContextRef context, JSObjectRef object)
+{
+}
+void JSMappedDataControlConsumer::finalize(JSObjectRef object)
+{
+ JSMappedDataControlConsumerPriv *priv = static_cast<JSMappedDataControlConsumerPriv*>(JSObjectGetPrivate(object));
+ LoggerD("finalize");
+ if (!priv) {
+ LoggerE("Private object is null");
+ }
+ delete priv;
+ priv = NULL;
+
+}
+
+bool JSMappedDataControlConsumer::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+{
+ return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+JSObjectRef JSMappedDataControlConsumer::createJSObject(JSContextRef context, std::string provId, std::string dataId, std::string type)
+{
+ IMappedDataControlConsumerPtr MappedDataControlConsumer(DataControlFactory::getInstance().getMappedDataControlConsumer(provId, dataId, type));
+ JSMappedDataControlConsumerPriv* priv = new JSMappedDataControlConsumerPriv( context, MappedDataControlConsumer);
+
+ return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSMappedDataControlConsumer::getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ DataControlConverter converter(context);
+ JSMappedDataControlConsumerPriv *priv = static_cast<JSMappedDataControlConsumerPriv*>(JSObjectGetPrivate(object));
+ IMappedDataControlConsumerPtr dataControlConsumer(priv->getObject());
+
+ std::string propertyNameStr = converter.toString(propertyName);
+ if(propertyNameStr == "type")
+ {
+ return converter.toJSValueRef(dataControlConsumer->getType());
+ }
+ else if(propertyNameStr == "providerId")
+ {
+ return converter.toJSValueRef(dataControlConsumer->getProviderId());
+ }
+ else if(propertyNameStr == "dataId")
+ {
+ return converter.toJSValueRef(dataControlConsumer->getDataId());
+ }
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerW("trying to get incorrect value");
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMappedDataControlConsumer::addValue(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toULong(0, false);
+ validator.toString(1, false);
+ validator.toString(2, false);
+ validator.toFunction(3, true);
+ validator.toFunction(4, true);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+
+ DataControlConverter converter(context);
+ JSMappedDataControlConsumerPriv *priv = static_cast<JSMappedDataControlConsumerPriv*>(JSObjectGetPrivate(thisObject));
+ JSValueRef successCallback = NULL;
+ JSValueRef errorCallBack = NULL;
+ size_t index = 0;
+ JSValueRef reserveArguments[5];
+
+ if (priv == NULL)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+ }
+
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+
+ Try
+ {
+
+
+ for (index = 0; index < 5; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(context);
+ }
+
+ IMappedDataControlConsumerPtr dataControlConsumer(priv->getObject());
+ EventAddValuePtr event(new EventAddValue);
+
+ unsigned int reqId = converter.toULong(reserveArguments[0]);
+ std::string key = converter.toString(reserveArguments[1]);
+ std::string value = converter.toString(reserveArguments[2]);
+
+ unsigned long dataSize = key.size() + value.size();
+
+ if (dataSize > PROTOCOL_DATA_MAX)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Data is too big");
+ }
+
+
+ successCallback = converter.toFunctionOrNull(reserveArguments[3]);
+ errorCallBack = converter.toFunctionOrNull(reserveArguments[4]);
+
+ cbm->setOnSuccess(successCallback);
+ cbm->setOnError(errorCallBack);
+
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData> (cbm));
+ DataControlListener& listener = DataControlListener::getInstance();
+
+ event->setReqId(reqId);
+ event->setKey(key);
+ event->setValue(value);
+ event->setForAsynchronousCall(&listener);
+
+ dataControlConsumer->addValue(event);
+ DataControlAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+
+ }
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMappedDataControlConsumer::updateValue(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toULong(0, false);
+ validator.toString(1, false);
+ validator.toString(2, false);
+ validator.toString(3, false);
+ validator.toFunction(4, false);
+ validator.toFunction(5, true);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+
+ DataControlConverter converter(context);
+ JSMappedDataControlConsumerPriv *priv = static_cast<JSMappedDataControlConsumerPriv*>(JSObjectGetPrivate(thisObject));
+ JSValueRef successCallback = NULL;
+ JSValueRef errorCallBack = NULL;
+ size_t index = 0;
+ JSValueRef reserveArguments[6];
+
+ if (priv == NULL)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+ }
+
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+
+ Try
+ {
+
+
+ for (index = 0; index < 6; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(context);
+ }
+
+ IMappedDataControlConsumerPtr dataControlConsumer(priv->getObject());
+ EventUpdateValuePtr event(new EventUpdateValue);
+
+ unsigned int reqId = converter.toULong(reserveArguments[0]);
+ std::string key = converter.toString(reserveArguments[1]);
+ std::string oldValue = converter.toString(reserveArguments[2]);
+ std::string newValue = converter.toString(reserveArguments[3]);
+ successCallback = converter.toFunctionOrNull(reserveArguments[4]);
+ errorCallBack = converter.toFunctionOrNull(reserveArguments[5]);
+
+ unsigned long dataSize = key.size() + oldValue.size() + newValue.size();
+
+ if (dataSize > PROTOCOL_DATA_MAX)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Data is too big");
+ }
+
+
+ cbm->setOnSuccess(successCallback);
+ cbm->setOnError(errorCallBack);
+
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+ DataControlListener& listener = DataControlListener::getInstance();
+
+
+ event->setReqId(reqId);
+ event->setKey(key);
+ event->setOldValue(oldValue);
+ event->setNewValue(newValue);
+ event->setForAsynchronousCall(&listener);
+
+ dataControlConsumer->updateValue(event);
+ DataControlAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+ }
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMappedDataControlConsumer::getValue(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ JSMappedDataControlConsumerPriv *priv = static_cast<JSMappedDataControlConsumerPriv*>(JSObjectGetPrivate(thisObject));
+ JSValueRef successCallback = NULL;
+ JSValueRef errorCallBack = NULL;
+ size_t index = 0;
+ JSValueRef reserveArguments[4];
+
+ if (priv == NULL)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+ }
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toULong(0, false);
+ validator.toString(1, false);
+ validator.toFunction(2, false);
+ validator.toFunction(3, true);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ JSContextRef globalContext = priv->getContext();
+ DataControlConverter converter(globalContext);
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+
+ Try
+ {
+ if (priv == NULL)
+ {
+ Throw(WrtDeviceApis::Commons::ConversionException);
+ }
+
+ for (index = 0; index < 4; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(globalContext);
+ }
+
+ IMappedDataControlConsumerPtr dataControlConsumer(priv->getObject());
+ EventGetValuePtr event(new EventGetValue);
+
+ unsigned int reqId = converter.toULong(reserveArguments[0]);
+ std::string key = converter.toString(reserveArguments[1]);
+
+
+ unsigned long dataSize = key.size();
+
+ if (dataSize > PROTOCOL_DATA_MAX)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Data is too big");
+ }
+
+ successCallback = converter.toFunctionOrNull(reserveArguments[2]);
+ errorCallBack = converter.toFunctionOrNull(reserveArguments[3]);
+
+ cbm->setOnSuccess(successCallback);
+ cbm->setOnError(errorCallBack);
+
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+ DataControlListener& listener = DataControlListener::getInstance();
+ event->setReqId(reqId);
+ event->setKey(key);
+ event->setForAsynchronousCall(&listener);
+ dataControlConsumer->getValue(event);
+ DataControlAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+
+ }
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMappedDataControlConsumer::removeValue(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toULong(0, false);
+ validator.toString(1, false);
+ validator.toString(2, false);
+ validator.toFunction(3, false);
+ validator.toFunction(4, true);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+
+ DataControlConverter converter(context);
+ JSMappedDataControlConsumerPriv *priv = static_cast<JSMappedDataControlConsumerPriv*>(JSObjectGetPrivate(thisObject));
+ JSValueRef successCallback = NULL;
+ JSValueRef errorCallBack = NULL;
+ size_t index = 0;
+ JSValueRef reserveArguments[5];
+
+ if (priv == NULL)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+ }
+
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+
+ Try
+ {
+
+ for (index = 0; index < 5; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(context);
+ }
+
+ IMappedDataControlConsumerPtr dataControlConsumer(priv->getObject());
+ EventRemoveValuePtr event(new EventRemoveValue);
+
+ unsigned int reqId = converter.toULong(reserveArguments[0]);
+ std::string key = converter.toString(reserveArguments[1]);
+ std::string value = converter.toString(reserveArguments[2]);
+
+ unsigned long dataSize = key.size() + value.size();
+
+ if (dataSize > PROTOCOL_DATA_MAX)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Data is too big");
+ }
+
+ successCallback = converter.toFunctionOrNull(reserveArguments[3]);
+ errorCallBack = converter.toFunctionOrNull(reserveArguments[4]);
+
+ cbm->setOnSuccess(successCallback);
+ cbm->setOnError(errorCallBack);
+
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+ DataControlListener& listener = DataControlListener::getInstance();
+
+
+ event->setReqId(reqId);
+ event->setKey(key);
+ event->setValue(value);
+ event->setForAsynchronousCall(&listener);
+ dataControlConsumer->removeValue(event);
+ DataControlAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+
+ }
+
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+}
+}
diff --git a/mobile_src/DataControl/JSMappedDataControlConsumer.h b/mobile_src/DataControl/JSMappedDataControlConsumer.h
new file mode 100755
index 0000000..20c1bb9
--- /dev/null
+++ b/mobile_src/DataControl/JSMappedDataControlConsumer.h
@@ -0,0 +1,82 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_TIZEN_JS_MAPPED_DATACONTROL_CONSUMER_H_
+#define TIZENAPIS_TIZEN_JS_MAPPED_DATACONTROL_CONSUMER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include "IMappedDataControlConsumer.h"
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<IMappedDataControlConsumerPtr>::Type JSMappedDataControlConsumerPriv;
+
+class JSMappedDataControlConsumer {
+public:
+ static const JSClassDefinition* getClassInfo();
+ static const JSClassRef getClassRef();
+ static JSObjectRef createJSObject(JSContextRef context, std::string provId, std::string dataId, std::string type);
+private:
+ static void initialize(JSContextRef context, JSObjectRef object);
+ static void finalize(JSObjectRef object);
+ static bool hasInstance(JSContextRef context, JSObjectRef constructor,
+ JSValueRef possibleInstance, JSValueRef* exception);
+
+ static JSValueRef getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSValueRef addValue(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+ static JSValueRef updateValue(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+
+ static JSValueRef removeValue(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+ static JSValueRef getValue(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+
+ static JSClassDefinition m_classInfo;
+ static JSStaticFunction m_function[];
+ static JSStaticValue m_property[];
+ static JSClassRef m_jsClassRef;
+
+};
+
+}
+}
+#endif
+
diff --git a/mobile_src/DataControl/JSSQLDataControlConsumer.cpp b/mobile_src/DataControl/JSSQLDataControlConsumer.cpp
new file mode 100644
index 0000000..eed4bb0
--- /dev/null
+++ b/mobile_src/DataControl/JSSQLDataControlConsumer.cpp
@@ -0,0 +1,681 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <JSWebAPIErrorFactory.h>
+#include <SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include <TimeTracer.h>
+#include <ArgumentValidator.h>
+#include <JSUtil.h>
+#include "DataType.h"
+#include "DataControlFactory.h"
+#include "JSSQLDataControlConsumer.h"
+#include "DataControlAsyncCallbackManager.h"
+#include "DataControlListener.h"
+#include "DataControlConverter.h"
+#include "plugin_config.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+using namespace DeviceAPI::Common;
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+JSClassRef JSSQLDataControlConsumer::m_jsClassRef = NULL;
+
+JSClassDefinition JSSQLDataControlConsumer::m_classInfo =
+{
+ 0,
+ kJSClassAttributeNone,
+ "DataControlConsumer",
+ NULL,
+ m_property,
+ m_function,
+ initialize,
+ finalize,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ hasInstance,
+ NULL
+};
+
+JSStaticValue JSSQLDataControlConsumer::m_property[] = {
+ { "type", getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { "providerId", getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { "dataId", getProperty, NULL, kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSSQLDataControlConsumer::m_function[] =
+{
+ { "insert", JSSQLDataControlConsumer::insert, kJSPropertyAttributeNone },
+ { "update", JSSQLDataControlConsumer::update, kJSPropertyAttributeNone },
+ { "remove", JSSQLDataControlConsumer::remove, kJSPropertyAttributeNone },
+ { "select", JSSQLDataControlConsumer::select, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+const JSClassRef JSSQLDataControlConsumer::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSSQLDataControlConsumer::getClassInfo()
+{
+ return &m_classInfo;
+}
+
+void JSSQLDataControlConsumer::initialize(JSContextRef context, JSObjectRef object)
+{
+}
+void JSSQLDataControlConsumer::finalize(JSObjectRef object)
+{
+ JSSQLDataControlConsumerPriv *priv = static_cast<JSSQLDataControlConsumerPriv*>(JSObjectGetPrivate(object));
+ LoggerD("finalize");
+
+ if (!priv) {
+ LoggerE("Private object is null");
+ }
+ delete priv;
+ priv = NULL;
+}
+
+bool JSSQLDataControlConsumer::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+{
+ return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+JSObjectRef JSSQLDataControlConsumer::createJSObject(JSContextRef context, std::string provId, std::string dataId, std::string type)
+{
+ ISQLDataControlConsumerPtr SqlDataControlConsumer(DataControlFactory::getInstance().getSQLDataControlConsumer(provId, dataId, type));
+ JSSQLDataControlConsumerPriv* priv = new JSSQLDataControlConsumerPriv( context, SqlDataControlConsumer);
+ return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSSQLDataControlConsumer::getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ DataControlConverter converter(context);
+ JSSQLDataControlConsumerPriv *priv = static_cast<JSSQLDataControlConsumerPriv*>(JSObjectGetPrivate(object));
+ ISQLDataControlConsumerPtr dataControlConsumer(priv->getObject());
+
+ std::string propertyNameStr = converter.toString(propertyName);
+ if(propertyNameStr == "type")
+ {
+ return converter.toJSValueRef(dataControlConsumer->getType());
+ }
+ else if(propertyNameStr == "providerId")
+ {
+ return converter.toJSValueRef(dataControlConsumer->getProviderId());
+ }
+ else if(propertyNameStr == "dataId")
+ {
+ return converter.toJSValueRef(dataControlConsumer->getDataId());
+ }
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerW("trying to get incorrect value");
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSQLDataControlConsumer::insert(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toULong(0, false);
+ validator.toObject(1, false);
+ validator.toFunction(2, true);
+ validator.toFunction(3, true);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+
+ DataControlConverter converter(context);
+ JSSQLDataControlConsumerPriv *priv = static_cast<JSSQLDataControlConsumerPriv*>(JSObjectGetPrivate(thisObject));
+ JSValueRef successCallback = NULL;
+ JSValueRef errorCallBack = NULL;
+ size_t index = 0;
+ JSValueRef reserveArguments[5];
+
+ if (priv == NULL)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+ }
+
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+
+ Try
+ {
+ for (index = 0; index < 4; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(context);
+ }
+
+ ISQLDataControlConsumerPtr dataControlConsumer(priv->getObject());
+ EventInsertPtr event(new EventInsert);
+
+ unsigned int reqId = converter.toULong(reserveArguments[0]);
+ RowData* rowData = converter.toRowDataPtr(reserveArguments[1]);
+ std::string dummyWhere = "";
+
+ try
+ {
+ converter.checkRowDataSize(rowData, dummyWhere);
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
+ }
+
+ unsigned int colSize = rowData->m_Data.size();
+ successCallback = converter.toFunctionOrNull(reserveArguments[2]);
+ errorCallBack = converter.toFunctionOrNull(reserveArguments[3]);
+
+ cbm->setOnSuccess(successCallback);
+ cbm->setOnError(errorCallBack);
+
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData> (cbm));
+ DataControlListener& listener = DataControlListener::getInstance();
+
+ event->setReqId(reqId);
+ event->setRowData(rowData);
+ event->setColumnSize(colSize);
+ event->setForAsynchronousCall(&listener);
+
+ dataControlConsumer->insertData(event);
+ DataControlAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+
+ }
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSSQLDataControlConsumer::update(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toULong(0, false);
+ validator.toObject(1, false);
+ validator.toString(2, false);
+ validator.toFunction(3, true);
+ validator.toFunction(4, true);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ DataControlConverter converter(context);
+ JSSQLDataControlConsumerPriv *priv = static_cast<JSSQLDataControlConsumerPriv*>(JSObjectGetPrivate(thisObject));
+ JSValueRef successCallback = NULL;
+ JSValueRef errorCallBack = NULL;
+ size_t index = 0;
+ JSValueRef reserveArguments[6];
+
+ if (priv == NULL)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+ }
+
+
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+
+ Try
+ {
+ for (index = 0; index < 6; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(context);
+ }
+
+ ISQLDataControlConsumerPtr dataControlConsumer(priv->getObject());
+ EventUpdatePtr event(new EventUpdate);
+
+ unsigned int reqId = converter.toULong(reserveArguments[0]);
+ RowData* rowData = converter.toRowDataPtr(reserveArguments[1]);
+ unsigned int colSize = rowData->m_Data.size();
+ std::string where = converter.toString(reserveArguments[2]);
+
+ try
+ {
+ converter.checkRowDataSize(rowData, where);
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
+ }
+
+ successCallback = converter.toFunctionOrNull(reserveArguments[3]);
+ errorCallBack = converter.toFunctionOrNull(reserveArguments[4]);
+
+ cbm->setOnSuccess(successCallback);
+ cbm->setOnError(errorCallBack);
+
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+ DataControlListener& listener = DataControlListener::getInstance();
+
+
+ event->setReqId(reqId);
+ event->setWhere(where);
+ event->setRowData(rowData);
+ event->setColumnSize(colSize);
+ event->setForAsynchronousCall(&listener);
+
+ dataControlConsumer->updateData(event);
+ DataControlAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+ }
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSSQLDataControlConsumer::select(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toULong(0, false);
+ validator.toArrayObject(1, false);
+ validator.toString(2, false);
+ validator.toFunction(3, false);
+ validator.toFunction(4, true);
+ validator.toULong(5, true);
+ validator.toULong(6, true);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+
+ JSSQLDataControlConsumerPriv *priv = static_cast<JSSQLDataControlConsumerPriv*>(JSObjectGetPrivate(thisObject));
+ JSValueRef successCallback = NULL;
+ JSValueRef errorCallBack = NULL;
+ size_t index = 0;
+ JSValueRef reserveArguments[7];
+
+ if (priv == NULL)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+ }
+
+ JSContextRef globalContext = priv->getContext();
+ DataControlConverter converter(globalContext);
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+
+ Try
+ {
+ for (index = 0; index < 7; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(globalContext);
+ }
+
+ ISQLDataControlConsumerPtr dataControlConsumer(priv->getObject());
+ EventSelectPtr event(new EventSelect);
+
+ unsigned int reqId = converter.toULong(reserveArguments[0]);
+ unsigned long dataSize = 0;
+
+ LoggerD(reqId);
+
+ std::vector<std::string> columns = converter.toVectorOfStrings(reserveArguments[1]);
+
+ if (columns.size() == 0)
+ Throw(WrtDeviceApis::Commons::ConversionException);
+
+ for (size_t index = 0; index < columns.size(); index++)
+ {
+ dataSize += columns[index].size();
+ }
+
+ std::string where = converter.toString(reserveArguments[2]);
+ dataSize += where.size();
+
+ if (dataSize > PROTOCOL_DATA_MAX)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Data is too big");
+ }
+
+ successCallback = converter.toFunctionOrNull(reserveArguments[3]);
+ errorCallBack = converter.toFunctionOrNull(reserveArguments[4]);
+
+ cbm->setOnSuccess(successCallback);
+ cbm->setOnError(errorCallBack);
+
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+ DataControlListener& listener = DataControlListener::getInstance();
+
+ if (JSValueIsUndefined(globalContext, reserveArguments[5]) == false)
+ {
+ std::string page = converter.toString(reserveArguments[5]);
+ event->setPage(page);
+ }
+
+ if (JSValueIsUndefined(globalContext,reserveArguments[6]) == false)
+ {
+ std::string number = converter.toString(reserveArguments[6]);
+ event->setNumberPerPage(number);
+ }
+
+ event->setReqId(reqId);
+ event->setWhere(where);
+ event->setForAsynchronousCall(&listener);
+ event->setColumns(columns);
+ dataControlConsumer->selectData(event);
+ DataControlAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+
+ }
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSQLDataControlConsumer::remove(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LoggerD("Enter");
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+ AceSecurityStatus status = DATACONTROL_CHECK_ACCESS(DATACONTROL_FUNC_CONSUMER);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ // argument validation with new validator
+ try
+ {
+ ArgumentValidator validator(context, argumentCount, arguments);
+ validator.toULong(0, false);
+ validator.toString(1, false);
+ validator.toFunction(2, true);
+ validator.toFunction(3, true);
+ }
+ catch (const BasePlatformException &err)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+ catch (...)
+ {
+ DeviceAPI::Common::UnknownException err("");
+ return JSWebAPIErrorFactory::postException(context, exception, err);
+ }
+
+ DataControlConverter converter(context);
+ JSSQLDataControlConsumerPriv *priv = static_cast<JSSQLDataControlConsumerPriv*>(JSObjectGetPrivate(thisObject));
+ JSValueRef successCallback = NULL;
+ JSValueRef errorCallBack = NULL;
+ size_t index = 0;
+ JSValueRef reserveArguments[4];
+
+ if (priv == NULL)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+ }
+
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+
+ Try
+ {
+
+
+ for (index = 0; index < 4; index++)
+ {
+ if (index < argumentCount)
+ reserveArguments[index] = arguments[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(context);
+ }
+
+ ISQLDataControlConsumerPtr dataControlConsumer(priv->getObject());
+ EventDeletePtr event(new EventDelete);
+
+ unsigned int reqId = converter.toULong(reserveArguments[0]);
+ std::string where = converter.toString(reserveArguments[1]);
+ successCallback = converter.toFunctionOrNull(reserveArguments[2]);
+ errorCallBack = converter.toFunctionOrNull(reserveArguments[3]);
+
+ unsigned long dataSize = where.size();
+
+ if (dataSize > PROTOCOL_DATA_MAX)
+ {
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Data is too big");
+ }
+
+
+ cbm->setOnSuccess(successCallback);
+ cbm->setOnError(errorCallBack);
+
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+ DataControlListener& listener = DataControlListener::getInstance();
+
+
+ event->setReqId(reqId);
+ event->setWhere(where);
+ event->setForAsynchronousCall(&listener);
+
+ dataControlConsumer->deleteData(event);
+ DataControlAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+
+ }
+
+ Catch (WrtDeviceApis::Commons::ConversionException)
+ {
+ LoggerE("ConversionException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "type mismatch error");
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LoggerE("InvalidArgumentException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "type mismatch error");
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LoggerE("UnsupportException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Unsupport Exception");
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("UnkownException");
+ return JSWebAPIErrorFactory::postException(context, exception,
+ JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unkown error");
+ }
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+
+}
+}
+
diff --git a/mobile_src/DataControl/JSSQLDataControlConsumer.h b/mobile_src/DataControl/JSSQLDataControlConsumer.h
new file mode 100755
index 0000000..d396db9
--- /dev/null
+++ b/mobile_src/DataControl/JSSQLDataControlConsumer.h
@@ -0,0 +1,82 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_TIZEN_JS_SQL_DATACONTROL_CONSUMER_H_
+#define TIZENAPIS_TIZEN_JS_SQL_DATACONTROL_CONSUMER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include "ISqlDataControlConsumer.h"
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ISQLDataControlConsumerPtr>::Type JSSQLDataControlConsumerPriv;
+
+class JSSQLDataControlConsumer {
+public:
+ static const JSClassDefinition* getClassInfo();
+ static const JSClassRef getClassRef();
+ static JSObjectRef createJSObject(JSContextRef context, std::string provId, std::string dataId, std::string type);
+private:
+ static void initialize(JSContextRef context, JSObjectRef object);
+ static void finalize(JSObjectRef object);
+ static bool hasInstance(JSContextRef context, JSObjectRef constructor,
+ JSValueRef possibleInstance, JSValueRef* exception);
+
+ static JSValueRef getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static JSValueRef insert(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+ static JSValueRef update(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+
+ static JSValueRef remove(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+ static JSValueRef select(
+ JSContextRef context, JSObjectRef object,
+ JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+ JSValueRef* exception);
+
+
+ static JSClassDefinition m_classInfo;
+ static JSStaticFunction m_function[];
+ static JSStaticValue m_property[];
+ static JSClassRef m_jsClassRef;
+
+};
+
+}
+}
+#endif
+
diff --git a/mobile_src/DataControl/JSSelectObjectArrayValues.cpp b/mobile_src/DataControl/JSSelectObjectArrayValues.cpp
new file mode 100644
index 0000000..33ba3a3
--- /dev/null
+++ b/mobile_src/DataControl/JSSelectObjectArrayValues.cpp
@@ -0,0 +1,392 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <algorithm>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <JSWebAPIErrorFactory.h>
+#include "DataControlFactory.h"
+#include "RowData.h"
+#include "DataControlConverter.h"
+#include "JSSelectObjectArrayValues.h"
+#include "DataControlConverter.h"
+#include <Logger.h>
+
+#define FUNCTION_CONCAT "concat"
+#define FUNCTION_JOIN "join"
+#define FUNCTION_POP "pop"
+#define FUNCTION_PUSH "push"
+#define FUNCTION_REVERSE "reverse"
+#define FUNCTION_SHIFT "shift"
+#define FUNCTION_SLICE "slice"
+#define FUNCTION_SORT "sort"
+#define FUNCTION_SPLICE "splice"
+#define FUNCTION_TOSTRING "toString"
+#define FUNCTION_UNSHIFT "unshift"
+#define FUNCTION_VALUEOF "valueOf"
+#define ARRAY "Array"
+#define ATTRIBUTE_LENGTH "length"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+using namespace DeviceAPI::Common;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSSelectObjectArrayValues::m_classInfo = {
+ 0,
+ kJSClassAttributeNone,
+ ARRAY,
+ 0,
+ m_property,
+ m_function,
+ initialize,
+ finalize,
+ hasProperty,
+ getProperty,
+ NULL,
+ NULL,
+ getPropertyNames,
+ NULL, //callAsFunction,
+ NULL, //callAsConstructor,
+ NULL, //hasInstance,
+ NULL, //convertToType,
+};
+
+JSStaticValue JSSelectObjectArrayValues::m_property[] = {
+ { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSSelectObjectArrayValues::m_function[] = {
+ { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+ { 0, 0, 0 }
+};
+
+JSClassRef JSSelectObjectArrayValues::m_jsClassRef = JSClassCreate(
+ JSSelectObjectArrayValues::getClassInfo());
+
+JSValueRef JSSelectObjectArrayValues::getLength(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ JSSelectObjectArrayValuesPriv* priv = static_cast<JSSelectObjectArrayValuesPriv*>(JSObjectGetPrivate(object));
+
+ if (!priv)
+ {
+ Throw(WrtDeviceApis::Commons::NullPointerException);
+ }
+
+ DataControlConverter converter(priv->getContext());
+ ISelectDataObjectPtr SelectDataOjbect = priv->getObject();
+
+ int number = SelectDataOjbect->getRowNumber();
+ return converter.toJSValueRef(number);
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+
+const JSClassDefinition* JSSelectObjectArrayValues::getClassInfo()
+{
+ return &(m_classInfo);
+}
+
+bool JSSelectObjectArrayValues::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+ return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+
+JSClassRef JSSelectObjectArrayValues::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+void JSSelectObjectArrayValues::initialize(JSContextRef context,
+ JSObjectRef object)
+{
+}
+
+void JSSelectObjectArrayValues::finalize(JSObjectRef object)
+{
+ JSSelectObjectArrayValuesPriv* priv =
+ static_cast<JSSelectObjectArrayValuesPriv*>(JSObjectGetPrivate(object));
+ delete priv;
+ JSObjectSetPrivate(object, NULL);
+}
+
+bool JSSelectObjectArrayValues::hasProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName)
+{
+ Try
+ {
+ JSSelectObjectArrayValuesPriv* priv = static_cast<JSSelectObjectArrayValuesPriv*>(JSObjectGetPrivate(object));
+
+ if (!priv)
+ {
+ Throw(WrtDeviceApis::Commons::NullPointerException);
+ }
+
+ DataControlConverter converter(priv->getContext());
+ int index = converter.toSizeT(propertyName);
+
+ ISelectDataObjectPtr SelectDataOjbect = priv->getObject();
+
+ if (index < SelectDataOjbect->getRowNumber())
+ {
+ return true;
+ }
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ }
+ return false;
+}
+
+JSValueRef JSSelectObjectArrayValues::getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ Try
+ {
+ JSSelectObjectArrayValuesPriv* priv = static_cast<JSSelectObjectArrayValuesPriv*>(JSObjectGetPrivate(object));
+
+ if (!priv)
+ {
+ Throw(WrtDeviceApis::Commons::NullPointerException);
+ }
+
+ DataControlConverter converter(priv->getContext());
+ int index = converter.toSizeT(propertyName);
+
+ ISelectDataObjectPtr SelectDataOjbect = priv->getObject();
+
+ if (index >= SelectDataOjbect->getRowNumber())
+ {
+ Throw(WrtDeviceApis::Commons::OutOfRangeException);
+ }
+ RowDataPtr data = SelectDataOjbect->getIndexedRow(index);
+ return converter.toJSRowData(data);
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSSelectObjectArrayValues::createJSObject(JSContextRef context, const std::string &filepath)
+{
+ ISelectDataObjectPtr SelectDataObject(DataControlFactory::getInstance().getSelectDataObject());
+ SelectDataObject->openResultPath(filepath);
+ JSSelectObjectArrayValuesPriv * priv = new JSSelectObjectArrayValuesPriv( context, SelectDataObject);
+ return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+bool JSSelectObjectArrayValues::setProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef value,
+ JSValueRef* exception)
+{
+ return false;
+}
+
+bool JSSelectObjectArrayValues::deleteProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ return false;
+}
+
+void JSSelectObjectArrayValues::getPropertyNames(JSContextRef context,
+ JSObjectRef object,
+ JSPropertyNameAccumulatorRef propertyNames)
+{
+ Try
+ {
+ JSSelectObjectArrayValuesPriv* priv = static_cast<JSSelectObjectArrayValuesPriv*>(JSObjectGetPrivate(object));
+
+ if (!priv)
+ {
+ Throw(WrtDeviceApis::Commons::NullPointerException);
+ }
+
+ DataControlConverter converter(priv->getContext());
+ ISelectDataObjectPtr SelectDataOjbect = priv->getObject();
+ int number = SelectDataOjbect->getRowNumber();
+
+ for (int i=0; i < number; i++)
+ {
+ ScopedJSStringRef name(converter.toJSStringRef(converter.toString(i)));
+ JSPropertyNameAccumulatorAddName(propertyNames, name.get());
+ }
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LoggerE("invalid property");
+ }
+}
+
+JSValueRef JSSelectObjectArrayValues::concat(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::join(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::pop(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::push(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::reverse(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::shift(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::slice(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::sort(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::splice(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::toString(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSSelectObjectArrayValues::unshift(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSelectObjectArrayValues::valueOf(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ return JSValueMakeUndefined(context);
+}
+
+}
+}
diff --git a/mobile_src/DataControl/JSSelectObjectArrayValues.h b/mobile_src/DataControl/JSSelectObjectArrayValues.h
new file mode 100755
index 0000000..6db2ee9
--- /dev/null
+++ b/mobile_src/DataControl/JSSelectObjectArrayValues.h
@@ -0,0 +1,177 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef _TIZEN_DATACONTROL_JS_SELECTOBJECT_ARRAYVALUES_H_
+#define _TIZEN_DATACONTROL_JS_SELECTOBJECT_ARRAYVALUES_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include "ISelectDataObject.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<ISelectDataObjectPtr>::Type JSSelectObjectArrayValuesPriv;
+
+class JSSelectObjectArrayValues
+{
+public:
+
+ static const JSClassDefinition* getClassInfo();
+
+ static JSClassRef getClassRef();
+ static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+ static JSObjectRef createJSObject(JSContextRef context, const std::string &filepath);
+private:
+
+ /**
+ * The callback invoked when an object is first created.
+ */
+ static void initialize(JSContextRef context,
+ JSObjectRef object);
+
+ /**
+ * The callback invoked when an object is finalized.
+ */
+ static void finalize(JSObjectRef object);
+
+ static JSValueRef getLength(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static bool hasProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName);
+
+ static JSValueRef getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static bool setProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef value,
+ JSValueRef* exception);
+
+ static bool deleteProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception);
+
+ static void getPropertyNames(JSContextRef context,
+ JSObjectRef object,
+ JSPropertyNameAccumulatorRef propertyNames);
+
+ static JSValueRef concat(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef join(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef pop(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef push(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef reverse(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef shift(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef slice(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef sort(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef splice(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef toString(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef unshift(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+ static JSValueRef valueOf(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
+ static bool checkValue(const std::string &value);
+
+ static JSClassRef m_jsClassRef;
+ /**
+ * This structure describes a statically declared function property.
+ */
+ static JSStaticFunction m_function[];
+
+ /**
+ * This structure contains properties and callbacks that define a type of object.
+ */
+ static JSClassDefinition m_classInfo;
+
+ /**
+ * This member variable contains the initialization values for the static properties of this class.
+ * The values are given according to the data structure JSPropertySpec
+ */
+ static JSStaticValue m_property[];
+};
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/MappedDataControlConsumer.cpp b/mobile_src/DataControl/MappedDataControlConsumer.cpp
new file mode 100644
index 0000000..229bc1a
--- /dev/null
+++ b/mobile_src/DataControl/MappedDataControlConsumer.cpp
@@ -0,0 +1,660 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <cassert>
+#include <Commons/Exception.h>
+#include "DataType.h"
+#include "MappedDataControlConsumer.h"
+#include <appsvc/appsvc.h>
+#include <string>
+#include <vector>
+#include <aul/aul.h>
+#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 {
+
+MappedDataControlConsumer::MappedDataControlConsumer(std::string& provId, std::string& dataId, std::string& type)
+{
+ LoggerD("Enter");
+
+
+ m_type = type;;
+ m_dataId = dataId;
+ m_providerId = provId;
+
+ 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().setDataControlGC((void*)this, true);
+
+}
+
+DPL::Mutex MappedDataControlConsumer::m_mutex;
+
+
+
+std::string MappedDataControlConsumer::getDataId()
+{
+ return m_dataId;
+}
+
+std::string MappedDataControlConsumer::getProviderId()
+{
+ return m_providerId;
+}
+
+std::string MappedDataControlConsumer::getType()
+{
+ return m_type;
+}
+
+void MappedDataControlConsumer::handleCommonErrorEvent(void* userData, unsigned int code, std::string msg)
+{
+ if (userData == NULL)
+ {
+ LoggerD("userData null");
+ return;
+ }
+
+ CommonPendingEvent* pEvent = (CommonPendingEvent*)userData;
+
+ try
+ {
+ if (dynamic_cast<EventAddValuePendingEvent*>(pEvent) != NULL)
+ {
+ EventAddValuePendingEvent* pendingAddValueEvent = (EventAddValuePendingEvent*)pEvent;
+ EventAddValuePtr addValueEvent = pendingAddValueEvent->getEvent();
+ addValueEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+ addValueEvent->setErrorMsg(msg);
+
+ WrtDeviceApis::Commons::EventRequestReceiver<EventAddValue>::ManualAnswer(addValueEvent);
+ }
+ else if (dynamic_cast<EventUpdateValuePendingEvent*>(pEvent) != NULL)
+ {
+ EventUpdateValuePendingEvent* pendingUpdateValueEvent = (EventUpdateValuePendingEvent*)pEvent;
+ EventUpdateValuePtr updateValueEvent = pendingUpdateValueEvent->getEvent();
+ updateValueEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+ updateValueEvent->setErrorMsg(msg);
+
+ WrtDeviceApis::Commons::EventRequestReceiver<EventUpdateValue>::ManualAnswer(updateValueEvent);
+ }
+ else if (dynamic_cast<EventGetValuePendingEvent*>(pEvent) != NULL)
+ {
+ EventGetValuePendingEvent* pendingGetValueEvent = (EventGetValuePendingEvent*)pEvent;
+ EventGetValuePtr getValueEvent = pendingGetValueEvent->getEvent();
+ getValueEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+ getValueEvent->setErrorMsg(msg);
+
+ WrtDeviceApis::Commons::EventRequestReceiver<EventGetValue>::ManualAnswer(getValueEvent);
+ }
+ 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);
+ }
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ }
+
+}
+
+
+void MappedDataControlConsumer::handlePendingEvent(const EventAddValuePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventAddValue>::ManualAnswer(event);
+}
+
+void MappedDataControlConsumer::handlePendingEvent(const EventRemoveValuePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventRemoveValue>::ManualAnswer(event);
+}
+
+void MappedDataControlConsumer::handlePendingEvent(const EventGetValuePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventGetValue>::ManualAnswer(event);
+}
+
+void MappedDataControlConsumer::handlePendingEvent(const EventUpdateValuePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventUpdateValue>::ManualAnswer(event);
+}
+
+
+void MappedDataControlConsumer::addValue(const EventAddValuePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventAddValue>::PostRequest(event);
+}
+
+void MappedDataControlConsumer::removeValue(const EventRemoveValuePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventRemoveValue>::PostRequest(event);
+}
+
+void MappedDataControlConsumer::getValue(const EventGetValuePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventGetValue>::PostRequest(event);
+}
+
+void MappedDataControlConsumer::updateValue(const EventUpdateValuePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventUpdateValue>::PostRequest(event);
+}
+
+bool MappedDataControlConsumer::checkReqIdUniqueness(unsigned int reqId)
+{
+ std::string reqIdStr;
+ std::stringstream ssReqId;
+
+ ssReqId << reqId;
+ reqIdStr = ssReqId.str();
+ return DataControlAsyncCallbackManagerSingleton::Instance().checkReqIdUnique(reqIdStr);
+}
+
+void MappedDataControlConsumer::OnRequestReceived(const EventAddValuePtr& 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");
+ }
+
+ 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)
+ {
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ LoggerE("Exception: " << ex.GetMessage());
+ }
+
+}
+
+#if 0
+void MappedDataControlConsumer::OnRequestReceived(const EventAddValuePtr& event)
+{
+ LoggerD("Enter");
+ bundle* passData = NULL;
+
+ try
+ {
+ std::string dataId = getDataId();
+ unsigned int reqId = event->getReqId();
+ std::string key = event->getKey();
+ std::string value = event->getValue();
+
+ std::stringstream ss, ssreqtype;
+ std::string reqIdStr, reqtypestr;
+ std::vector<std::string> queryItem;
+
+ if (checkReqIdUniqueness(reqId) == false)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+ }
+
+
+ // conversion
+ ss << reqId;
+ reqIdStr = ss.str();
+
+ ssreqtype << _DATACONTROL_REQUEST_TYPE_MAP_INSERT;
+ reqtypestr = ssreqtype.str();
+
+ passData = bundle_create();
+
+ if (passData == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "ipc memory allocation fail");
+ }
+
+ appsvc_set_operation(passData, APPSVC_OPERATION_DEFAULT);
+
+ appsvc_set_appid(passData, m_appId.c_str());
+
+ bundle_add(passData, OSP_K_REQUEST_ID, reqIdStr.c_str());
+ bundle_add(passData, OSP_K_CALLER_TYPE, OSP_V_CALLER_TYPE_OSP);
+ bundle_add(passData, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, reqtypestr.c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROVIDER, m_providerId.c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE); // version
+
+ queryItem.push_back(dataId); // dataid
+ queryItem.push_back(key); // key
+ queryItem.push_back(value); // value
+
+ addArrayToBundle(passData, queryItem);
+
+ // FIXEME
+ // reqid sholud be known
+ 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)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Error");
+ }
+
+ event->switchToManualAnswer();
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ LoggerE("Exception: " << ex.GetMessage());
+
+
+ }
+
+ if (passData)
+ {
+ bundle_free(passData);
+ passData = NULL;
+ }
+
+}
+#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
+ {
+ std::string dataId = getDataId();
+ std::vector<std::string> queryItem;
+ std::string key = event->getKey();
+ std::string value = event->getValue();
+
+ unsigned int reqId = event->getReqId();
+ std::stringstream ss, ssreqtype;
+ std::string reqIdStr, reqtypestr;
+
+ ss << reqId;
+ reqIdStr = ss.str();
+
+ ssreqtype << _DATACONTROL_REQUEST_TYPE_MAP_DELETE;
+ reqtypestr = ssreqtype.str();
+
+ if (checkReqIdUniqueness(reqId) == false)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+ }
+
+ passData = bundle_create();
+
+ if (passData == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "ipc memory allocation fail");
+ }
+
+ appsvc_set_operation(passData, APPSVC_OPERATION_DEFAULT);
+ appsvc_set_appid(passData, m_appId.c_str());
+
+ bundle_add(passData, OSP_K_REQUEST_ID, reqIdStr.c_str());
+ bundle_add(passData, OSP_K_CALLER_TYPE, OSP_V_CALLER_TYPE_OSP);
+ bundle_add(passData, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, reqtypestr.c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROVIDER, m_providerId.c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE); // version
+
+
+ queryItem.push_back(dataId); // dataid
+ queryItem.push_back(key);
+ queryItem.push_back(value);
+
+
+ addArrayToBundle(passData, queryItem);
+ EventRemoveValuePendingEvent* pendingEvent = new EventRemoveValuePendingEvent(this, dataId, m_appId, m_providerId, "", event);
+
+ int pid = appsvc_run_service(passData, reqId, dataControlCommonCallback, (void*)pendingEvent);
+
+ if (pid < 0)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "dataconstrol request fail.(can not launch)");
+ }
+
+ event->switchToManualAnswer();
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+
+ if (passData)
+ {
+ bundle_free(passData);
+ passData = NULL;
+ }
+
+}
+#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");
+ bundle* passData = NULL;
+
+ try
+ {
+ std::string dataId = getDataId();
+ std::vector<std::string> queryItem;
+
+ unsigned int reqId = event->getReqId();
+ std::stringstream ss, ssreqtype;
+ std::string reqIdStr, reqtypestr;
+ std::string key = event->getKey();
+
+ if (checkReqIdUniqueness(reqId) == false)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+ }
+
+
+ ss << reqId;
+ reqIdStr = ss.str();
+
+ ssreqtype << _DATACONTROL_REQUEST_TYPE_MAP_QUERY;
+ reqtypestr = ssreqtype.str();
+
+ passData = bundle_create();
+
+ if (passData == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "ipc memory allocation fail");
+ }
+
+ appsvc_set_operation(passData, APPSVC_OPERATION_DEFAULT);
+ appsvc_set_appid(passData, m_appId.c_str());
+
+ bundle_add(passData, OSP_K_REQUEST_ID, reqIdStr.c_str());
+ bundle_add(passData, OSP_K_CALLER_TYPE, OSP_V_CALLER_TYPE_OSP);
+ bundle_add(passData, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, reqtypestr.c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROVIDER, m_providerId.c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE); // version
+
+
+
+ queryItem.push_back(dataId); // dataid
+ queryItem.push_back(key);
+ queryItem.push_back("1");
+ queryItem.push_back("1");
+
+ addArrayToBundle(passData, queryItem);
+ EventGetValuePendingEvent* pendingEvent = new EventGetValuePendingEvent(this, dataId, m_appId, m_providerId, "", event);
+
+ int pid = appsvc_run_service(passData, reqId, dataControlCommonCallback, (void*)pendingEvent);
+
+ if (pid < 0)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "dataconstrol request fail.(can not launch)");
+ }
+
+ event->switchToManualAnswer();
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+
+ if (passData)
+ {
+ bundle_free(passData);
+ passData = NULL;
+ }
+
+}
+#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
+ {
+ std::string dataId = getDataId();
+ std::vector<std::string> queryItem;
+
+ unsigned int reqId = event->getReqId();
+ std::stringstream ss, ssreqtype;
+ std::string reqIdStr, reqtypestr;
+ std::string key = event->getKey();
+ std::string oldValue = event->getOldValue();
+ std::string newValue = event->getNewValue();
+
+ if (checkReqIdUniqueness(reqId) == false)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+ }
+
+ passData = bundle_create();
+
+ if (passData == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "ipc memory allocation fail");
+ }
+
+ appsvc_set_operation(passData, APPSVC_OPERATION_DEFAULT);
+ appsvc_set_appid(passData, m_appId.c_str());
+
+ ss << reqId;
+ reqIdStr = ss.str();
+
+ ssreqtype << _DATACONTROL_REQUEST_TYPE_MAP_UPDATE;
+ reqtypestr = ssreqtype.str();
+
+
+ bundle_add(passData, OSP_K_REQUEST_ID, reqIdStr.c_str());
+ bundle_add(passData, OSP_K_CALLER_TYPE, OSP_V_CALLER_TYPE_OSP);
+ bundle_add(passData, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
+ bundle_add(passData, OSP_K_DATACONTROL_REQUEST_TYPE, reqtypestr.c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROVIDER, m_providerId.c_str());
+ bundle_add(passData, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_K_DATACONTROL_PROTOCOL_VERSION_VALUE); // version
+
+
+ queryItem.push_back(dataId); // dataid
+ queryItem.push_back(key);
+ queryItem.push_back(oldValue);
+ queryItem.push_back(newValue);
+
+ addArrayToBundle(passData, queryItem);
+ EventUpdateValuePendingEvent* pendingEvent = new EventUpdateValuePendingEvent(this, dataId, m_appId, m_providerId, "", event);
+
+ int pid = appsvc_run_service(passData, reqId, dataControlCommonCallback, (void*)pendingEvent);
+
+ if (pid < 0)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "dataconstrol request fail.(can not launch)");
+ }
+
+ event->switchToManualAnswer();
+
+ DPL::Mutex::ScopedLock lock(&m_mutex);
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+
+ if (passData)
+ {
+ bundle_free(passData);
+ passData = NULL;
+ }
+
+
+}
+#endif
+
+
+}
+}
+
+
diff --git a/mobile_src/DataControl/MappedDataControlConsumer.h b/mobile_src/DataControl/MappedDataControlConsumer.h
new file mode 100755
index 0000000..8b88a92
--- /dev/null
+++ b/mobile_src/DataControl/MappedDataControlConsumer.h
@@ -0,0 +1,90 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef TIZENAPIS_PLATFORM_MAPPED_DATACONTRIL_CONSUMER_H_
+#define TIZENAPIS_PLATFORM_MAPPED_DATACONTRIL_CONSUMER_H_
+
+#include <vector>
+#include <string>
+#include <dpl/noncopyable.h>
+#include <bundle.h>
+#include "IMappedDataControlConsumer.h"
+#include "DataControlFactory.h"
+#include <dpl/mutex.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class MappedDataControlConsumer : public IMappedDataControlConsumer
+{
+ friend class DataControl::DataControlFactory;
+
+public:
+
+ virtual void addValue(const EventAddValuePtr& event);
+ virtual void removeValue(const EventRemoveValuePtr& event);
+ virtual void getValue(const EventGetValuePtr& event);
+ virtual void updateValue(const EventUpdateValuePtr& event);
+
+ virtual ~MappedDataControlConsumer();
+
+ std::string getType();
+ std::string getDataId();
+ std::string getProviderId();
+
+ void handlePendingEvent(const EventAddValuePtr& event);
+ void handlePendingEvent(const EventRemoveValuePtr& event);
+ void handlePendingEvent(const EventGetValuePtr& event);
+ void handlePendingEvent(const EventUpdateValuePtr& event);
+ void handleCommonErrorEvent(void* userData, unsigned int code, std::string msg);
+private:
+ std::string m_type;
+ std::string m_dataId;
+ std::string m_providerId;
+ std::string m_appId;
+ std::string m_ProviderPkgId;
+ std::string m_currentAppId;
+
+ bool checkReqIdUniqueness(unsigned int reqId);
+
+ static DPL::Mutex m_mutex;
+
+
+
+protected:
+ MappedDataControlConsumer(std::string& provId, std::string& dataId, std::string& type);
+
+ virtual void OnRequestReceived(const EventAddValuePtr& event);
+ virtual void OnRequestReceived(const EventRemoveValuePtr& event);
+ virtual void OnRequestReceived(const EventGetValuePtr& event);
+ virtual void OnRequestReceived(const EventUpdateValuePtr& event);
+
+
+
+private:
+
+
+};
+
+
+
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/RowData.h b/mobile_src/DataControl/RowData.h
new file mode 100644
index 0000000..33ee4c9
--- /dev/null
+++ b/mobile_src/DataControl/RowData.h
@@ -0,0 +1,66 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#ifndef TIZENAPIS_API_ROWDATA_H_
+#define TIZENAPIS_API_ROWDATA_H_
+
+#include <dpl/shared_ptr.h>
+#include <map>
+#include <vector>
+#include <Commons/Exception.h>
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+
+class RowData
+{
+public:
+ std::map<std::string, std::string> m_Data;
+
+ RowData() { ThrowMsg(WrtDeviceApis::Commons::ConversionException, "empty constructor not allowed"); }
+
+ RowData(std::vector<std::string>& keys, std::vector<std::string>& values)
+ {
+ if (keys.size() == 0)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::ConversionException, "size 0 attribute");
+ }
+
+ if (keys.size() != values.size())
+ {
+ ThrowMsg(WrtDeviceApis::Commons::ConversionException, "columns & values size mismatch");
+ }
+
+ for (size_t index = 0; index < keys.size(); index++)
+ {
+ m_Data[keys[index]] = values[index];
+ }
+ }
+
+ ~RowData() { }
+
+};
+
+typedef DPL::SharedPtr<RowData> RowDataPtr;
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/SelectDataObject.cpp b/mobile_src/DataControl/SelectDataObject.cpp
new file mode 100644
index 0000000..e294777
--- /dev/null
+++ b/mobile_src/DataControl/SelectDataObject.cpp
@@ -0,0 +1,279 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "SelectDataObject.h"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+#include <string.h>
+#include "DataType.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+#define TEXT_DEL 0x0a
+
+
+SelectDataObject::SelectDataObject()
+{
+ LoggerD("Enter");
+
+ m_colCount = 0;
+ m_rowCount = 0;
+ m_colTotalSize = 0;
+}
+
+SelectDataObject::~SelectDataObject()
+{
+ LoggerD("Enter");
+ m_istream.close();
+
+ if (unlink(m_filePath.c_str()) != 0)
+ {
+ LoggerE("Error while removing SelectDataObject.");
+ }
+
+}
+
+void SelectDataObject::openResultPath(const std::string& filepath)
+{
+ LoggerD("Enter");
+
+ m_filePath = filepath;
+ m_istream.open(m_filePath.c_str(), std::ios::binary);
+
+ if (m_istream.is_open())
+ {
+ //LoggerD("load header");
+ loadHeader();
+// LoggerD("print header"); // debug
+// printHeader();
+ }
+ else
+ {
+ LoggerD("fail open" << filepath);
+ }
+}
+
+RowDataPtr SelectDataObject::getIndexedRow(const int fetchIndex)
+{
+ char *buf = NULL;
+
+ size_t dataStart = sizeof(int) * 3 + m_colTotalSize + sizeof(int) * m_headerInfo.size();
+
+ int memorizedSize = 255;
+ int size = 0;
+ int type = 0;
+ int rowIndex = fetchIndex;
+ // move stream to current index
+ int index = 0;
+
+ std::vector<std::string> keys, values;
+ std::string data;
+ std::stringstream ssdata;
+ int ospIntData = 0;
+ long long ospBigIntData = 0;
+ double ospDoubleData = 0;
+
+
+ if (rowIndex >= m_rowCount)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::OutOfRangeException, "The requested index bigger than result row count");
+ }
+
+ m_istream.seekg(dataStart, std::ios::beg);
+
+ for (index = 0; index < (int)m_headerInfo.size(); index++)
+ {
+ keys.push_back(m_headerInfo[index].m_name);
+ }
+
+
+ for (index = 0; index < rowIndex; index++)
+ {
+ moveOneRow();
+ }
+
+ buf = new char[memorizedSize + 1];
+
+ if (buf == NULL)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Out of memory");
+ }
+
+ for (index = 0; index < m_colCount; index++)
+ {
+ size = 0;
+
+ m_istream.read((char*)&type, sizeof(type)); // skip type
+ m_istream.read((char*)&size, sizeof(int)); // read size
+// LoggerD(type << " - " << 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);
+
+ switch (type)
+ {
+ case DB_COLUMNTYPE_TEXT:
+ case DB_COLUMNTYPE_BLOB:
+ m_istream.read((char*)buf, size);
+ data = buf;
+ break;
+ case DB_COLUMNTYPE_INT:
+ ssdata.str("");
+ ospIntData = 0;
+ m_istream.read((char*)&ospIntData, size);
+ ssdata << ospIntData;
+ data = ssdata.str();
+ break;
+ case DB_COLUMNTYPE_INT64:
+ ssdata.str("");
+ m_istream.read((char*)&ospBigIntData, size);
+ ssdata << ospBigIntData;
+ data = ssdata.str();
+ break;
+ case DB_COLUMNTYPE_DOUBLE:
+ ssdata.flush();
+ m_istream.read((char*)&ospDoubleData, size);
+ ssdata << ospDoubleData;
+ data = ssdata.str();
+ break;
+ case DB_COLUMNTYPE_NULL:
+ case DB_COLUMNTYPE_UNDEFINED:
+ data = "";
+ break;
+ default:
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Not support type");
+ break;
+ }
+ values.push_back(data);
+ }
+
+ if (buf)
+ {
+ delete[] buf;
+ }
+
+ RowDataPtr rowData(new RowData(keys, values));
+ return rowData;
+}
+
+
+void SelectDataObject::setResultSetPath(const std::string& path)
+{
+ m_filePath = path;
+}
+
+int SelectDataObject::getRowNumber()
+{
+ return m_rowCount;
+}
+
+
+void SelectDataObject::loadHeader()
+{
+ char buf[255] = {0,};
+
+ m_istream.seekg(0, std::ios::beg);
+ m_istream.read((char*)&m_rowCount, sizeof(int));
+ m_istream.read((char*)&m_colCount, sizeof(int));
+ m_istream.read((char*)&m_colTotalSize, sizeof(int));
+
+ int index = 0, j = 0;
+ char c;
+
+ for (index = 0; index < m_colCount; index++)
+ {
+ ColScheme header;
+
+ header.m_type = 0;
+ header.m_name = "";
+
+ m_istream.read((char*)&header.m_type, sizeof(int));
+
+ std::cout << header.m_type;
+
+
+ m_headerInfo.push_back(header);
+ }
+
+ for (index = 0; index < m_colCount; index++)
+ {
+ memset(buf, 0, sizeof(buf));
+
+ for (j = 0; (c = (char)m_istream.get()) != TEXT_DEL && m_istream.good() ; j++)
+ {
+ buf[j] = c;
+ }
+ buf[j] = '\0';
+
+ std::cout << buf;
+
+ m_headerInfo[index].m_name = buf;
+ }
+
+}
+void SelectDataObject::printHeader()
+{
+ LoggerD("Eneter");
+
+ for (size_t index = 0; index < m_headerInfo.size(); index++)
+ {
+ LoggerD(m_headerInfo[index].m_type << " " << m_headerInfo[index].m_name);
+ }
+
+}
+void SelectDataObject::moveOneRow()
+{
+ int size = 0;
+ int index = 0;
+
+ if (m_istream.good() == false)
+ LoggerD("Error");
+
+ for (index = 0; index < m_colCount; index++)
+ {
+ size = 0;
+ m_istream.seekg(sizeof(int), std::ios::cur); // skip type
+ m_istream.read((char*)&size, sizeof(int)); // read size
+// LoggerD(size << " ");
+ m_istream.seekg(size, std::ios::cur); // skip data
+ }
+
+}
+
+
+}
+}
diff --git a/mobile_src/DataControl/SelectDataObject.h b/mobile_src/DataControl/SelectDataObject.h
new file mode 100755
index 0000000..b154bfc
--- /dev/null
+++ b/mobile_src/DataControl/SelectDataObject.h
@@ -0,0 +1,69 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef TIZENAPIS_PLATFROM_SELECT_DATA_OBJECT_H_
+#define TIZENAPIS_PLATFROM_SELECT_DATA_OBJECT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include <dpl/mutex.h>
+#include "ISelectDataObject.h"
+#include "DataControlFactory.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+
+class ColScheme
+{
+public:
+ int m_type;
+ std::string m_name;
+};
+
+
+class SelectDataObject : public ISelectDataObject
+{
+public:
+ virtual ~SelectDataObject();
+ friend class DataControlFactory;
+
+ virtual int getRowNumber();
+ virtual void setResultSetPath(const std::string& path);
+ virtual RowDataPtr getIndexedRow(const int fetchIndex);
+ virtual void openResultPath(const std::string& filepath);
+protected:
+ SelectDataObject();
+private:
+ void loadHeader();
+ void printHeader();
+ void moveOneRow();
+
+ std::string m_filePath;
+ int m_colCount;
+ int m_rowCount;
+ int m_colTotalSize;
+ std::ifstream m_istream;
+ std::vector<ColScheme> m_headerInfo;
+};
+
+
+}
+}
+
+#endif
+
diff --git a/mobile_src/DataControl/SqlDataControlConsumer.cpp b/mobile_src/DataControl/SqlDataControlConsumer.cpp
new file mode 100644
index 0000000..eafb1c0
--- /dev/null
+++ b/mobile_src/DataControl/SqlDataControlConsumer.cpp
@@ -0,0 +1,542 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <cassert>
+#include <Commons/Exception.h>
+#include "DataType.h"
+#include "SqlDataControlConsumer.h"
+#include <appsvc/appsvc.h>
+#include <string>
+#include <vector>
+#include <aul/aul.h>
+#include <sstream>
+#include <app.h>
+#include <app_info.h>
+// To get ppid
+#include <unistd.h>
+#include <security-server.h>
+#include <sstream>
+#include "DataControlAsyncCallbackManager.h"
+#include "DataControlCallback.h"
+#include "DataControlPendingEvent.h"
+
+namespace DeviceAPI {
+namespace DataControl {
+
+SQLDataControlConsumer::SQLDataControlConsumer(std::string& provId, std::string& dataId, std::string& type)
+{
+ LoggerD("Enter");
+
+ m_type = type;
+ m_dataId = dataId;
+ m_providerId = provId;
+
+ m_appId = getProviderApplicationId(OSP_PKGINFO_SQL_TYPE, provId);
+ m_ProviderPkgId = getProviderPkgId(m_appId);
+ security_server_app_give_access(m_ProviderPkgId.c_str(), -1);
+
+ m_currentAppId = getCurrentApplicationId();
+ createResultDir();
+ DataControlAsyncCallbackManagerSingleton::Instance().setDataControlGC((void*)this, false);
+}
+
+SQLDataControlConsumer::~SQLDataControlConsumer()
+{
+ LoggerD("Enter");
+ DataControlAsyncCallbackManagerSingleton::Instance().setDataControlGC((void*)this, true);
+}
+
+DPL::Mutex SQLDataControlConsumer::m_mutex;
+
+bool SQLDataControlConsumer::checkReqIdUniqueness(unsigned int reqId)
+{
+ std::string reqIdStr;
+ std::stringstream ssReqId;
+
+ ssReqId << reqId;
+ reqIdStr = ssReqId.str();
+ return DataControlAsyncCallbackManagerSingleton::Instance().checkReqIdUnique(reqIdStr);
+}
+
+
+std::string SQLDataControlConsumer::getDataId()
+{
+ return m_dataId;
+}
+
+std::string SQLDataControlConsumer::getProviderId()
+{
+ return m_providerId;
+}
+
+std::string SQLDataControlConsumer::getType()
+{
+ return m_type;
+}
+
+
+
+
+void SQLDataControlConsumer::saveArrayToFile(std::string filename, RowData *rowData)
+{
+ std::fstream insertUpdateFile;
+ std::map<std::string, std::string>::iterator it;
+ int strLength = 0;
+ insertUpdateFile.open(filename.c_str(), std::ios::out | std::ios::binary);
+
+ if (!insertUpdateFile.is_open())
+ {
+ LoggerD("fail open" << filename);
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "DataControl IPC Error");
+ }
+
+ for (it = rowData->m_Data.begin(); it != rowData->m_Data.end(); ++it)
+ {
+ strLength = it->first.size();
+ insertUpdateFile.write((const char*)&strLength, sizeof(int));
+ insertUpdateFile.write(it->first.c_str(), strLength);
+
+ strLength = it->second.size();
+ insertUpdateFile.write((const char*)&strLength, sizeof(int));
+ insertUpdateFile.write(it->second.c_str(), strLength);
+ }
+
+ insertUpdateFile.close();
+
+}
+
+
+void SQLDataControlConsumer::handleCommonErrorEvent(void* userData, unsigned int code, std::string msg)
+{
+ if (userData == NULL)
+ {
+ LoggerD("userData null");
+ return;
+ }
+
+ CommonPendingEvent* pEvent = (CommonPendingEvent*)userData;
+
+ try
+ {
+ if (dynamic_cast<EventInsertPendingEvent*>(pEvent) != NULL)
+ {
+ EventInsertPendingEvent* pendingInsertEvent = (EventInsertPendingEvent*)pEvent;
+ EventInsertPtr insertEvent = pendingInsertEvent->getEvent();
+ insertEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+ insertEvent->setErrorMsg(msg);
+
+ WrtDeviceApis::Commons::EventRequestReceiver<EventInsert>::ManualAnswer(insertEvent);
+
+ }
+ else if (dynamic_cast<EventUpdatePendingEvent*>(pEvent) != NULL)
+ {
+ EventUpdatePendingEvent* pendingUpdateEvent = (EventUpdatePendingEvent*)pEvent;
+ EventUpdatePtr updateEvent = pendingUpdateEvent->getEvent();
+ updateEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+ updateEvent->setErrorMsg(msg);
+
+ WrtDeviceApis::Commons::EventRequestReceiver<EventUpdate>::ManualAnswer(updateEvent);
+ }
+ else if (dynamic_cast<EventSelectPendingEvent*>(pEvent) != NULL)
+ {
+ EventSelectPendingEvent* pendingSelectEvent = (EventSelectPendingEvent*)pEvent;
+ EventSelectPtr selectEvent = pendingSelectEvent->getEvent();
+ selectEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+ selectEvent->setErrorMsg(msg);
+
+ WrtDeviceApis::Commons::EventRequestReceiver<EventSelect>::ManualAnswer(selectEvent);
+ }
+ else if (dynamic_cast<EventDeletePendingEvent*>(pEvent) != NULL)
+ {
+ EventDeletePendingEvent* pendingDeleteEvent = (EventDeletePendingEvent*)pEvent;
+ EventDeletePtr deleteEvent = pendingDeleteEvent->getEvent();
+ deleteEvent->setExceptionCode((WrtDeviceApis::Commons::ExceptionCodes::Enumeration)code);
+ deleteEvent->setErrorMsg(msg);
+
+ WrtDeviceApis::Commons::EventRequestReceiver<EventDelete>::ManualAnswer(deleteEvent);
+ }
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ }
+
+}
+
+void SQLDataControlConsumer::handlePendingEvent(const EventInsertPtr& event)
+{
+ LoggerD("OK");
+ WrtDeviceApis::Commons::EventRequestReceiver<EventInsert>::ManualAnswer(event);
+ CommonPendingEvent* userData = NULL;
+ unsigned short currentJob = 0;
+ try {
+ userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingIpcOperation();
+
+ if (userData)
+ {
+ SendAppControlLaunchToProvider(userData, currentJob);
+ }
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+ LoggerE("Exception: " << ex.GetMessage());
+
+ if (userData)
+ {
+ handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
+ }
+ }
+
+}
+void SQLDataControlConsumer::handlePendingEvent(const EventDeletePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventDelete>::ManualAnswer(event);
+ CommonPendingEvent* userData = NULL;
+ unsigned short currentJob = 0;
+
+ try {
+ userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingIpcOperation();
+
+ if (userData)
+ {
+ SendAppControlLaunchToProvider(userData, currentJob);
+ }
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+ LoggerE("Exception: " << ex.GetMessage());
+
+ if (userData)
+ {
+ handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
+ }
+ }
+
+
+}
+void SQLDataControlConsumer::handlePendingEvent(const EventSelectPtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventSelect>::ManualAnswer(event);
+ CommonPendingEvent* userData = NULL;
+ unsigned short currentJob = 0;
+
+ try {
+ userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingIpcOperation();
+
+ if (userData)
+ {
+ SendAppControlLaunchToProvider(userData, currentJob);
+ }
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+ LoggerE("Exception: " << ex.GetMessage());
+
+ if (userData)
+ {
+ handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
+ }
+
+ }
+
+
+}
+
+void SQLDataControlConsumer::handlePendingEvent(const EventUpdatePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventUpdate>::ManualAnswer(event);
+ CommonPendingEvent* userData = NULL;
+ unsigned short currentJob = 0;
+
+ try {
+ userData = (CommonPendingEvent*)DataControlAsyncCallbackManagerSingleton::Instance().getRemainingIpcOperation();
+
+ if (userData)
+ {
+ SendAppControlLaunchToProvider(userData, currentJob);
+ }
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ if (event.Get() == NULL)
+ {
+ LoggerD("event removed, invalid cb");
+ return;
+ }
+ LoggerE("Exception: " << ex.GetMessage());
+
+ if (userData)
+ {
+ handleCommonErrorEvent(userData, ex.getCode(), ex.GetMessage());
+ }
+ }
+
+}
+
+
+void SQLDataControlConsumer::insertData(const EventInsertPtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventInsert>::PostRequest(event);
+}
+
+void SQLDataControlConsumer::deleteData(const EventDeletePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventDelete>::PostRequest(event);
+}
+
+void SQLDataControlConsumer::selectData(const EventSelectPtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventSelect>::PostRequest(event);
+}
+
+void SQLDataControlConsumer::updateData(const EventUpdatePtr& event)
+{
+ WrtDeviceApis::Commons::EventRequestReceiver<EventUpdate>::PostRequest(event);
+}
+
+void SQLDataControlConsumer::createResultDir()
+{
+ struct stat info;
+ memset(&info, 0, sizeof(struct stat));
+
+ int status = lstat(DATACONTROL_PROTOCOL_DIR_TOP, &info);
+
+ if (status != 0 && errno == ENOENT)
+ {
+ if (mkdir(DATACONTROL_PROTOCOL_DIR_TOP, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+ {
+ LoggerD("make error");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "result dir could not be created.");
+ }
+ }
+
+ status = lstat(DATACONTROL_PROTOCOL_DIR_MIDDLE, &info);
+
+ if (status != 0 && errno == ENOENT)
+ {
+ if (mkdir(DATACONTROL_PROTOCOL_DIR_MIDDLE, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+ {
+ LoggerD("make error");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "result dir could not be created.");
+ }
+ }
+
+ status = lstat(DATACONTROL_PROTOCOL_DIR, &info);
+
+ // already exist
+ if (status == 0)
+ {
+ LoggerD("already exist");
+ return;
+ }
+ else if (errno == ENOENT)
+ {
+ if (mkdir(DATACONTROL_PROTOCOL_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+ {
+ LoggerD("make error");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "result dir could not be created.");
+ }
+ return;
+ }
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "result dir could be error during checking status");
+}
+
+void SQLDataControlConsumer::OnRequestReceived(const EventInsertPtr& event)
+{
+ LoggerD("Enter");
+
+ try
+ {
+ RowData* rowData = event->getRowData();
+ unsigned int reqId = event->getReqId();
+ std::string ipcFilename = generateFileName(reqId, m_currentAppId);
+ std::string reqIdStr = convertIntToString(reqId);
+ unsigned short currentJob = 0;
+
+ if (checkReqIdUniqueness(reqId) == false)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+ }
+
+ if (rowData == NULL || rowData->m_Data.size() == 0)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "No insertion data");
+ }
+
+ saveArrayToFile(ipcFilename, rowData);
+ delete rowData;
+
+ EventInsertPendingEvent* pendingEvent = new EventInsertPendingEvent((void*)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());
+
+
+ }
+}
+void SQLDataControlConsumer::OnRequestReceived(const EventDeletePtr& event)
+{
+ LoggerD("Enter");
+ bundle* passData = NULL;
+
+ try
+ {
+ unsigned int reqId = event->getReqId();
+ std::string reqIdStr = convertIntToString(reqId);
+ unsigned short currentJob = 0;
+
+ if (checkReqIdUniqueness(reqId) == false)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+ }
+
+ EventDeletePendingEvent* pendingEvent = new EventDeletePendingEvent(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)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+
+ if (passData)
+ {
+ bundle_free(passData);
+ passData = NULL;
+ }
+
+}
+void SQLDataControlConsumer::OnRequestReceived(const EventSelectPtr& event)
+{
+ try
+ {
+ unsigned int reqId = event->getReqId();
+ std::string reqIdStr = convertIntToString(reqId);
+ unsigned short currentJob = 0;
+
+ if (checkReqIdUniqueness(reqId) == false)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+ }
+
+ EventSelectPendingEvent* pendingEvent = new EventSelectPendingEvent(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)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+
+}
+
+void SQLDataControlConsumer::OnRequestReceived(const EventUpdatePtr& event)
+{
+ LoggerD("Enter");
+
+ try
+ {
+ unsigned int reqId = event->getReqId();
+ RowData* rowData = event->getRowData();
+ std::string ipcFilename = generateFileName(reqId, m_currentAppId);
+ std::stringstream ssReqId;
+ unsigned short currentJob = 0;
+ ssReqId << reqId;
+
+ if (checkReqIdUniqueness(reqId) == false)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::AlreadyInUseException, "Duplicated requested id");
+ }
+
+ if (rowData == NULL || rowData->m_Data.size() == 0)
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "No update data");
+ }
+
+ saveArrayToFile(ipcFilename, rowData);
+ delete rowData;
+
+ EventUpdatePendingEvent* pendingEvent = new EventUpdatePendingEvent(this, m_dataId,
+ m_appId, m_providerId, m_currentAppId, event);
+
+ if (DataControlAsyncCallbackManagerSingleton::Instance().checkRequestIpcOperation())
+ {
+ SendAppControlLaunchToProvider(pendingEvent, currentJob);
+ }
+ event->switchToManualAnswer();
+ DataControlAsyncCallbackManagerSingleton::Instance().addSQLUserData(ssReqId.str(), (void*)pendingEvent);
+
+ }
+ catch (const WrtDeviceApis::Commons::Exception& ex)
+ {
+ LoggerE("Exception: " << ex.GetMessage());
+ event->setExceptionCode(ex.getCode());
+ event->setErrorMsg(ex.GetMessage());
+ }
+
+}
+}
+}
+
+
diff --git a/mobile_src/DataControl/SqlDataControlConsumer.h b/mobile_src/DataControl/SqlDataControlConsumer.h
new file mode 100755
index 0000000..bb08c08
--- /dev/null
+++ b/mobile_src/DataControl/SqlDataControlConsumer.h
@@ -0,0 +1,86 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef TIZENAPIS_PLATFORM_SQL_DATACONTRIL_CONSUMER_H_
+#define TIZENAPIS_PLATFORM_SQL_DATACONTRIL_CONSUMER_H_
+
+#include <vector>
+#include <string>
+#include <dpl/noncopyable.h>
+#include <bundle.h>
+#include "ISqlDataControlConsumer.h"
+#include "DataControlFactory.h"
+#include <dpl/mutex.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+class SQLDataControlConsumer : public ISQLDataControlConsumer
+{
+ friend class DataControlFactory;
+
+public:
+
+ virtual void insertData(const EventInsertPtr& event);
+ virtual void deleteData(const EventDeletePtr& event);
+ virtual void selectData(const EventSelectPtr& event);
+ virtual void updateData(const EventUpdatePtr& event);
+
+ virtual ~SQLDataControlConsumer();
+ void setType(std::string& type);
+ void setProviderId(const std::string& id );
+ void setDataId(const std::string& id );
+
+ std::string getType();
+ std::string getDataId();
+ std::string getProviderId();
+
+ void handlePendingEvent(const EventInsertPtr& event);
+ void handlePendingEvent(const EventDeletePtr& event);
+ void handlePendingEvent(const EventSelectPtr& event);
+ void handlePendingEvent(const EventUpdatePtr& event);
+ void handleCommonErrorEvent(void* userData, unsigned int code, std::string msg);
+
+private:
+ std::string m_type;
+ std::string m_dataId;
+ std::string m_providerId;
+ std::string m_appId;
+ std::string m_currentAppId;
+ std::string m_ProviderPkgId;
+
+ bool checkReqIdUniqueness(unsigned int reqId);
+
+ void saveArrayToFile(std::string filename, RowData* rowData);
+ void createResultDir();
+ static DPL::Mutex m_mutex;
+protected:
+ SQLDataControlConsumer(std::string& provId, std::string& dataId, std::string& type);
+
+ virtual void OnRequestReceived(const EventInsertPtr& event);
+ virtual void OnRequestReceived(const EventDeletePtr& event);
+ virtual void OnRequestReceived(const EventSelectPtr& event);
+ virtual void OnRequestReceived(const EventUpdatePtr& event);
+
+
+
+};
+
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/config.xml b/mobile_src/DataControl/config.xml
new file mode 100755
index 0000000..9d0447d
--- /dev/null
+++ b/mobile_src/DataControl/config.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+ <library-name>libwrt-plugins-tizen-datacontrol.so</library-name>
+ <feature-install-uri>datacontrol.install.uri</feature-install-uri>
+
+ <api-feature>
+ <name>http://tizen.org/privilege/datacontrol.consumer</name>
+ <device-capability>datacontrol.consumer</device-capability>
+ </api-feature>
+</plugin-properties>
+
diff --git a/mobile_src/DataControl/plugin_config.cpp b/mobile_src/DataControl/plugin_config.cpp
new file mode 100755
index 0000000..b9b1cd3
--- /dev/null
+++ b/mobile_src/DataControl/plugin_config.cpp
@@ -0,0 +1,82 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define DATACONTROL_FEATURE_API_CONSUMER "http://tizen.org/privilege/datacontrol.consumer"
+#define DATACONTROL_DEVICE_CAP_CONSUMER "datacontrol.consumer"
+
+
+namespace DeviceAPI {
+namespace DataControl {
+
+static WrtDeviceApis::Commons::FunctionMapping createDataConrolFunctions();
+static WrtDeviceApis::Commons::FunctionMapping DataConrolFunctions = createDataConrolFunctions();
+
+
+
+#pragma GCC visibility push(default)
+
+DEFINE_FUNCTION_GETTER(DataControl, DataConrolFunctions);
+
+#pragma GCC visibility pop
+
+
+static WrtDeviceApis::Commons::FunctionMapping createDataConrolFunctions()
+{
+ using namespace WrtDeviceApis::Commons;
+
+ ACE_CREATE_DEVICE_CAP(DEVICE_CAP_DATACONTROL_CONSUMER, DATACONTROL_DEVICE_CAP_CONSUMER);
+
+ ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_DATACONTROL_CONSUMER);
+ ACE_ADD_DEVICE_CAP(DEVICE_LIST_DATACONTROL_CONSUMER, DEVICE_CAP_DATACONTROL_CONSUMER);
+
+
+ ACE_CREATE_FEATURE(FEATURE_CONSUMER, DATACONTROL_FEATURE_API_CONSUMER);
+
+
+ ACE_CREATE_FEATURE_LIST(FEATURES_CONSUMER_CREATOR);
+
+ ACE_CREATE_FEATURE_LIST(FEATURES_CONSUMER);
+ ACE_ADD_API_FEATURE(FEATURES_CONSUMER, FEATURE_CONSUMER);
+
+
+ FunctionMapping DataConrolFunctions;
+
+ AceFunction DataControlConsumer = ACE_CREATE_FUNCTION(FUNCTION_DATACONTROL_CONSUMER, DATACONTROL_FUNC_CONSUMER,
+ FEATURES_CONSUMER, DEVICE_LIST_DATACONTROL_CONSUMER);
+ DataConrolFunctions.insert(std::make_pair(DATACONTROL_FUNC_CONSUMER, DataControlConsumer));
+
+
+
+
+ return DataConrolFunctions;
+}
+
+
+}
+}
+
+#undef DATACONTROL_FEATURE_API_CONSUMER
+#undef DATACONTROL_DEVICE_CAP_CONSUMER
+
diff --git a/mobile_src/DataControl/plugin_config.h b/mobile_src/DataControl/plugin_config.h
new file mode 100755
index 0000000..bbc9446
--- /dev/null
+++ b/mobile_src/DataControl/plugin_config.h
@@ -0,0 +1,38 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef TIZENAPIS_TIZEN_JS_DATACONTROL_PLUGIN_CONFIG_H_
+#define TIZENAPIS_TIZEN_JS_DATACONTROL_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace DeviceAPI {
+namespace DataControl {
+
+#define DATACONTROL_FUNC_CONSUMER "DataControlConsumer"
+
+
+DECLARE_FUNCTION_GETTER(DataControl);
+
+#define DATACONTROL_CHECK_ACCESS(functionName) \
+ aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >( \
+ getDataControlFunctionData, \
+ functionName)
+}
+}
+
+#endif
diff --git a/mobile_src/DataControl/plugin_initializer.cpp b/mobile_src/DataControl/plugin_initializer.cpp
new file mode 100644
index 0000000..db350ec
--- /dev/null
+++ b/mobile_src/DataControl/plugin_initializer.cpp
@@ -0,0 +1,87 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <TimeTracer.h>
+
+#include "JSDataControlManager.h"
+#include "DataControlAsyncCallbackManager.h"
+#include <Logger.h>
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace DeviceAPI {
+namespace DataControl {
+
+void on_widget_start_callback(int widgetId)
+{
+ LoggerD("[Tizen\\DataControl ] on_widget_start_callback ("<<widgetId<<")");
+ TIME_TRACER_INIT();
+ Try
+ {
+ WrtAccessSingleton::Instance().initialize(widgetId);
+ }
+ Catch(Commons::Exception)
+ {
+ LoggerE("WrtAccess initialization failed");
+ }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+ LoggerD("[Tizen\\DataControl] on_widget_stop_callback ("<<widgetId<<")");
+ TIME_TRACER_EXPORT_REPORT_TO(TIME_TRACER_EXPORT_FILE,"DataControl");
+ TIME_TRACER_RELEASE();
+ Try
+ {
+ WrtAccessSingleton::Instance().deinitialize(widgetId);
+ }
+ Catch(Commons::Exception)
+ {
+ LoggerE("WrtAccess deinitialization failed");
+ }
+}
+
+void on_frame_load_callback(const void * context)
+{
+ LoggerD("[SEC\\application] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+ LoggerD("[SEC\\application] on_frame_unload_callback (" << context << ")");
+
+ DeviceAPI::DataControl::DataControlAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
+PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
+
+#define DATACONTROL "datacontrol"
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, DATACONTROL,
+ (js_class_template_getter)DeviceAPI::DataControl::JSDataControlManager::getClassRef,NULL)
+PLUGIN_CLASS_MAP_END
+
+} // DataControl
+} // DeviceAPI