From: Joohyun Kim Date: Thu, 11 Jul 2013 01:40:13 +0000 (+0900) Subject: Add setting features on common-service X-Git-Tag: 2.2_release~22^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=320b1979c680bcab969ca9b564c98372bfc10534;p=framework%2Fosp%2Fcommon-service.git Add setting features on common-service Change-Id: I122ea5c46c0bcf95ed67c39431612144954b436a Signed-off-by: Joohyun Kim --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a54dec2..00a0a91 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,12 +27,15 @@ INCLUDE_DIRECTORIES ( ) SET (${this_target}_SOURCE_FILES + src/system/FSys_SettingService.cpp src/FApp_PackageManagerStub.cpp src/FUi_UiManagerStub.cpp src/CommonService.cpp src/CommonServiceEntry.cpp ) +#ADD_SUBDIRECTORY(src/system) + ## SET EXTRA COMPILER FLAGS SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE -Wall -pthread -g3" ) #SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fstack-protector -Wstack-protector" ) diff --git a/inc/CommonService.h b/inc/CommonService.h index cd29365..3070b73 100644 --- a/inc/CommonService.h +++ b/inc/CommonService.h @@ -33,6 +33,11 @@ namespace Tizen { namespace Ui class _UiManagerStub; }} // Tizen::Ui +namespace Tizen { namespace System +{ +class _SettingService; +}} + /** * @class CommonService * @brief @@ -58,6 +63,7 @@ private: Tizen::App::_PackageManagerStub* __pPackageManagerStub; std::unique_ptr __pUiManagerStub; + Tizen::System::_SettingService* __pSettingService; }; #endif // _COMMON_SERVICE_H_ diff --git a/packaging/osp-common-service.spec b/packaging/osp-common-service.spec index 058f388..2db575a 100755 --- a/packaging/osp-common-service.spec +++ b/packaging/osp-common-service.spec @@ -6,6 +6,7 @@ Group: System/Libraries License: Apache License, Version 2.0 or Flora Source0: %{name}-%{version}.tar.gz BuildRequires: cmake +BuildRequires: pkgconfig(osp-system-server) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(chromium) BuildRequires: pkgconfig(capi-appfw-package-manager) diff --git a/src/CommonService.cpp b/src/CommonService.cpp index f4f7e95..bacaecc 100644 --- a/src/CommonService.cpp +++ b/src/CommonService.cpp @@ -20,6 +20,7 @@ #include "FApp_PackageManagerStub.h" #include "FUi_UiManagerStub.h" +#include "system/FSys_SettingService.h" using namespace std; using namespace Tizen::App; @@ -29,8 +30,8 @@ using namespace Tizen::Ui; CommonService::CommonService(void) : __pPackageManagerStub(null) -{ - + , __pSettingService(null) +{ } CommonService::~CommonService(void) @@ -120,4 +121,6 @@ CommonService::InitializeServices(void) SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "Propagating."); __pUiManagerStub = move(pUiManagerStub); + __pSettingService = _SettingService::GetInstance(); } + diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt new file mode 100644 index 0000000..e413a3b --- /dev/null +++ b/src/system/CMakeLists.txt @@ -0,0 +1,27 @@ +SET (this_target system) + +INCLUDE_DIRECTORIES( + ${SLP_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/inc + /usr/include/osp/system-server + ./ + ) + +SET (${this_target}_SOURCE_FILES + FSys_SettingService.cpp +) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") + +## SET EXTRA COMPILER FLAGS +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC" ) + +## SET C COMPILER FLAGS +SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +## SET CPP COMPILER FLAGS +SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +## Create Library +ADD_LIBRARY (${this_target} STATIC ${${this_target}_SOURCE_FILES}) + diff --git a/src/system/FSys_SettingService.cpp b/src/system/FSys_SettingService.cpp new file mode 100644 index 0000000..1f3949f --- /dev/null +++ b/src/system/FSys_SettingService.cpp @@ -0,0 +1,513 @@ +// +// 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. +// + +/** + * @file FSys_SettingService.cpp + * @brief This is the implementation file for _SettingService class. + */ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "FSys_SettingService.h" + +using namespace std; +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; +using namespace Tizen::Security; + +namespace Tizen { namespace System { + +const static wchar_t* SETTING_SERVICE_ID = L"osp.sys.ipcserver.setting_service"; + +const static wchar_t* SETTING_SERVICE_COMMAND_GET_BOOL = L"osp.sys.ipcserver.setting_service.command.get.bool"; +const static wchar_t* SETTING_SERVICE_COMMAND_GET_INT = L"osp.sys.ipcserver.setting_service.command.get.int"; +const static wchar_t* SETTING_SERVICE_COMMAND_GET_STRING = L"osp.sys.ipcserver.setting_service.command.get.string"; +const static wchar_t* SETTING_SERVICE_COMMAND_SET_BOOL = L"osp.sys.ipcserver.setting_service.command.set.bool"; +const static wchar_t* SETTING_SERVICE_COMMAND_SET_INT = L"osp.sys.ipcserver.setting_service.command.set.int"; +const static wchar_t* SETTING_SERVICE_COMMAND_SET_STRING = L"osp.sys.ipcserver.setting_service.command.set.string"; +const static wchar_t* SETTING_SERVICE_COMMAND_SET_PRIV_BOOL = L"osp.sys.ipcserver.setting_service.command.set.priv.bool"; +const static wchar_t* SETTING_SERVICE_COMMAND_SET_PRIV_STRING = L"osp.sys.ipcserver.setting_service.command.set.priv.string"; +const static wchar_t* SETTING_SERVICE_COMMAND_SET_ASYNC_BOOL = L"osp.sys.ipcserver.setting_service.command.set.async.bool"; +const static wchar_t* SETTING_SERVICE_COMMAND_SET_PRIV_ASYNC_BOOL = L"osp.sys.ipcserver.setting_service.command.set.priv.async.bool"; +const static wchar_t* SETTING_SERVICE_COMMAND_RESULT = L"osp.sys.ipcserver.setting_service.command.result"; + +const static wchar_t* SETTING_SERVICE_COMMAND_SUBSCRIBE = L"osp.sys.ipcserver.setting_service.command.subscribe"; +const static wchar_t* SETTING_SERVICE_COMMAND_UNSUBSCRIBE = L"osp.sys.ipcserver.setting_service.command.unsubscribe"; +const static wchar_t* SETTING_SERVICE_COMMAND_EVENT = L"osp.sys.ipcserver.setting_service.command.event"; + +const static wchar_t* SETTING_SERVICE_COMMAND_SUPPORTED = L"osp.sys.ipcserver.setting_service.command.supported"; + +const static wchar_t* SETTING_SERVICE_COMMAND_SUBSCRIBE_INTERNAL = L"osp.sys.ipcserver.setting_service.command.subscribe.internal"; +const static wchar_t* SETTING_SERVICE_COMMAND_UNSUBSCRIBE_INTERNAL = L"osp.sys.ipcserver.setting_service.command.unsubscribe.internal"; +const static wchar_t* SETTING_SERVICE_COMMAND_EVENT_INTERNAL = L"osp.sys.ipcserver.setting_service.command.event.internal"; + +const static int SETTING_SERVICE_IPC_MSG_COMMAND = 0; +const static int SETTING_SERVICE_IPC_MSG_KEY = 1; +const static int SETTING_SERVICE_IPC_MSG_VALUE = 2; + +const static wchar_t* _SETTINGS_KEY_FONT_SIZE = L"http://tizen.org/setting/font.size"; +const static wchar_t* _SETTINGS_KEY_FONT_TYPE = L"http://tizen.org/setting/font.type"; +const static wchar_t* _SETTINGS_KEY_LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country"; +const static wchar_t* _SETTINGS_KEY_LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language"; + +_SettingService* _SettingService::__pSettingService = null; + +_SettingService::_SettingService() + : __serviceId(SETTING_SERVICE_ID) + , __pSettingInfo(null) + , __asyncList(SingleObjectDeleter) + , __eventList(SingleObjectDeleter) +{ + result r = E_SUCCESS; + + r = __ipcServer.Construct(__serviceId, *this, true); + SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, r, "It is failed to construct IPC server."); + + r = __ipcServer.Start(); + SysTryCatch(NID_SYS, r == E_SUCCESS, , r, "It is failed to start IPC server."); + + __pSettingInfo = _SettingInfo::GetInstance(); + SysTryCatch(NID_SYS, __pSettingInfo != null, r = E_SYSTEM, E_SYSTEM, "It is failed to get instance of _SettingInfo."); + + __pSettingInfo->AddSettingEventListener(*this); + r = __asyncList.Construct(); + SysTryCatch(NID_SYS, r == E_SUCCESS, , r, "It is failed to construct async list."); + + r = __eventList.Construct(); + SysTryCatch(NID_SYS, r == E_SUCCESS, , r, "It is failed to construct event list."); + + r = __eventListForInternal.Construct(); + SysTryCatch(NID_SYS, r == E_SUCCESS, , r, "It is failed to construct event list for internal."); + +CATCH: + if(r != E_SUCCESS) + { + __pSettingInfo = null; + SysLogException(NID_SYS, r, "It is failed to construct _SettingService."); + __ipcServer.Stop(); + } +} + +_SettingService::~_SettingService() +{ + __pSettingInfo->RemoveSettingEventListener(*this); + __pSettingInfo = null; + result r = __ipcServer.Stop(); + SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, r, "It is failed to stop IPC server."); +} + +_SettingService* +_SettingService::GetInstance(void) +{ + static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; + if(__pSettingService == null) + { + pthread_once(&onceBlock, InitSingleton); + } + return __pSettingService; +} + +void +_SettingService::InitSingleton(void) +{ + _SettingService* pSettingService = new (nothrow) _SettingService(); + SysTryReturnVoidResult(NID_SYS, pSettingService != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", + GetErrorMessage(E_OUT_OF_MEMORY)); + + __pSettingService = pSettingService; + atexit(DestroySingleton); +} + +void +_SettingService::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message) +{ + __currentPkgId = server.GetClientPackageId(); + __currentPid = server.GetClientId(); + IPC_BEGIN_MESSAGE_MAP(_SettingService, message) + IPC_MESSAGE_HANDLER_EX(IoService_Request, &server, OnRequestOccured) + IPC_END_MESSAGE_MAP_EX() +} + +bool +_SettingService::OnRequestOccured(const ArrayList& request, ArrayList* response) +{ + result r = E_SUCCESS; + String* pCommand = null; + String* pKey = null; + String* pValue = null; + + SysTryCatch(NID_SYS, response != null, r = E_SYSTEM, r, "There is no response instance."); + + pCommand = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_COMMAND); + SysTryCatch(NID_SYS, pCommand != null, r = E_SYSTEM, r, "There is no command information."); + + SysLog(NID_SYS, "Required command is [%ls].", pCommand->GetPointer()); + + if(*pCommand == SETTING_SERVICE_COMMAND_GET_INT) + { + int value = 0; + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + r = __pSettingInfo->GetValue(*pKey, value); + pValue = new (nothrow) String(); + SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "It is failed to create pValue."); + pValue->Append(value); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_GET_BOOL) + { + bool value = false; + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + r = __pSettingInfo->GetValue(*pKey, value); + pValue = new (nothrow) String(); + SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "It is failed to create pValue."); + pValue->Append(value); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_GET_STRING) + { + String value; + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + r = __pSettingInfo->GetValue(*pKey, value); + pValue = new (nothrow) String(value); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SET_INT) + { + int value = 0; + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + pValue = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); + Integer::Parse(*pValue, value); + r = __pSettingInfo->SetValue(*pKey, value); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SET_BOOL) + { + bool value = false; + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + pValue = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); + value = Boolean::Parse(*pValue); + r = __pSettingInfo->SetValue(*pKey, value); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SET_STRING) + { + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + pValue = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); + r = __pSettingInfo->SetValue(*pKey, *pValue); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SET_PRIV_BOOL) + { + bool value = false; + + r = _AccessController::CheckSystemPrivilege(__currentPkgId, _PRV_SYSTEMSETTING_WRITE, _PRV_SETTINGMANAGER_WRITE); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_PRIVILEGE_DENIED, r, "The application[%ls] does not have the privilege to call this method.", __currentPkgId.GetPointer()); + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + pValue = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); + value = Boolean::Parse(*pValue); + r = __pSettingInfo->SetValueForPrivilegedKey(*pKey, value); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SET_PRIV_STRING) + { + r = _AccessController::CheckSystemPrivilege(__currentPkgId, _PRV_SYSTEMSETTING_WRITE, _PRV_SETTINGMANAGER_WRITE); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_PRIVILEGE_DENIED, r, "The application[%ls] does not have the privilege to call this method.", __currentPkgId.GetPointer()); + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + pValue = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); + r = __pSettingInfo->SetValueForPrivilegedKey(*pKey, *pValue); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SET_ASYNC_BOOL) + { + bool value = false; + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + pValue = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); + + SysLog(NID_SYS, "Key is %ls, Value is %ls, pid is %d.", pKey->GetPointer(), pValue->GetPointer(), __currentPid); + if(*pValue == L"true") + { + value = true; + } + else + { + value = false; + } + unique_ptr reservedKey(new (nothrow)String(*pKey)); + SysTryCatch(NID_SYS, __asyncList.ContainsKey(*(reservedKey.get())) == false, r = E_IN_PROGRESS, r, "Required key(%ls) is already under processing.", pKey->GetPointer()); + unique_ptr reservedPid(new (nothrow)Integer(__currentPid)); + + r = __asyncList.Add(reservedKey.get(), reservedPid.get()); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to add aync list."); + reservedPid.release(); + reservedKey.release(); + + r = __pSettingInfo->SetValueAsync(*pKey, value, this); + if(r != E_SUCCESS) + { + __asyncList.Remove(*pKey); + } + SysLog(NID_SYS, "Result is %s.", GetErrorMessage(r)); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SET_PRIV_ASYNC_BOOL) + { + bool value = false; + r = _AccessController::CheckSystemPrivilege(__currentPkgId, _PRV_SYSTEMSETTING_WRITE, _PRV_SETTINGMANAGER_WRITE); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_PRIVILEGE_DENIED, r, "The application[%ls] does not have the privilege to call this method.", __currentPkgId.GetPointer()); + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + pValue = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); + + SysLog(NID_SYS, "Key is %ls, Value is %ls, pid is %d.", pKey->GetPointer(), pValue->GetPointer(), __currentPid); + if(*pValue == L"true") + { + value = true; + } + else + { + value = false; + } + + unique_ptr reservedKey(new (nothrow)String(*pKey)); + SysTryCatch(NID_SYS, __asyncList.ContainsKey(*(reservedKey.get())) == false, r = E_IN_PROGRESS, r, "Required key(%ls) is already under processing.", pKey->GetPointer()); + unique_ptr reservedPid(new (nothrow)Integer(__currentPid)); + + r = __asyncList.Add(reservedKey.get(), reservedPid.get()); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to add aync list."); + reservedPid.release(); + reservedKey.release(); + + r = __pSettingInfo->SetValueAsyncForPrivilegedKey(*pKey, value, this); + if(r != E_SUCCESS) + { + __asyncList.Remove(*pKey); + } + SysLog(NID_SYS, "Result is %s.", GetErrorMessage(r)); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SUBSCRIBE) + { + unique_ptr pid(new (nothrow) Integer(__currentPid)); + + SysTryCatch(NID_SYS, __eventList.Contains(*(pid.get())) == false, r = E_OBJ_ALREADY_EXIST, r, "Required application(%ls, %d) is already subscribe event.", __currentPkgId.GetPointer(), __currentPid); + r = __eventList.Add(pid.get()); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to add application(%ls, %d) on event list", __currentPkgId.GetPointer(), __currentPid); + pid.release(); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_UNSUBSCRIBE) + { + unique_ptr pid(new (nothrow) Integer(__currentPid)); + + SysTryCatch(NID_SYS, __eventList.Contains(*(pid.get())) == true, r = E_OBJ_NOT_FOUND, r, "Required application(%ls, %d) is not subscribe event.", __currentPkgId.GetPointer(), __currentPid); + r = __eventList.Remove(*(pid.get()), true); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to remove application(%ls, %d) on event list", __currentPkgId.GetPointer(), __currentPid); + pid.release(); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SUPPORTED) + { + bool value = false; + + pKey = (String*)request.GetAt(SETTING_SERVICE_IPC_MSG_KEY); + SysTryCatch(NID_SYS, pKey != null, r = E_SYSTEM, r, "There is no key information."); + value = __pSettingInfo->HasKey(*pKey); + pValue = new (nothrow) String(); + SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "It is failed to create pValue."); + pValue->Append(value); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_SUBSCRIBE_INTERNAL) + { + unique_ptr pid(new (nothrow) Integer(__currentPid)); + + SysTryCatch(NID_SYS, __eventListForInternal.Contains(*(pid.get())) == false, r = E_OBJ_ALREADY_EXIST, r, "Required application(%ls, %d) is already subscribe event.", __currentPkgId.GetPointer(), __currentPid); + r = __eventListForInternal.Add(pid.get()); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to add application(%ls, %d) on event list", __currentPkgId.GetPointer(), __currentPid); + pid.release(); + } + else if(*pCommand == SETTING_SERVICE_COMMAND_UNSUBSCRIBE_INTERNAL) + { + unique_ptr pid(new (nothrow) Integer(__currentPid)); + + SysTryCatch(NID_SYS, __eventListForInternal.Contains(*(pid.get())) == true, r = E_OBJ_NOT_FOUND, r, "Required application(%ls, %d) is not subscribe event.", __currentPkgId.GetPointer(), __currentPid); + r = __eventListForInternal.Remove(*(pid.get()), true); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to remove application(%ls, %d) on event list", __currentPkgId.GetPointer(), __currentPid); + pid.release(); + } + else + { + return false; + } + +CATCH: + if(response != null) + { + String* pCommandCode = new (nothrow) String(*pCommand); + String* pResultCode = new (nothrow) String(GetErrorMessage(r)); + + SysLog(NID_SYS, "Result value is %ls.", pCommandCode->GetPointer()); + SysLog(NID_SYS, "Result value is %ls.", pResultCode->GetPointer()); + + response->Add(pCommandCode); + response->Add(pResultCode); + if(pValue != null) + { + SysLog(NID_SYS, "Result value is %ls.", pValue->GetPointer()); + response->Add(pValue); + } + } + + return true; +} + +void +_SettingService::OnResultReceivedForSetValueAsync(const String& key, result rCode) +{ + SysLog(NID_SYS, "Key is %ls, result is %s.", key.GetPointer(), GetErrorMessage(rCode)); + Integer* pid = (Integer*) __asyncList.GetValue(key); + ArrayList* pData = null; + result r = E_SUCCESS; + String cmdCode(SETTING_SERVICE_COMMAND_RESULT); + String keyCode; + String resultCode; + + SysTryCatch(NID_SYS, pid != null, r = E_SYSTEM, r, "Required key(%ls) is not reserved.", key.GetPointer()); + pData = new (nothrow) ArrayList; + pData->Construct(); + keyCode.Append(key); + resultCode.Append(GetErrorMessage(rCode)); + pData->Add(cmdCode); + pData->Add(keyCode); + pData->Add(resultCode); + + r = __ipcServer.SendResponse(pid->value, new (nothrow) IoService_Data(*pData)); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to send result to %d.", pid->value); + +CATCH: + __asyncList.Remove(key, true); + + if(pData != null) + { + delete pData; + } +} + +void +_SettingService::OnSettingChanged(Tizen::Base::String& key) +{ + result r = E_SUCCESS; + IEnumerator* pEnum = null; + + if(key == _SETTINGS_KEY_FONT_SIZE || key == _SETTINGS_KEY_FONT_TYPE + || key == _SETTINGS_KEY_LOCALE_COUNTRY || key == _SETTINGS_KEY_LOCALE_LANGUAGE) + { + pEnum = __eventListForInternal.GetEnumeratorN(); + + while(pEnum->MoveNext() == E_SUCCESS) + { + Integer* pid = (Integer*) pEnum->GetCurrent(); + + ArrayList* pData = new (nothrow) ArrayList; + pData->Construct(); + String cmdCode(SETTING_SERVICE_COMMAND_EVENT); + String keyCode(key); + pData->Add(cmdCode); + pData->Add(keyCode); + + r = __ipcServer.SendResponse(pid->value, new (nothrow) IoService_Data(*pData)); + SysLog(NID_SYS, "Internal setting event is delivered to %d. result is %s.", pid->value, GetErrorMessage(r)); + } + delete pEnum; + } + + pEnum = __eventList.GetEnumeratorN(); + while(pEnum->MoveNext() == E_SUCCESS) + { + Integer* pid = (Integer*) pEnum->GetCurrent(); + + ArrayList* pData = new (nothrow) ArrayList; + pData->Construct(); + String cmdCode(SETTING_SERVICE_COMMAND_EVENT); + String keyCode(key); + pData->Add(cmdCode); + pData->Add(keyCode); + + r = __ipcServer.SendResponse(pid->value, new (nothrow) IoService_Data(*pData)); + SysLog(NID_SYS, "Setting event is delivered to %d. result is %s.", pid->value, GetErrorMessage(r)); + } + + delete pEnum; +} + +void +_SettingService::OnIpcServerStarted(const _IpcServer& server) +{ +} + +void +_SettingService::OnIpcServerStopped(const _IpcServer& server) +{ +} + +void +_SettingService::OnIpcClientConnected(const _IpcServer& server, int clientId) +{ +} + +void +_SettingService::OnIpcClientDisconnected(const _IpcServer&server, int clientId) +{ +} + +void +_SettingService::OnApplicationLaunched(const AppId& appId, int pid) +{ +} + +void +_SettingService::OnApplicationTerminated(const AppId& appId, int pid) +{ + Integer reservedKey(pid); + result r = __eventList.Remove(reservedKey, true); + SysLog(NID_SYS, "Application(%d) is terminated and unsubscribe result is %s.", pid, GetErrorMessage(r)); + r = __eventListForInternal.Remove(reservedKey, true); + SysLog(NID_SYS, "unsubscribe result is %s on internal event.", GetErrorMessage(r)); +} + +void +_SettingService::DestroySingleton(void) +{ + delete __pSettingService; +} + +}} + diff --git a/src/system/FSys_SettingService.h b/src/system/FSys_SettingService.h new file mode 100644 index 0000000..b9c62a7 --- /dev/null +++ b/src/system/FSys_SettingService.h @@ -0,0 +1,89 @@ +// +// Open Service Platform +// 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. +// + +/** + * @file FSys_SettingService.h + * @brief This is the header file of the _SettingService class. + * + * This header file contains the declarations of the _SettingService class. + */ + + +#ifndef _FSYS_SETTING_SERVICE_INTERNAL_H_ +#define _FSYS_SETTING_SERVICE_INTERNAL_H_ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +namespace Tizen { namespace System +{ + +class _SettingService + : public Tizen::Base::Object + , public Tizen::App::_IAppEventListener + , public Tizen::Io::_IIpcServerEventListener + , public Tizen::System::ISettingInfoSetValueAsyncResultListener + , public Tizen::System::ISettingEventListener +{ +private: + _SettingService(); + ~_SettingService(); + + static void InitSingleton(void); + static void DestroySingleton(void); + +public: + static _SettingService* GetInstance(void); + +private: + bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response); + void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message); + void OnIpcServerStarted(const Tizen::Io::_IpcServer& server); + void OnIpcServerStopped(const Tizen::Io::_IpcServer& server); + void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId); + void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId); + + void OnApplicationLaunched(const Tizen::App::AppId& appId, int pid); + void OnApplicationTerminated(const Tizen::App::AppId& appId, int pid); + + void OnResultReceivedForSetValueAsync(const Tizen::Base::String& key, result r); + void OnSettingChanged(Tizen::Base::String& key); + +private: + static _SettingService* __pSettingService; + Tizen::Io::_IpcServer __ipcServer; + Tizen::Base::String __serviceId; + _SettingInfo* __pSettingInfo; + Tizen::Base::Collection::HashMap __asyncList; + Tizen::Base::Collection::ArrayList __eventList; + Tizen::Base::Collection::ArrayList __eventListForInternal; + + Tizen::App::AppId __currentPkgId; + int __currentPid; +}; + +}} +#endif