From 94123c7b2460d338cea0b13d86e4c07f518147e1 Mon Sep 17 00:00:00 2001 From: Joohyun Kim Date: Tue, 20 Aug 2013 15:36:11 +0900 Subject: [PATCH] Remove primitive SettingClient Change-Id: Iea881b48585c4457500c8ec675f982148bfa4a3b Signed-off-by: Joohyun Kim --- .../providers/FSys_SettingNetworkProvider.cpp | 0 src/system/CMakeLists.txt | 1 - src/system/FSys_SettingClient.cpp | 637 ++++++----- src/system/FSys_SettingClient.h | 119 ++- src/system/FSys_SettingClientEx.cpp | 1104 -------------------- src/system/FSys_SettingClientEx.h | 205 ---- src/system/FSys_SettingInfoImpl.cpp | 312 +----- 7 files changed, 460 insertions(+), 1918 deletions(-) mode change 100755 => 100644 src/system-server/setting/providers/FSys_SettingNetworkProvider.cpp delete mode 100644 src/system/FSys_SettingClientEx.cpp delete mode 100644 src/system/FSys_SettingClientEx.h diff --git a/src/system-server/setting/providers/FSys_SettingNetworkProvider.cpp b/src/system-server/setting/providers/FSys_SettingNetworkProvider.cpp old mode 100755 new mode 100644 diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index 1c04976..ddf29e4 100644 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -42,7 +42,6 @@ SET (${this_target}_SOURCE_FILES FSys_EnvironmentImpl.cpp FSys_DeviceEventListenerContainer.cpp FSys_SettingClient.cpp - FSys_SettingClientEx.cpp FSys_SystemClient.cpp FSys_SystemServiceMessageClient.cpp ) diff --git a/src/system/FSys_SettingClient.cpp b/src/system/FSys_SettingClient.cpp index 0b9749b..f7a1619 100644 --- a/src/system/FSys_SettingClient.cpp +++ b/src/system/FSys_SettingClient.cpp @@ -21,13 +21,15 @@ #include -#include "FSys_SettingClient.h" - +#include #include +#include #include #include + #include "FSys_CommunicationDispatcherClient.h" +#include "FSys_SettingClient.h" using namespace std; @@ -126,127 +128,48 @@ static const wchar_t* _SETTING_COMMAND_FACTORY_RESET = L"osp.setting.command.fac static const wchar_t* _USBMODE = L"UsbMode"; static const wchar_t* _USBMODE_MTP = L"MTP"; -static const wchar_t* _SETTING_SERVICE_ID = L"osp.setting.service"; -static const wchar_t* _SETTING_SERVICE_TYPE_EVENT = L"osp.setting.service.type.event"; - -static const wchar_t* _SETTING_COMMAND_GET_BOOL = L"osp.setting.command.get.bool"; -static const wchar_t* _SETTING_COMMAND_SET_BOOL = L"osp.setting.command.set.bool"; -static const wchar_t* _SETTING_COMMAND_SET_BOOL_ASYNC = L"osp.setting.command.set.bool.async"; -static const wchar_t* _SETTING_COMMAND_GET_BOOL_PRIV = L"osp.setting.command.get.bool.priv"; -static const wchar_t* _SETTING_COMMAND_SET_BOOL_PRIV = L"osp.setting.command.set.bool.priv"; -static const wchar_t* _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV = L"osp.setting.command.set.bool.async.priv"; - -static const wchar_t* _SETTING_COMMAND_GET_INT = L"osp.setting.command.get.int"; -static const wchar_t* _SETTING_COMMAND_SET_INT = L"osp.setting.command.set.int"; - -static const wchar_t* _SETTING_COMMAND_GET_STRING = L"osp.setting.command.get.string"; -static const wchar_t* _SETTING_COMMAND_SET_STRING = L"osp.setting.command.set.string"; -static const wchar_t* _SETTING_COMMAND_SET_STRING_PRIV = L"osp.setting.command.set.string.priv"; -static const wchar_t* _SETTING_COMMAND_SET_STRING_ASYNC = L"osp.setting.command.set.string.async"; - -static const wchar_t* _SETTING_COMMAND_ADD_EVENT = L"osp.setting.command.add.event"; -static const wchar_t* _SETTING_COMMAND_REMOVE_EVENT = L"osp.setting.command.remove.event"; - -static const wchar_t* _SETTING_COMMAND_SUPPORTED = L"osp.setting.command.supported"; - -static const wchar_t* _SETTING_RESULT_SUCCESS = L"osp.system.result.success"; -static const wchar_t* _SETTING_RESULT_SYSTEM = L"osp.system.result.system"; -static const wchar_t* _SETTING_RESULT_INVALID_ARG = L"osp.system.result.invalid_arg"; -static const wchar_t* _SETTING_RESULT_PRIVILEGE_DENIED = L"osp.system.result.privilege_denied"; -static const wchar_t* _SETTING_RESULT_UNSUPPORTED_OPERATION = L"osp.system.result.unsupported_operation"; -static const wchar_t* _SETTING_RESULT_OBJ_NOT_FOUND = L"osp.system.result.obj_not_found"; -static const wchar_t* _SETTING_RESULT_OBJ_ALREADY_EXIST = L"osp.system.result.obj_already_exist"; -static const wchar_t* _SETTING_RESULT_IN_PROGRESS = L"osp.system.result.in_progress"; +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 int SETTING_SERVICE_IPC_MSG_RESULT = 1; + +const static wchar_t* _SETTING_RESULT_SUCCESS = L"E_SUCCESS"; +const static wchar_t* _SETTING_RESULT_INVALID_ARG = L"E_INVALID_ARG"; +const static wchar_t* _SETTING_RESULT_PRIVILEGE_DENIED = L"E_PRIVILEGE_DENIED"; +const static wchar_t* _SETTING_RESULT_UNSUPPORTED_OPERATION = L"E_UNSUPPORTED_OPERATION"; +const static wchar_t* _SETTING_RESULT_OBJ_NOT_FOUND = L"E_OBJ_NOT_FOUND"; +const static wchar_t* _SETTING_RESULT_OBJ_ALREADY_EXIST = L"E_OBJ_ALREADY_EXIST"; +const static wchar_t* _SETTING_RESULT_IN_PROGRESS = L"E_IN_PROGRESS"; +const static wchar_t* _SETTING_RESULT_SYSTEM = L"E_SYSTEM"; _SettingClient* _SettingClient::__pSettingClient = null; -class _SettingEventArg : public IEventArg -{ -public: - String KeyName; -}; - -class _SettingEvent : public Event -{ -public: - _SettingEvent() - : __count(0) - { - } - - result AddSettingEventListener(ISettingEventListener& listener) - { - result r = AddListener(listener); - SysTryReturnResult(NID_SYS, __count >= 0, E_SYSTEM, "Listenr count[%d] is error.", __count); - - if(r == E_SUCCESS) - { - __count++; - } - return r; - } - - result RemoveSettingEventListener(ISettingEventListener& listener) - { - result r = RemoveListener(listener); - SysTryReturnResult(NID_SYS, __count > 0, E_SYSTEM, "Listenr count[%d] is error.", __count); - if(r == E_SUCCESS) - { - __count--; - } - return r; - } - - int GetCount(void) - { - return __count; - } - -private: - int __count; -protected: - virtual void FireImpl(IEventListener& listener, const IEventArg& arg) - { - ISettingEventListener* pListener = dynamic_cast (&listener); - const _SettingEventArg* pArg = dynamic_cast(&arg); - - if(pListener == null || pArg == null) - { - SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnt"); - return; - } - - String value =pArg->KeyName; - pListener->OnSettingChanged(value); - } -}; - -class _SettingAsyncEventArg : public IEventArg -{ -public: - String Key; - result errorCode; -}; - -class _SettingAsyncEvent : public Event -{ -protected: - virtual void FireImpl(IEventListener& listener, const IEventArg& arg) - { - ISettingInfoSetValueAsyncResultListener* pListener = dynamic_cast (&listener); - const _SettingAsyncEventArg* pArg = dynamic_cast(&arg); - - if(pListener == null || pArg == null) - { - SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnts [%x/%x].", pListener, pArg); - return; - } - - result r = pArg->errorCode; - pListener->OnResultReceivedForSetValueAsync(pArg->Key, r); - RemoveListener(listener); - } -}; +int common_service = 1; void _SettingClient::InitSettingClient(void) @@ -267,45 +190,79 @@ _SettingClient::GetInstance(void) } _SettingClient::_SettingClient() - : __pSettingEvent(null) - , __pSettingEventForInternal(null) - , __subscribed(false) - , __pIpcClient(null) + : __subscribed(false) + , __subscribedForInternal(false) , __pListener(null) + , __pSettingEvent(null) + , __pSettingEventForInternal(null) { result r = E_SUCCESS; - static String SETTING_SERVICE_ID(_SETTING_SERVICE_ID); - - __pSettingEvent = new (std::nothrow) _SettingEvent(); + static String serviceId(SETTING_SERVICE_ID); + + unique_ptr<_SettingEvent> settingEvent(new(nothrow) _SettingEvent()); + unique_ptr<_SettingEvent> settingEventForInternal(new(nothrow) _SettingEvent()); - __pSettingEventForInternal = new (std::nothrow) _SettingEvent(); + __pIpcClient = new (nothrow) _IpcClient(); + r = __pIpcClient->Construct(serviceId, this); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to construct IPC client."); + r = __asyncEventList.Construct(); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to construct asyn event list."); - _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance(); - SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient."); + SysTryCatch(NID_SYS, settingEvent.get() != null && settingEventForInternal.get() != null, r = E_SYSTEM, r, "It is failed to create event instances."); - r = pCommunicationDispatcherClient->RegisterCommunicationListener(SETTING_SERVICE_ID, *this); - SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient."); - - __pIpcClient = pCommunicationDispatcherClient->GetIpcClient(); - - __asyncEventList.Construct(); CATCH: + if(r == E_SUCCESS) + { + __pSettingEvent = settingEvent.release(); + __pSettingEventForInternal = settingEventForInternal.release(); + } SetLastResult(r); } _SettingClient::~_SettingClient() { + __subscribed = false; + __subscribedForInternal = false; + __pListener = null; + + if(__pSettingEvent != null) + { + delete __pSettingEvent; + } + + if(__pSettingEventForInternal != null) + { + delete __pSettingEventForInternal; + } +} + +void +_SettingClient::OnIpcServerDisconnected(_IpcClient& client) +{ result r = E_SUCCESS; - String key(_SETTING_SERVICE_ID); - _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance(); - SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient."); + int count = 0; + int max = 10; + SysLog(NID_SYS, "Common-service is down."); + delete __pIpcClient; + __pIpcClient = new (nothrow) _IpcClient(); - r = pCommunicationDispatcherClient->UnregisterCommunicationListener(key); - SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient."); + r = E_SYSTEM; + while(r != E_SUCCESS) + { + r = __pIpcClient->Construct(SETTING_SERVICE_ID, this); - __pIpcClient = null; -CATCH: - SetLastResult(r); + if(count == max) + { + break; + } + count ++; + Thread::Sleep(1000); + } + SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, r, "It is failed to establish connection to common-service."); + + __subscribed = false; + __subscribedForInternal = false; + SubscribeEvent(); } result @@ -522,67 +479,80 @@ result _SettingClient::GetOnService(String commandId, String key, String& response) { result r = E_SUCCESS; + + SysTryReturnResult(NID_SYS, commandId.GetLength() > 0 && key.GetLength() > 0, E_INVALID_ARG, "There are invalid parameters."); String requestKey = ConvertKeyOspToTizen(key); + String* pResult = null; + String* pValue = null; ArrayList requestMessages; ArrayList responseMessages; - requestMessages.Construct(); - responseMessages.Construct(); + r = requestMessages.Construct(); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct request message."); + r = responseMessages.Construct(); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct response message."); - String serviceId(_SETTING_SERVICE_ID); + r = requestMessages.Add(commandId); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add command id on request message."); + r = requestMessages.Add(requestKey); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required key on request message."); - requestMessages.Add(serviceId); - requestMessages.Add(commandId); - requestMessages.Add(requestKey); + IoService_Request message(requestMessages, &responseMessages); - unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); + r = __pIpcClient->SendRequest(message); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - r = __pIpcClient->SendRequest(*(pMsg.get())); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - - String* pResult = (String*)responseMessages.GetAt(2); - SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); + pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); + SysTryCatch(NID_SYS, pResult != null, r = E_SYSTEM, r, "There is no result code."); r = ConvertCode(*pResult); + if(r == E_SUCCESS) { - String* pValue = (String*)responseMessages.GetAt(3); - SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value."); + pValue = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); + SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "There is no result value."); response = *pValue; } + +CATCH: responseMessages.RemoveAll(true); return r; } result -_SettingClient::SetOnService(String commandId, String key, String& value) +_SettingClient::SetOnService(String commandId, String key, String value) { result r = E_SUCCESS; + + SysTryReturnResult(NID_SYS, commandId.GetLength() > 0 && key.GetLength() > 0, E_INVALID_ARG, "There are invalid parameters."); String requestKey = ConvertKeyOspToTizen(key); + String* pResult = null; ArrayList requestMessages; ArrayList responseMessages; - requestMessages.Construct(); - responseMessages.Construct(); + r = requestMessages.Construct(); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct request message."); + r = responseMessages.Construct(); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct response message."); - String serviceId(_SETTING_SERVICE_ID); + r = requestMessages.Add(commandId); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add command id on request message."); + r = requestMessages.Add(requestKey); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required key on request message."); + r = requestMessages.Add(value); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required value on request message."); - requestMessages.Add(serviceId); - requestMessages.Add(commandId); - requestMessages.Add(requestKey); - requestMessages.Add(value); + IoService_Request message(requestMessages, &responseMessages); - unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - r = __pIpcClient->SendRequest(*(pMsg.get())); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); + r = __pIpcClient->SendRequest(message); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - String* pResult = (String*)responseMessages.GetAt(2); - SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); - SysLog(NID_SYS, "Result is %ls.", pResult->GetPointer()); + pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); + SysTryCatch(NID_SYS, pResult != null, r = E_SYSTEM, r, "There is no result code."); r = ConvertCode(*pResult); - SysLog(NID_SYS, "r is %s.", GetErrorMessage(r)); +CATCH: responseMessages.RemoveAll(true); return r; } @@ -591,22 +561,18 @@ result _SettingClient::GetValue(const String& key, bool& value) { String response; - result r = GetOnService(_SETTING_COMMAND_GET_BOOL, key, response); + result r = GetOnService(SETTING_SERVICE_COMMAND_GET_BOOL, key, response); + SysLog(NID_SYS, "result is %ls.", response.GetPointer()); if(r == E_SUCCESS) { - if(response == L"0") - { - value = false; - } - else if(response == L"1") + if(response == L"1") { value = true; } else { - SysLogException(NID_SYS, E_SYSTEM, "There are wrong value [%ls].", key.GetPointer()); - return E_SYSTEM; + value = false; } } @@ -617,7 +583,7 @@ result _SettingClient::GetValue(const String& key, int& value) { String response; - result r = GetOnService(_SETTING_COMMAND_GET_INT, key, response); + result r = GetOnService(SETTING_SERVICE_COMMAND_GET_INT, key, response); if(r == E_SUCCESS) { @@ -660,11 +626,11 @@ _SettingClient::GetValue(const String& key, String& value) if(key == _LANGUAGE) //This is not full compatible. { - r = GetOnService(_SETTING_COMMAND_GET_STRING, _LOCALE_LANGUAGE, response); + r = GetOnService(SETTING_SERVICE_COMMAND_GET_STRING, _LOCALE_LANGUAGE, response); } else { - r = GetOnService(_SETTING_COMMAND_GET_STRING, key, response); + r = GetOnService(SETTING_SERVICE_COMMAND_GET_STRING, key, response); } if(r == E_SUCCESS) @@ -684,42 +650,15 @@ _SettingClient::GetValue(const String& key, String& value) result _SettingClient::GetValueForPrivilegedKey(const String& key, bool& value) { - String response; - result r = GetOnService(_SETTING_COMMAND_GET_BOOL_PRIV, key, response); - - if(r == E_SUCCESS) - { - if(response == L"0") - { - value = false; - } - else if(response == L"1") - { - value = true; - } - else - { - SysLogException(NID_SYS, E_SYSTEM, "There are wrong value [%ls].", key.GetPointer()); - return E_SYSTEM; - } - } - - return r; + return E_OBJ_NOT_FOUND; } result _SettingClient::SetValue(const String& key, const bool& value) { String requestValue; - if(value == true) - { - requestValue.Append("true"); - } - else - { - requestValue.Append("false"); - } - return SetOnService(_SETTING_COMMAND_SET_BOOL, key, requestValue); + requestValue = Boolean::ToString(value); + return SetOnService(SETTING_SERVICE_COMMAND_SET_BOOL, key, requestValue); } result @@ -727,7 +666,7 @@ _SettingClient::SetValue(const String& key, const int& value) { String requestValue; requestValue.Append(value); - return SetOnService(_SETTING_COMMAND_SET_INT, key, requestValue); + return SetOnService(SETTING_SERVICE_COMMAND_SET_INT, key, requestValue); } result @@ -735,22 +674,15 @@ _SettingClient::SetValue(const String& key, const String& value) { String requestValue; requestValue.Append(value); - return SetOnService(_SETTING_COMMAND_SET_STRING, key, requestValue); + return SetOnService(SETTING_SERVICE_COMMAND_SET_STRING, key, requestValue); } result _SettingClient::SetValueForPrivilegedKey(const String& key, bool value) { String requestValue; - if(value == true) - { - requestValue.Append("true"); - } - else - { - requestValue.Append("false"); - } - return SetOnService(_SETTING_COMMAND_SET_BOOL_PRIV, key, requestValue); + requestValue = Boolean::ToString(value); + return SetOnService(SETTING_SERVICE_COMMAND_SET_PRIV_BOOL, key, requestValue); } result @@ -758,7 +690,7 @@ _SettingClient::SetValueForPrivilegedKey(const String& key, String value) { String requestValue; requestValue.Append(value); - return SetOnService(_SETTING_COMMAND_SET_STRING_PRIV, key, requestValue); + return SetOnService(SETTING_SERVICE_COMMAND_SET_PRIV_STRING, key, requestValue); } @@ -770,16 +702,8 @@ _SettingClient::SetValueAsync(const String& key, bool value, ISettingInfoSetValu SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer()); - if(value == true) - { - requestValue.Append("true"); - } - else - { - requestValue.Append("false"); - } - - r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC, key, requestValue); + requestValue = Boolean::ToString(value); + r = SetOnService(SETTING_SERVICE_COMMAND_SET_ASYNC_BOOL, key, requestValue); if(r == E_SUCCESS) { @@ -803,16 +727,8 @@ _SettingClient::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISe SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer()); - if(value == true) - { - requestValue.Append("true"); - } - else - { - requestValue.Append("false"); - } - - r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC_PRIV, key, requestValue); + requestValue = Boolean::ToString(value); + r = SetOnService(SETTING_SERVICE_COMMAND_SET_PRIV_ASYNC_BOOL, key, requestValue); if(r == E_SUCCESS) { @@ -829,66 +745,53 @@ _SettingClient::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISe } void +_SettingClient::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message) +{ + IPC_BEGIN_MESSAGE_MAP(_SettingClient, message) + IPC_MESSAGE_HANDLER_EX(IoService_Data, &client, OnDataReceived) + IPC_END_MESSAGE_MAP_EX() +} + +void _SettingClient::OnDataReceived(const ArrayList& data) { result r = E_SUCCESS; - String* pServiceId = (String*)(data.GetAt(0)); - String* pResponseId = (String*)(data.GetAt(1)); - String* pKey = (String*)(data.GetAt(2)); + String* pCommandCode = (String*)data.GetAt(SETTING_SERVICE_IPC_MSG_COMMAND); + String* pKey = (String*)data.GetAt(SETTING_SERVICE_IPC_MSG_KEY); String* pValue = null; - SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service Id."); - SysTryReturnVoidResult(NID_SYS, pResponseId != null, E_SYSTEM, "There is response Id."); - SysTryReturnVoidResult(NID_SYS, pKey != null, E_SYSTEM, "There is no key."); + SysTryCatch(NID_SYS, pCommandCode != null && pKey != null, r = E_SYSTEM, r, "There is no valid data."); - SysLog(NID_SYS, "ServiceId: %ls, ResponseId: %ls, Key: %ls", pServiceId->GetPointer(), pResponseId->GetPointer(), pKey->GetPointer()); + SysLog(NID_SYS, "CommandCode: %ls", pCommandCode->GetPointer()); + SysLog(NID_SYS, "Key: %ls", pKey->GetPointer()); - if(*pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC || *pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV - || *pResponseId == _SETTING_COMMAND_SET_STRING_ASYNC) + if(*pCommandCode == SETTING_SERVICE_COMMAND_RESULT) { - pValue = (String*)(data.GetAt(3)); + pValue = (String*)(data.GetAt(SETTING_SERVICE_IPC_MSG_VALUE)); + SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "There is no valid value."); - SysTryReturnVoidResult(NID_SYS, pValue != null, E_SYSTEM, "There is no value."); - SysLog(NID_SYS, "Value: %ls", pValue->GetPointer()); + r = ConvertCode(*pValue); _SettingAsyncEvent* pEvent = dynamic_cast <_SettingAsyncEvent*> (__asyncEventList.GetValue(*pKey)); - r = ConvertCode(*pValue); - if(pEvent != null) - { - _SettingAsyncEventArg* pSettingAsyncEventArg = new (std::nothrow) _SettingAsyncEventArg; - pSettingAsyncEventArg->Key = *pKey; - pSettingAsyncEventArg->errorCode = r; - pEvent->Fire(*pSettingAsyncEventArg); - } - r = __asyncEventList.Remove(*pKey, true); + SysTryCatch(NID_SYS, pEvent != null, r = E_SYSTEM, r, "There is no reserved event."); + + _SettingAsyncEventArg* pSettingAsyncEventArg = new (std::nothrow) _SettingAsyncEventArg; + SysTryCatch(NID_SYS, pSettingAsyncEventArg != null, r = E_SYSTEM, r, "There is no reserved event."); + + pSettingAsyncEventArg->Key = *pKey; + pSettingAsyncEventArg->errorCode = r; + pEvent->Fire(*pSettingAsyncEventArg); + + r = __asyncEventList.Remove(*pKey, true); } - else if(*pResponseId == _SETTING_SERVICE_TYPE_EVENT) + else if(*pCommandCode == SETTING_SERVICE_COMMAND_EVENT) { SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready."); _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg(); pSettingEventArg->KeyName = *pKey; - - if(pSettingEventArg->KeyName == _LOCALE_LANGUAGE - || pSettingEventArg->KeyName == _LOCALE_COUNTRY - || pSettingEventArg->KeyName == _FONT_TYPE - || pSettingEventArg->KeyName == _FONT_SIZE) - { - if(__pSettingEventForInternal != null) - { - _SettingEventArg* pSettingEventArgForInternal = new (std::nothrow) _SettingEventArg(); - pSettingEventArgForInternal->KeyName = pSettingEventArg->KeyName; - __pSettingEventForInternal->Fire(*pSettingEventArgForInternal); - } - else - { - SysLogException(NID_SYS, E_SYSTEM, "Internal Event is not ready."); - } - } - - if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true) { String ospKey; @@ -904,13 +807,26 @@ _SettingClient::OnDataReceived(const ArrayList& data) __pSettingEvent->Fire(*pSettingEventArg); } } + else if(*pCommandCode == SETTING_SERVICE_COMMAND_EVENT_INTERNAL) + { + SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready."); + + _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg(); + pSettingEventArg->KeyName = *pKey; + + __pSettingEventForInternal->Fire(*pSettingEventArg); + } + +CATCH: + ArrayList* pData = const_cast< ArrayList *> (&data); + pData->RemoveAll(true); } bool _SettingClient::HasKey(const String& key) { String response; - result r = GetOnService(_SETTING_COMMAND_SUPPORTED, key, response); + result r = GetOnService(SETTING_SERVICE_COMMAND_SUPPORTED, key, response); SysLog(NID_SYS, "HasKey result key:%ls, %ls", key.GetPointer(), response.GetPointer()); if(response == L"1" && r == E_SUCCESS) @@ -964,69 +880,114 @@ _SettingClient::SubscribeEvent(void) _SettingEvent* pSettingEventForInternal = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal); SysTryReturnResult(NID_SYS, pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready."); - if(pSettingEvent->GetCount() > 0 || pSettingEventForInternal->GetCount() >0) + if(pSettingEvent->GetCount() > 0 && __subscribed == false) { - if(__subscribed == false) + ArrayList requestMessages; + ArrayList responseMessages; + + requestMessages.Construct(); + responseMessages.Construct(); + + String commandId(SETTING_SERVICE_COMMAND_SUBSCRIBE); + + requestMessages.Add(commandId); + + unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); + + r = __pIpcClient->SendRequest(*(pMsg.get())); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); + + String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); + SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); + r = ConvertCode(*pResult); + + if(r == E_SUCCESS) { - ArrayList requestMessages; - ArrayList responseMessages; + __subscribed = true; + } + responseMessages.RemoveAll(true); + } + else if(pSettingEvent->GetCount() == 0 && __subscribed == true) + { + ArrayList requestMessages; + ArrayList responseMessages; - requestMessages.Construct(); - responseMessages.Construct(); + requestMessages.Construct(); + responseMessages.Construct(); - String serviceId(_SETTING_SERVICE_ID); - String eventId(_SETTING_COMMAND_ADD_EVENT); + String commandId(SETTING_SERVICE_COMMAND_UNSUBSCRIBE); - requestMessages.Add(serviceId); - requestMessages.Add(eventId); + requestMessages.Add(commandId); - unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); + unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - r = __pIpcClient->SendRequest(*(pMsg.get())); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); + r = __pIpcClient->SendRequest(*(pMsg.get())); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - String* pResult = (String*)responseMessages.GetAt(2); - SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); - r = ConvertCode(*pResult); + String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); + SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); + r = ConvertCode(*pResult); - if(r == E_SUCCESS) - { - __subscribed = true; - } - responseMessages.RemoveAll(true); + if(r == E_SUCCESS) + { + __subscribed = false; } + responseMessages.RemoveAll(true); } - else if(pSettingEvent->GetCount() == 0 && pSettingEventForInternal->GetCount() == 0) + + if(pSettingEventForInternal->GetCount() > 0 && __subscribedForInternal == false) { - if(__subscribed == true) + ArrayList requestMessages; + ArrayList responseMessages; + + requestMessages.Construct(); + responseMessages.Construct(); + + String commandId(SETTING_SERVICE_COMMAND_SUBSCRIBE_INTERNAL); + + requestMessages.Add(commandId); + + unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); + + r = __pIpcClient->SendRequest(*(pMsg.get())); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); + + String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); + SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); + r = ConvertCode(*pResult); + + if(r == E_SUCCESS) { - ArrayList requestMessages; - ArrayList responseMessages; + __subscribedForInternal = true; + } + responseMessages.RemoveAll(true); + } + else if(pSettingEventForInternal->GetCount() == 0 && __subscribedForInternal == true) + { + ArrayList requestMessages; + ArrayList responseMessages; - requestMessages.Construct(); - responseMessages.Construct(); + requestMessages.Construct(); + responseMessages.Construct(); - String serviceId(_SETTING_SERVICE_ID); - String eventId(_SETTING_COMMAND_REMOVE_EVENT); + String commandId(SETTING_SERVICE_COMMAND_UNSUBSCRIBE_INTERNAL); - requestMessages.Add(serviceId); - requestMessages.Add(eventId); + requestMessages.Add(commandId); - unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); + unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - r = __pIpcClient->SendRequest(*(pMsg.get())); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); + r = __pIpcClient->SendRequest(*(pMsg.get())); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - String* pResult = (String*)responseMessages.GetAt(2); - SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); - r = ConvertCode(*pResult); + String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); + SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); + r = ConvertCode(*pResult); - if(r == E_SUCCESS) - { - __subscribed = false; - } - responseMessages.RemoveAll(true); + if(r == E_SUCCESS) + { + __subscribedForInternal = false; } + responseMessages.RemoveAll(true); } return r; @@ -1040,10 +1001,13 @@ _SettingClient::AddSettingEventListener(ISettingEventListener& listener) SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready."); result r = pSettingEvent->AddSettingEventListener(listener); - if (r == E_INVALID_OPERATION) + + if (r == E_OBJ_ALREADY_EXIST) { - r = E_SYSTEM; + SysLogException(NID_SYS, E_OBJ_ALREADY_EXIST, "It is already registered."); + return E_OBJ_ALREADY_EXIST; } + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add event listener."); r = SubscribeEvent(); @@ -1060,8 +1024,13 @@ _SettingClient::RemoveSettingEventListener(ISettingEventListener& listener) SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready."); result r = pSettingEvent->RemoveSettingEventListener(listener); - - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to remove event listener."); + + if (r == E_OBJ_NOT_FOUND) + { + SysLogException(NID_SYS, E_OBJ_NOT_FOUND, "It is not registered."); + return E_OBJ_NOT_FOUND; + } + SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to remove event listener.[%s]", GetErrorMessage(r)); r = SubscribeEvent(); SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener."); diff --git a/src/system/FSys_SettingClient.h b/src/system/FSys_SettingClient.h index ef9ef98..fc1333e 100644 --- a/src/system/FSys_SettingClient.h +++ b/src/system/FSys_SettingClient.h @@ -22,8 +22,6 @@ #ifndef _FSYSTEM_INTERNAL_SETTING_CLIENT_H_ #define _FSYSTEM_INTERNAL_SETTING_CLIENT_H_ -#include - #include #include #include @@ -34,15 +32,109 @@ #include #include #include -#include #include +#include +#include + namespace Tizen { namespace System { +class _SettingEventArg : public Tizen::Base::Runtime::IEventArg +{ +public: + Tizen::Base::String KeyName; +}; + +class _SettingEvent : public Tizen::Base::Runtime::Event +{ +public: + _SettingEvent() + : __count(0) + { + } + + result AddSettingEventListener(ISettingEventListener& listener) + { + result r = AddListener(listener); + SysTryReturnResult(NID_SYS, __count >= 0, E_SYSTEM, "Listenr count[%d] is error.", __count); + + if(r == E_SUCCESS) + { + __count++; + } + return r; + } + + result RemoveSettingEventListener(ISettingEventListener& listener) + { + result r = RemoveListener(listener); + if(r == E_OBJ_NOT_FOUND) + { + return E_OBJ_NOT_FOUND; + } + SysTryReturnResult(NID_SYS, __count > 0, E_SYSTEM, "Listenr count[%d] is error.", __count); + if(r == E_SUCCESS) + { + __count--; + } + return r; + } + + int GetCount(void) + { + return __count; + } + +private: + int __count; +protected: + virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) + { + ISettingEventListener* pListener = dynamic_cast (&listener); + const _SettingEventArg* pArg = dynamic_cast(&arg); + + if(pListener == null || pArg == null) + { + SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnt"); + return; + } + + Tizen::Base::String value =pArg->KeyName; + pListener->OnSettingChanged(value); + } +}; + +class _SettingAsyncEventArg : public Tizen::Base::Runtime::IEventArg +{ +public: + Tizen::Base::String Key; + result errorCode; +}; + +class _SettingAsyncEvent : public Tizen::Base::Runtime::Event +{ +protected: + virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) + { + ISettingInfoSetValueAsyncResultListener* pListener = dynamic_cast (&listener); + const _SettingAsyncEventArg* pArg = dynamic_cast(&arg); + + if(pListener == null || pArg == null) + { + SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnts [%x/%x].", pListener, pArg); + return; + } + + result r = pArg->errorCode; + pListener->OnResultReceivedForSetValueAsync(pArg->Key, r); + RemoveListener(listener); + } +}; + class _SettingClient : public Tizen::Base::Object - , public Tizen::System::_ICommunicationDispatcherListener + , public Tizen::Io::_IIpcClientEventListener { private: _SettingClient(void); @@ -76,6 +168,9 @@ public: result ResetToFactoryDefault(void); + void OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message); + void OnIpcServerDisconnected(Tizen::Io::_IpcClient& client); + static _SettingClient* GetInstance(void); private: @@ -86,23 +181,23 @@ private: result ConvertKeyTizenToOsp(Tizen::Base::String tizenKey, Tizen::Base::String& ospKey); result GetOnService(Tizen::Base::String commandId, Tizen::Base::String key, Tizen::Base::String& response); - result SetOnService(Tizen::Base::String commandId, Tizen::Base::String key, Tizen::Base::String& value); + result SetOnService(Tizen::Base::String commandId, Tizen::Base::String key, Tizen::Base::String value); result SetVolume(const Tizen::Base::String& soundCategory, int level); result SubscribeEvent(void); static void InitSettingClient(void); private: - Tizen::Base::Collection::HashMap __asyncEventList; - Tizen::Base::Runtime::Event* __pSettingEvent; - Tizen::Base::Runtime::Event* __pSettingEventForInternal; - bool __subscribed; + Tizen::Base::Collection::HashMap __asyncEventList; + Tizen::Io::_IpcClient* __pIpcClient; - Tizen::Io::_IpcClient* __pIpcClient; - ISettingEventListener* __pListener; + bool __subscribed; + bool __subscribedForInternal; + ISettingEventListener* __pListener; + _SettingEvent* __pSettingEvent; + _SettingEvent* __pSettingEventForInternal; static _SettingClient* __pSettingClient; - }; } } // Tizen::System diff --git a/src/system/FSys_SettingClientEx.cpp b/src/system/FSys_SettingClientEx.cpp deleted file mode 100644 index bcaa8bc..0000000 --- a/src/system/FSys_SettingClientEx.cpp +++ /dev/null @@ -1,1104 +0,0 @@ -// -// 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_SettingClientEx.cpp - * @brief This is the implementation file for _SettingClientEx class. - */ - -#include - -#include -#include -#include - -#include -#include - -#include "FSys_CommunicationDispatcherClient.h" -#include "FSys_SettingClientEx.h" - -using namespace std; - -using namespace Tizen::App; -using namespace Tizen::Base; -using namespace Tizen::Base::Collection; -using namespace Tizen::Base::Runtime; -using namespace Tizen::Io; - -namespace Tizen { namespace System -{ -//MOTION -static const wchar_t* _MOTION_UI = L"http://tizen.org/setting/motion.ui"; -static const wchar_t* _ENABLE_MOTION = L"EnableMotion"; - -//Font -static const wchar_t* _FONT_SIZE = L"http://tizen.org/setting/font.size"; -static const wchar_t* _FONTSIZE = L"FontSize"; - -static const wchar_t* _FONT_TYPE = L"http://tizen.org/setting/font.type"; -static const wchar_t* _FONTTYPE = L"FontType"; - - -//Locale -//Locale Country -static const wchar_t* _LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country"; -static const wchar_t* _COUNTRY = L"Country"; - -//Locale Format -static const wchar_t* _LOCALE_DATE_FORMAT = L"http://tizen.org/setting/locale.date.format"; -static const wchar_t* _DATE_FORMAT = L"DateFormat"; - -static const wchar_t* _LOCALE_TIME_FORMAT = L"http://tizen.org/setting/locale.time.format"; -static const wchar_t* _TIME_FORMAT = L"TimeFormat"; - -static const wchar_t* _LOCALE_TIME_FORMAT_24HOUR = L"http://tizen.org/setting/locale.time.format.24hour"; -static const wchar_t* _HOUR_FORMAT_SELECTED = L"24HourFormatSelected"; - -//Locale Language -static const wchar_t* _LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language"; -static const wchar_t* _LANGUAGE = L"Language"; - -//Locale Time -static const wchar_t* _LOCALE_DATETIME_FORMAT = L"http://tizen.org/setting/locale.date_time.format"; -static const wchar_t* _DATE_TIME_FORMAT = L"DateTimeFormat"; - - -//Location -static const wchar_t* _LOCATION_GPS = L"http://tizen.org/setting/location.gps"; -static const wchar_t* _GPS_ENABLED = L"GPSEnabled"; - -static const wchar_t* _LOCATION_WPS = L"http://tizen.org/setting/location.wps"; -static const wchar_t* _WPS_ENABLED = L"WPSEnabled"; - -//Network -static const wchar_t* _NETWORK_FLIGHTMODE = L"http://tizen.org/setting/network.flight_mode"; -static const wchar_t* _FLIGHT_MODE_ENABLED = L"FlightModeEnabled"; - -//Network Telephony -static const wchar_t* _NETWORK_TELEPHONY_PACKETSERVICE = L"http://tizen.org/setting/network.telephony.packet_service"; -static const wchar_t* _PACKET_SERVICE_ALLOWED = L"PacketServiceAllowed"; - -static const wchar_t* _NETWORK_TELEPHONY_ROAMING = L"http://tizen.org/setting/network.telephony.roaming"; -static const wchar_t* _DATA_ROAMING_ENABLED = L"DataRoamingEnabled"; - -//Screen -static const wchar_t* _SCREEN_WALLPAPER = L"http://tizen.org/setting/screen.wallpaper"; -static const wchar_t* _WALLPAPER = L"Wallpaper"; - -//Sound -static const wchar_t* _SOUND_MEDIA_VOLUME = L"http://tizen.org/setting/sound.media.volume"; -static const wchar_t* _MEDIA_SOUND_VOLUME = L"MediaSoundVolume"; - -static const wchar_t* _SOUND_NOTIFICATION_VOLUME = L"http://tizen.org/setting/sound.notification.volume"; -static const wchar_t* _NOTIFICATION_SOUND_VOLUME = L"NotificationSoundVolume"; - -static const wchar_t* _SOUND_RINGTONE = L"http://tizen.org/setting/sound.ringtone"; -static const wchar_t* _RINGTONE = L"Ringtone"; - -static const wchar_t* _SOUND_RINGTONE_VOLUME = L"http://tizen.org/setting/sound.ringtone.volume"; -static const wchar_t* _RINGTONE_SOUND_VOLUME = L"RingtoneSoundVolume"; - -static const wchar_t* _SOUND_SYSTEM_VOLUME = L"http://tizen.org/setting/sound.system.volume"; -static const wchar_t* _SYSTEM_SOUND_VOLUME = L"SystemSoundVolume"; - -static const wchar_t* _SOUND_SILENTMODE = L"http://tizen.org/setting/sound.silent_mode"; -static const wchar_t* _SILENT_MODE = L"SilentMode"; - -//Vibration -static const wchar_t* _TOUCH_VIBRATION_LEVEL = L"TouchVibrationLevel"; -static const wchar_t* _VIBRATOR_LEVEL = L"http://tizen.org/setting/vibrator.level"; - -static const wchar_t* _SETTING_COMMAND_FACTORY_RESET = L"osp.setting.command.factory.reset"; - -//USB -static const wchar_t* _USBMODE = L"UsbMode"; -static const wchar_t* _USBMODE_MTP = L"MTP"; - -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 int SETTING_SERVICE_IPC_MSG_RESULT = 1; - -const static wchar_t* _SETTING_RESULT_SUCCESS = L"E_SUCCESS"; -const static wchar_t* _SETTING_RESULT_INVALID_ARG = L"E_INVALID_ARG"; -const static wchar_t* _SETTING_RESULT_PRIVILEGE_DENIED = L"E_PRIVILEGE_DENIED"; -const static wchar_t* _SETTING_RESULT_UNSUPPORTED_OPERATION = L"E_UNSUPPORTED_OPERATION"; -const static wchar_t* _SETTING_RESULT_OBJ_NOT_FOUND = L"E_OBJ_NOT_FOUND"; -const static wchar_t* _SETTING_RESULT_OBJ_ALREADY_EXIST = L"E_OBJ_ALREADY_EXIST"; -const static wchar_t* _SETTING_RESULT_IN_PROGRESS = L"E_IN_PROGRESS"; -const static wchar_t* _SETTING_RESULT_SYSTEM = L"E_SYSTEM"; - -_SettingClientEx* _SettingClientEx::__pSettingClient = null; - -int common_service = 1; - -void -_SettingClientEx::InitSettingClient(void) -{ - static _SettingClientEx settingManager; - __pSettingClient = &settingManager; -} - -_SettingClientEx* -_SettingClientEx::GetInstance(void) -{ - static pthread_once_t once_block = PTHREAD_ONCE_INIT; - if(__pSettingClient == null) - { - pthread_once(&once_block, InitSettingClient); - } - return __pSettingClient; -} - -_SettingClientEx::_SettingClientEx() - : __subscribed(false) - , __subscribedForInternal(false) - , __pListener(null) - , __pSettingEvent(null) - , __pSettingEventForInternal(null) -{ - result r = E_SUCCESS; - static String serviceId(SETTING_SERVICE_ID); - - unique_ptr<_SettingEvent> settingEvent(new(nothrow) _SettingEvent()); - unique_ptr<_SettingEvent> settingEventForInternal(new(nothrow) _SettingEvent()); - - __pIpcClient = new (nothrow) _IpcClient(); - r = __pIpcClient->Construct(serviceId, this); - SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to construct IPC client."); - r = __asyncEventList.Construct(); - SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to construct asyn event list."); - - SysTryCatch(NID_SYS, settingEvent.get() != null && settingEventForInternal.get() != null, r = E_SYSTEM, r, "It is failed to create event instances."); - -CATCH: - if(r == E_SUCCESS) - { - __pSettingEvent = settingEvent.release(); - __pSettingEventForInternal = settingEventForInternal.release(); - } - SetLastResult(r); -} - -_SettingClientEx::~_SettingClientEx() -{ - __subscribed = false; - __subscribedForInternal = false; - __pListener = null; - - if(__pSettingEvent != null) - { - delete __pSettingEvent; - } - - if(__pSettingEventForInternal != null) - { - delete __pSettingEventForInternal; - } -} - -void -_SettingClientEx::OnIpcServerDisconnected(_IpcClient& client) -{ - result r = E_SUCCESS; - int count = 0; - int max = 10; - SysLog(NID_SYS, "Common-service is down."); - delete __pIpcClient; - __pIpcClient = new (nothrow) _IpcClient(); - - r = E_SYSTEM; - while(r != E_SUCCESS) - { - r = __pIpcClient->Construct(SETTING_SERVICE_ID, this); - - if(count == max) - { - break; - } - count ++; - Thread::Sleep(1000); - } - SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, r, "It is failed to establish connection to common-service."); - - __subscribed = false; - __subscribedForInternal = false; - SubscribeEvent(); -} - -result -_SettingClientEx::ConvertCode(String code) -{ - result r = E_SUCCESS; - if(code == _SETTING_RESULT_SUCCESS) - { - r = E_SUCCESS; - } - else if(code == _SETTING_RESULT_INVALID_ARG) - { - r = E_INVALID_ARG; - } - else if(code == _SETTING_RESULT_PRIVILEGE_DENIED) - { - r = E_PRIVILEGE_DENIED; - } - else if(code == _SETTING_RESULT_UNSUPPORTED_OPERATION) - { - r = E_UNSUPPORTED_OPERATION; - } - else if(code == _SETTING_RESULT_OBJ_NOT_FOUND) - { - r = E_OBJ_NOT_FOUND; - } - else if(code == _SETTING_RESULT_OBJ_ALREADY_EXIST) - { - r = E_OBJ_ALREADY_EXIST; - } - else if(code == _SETTING_RESULT_IN_PROGRESS) - { - r = E_IN_PROGRESS; - } - else if(code == _SETTING_RESULT_SYSTEM) - { - r = E_SYSTEM; - } - else - { - r = E_SYSTEM; - } - return r; -} - -String -_SettingClientEx::ConvertKeyOspToTizen(String ospKey) -{ - String tizenKey = ospKey; - - if(tizenKey == _HOUR_FORMAT_SELECTED) - tizenKey = _LOCALE_TIME_FORMAT_24HOUR; - - else if(tizenKey == _ENABLE_MOTION) - tizenKey = _MOTION_UI; - - else if(tizenKey == _DATA_ROAMING_ENABLED) - tizenKey = _NETWORK_TELEPHONY_ROAMING; - - else if(tizenKey == _GPS_ENABLED) - tizenKey = _LOCATION_GPS; - - else if(tizenKey == _PACKET_SERVICE_ALLOWED) - tizenKey = _NETWORK_TELEPHONY_PACKETSERVICE; - - else if(tizenKey == _SILENT_MODE) - tizenKey = _SOUND_SILENTMODE; - - else if(tizenKey == _WPS_ENABLED) - tizenKey = _LOCATION_WPS; - - else if(tizenKey == _FLIGHT_MODE_ENABLED) - tizenKey = _NETWORK_FLIGHTMODE; - - else if(tizenKey == _TOUCH_VIBRATION_LEVEL) - tizenKey = _VIBRATOR_LEVEL; - - else if(tizenKey == _MEDIA_SOUND_VOLUME) - tizenKey = _SOUND_MEDIA_VOLUME; - - else if(tizenKey == _NOTIFICATION_SOUND_VOLUME) - tizenKey = _SOUND_NOTIFICATION_VOLUME; - - else if(tizenKey == _RINGTONE_SOUND_VOLUME) - tizenKey = _SOUND_RINGTONE_VOLUME; - - else if(tizenKey == _SYSTEM_SOUND_VOLUME) - tizenKey = _SOUND_SYSTEM_VOLUME; - - else if(tizenKey == _COUNTRY) - tizenKey = _LOCALE_COUNTRY; - - else if(tizenKey == _DATE_FORMAT) - tizenKey = _LOCALE_DATE_FORMAT; - - else if(tizenKey == _DATE_TIME_FORMAT) - tizenKey = _LOCALE_DATETIME_FORMAT; - - else if(tizenKey == _FONTTYPE) - tizenKey = _FONT_TYPE; - - else if(tizenKey == _FONTSIZE) - tizenKey = _FONT_SIZE; - - else if(tizenKey == _RINGTONE) - tizenKey = _SOUND_RINGTONE; - - else if(tizenKey == _TIME_FORMAT) - tizenKey = _LOCALE_TIME_FORMAT; - - else if(tizenKey == _WALLPAPER) - tizenKey = _SCREEN_WALLPAPER; - - return tizenKey; -} - -result -_SettingClientEx::ConvertKeyTizenToOsp(String tizenKey, String& ospKey) -{ - result r = E_SUCCESS; - if(tizenKey == _LOCALE_TIME_FORMAT_24HOUR) - { - ospKey = _HOUR_FORMAT_SELECTED; - } - else if(tizenKey == _MOTION_UI) - { - ospKey = _ENABLE_MOTION; - } - else if(tizenKey == _NETWORK_TELEPHONY_ROAMING) - { - ospKey = _DATA_ROAMING_ENABLED; - } - else if(tizenKey == _LOCATION_GPS) - { - ospKey = _GPS_ENABLED; - } - else if(tizenKey == _NETWORK_TELEPHONY_PACKETSERVICE) - { - ospKey = _PACKET_SERVICE_ALLOWED; - } - else if(tizenKey == _SOUND_SILENTMODE) - { - ospKey = _SILENT_MODE; - } - else if(tizenKey == _LOCATION_WPS) - { - ospKey = _WPS_ENABLED; - } - else if(tizenKey == _NETWORK_FLIGHTMODE) - { - ospKey = _FLIGHT_MODE_ENABLED; - } - else if(tizenKey == _VIBRATOR_LEVEL) - { - ospKey = _TOUCH_VIBRATION_LEVEL; - } - else if(tizenKey == _SOUND_MEDIA_VOLUME) - { - ospKey = _MEDIA_SOUND_VOLUME; - } - else if(tizenKey == _SOUND_NOTIFICATION_VOLUME) - { - ospKey = _NOTIFICATION_SOUND_VOLUME; - } - else if(tizenKey == _SOUND_RINGTONE_VOLUME) - { - ospKey = _RINGTONE_SOUND_VOLUME; - } - else if(tizenKey == _SOUND_SYSTEM_VOLUME) - { - ospKey = _SYSTEM_SOUND_VOLUME; - } - else if(tizenKey == _LOCALE_COUNTRY) - { - ospKey = _COUNTRY; - } - else if(tizenKey == _LOCALE_DATE_FORMAT) - { - ospKey = _DATE_FORMAT; - } - else if(tizenKey == _LOCALE_DATETIME_FORMAT) - { - ospKey = _DATE_TIME_FORMAT; - } - else if(tizenKey == _FONT_TYPE) - { - ospKey = _FONTTYPE; - } - else if(tizenKey == _FONT_SIZE) - { - ospKey = _FONTSIZE; - } - else if(tizenKey == _SOUND_RINGTONE) - { - ospKey = _RINGTONE; - } - else if(tizenKey == _LOCALE_TIME_FORMAT) - { - ospKey = _TIME_FORMAT; - } - else if(tizenKey == _SCREEN_WALLPAPER) - { - ospKey = _WALLPAPER; - } - else - { - r = E_INVALID_ARG; - } - - return r; -} - -result -_SettingClientEx::GetOnService(String commandId, String key, String& response) -{ - result r = E_SUCCESS; - - SysTryReturnResult(NID_SYS, commandId.GetLength() > 0 && key.GetLength() > 0, E_INVALID_ARG, "There are invalid parameters."); - String requestKey = ConvertKeyOspToTizen(key); - String* pResult = null; - String* pValue = null; - - ArrayList requestMessages; - ArrayList responseMessages; - - r = requestMessages.Construct(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct request message."); - r = responseMessages.Construct(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct response message."); - - r = requestMessages.Add(commandId); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add command id on request message."); - r = requestMessages.Add(requestKey); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required key on request message."); - - IoService_Request message(requestMessages, &responseMessages); - - r = __pIpcClient->SendRequest(message); - SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - - pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); - SysTryCatch(NID_SYS, pResult != null, r = E_SYSTEM, r, "There is no result code."); - r = ConvertCode(*pResult); - - if(r == E_SUCCESS) - { - pValue = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_VALUE); - SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "There is no result value."); - response = *pValue; - } - -CATCH: - responseMessages.RemoveAll(true); - return r; -} - -result -_SettingClientEx::SetOnService(String commandId, String key, String value) -{ - result r = E_SUCCESS; - - SysTryReturnResult(NID_SYS, commandId.GetLength() > 0 && key.GetLength() > 0, E_INVALID_ARG, "There are invalid parameters."); - String requestKey = ConvertKeyOspToTizen(key); - String* pResult = null; - - ArrayList requestMessages; - ArrayList responseMessages; - - r = requestMessages.Construct(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct request message."); - r = responseMessages.Construct(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct response message."); - - r = requestMessages.Add(commandId); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add command id on request message."); - r = requestMessages.Add(requestKey); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required key on request message."); - r = requestMessages.Add(value); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required value on request message."); - - IoService_Request message(requestMessages, &responseMessages); - - r = __pIpcClient->SendRequest(message); - SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - - pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); - SysTryCatch(NID_SYS, pResult != null, r = E_SYSTEM, r, "There is no result code."); - r = ConvertCode(*pResult); - -CATCH: - responseMessages.RemoveAll(true); - return r; -} - -result -_SettingClientEx::GetValue(const String& key, bool& value) -{ - String response; - result r = GetOnService(SETTING_SERVICE_COMMAND_GET_BOOL, key, response); - - SysLog(NID_SYS, "result is %ls.", response.GetPointer()); - if(r == E_SUCCESS) - { - if(response == L"1") - { - value = true; - } - else - { - value = false; - } - } - - return r; -} - -result -_SettingClientEx::GetValue(const String& key, int& value) -{ - String response; - result r = GetOnService(SETTING_SERVICE_COMMAND_GET_INT, key, response); - - if(r == E_SUCCESS) - { - r = Integer::Parse(response, value); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to convert to integer from [%s]", response.GetPointer()); - } - - return r; -} - -result -_SettingClientEx::GetValue(const String& key, long long& value) -{ - return E_OBJ_NOT_FOUND; -} - -result -_SettingClientEx::GetValue(const String& key, double& value) -{ - return E_OBJ_NOT_FOUND; -} - -result -_SettingClientEx::GetValue(const String& key, UuId& value) -{ - return E_OBJ_NOT_FOUND; -} - -result -_SettingClientEx::GetValue(const String& key, String& value) -{ - String response; - result r = E_SUCCESS; - - if(key == _USBMODE) //This is compatible issue. USB mode is fixed on Tizen. - { - value = _USBMODE_MTP; - return E_SUCCESS; - } - - if(key == _LANGUAGE) //This is not full compatible. - { - r = GetOnService(SETTING_SERVICE_COMMAND_GET_STRING, _LOCALE_LANGUAGE, response); - } - else - { - r = GetOnService(SETTING_SERVICE_COMMAND_GET_STRING, key, response); - } - - if(r == E_SUCCESS) - { - value = response; - } - - if(key == _LANGUAGE) //This is not full compatible. - { - r = value.SubString(0, 3, value); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to sub string on %ls.", value.GetPointer()); - } - - return r; -} - -result -_SettingClientEx::GetValueForPrivilegedKey(const String& key, bool& value) -{ - return E_OBJ_NOT_FOUND; -} - -result -_SettingClientEx::SetValue(const String& key, const bool& value) -{ - String requestValue; - requestValue = Boolean::ToString(value); - return SetOnService(SETTING_SERVICE_COMMAND_SET_BOOL, key, requestValue); -} - -result -_SettingClientEx::SetValue(const String& key, const int& value) -{ - String requestValue; - requestValue.Append(value); - return SetOnService(SETTING_SERVICE_COMMAND_SET_INT, key, requestValue); -} - -result -_SettingClientEx::SetValue(const String& key, const String& value) -{ - String requestValue; - requestValue.Append(value); - return SetOnService(SETTING_SERVICE_COMMAND_SET_STRING, key, requestValue); -} - -result -_SettingClientEx::SetValueForPrivilegedKey(const String& key, bool value) -{ - String requestValue; - requestValue = Boolean::ToString(value); - return SetOnService(SETTING_SERVICE_COMMAND_SET_PRIV_BOOL, key, requestValue); -} - -result -_SettingClientEx::SetValueForPrivilegedKey(const String& key, String value) -{ - String requestValue; - requestValue.Append(value); - return SetOnService(SETTING_SERVICE_COMMAND_SET_PRIV_STRING, key, requestValue); -} - - -result -_SettingClientEx::SetValueAsync(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener) -{ - result r = E_SUCCESS; - String requestValue; - - SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer()); - - requestValue = Boolean::ToString(value); - r = SetOnService(SETTING_SERVICE_COMMAND_SET_ASYNC_BOOL, key, requestValue); - - if(r == E_SUCCESS) - { - if(listener != null) - { - _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent(); - pEvent->AddListener(*listener); - - __asyncEventList.Add(new String(key), pEvent); - } - } - - return r; -} - -result -_SettingClientEx::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener) -{ - result r = E_SUCCESS; - String requestValue; - - SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer()); - - requestValue = Boolean::ToString(value); - r = SetOnService(SETTING_SERVICE_COMMAND_SET_PRIV_ASYNC_BOOL, key, requestValue); - - if(r == E_SUCCESS) - { - if(listener != null) - { - _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent(); - pEvent->AddListener(*listener); - - __asyncEventList.Add(new String(key), pEvent); - } - } - - return r; -} - -void -_SettingClientEx::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message) -{ - IPC_BEGIN_MESSAGE_MAP(_SettingClientEx, message) - IPC_MESSAGE_HANDLER_EX(IoService_Data, &client, OnDataReceived) - IPC_END_MESSAGE_MAP_EX() -} - -void -_SettingClientEx::OnDataReceived(const ArrayList& data) -{ - result r = E_SUCCESS; - String* pCommandCode = (String*)data.GetAt(SETTING_SERVICE_IPC_MSG_COMMAND); - String* pKey = (String*)data.GetAt(SETTING_SERVICE_IPC_MSG_KEY); - String* pValue = null; - - SysTryCatch(NID_SYS, pCommandCode != null && pKey != null, r = E_SYSTEM, r, "There is no valid data."); - - SysLog(NID_SYS, "CommandCode: %ls", pCommandCode->GetPointer()); - SysLog(NID_SYS, "Key: %ls", pKey->GetPointer()); - - if(*pCommandCode == SETTING_SERVICE_COMMAND_RESULT) - { - pValue = (String*)(data.GetAt(SETTING_SERVICE_IPC_MSG_VALUE)); - SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "There is no valid value."); - - r = ConvertCode(*pValue); - - _SettingAsyncEvent* pEvent = dynamic_cast <_SettingAsyncEvent*> (__asyncEventList.GetValue(*pKey)); - - SysTryCatch(NID_SYS, pEvent != null, r = E_SYSTEM, r, "There is no reserved event."); - - _SettingAsyncEventArg* pSettingAsyncEventArg = new (std::nothrow) _SettingAsyncEventArg; - SysTryCatch(NID_SYS, pSettingAsyncEventArg != null, r = E_SYSTEM, r, "There is no reserved event."); - - pSettingAsyncEventArg->Key = *pKey; - pSettingAsyncEventArg->errorCode = r; - pEvent->Fire(*pSettingAsyncEventArg); - - r = __asyncEventList.Remove(*pKey, true); - } - else if(*pCommandCode == SETTING_SERVICE_COMMAND_EVENT) - { - SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready."); - - _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg(); - pSettingEventArg->KeyName = *pKey; - - if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true) - { - String ospKey; - r = ConvertKeyTizenToOsp(pSettingEventArg->KeyName, ospKey); - if(r == E_SUCCESS) - { - pSettingEventArg->KeyName = ospKey; - __pSettingEvent->Fire(*pSettingEventArg); - } - } - else - { - __pSettingEvent->Fire(*pSettingEventArg); - } - } - else if(*pCommandCode == SETTING_SERVICE_COMMAND_EVENT_INTERNAL) - { - SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready."); - - _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg(); - pSettingEventArg->KeyName = *pKey; - - __pSettingEventForInternal->Fire(*pSettingEventArg); - } - -CATCH: - ArrayList* pData = const_cast< ArrayList *> (&data); - pData->RemoveAll(true); -} - -bool -_SettingClientEx::HasKey(const String& key) -{ - String response; - result r = GetOnService(SETTING_SERVICE_COMMAND_SUPPORTED, key, response); - - SysLog(NID_SYS, "HasKey result key:%ls, %ls", key.GetPointer(), response.GetPointer()); - if(response == L"1" && r == E_SUCCESS) - { - return true; - } - return false; -} - -result -_SettingClientEx::ResetToFactoryDefault(void) -{ - String value; - String response; - value = "none"; - result r = GetOnService(_SETTING_COMMAND_FACTORY_RESET, value, response); - SysLog(NID_SYS, "Reset result is %s[%ls].", GetErrorMessage(r), response.GetPointer()); - return r; -} - -//For OSP_COMPAT mode -result -_SettingClientEx::SetVolume(const String& soundCategory, int level) -{ - result r = SetValue(soundCategory, level); - if (r == E_INVALID_ARG) - { - r = E_OUT_OF_RANGE; - } - else if(r == E_OBJ_NOT_FOUND) - { - r = E_INVALID_ARG; - } - else if(r == E_UNSUPPORTED_OPERATION) - { - r = E_SYSTEM; - } - return r; -} - -//Event Management -result -_SettingClientEx::SubscribeEvent(void) -{ - result r = E_SUCCESS; - SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready."); - _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent); - SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready."); - - SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready."); - _SettingEvent* pSettingEventForInternal = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal); - SysTryReturnResult(NID_SYS, pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready."); - - if(pSettingEvent->GetCount() > 0 && __subscribed == false) - { - ArrayList requestMessages; - ArrayList responseMessages; - - requestMessages.Construct(); - responseMessages.Construct(); - - String commandId(SETTING_SERVICE_COMMAND_SUBSCRIBE); - - requestMessages.Add(commandId); - - unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - - r = __pIpcClient->SendRequest(*(pMsg.get())); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - - String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); - SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); - r = ConvertCode(*pResult); - - if(r == E_SUCCESS) - { - __subscribed = true; - } - responseMessages.RemoveAll(true); - } - else if(pSettingEvent->GetCount() == 0 && __subscribed == true) - { - ArrayList requestMessages; - ArrayList responseMessages; - - requestMessages.Construct(); - responseMessages.Construct(); - - String commandId(SETTING_SERVICE_COMMAND_UNSUBSCRIBE); - - requestMessages.Add(commandId); - - unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - - r = __pIpcClient->SendRequest(*(pMsg.get())); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - - String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); - SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); - r = ConvertCode(*pResult); - - if(r == E_SUCCESS) - { - __subscribed = false; - } - responseMessages.RemoveAll(true); - } - - if(pSettingEventForInternal->GetCount() > 0 && __subscribedForInternal == false) - { - ArrayList requestMessages; - ArrayList responseMessages; - - requestMessages.Construct(); - responseMessages.Construct(); - - String commandId(SETTING_SERVICE_COMMAND_SUBSCRIBE_INTERNAL); - - requestMessages.Add(commandId); - - unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - - r = __pIpcClient->SendRequest(*(pMsg.get())); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - - String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); - SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); - r = ConvertCode(*pResult); - - if(r == E_SUCCESS) - { - __subscribedForInternal = true; - } - responseMessages.RemoveAll(true); - } - else if(pSettingEventForInternal->GetCount() == 0 && __subscribedForInternal == true) - { - ArrayList requestMessages; - ArrayList responseMessages; - - requestMessages.Construct(); - responseMessages.Construct(); - - String commandId(SETTING_SERVICE_COMMAND_UNSUBSCRIBE_INTERNAL); - - requestMessages.Add(commandId); - - unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - - r = __pIpcClient->SendRequest(*(pMsg.get())); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); - - String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT); - SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code."); - r = ConvertCode(*pResult); - - if(r == E_SUCCESS) - { - __subscribedForInternal = false; - } - responseMessages.RemoveAll(true); - } - - return r; -} - -result -_SettingClientEx::AddSettingEventListener(ISettingEventListener& listener) -{ - SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready."); - _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent); - SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready."); - - result r = pSettingEvent->AddSettingEventListener(listener); - - if (r == E_OBJ_ALREADY_EXIST) - { - SysLogException(NID_SYS, E_OBJ_ALREADY_EXIST, "It is already registered."); - return E_OBJ_ALREADY_EXIST; - } - - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add event listener."); - - r = SubscribeEvent(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener."); - - return r; -} - -result -_SettingClientEx::RemoveSettingEventListener(ISettingEventListener& listener) -{ - SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready."); - _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent); - SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready."); - - result r = pSettingEvent->RemoveSettingEventListener(listener); - - if (r == E_OBJ_NOT_FOUND) - { - SysLogException(NID_SYS, E_OBJ_NOT_FOUND, "It is not registered."); - return E_OBJ_NOT_FOUND; - } - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to remove event listener.[%s]", GetErrorMessage(r)); - - r = SubscribeEvent(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener."); - - return r; -} - -// Event for internal -result -_SettingClientEx::AddSettingEventListenerForInternal(ISettingEventListener& listener) -{ - SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener event is not ready."); - _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal); - SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready."); - - result r = pSettingEvent->AddSettingEventListener(listener); - SysLog(NID_SYS, "Add Setting event result is %s for internal.", GetErrorMessage(r)); - - if (r == E_INVALID_OPERATION) - { - r = E_SYSTEM; - } - - SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to add event listener."); - - r = SubscribeEvent(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener."); - - return r; -} - -result -_SettingClientEx::RemoveSettingEventListenerForInternal(ISettingEventListener& listener) -{ - SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready."); - _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal); - SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready."); - - result r = pSettingEvent->RemoveSettingEventListener(listener); - SysLog(NID_SYS, "Remove setting event result is %s for internal.", GetErrorMessage(r)); - - SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to remove event listener."); - - r = SubscribeEvent(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener."); - - return r; -} - -//For OSP_COMPAT mode -result -_SettingClientEx::SetSettingEventListener(ISettingEventListener* pListener) -{ - result r = E_SUCCESS; - if(__pListener != null) - { - r = RemoveSettingEventListener(*pListener); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to unregister exist listener."); - if(pListener != null) - { - r = AddSettingEventListener(*pListener); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to register listener."); - } - } - - __pListener = pListener; - - return r; -} - -} } // Tizen::System diff --git a/src/system/FSys_SettingClientEx.h b/src/system/FSys_SettingClientEx.h deleted file mode 100644 index bd0f082..0000000 --- a/src/system/FSys_SettingClientEx.h +++ /dev/null @@ -1,205 +0,0 @@ -// -// 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_SettingClientEx.h - * @brief This is the header file for _SettingClientEx class. - */ - -#ifndef _FSYSTEM_INTERNAL_SETTING_CLIENT_EX_H_ -#define _FSYSTEM_INTERNAL_SETTING_CLIENT_EX_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace Tizen { namespace System -{ - -class _SettingEventArg : public Tizen::Base::Runtime::IEventArg -{ -public: - Tizen::Base::String KeyName; -}; - -class _SettingEvent : public Tizen::Base::Runtime::Event -{ -public: - _SettingEvent() - : __count(0) - { - } - - result AddSettingEventListener(ISettingEventListener& listener) - { - result r = AddListener(listener); - SysTryReturnResult(NID_SYS, __count >= 0, E_SYSTEM, "Listenr count[%d] is error.", __count); - - if(r == E_SUCCESS) - { - __count++; - } - return r; - } - - result RemoveSettingEventListener(ISettingEventListener& listener) - { - result r = RemoveListener(listener); - if(r == E_OBJ_NOT_FOUND) - { - return E_OBJ_NOT_FOUND; - } - SysTryReturnResult(NID_SYS, __count > 0, E_SYSTEM, "Listenr count[%d] is error.", __count); - if(r == E_SUCCESS) - { - __count--; - } - return r; - } - - int GetCount(void) - { - return __count; - } - -private: - int __count; -protected: - virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) - { - ISettingEventListener* pListener = dynamic_cast (&listener); - const _SettingEventArg* pArg = dynamic_cast(&arg); - - if(pListener == null || pArg == null) - { - SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnt"); - return; - } - - Tizen::Base::String value =pArg->KeyName; - pListener->OnSettingChanged(value); - } -}; - -class _SettingAsyncEventArg : public Tizen::Base::Runtime::IEventArg -{ -public: - Tizen::Base::String Key; - result errorCode; -}; - -class _SettingAsyncEvent : public Tizen::Base::Runtime::Event -{ -protected: - virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) - { - ISettingInfoSetValueAsyncResultListener* pListener = dynamic_cast (&listener); - const _SettingAsyncEventArg* pArg = dynamic_cast(&arg); - - if(pListener == null || pArg == null) - { - SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnts [%x/%x].", pListener, pArg); - return; - } - - result r = pArg->errorCode; - pListener->OnResultReceivedForSetValueAsync(pArg->Key, r); - RemoveListener(listener); - } -}; - -class _SettingClientEx - : public Tizen::Base::Object - , public Tizen::Io::_IIpcClientEventListener -{ -private: - _SettingClientEx(void); - virtual ~_SettingClientEx(void); - -public: - result GetValue(const Tizen::Base::String& key, bool& value); - result GetValueForPrivilegedKey(const Tizen::Base::String& key, bool& value); - result GetValue(const Tizen::Base::String& key, double& value); - result GetValue(const Tizen::Base::String& key, int& value); - result GetValue(const Tizen::Base::String& key, long long& value); - result GetValue(const Tizen::Base::String& key, Tizen::Base::String& value); - result GetValue(const Tizen::Base::String& key, Tizen::Base::UuId& value); - - bool HasKey(const Tizen::Base::String& key); - - result SetValue(const Tizen::Base::String& key, const bool& value); - result SetValueForPrivilegedKey(const Tizen::Base::String& key, bool value); - result SetValueAsync(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener); - result SetValueAsyncForPrivilegedKey(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener); - result SetValue(const Tizen::Base::String& key, const int& value); - result SetValue(const Tizen::Base::String& key, const Tizen::Base::String& value); - result SetValueForPrivilegedKey(const Tizen::Base::String& key, Tizen::Base::String value); - - result AddSettingEventListenerForInternal(ISettingEventListener& listener); - result RemoveSettingEventListenerForInternal(ISettingEventListener& listener); - result AddSettingEventListener(ISettingEventListener& listener); - result RemoveSettingEventListener(ISettingEventListener& listener); - - result SetSettingEventListener(ISettingEventListener* pListener); - - result ResetToFactoryDefault(void); - - void OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message); - void OnIpcServerDisconnected(Tizen::Io::_IpcClient& client); - - static _SettingClientEx* GetInstance(void); - -private: - void OnDataReceived(const Tizen::Base::Collection::ArrayList& data); - result ConvertCode(Tizen::Base::String code); - - Tizen::Base::String ConvertKeyOspToTizen(Tizen::Base::String ospKey); - result ConvertKeyTizenToOsp(Tizen::Base::String tizenKey, Tizen::Base::String& ospKey); - - result GetOnService(Tizen::Base::String commandId, Tizen::Base::String key, Tizen::Base::String& response); - result SetOnService(Tizen::Base::String commandId, Tizen::Base::String key, Tizen::Base::String value); - result SetVolume(const Tizen::Base::String& soundCategory, int level); - - result SubscribeEvent(void); - - static void InitSettingClient(void); -private: - Tizen::Base::Collection::HashMap __asyncEventList; - Tizen::Io::_IpcClient* __pIpcClient; - - bool __subscribed; - bool __subscribedForInternal; - ISettingEventListener* __pListener; - - _SettingEvent* __pSettingEvent; - _SettingEvent* __pSettingEventForInternal; - static _SettingClientEx* __pSettingClient; -}; - -} } // Tizen::System - -#endif //_FSYSTEM_INTERNAL_SETTING_CLIENT_EX_H_ diff --git a/src/system/FSys_SettingInfoImpl.cpp b/src/system/FSys_SettingInfoImpl.cpp index d131e3f..bc30c23 100644 --- a/src/system/FSys_SettingInfoImpl.cpp +++ b/src/system/FSys_SettingInfoImpl.cpp @@ -32,7 +32,6 @@ #include #include "FSys_SettingClient.h" -#include "FSys_SettingClientEx.h" using namespace std; @@ -79,32 +78,13 @@ static const int _FONT_SIZE_SMALL_VCONF = 0; static _SettingClient* pSettingClient = null; -static _SettingClientEx* pSettingClientEx = null; -static const wchar_t* _COMMON_SERVICE_ENABLED = L"/opt/usr/etc/setting_common"; -static bool common_mode = false; void _SettingInfoImpl::InitSettingClient(void) { - if(pSettingClient == null && pSettingClientEx == null) + if(pSettingClient == null) { -/* - if(File::IsFileExist(_COMMON_SERVICE_ENABLED) == false) - { - if(pSettingClient == null) - { - pSettingClient = _SettingClient::GetInstance(); - } - } - else -*/ - { - common_mode = true; - if(pSettingClientEx == null) - { - pSettingClientEx = _SettingClientEx::GetInstance(); - } - } + pSettingClient = _SettingClient::GetInstance(); } } result @@ -140,16 +120,8 @@ _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::String& else { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - r = pSettingClient->GetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - r = pSettingClientEx->GetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + r = pSettingClient->GetValue(key, value); } return r; } @@ -158,80 +130,40 @@ result _SettingInfoImpl::GetValue(const Tizen::Base::String& key, int& value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->GetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->GetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->GetValue(key, value); } result _SettingInfoImpl::GetValue(const Tizen::Base::String& key, long long& value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->GetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->GetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->GetValue(key, value); } result _SettingInfoImpl::GetValue(const Tizen::Base::String& key, double& value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->GetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->GetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->GetValue(key, value); } result _SettingInfoImpl::GetValue(const Tizen::Base::String& key, bool& value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->GetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->GetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->GetValue(key, value); } result _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::UuId& value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->GetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->GetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->GetValue(key, value); } result @@ -240,16 +172,8 @@ _SettingInfoImpl::SetWallpaper(const Tizen::Base::String& filePath) InitSettingClient(); result r = E_SUCCESS; - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - r = pSettingClient->SetValue(_SETTING_SCREEN_WALLPAPER, filePath); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - r = pSettingClientEx->SetValue(_SETTING_SCREEN_WALLPAPER, filePath); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + r = pSettingClient->SetValue(_SETTING_SCREEN_WALLPAPER, filePath); if(r == E_INVALID_ARG) r = E_FILE_NOT_FOUND; @@ -266,48 +190,24 @@ _SettingInfoImpl::GetValueForPrivilegedKey(const String& key, bool& value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->GetValueForPrivilegedKey(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->GetValueForPrivilegedKey(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->GetValueForPrivilegedKey(key, value); } result _SettingInfoImpl::SetValue(const String& key, bool value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->SetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->SetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->SetValue(key, value); } result _SettingInfoImpl::SetValue(const String& key, int value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->SetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->SetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->SetValue(key, value); } @@ -322,16 +222,8 @@ _SettingInfoImpl::SetValue(const String& key, String value) else { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->SetValue(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->SetValue(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->SetValue(key, value); } return r; } @@ -340,63 +232,31 @@ result _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, bool value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->SetValueForPrivilegedKey(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->SetValueForPrivilegedKey(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->SetValueForPrivilegedKey(key, value); } result _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, String value) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->SetValueForPrivilegedKey(key, value); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->SetValueForPrivilegedKey(key, value); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->SetValueForPrivilegedKey(key, value); } bool _SettingInfoImpl::HasKey(const String& key) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->HasKey(key); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->HasKey(key); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->HasKey(key); } result _SettingInfoImpl::ResetToFactoryDefault(void) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->ResetToFactoryDefault(); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->ResetToFactoryDefault(); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->ResetToFactoryDefault(); } result @@ -404,16 +264,8 @@ _SettingInfoImpl::SetRingtone(const Tizen::Base::String& filePath) { result r = E_SUCCESS; InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - r = pSettingClient->SetValue(_SETTING_SOUND_RINGTONE, filePath); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - r = pSettingClientEx->SetValue(_SETTING_SOUND_RINGTONE, filePath); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + r = pSettingClient->SetValue(_SETTING_SOUND_RINGTONE, filePath); if(r == E_INVALID_ARG) r = E_FILE_NOT_FOUND; @@ -453,16 +305,8 @@ _SettingInfoImpl::SetVolume(const Tizen::Base::String& soundCategory, int level) } InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - r = pSettingClient->SetValue(key, level); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - r = pSettingClientEx->SetValue(key, level); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + r = pSettingClient->SetValue(key, level); if (r == E_OBJ_NOT_FOUND) { @@ -483,112 +327,56 @@ result _SettingInfoImpl::AddSettingEventListener(ISettingEventListener& listener) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->AddSettingEventListener(listener); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->AddSettingEventListener(listener); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->AddSettingEventListener(listener); } result _SettingInfoImpl::RemoveSettingEventListener(ISettingEventListener& listener) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->RemoveSettingEventListener(listener); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->RemoveSettingEventListener(listener); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->RemoveSettingEventListener(listener); } result _SettingInfoImpl::AddSettingEventListenerForInternal(ISettingEventListener& listener) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->AddSettingEventListenerForInternal(listener); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->AddSettingEventListenerForInternal(listener); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->AddSettingEventListenerForInternal(listener); } result _SettingInfoImpl::RemoveSettingEventListenerForInternal(ISettingEventListener& listener) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->RemoveSettingEventListenerForInternal(listener); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->RemoveSettingEventListenerForInternal(listener); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->RemoveSettingEventListenerForInternal(listener); } result _SettingInfoImpl::SetSettingEventListener(ISettingEventListener* pListener) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->SetSettingEventListener(pListener); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->SetSettingEventListener(pListener); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->SetSettingEventListener(pListener); } result _SettingInfoImpl::SetValueAsync(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->SetValueAsync(key, value, listener); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->SetValueAsync(key, value, listener); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->SetValueAsync(key, value, listener); } result _SettingInfoImpl::SetValueAsyncForPrivilegedKey(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener) { InitSettingClient(); - if(common_mode == false) - { - SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClient->SetValueAsyncForPrivilegedKey(key, value, listener); - } - else - { - SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager"); - return pSettingClientEx->SetValueAsyncForPrivilegedKey(key, value, listener); - } + SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager"); + return pSettingClient->SetValueAsyncForPrivilegedKey(key, value, listener); } _SettingInfoImpl* -- 2.7.4