+//
+// 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 <unique_ptr.h>
+
+#include <FBaseBoolean.h>
+#include <FBaseSysLog.h>
+
+#include <FApp_AppInfo.h>
+#include <FIo_AppServiceIpcMessages.h>
+
+#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());
+
+ r = __ipcClient.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;
+ }
+}
+
+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.");
+
+ //unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
+
+ IoService_Request message(requestMessages, &responseMessages);
+
+ //r = __ipcClient.SendRequest(*(pMsg.get()));
+ r = __ipcClient.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 && value.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 = __ipcClient.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_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<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
+
+ r = __ipcClient.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<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
+
+ r = __ipcClient.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<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
+
+ r = __ipcClient.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<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
+
+ r = __ipcClient.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_INVALID_OPERATION)
+ {
+ r = E_SYSTEM;
+ }
+ 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);
+ SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "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;
+}
+
+// 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