2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FSys_SettingClientEx.cpp
19 * @brief This is the implementation file for _SettingClientEx class.
22 #include <unique_ptr.h>
24 #include <FBaseBoolean.h>
25 #include <FBaseSysLog.h>
27 #include <FApp_AppInfo.h>
28 #include <FIo_AppServiceIpcMessages.h>
30 #include "FSys_CommunicationDispatcherClient.h"
31 #include "FSys_SettingClientEx.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Io;
41 namespace Tizen { namespace System
44 static const wchar_t* _MOTION_UI = L"http://tizen.org/setting/motion.ui";
45 static const wchar_t* _ENABLE_MOTION = L"EnableMotion";
48 static const wchar_t* _FONT_SIZE = L"http://tizen.org/setting/font.size";
49 static const wchar_t* _FONTSIZE = L"FontSize";
51 static const wchar_t* _FONT_TYPE = L"http://tizen.org/setting/font.type";
52 static const wchar_t* _FONTTYPE = L"FontType";
57 static const wchar_t* _LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
58 static const wchar_t* _COUNTRY = L"Country";
61 static const wchar_t* _LOCALE_DATE_FORMAT = L"http://tizen.org/setting/locale.date.format";
62 static const wchar_t* _DATE_FORMAT = L"DateFormat";
64 static const wchar_t* _LOCALE_TIME_FORMAT = L"http://tizen.org/setting/locale.time.format";
65 static const wchar_t* _TIME_FORMAT = L"TimeFormat";
67 static const wchar_t* _LOCALE_TIME_FORMAT_24HOUR = L"http://tizen.org/setting/locale.time.format.24hour";
68 static const wchar_t* _HOUR_FORMAT_SELECTED = L"24HourFormatSelected";
71 static const wchar_t* _LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
72 static const wchar_t* _LANGUAGE = L"Language";
75 static const wchar_t* _LOCALE_DATETIME_FORMAT = L"http://tizen.org/setting/locale.date_time.format";
76 static const wchar_t* _DATE_TIME_FORMAT = L"DateTimeFormat";
80 static const wchar_t* _LOCATION_GPS = L"http://tizen.org/setting/location.gps";
81 static const wchar_t* _GPS_ENABLED = L"GPSEnabled";
83 static const wchar_t* _LOCATION_WPS = L"http://tizen.org/setting/location.wps";
84 static const wchar_t* _WPS_ENABLED = L"WPSEnabled";
87 static const wchar_t* _NETWORK_FLIGHTMODE = L"http://tizen.org/setting/network.flight_mode";
88 static const wchar_t* _FLIGHT_MODE_ENABLED = L"FlightModeEnabled";
91 static const wchar_t* _NETWORK_TELEPHONY_PACKETSERVICE = L"http://tizen.org/setting/network.telephony.packet_service";
92 static const wchar_t* _PACKET_SERVICE_ALLOWED = L"PacketServiceAllowed";
94 static const wchar_t* _NETWORK_TELEPHONY_ROAMING = L"http://tizen.org/setting/network.telephony.roaming";
95 static const wchar_t* _DATA_ROAMING_ENABLED = L"DataRoamingEnabled";
98 static const wchar_t* _SCREEN_WALLPAPER = L"http://tizen.org/setting/screen.wallpaper";
99 static const wchar_t* _WALLPAPER = L"Wallpaper";
102 static const wchar_t* _SOUND_MEDIA_VOLUME = L"http://tizen.org/setting/sound.media.volume";
103 static const wchar_t* _MEDIA_SOUND_VOLUME = L"MediaSoundVolume";
105 static const wchar_t* _SOUND_NOTIFICATION_VOLUME = L"http://tizen.org/setting/sound.notification.volume";
106 static const wchar_t* _NOTIFICATION_SOUND_VOLUME = L"NotificationSoundVolume";
108 static const wchar_t* _SOUND_RINGTONE = L"http://tizen.org/setting/sound.ringtone";
109 static const wchar_t* _RINGTONE = L"Ringtone";
111 static const wchar_t* _SOUND_RINGTONE_VOLUME = L"http://tizen.org/setting/sound.ringtone.volume";
112 static const wchar_t* _RINGTONE_SOUND_VOLUME = L"RingtoneSoundVolume";
114 static const wchar_t* _SOUND_SYSTEM_VOLUME = L"http://tizen.org/setting/sound.system.volume";
115 static const wchar_t* _SYSTEM_SOUND_VOLUME = L"SystemSoundVolume";
117 static const wchar_t* _SOUND_SILENTMODE = L"http://tizen.org/setting/sound.silent_mode";
118 static const wchar_t* _SILENT_MODE = L"SilentMode";
121 static const wchar_t* _TOUCH_VIBRATION_LEVEL = L"TouchVibrationLevel";
122 static const wchar_t* _VIBRATOR_LEVEL = L"http://tizen.org/setting/vibrator.level";
124 static const wchar_t* _SETTING_COMMAND_FACTORY_RESET = L"osp.setting.command.factory.reset";
127 static const wchar_t* _USBMODE = L"UsbMode";
128 static const wchar_t* _USBMODE_MTP = L"MTP";
130 const static wchar_t* SETTING_SERVICE_ID = L"osp.sys.ipcserver.setting_service";
132 const static wchar_t* SETTING_SERVICE_COMMAND_GET_BOOL = L"osp.sys.ipcserver.setting_service.command.get.bool";
133 const static wchar_t* SETTING_SERVICE_COMMAND_GET_INT = L"osp.sys.ipcserver.setting_service.command.get.int";
134 const static wchar_t* SETTING_SERVICE_COMMAND_GET_STRING = L"osp.sys.ipcserver.setting_service.command.get.string";
135 const static wchar_t* SETTING_SERVICE_COMMAND_SET_BOOL = L"osp.sys.ipcserver.setting_service.command.set.bool";
136 const static wchar_t* SETTING_SERVICE_COMMAND_SET_INT = L"osp.sys.ipcserver.setting_service.command.set.int";
137 const static wchar_t* SETTING_SERVICE_COMMAND_SET_STRING = L"osp.sys.ipcserver.setting_service.command.set.string";
139 const static wchar_t* SETTING_SERVICE_COMMAND_SET_PRIV_BOOL = L"osp.sys.ipcserver.setting_service.command.set.priv.bool";
140 const static wchar_t* SETTING_SERVICE_COMMAND_SET_PRIV_STRING = L"osp.sys.ipcserver.setting_service.command.set.priv.string";
141 const static wchar_t* SETTING_SERVICE_COMMAND_SET_ASYNC_BOOL = L"osp.sys.ipcserver.setting_service.command.set.async.bool";
142 const static wchar_t* SETTING_SERVICE_COMMAND_SET_PRIV_ASYNC_BOOL = L"osp.sys.ipcserver.setting_service.command.set.priv.async.bool";
143 const static wchar_t* SETTING_SERVICE_COMMAND_RESULT = L"osp.sys.ipcserver.setting_service.command.result";
145 const static wchar_t* SETTING_SERVICE_COMMAND_SUBSCRIBE = L"osp.sys.ipcserver.setting_service.command.subscribe";
146 const static wchar_t* SETTING_SERVICE_COMMAND_UNSUBSCRIBE = L"osp.sys.ipcserver.setting_service.command.unsubscribe";
147 const static wchar_t* SETTING_SERVICE_COMMAND_EVENT = L"osp.sys.ipcserver.setting_service.command.event";
149 const static wchar_t* SETTING_SERVICE_COMMAND_SUPPORTED = L"osp.sys.ipcserver.setting_service.command.supported";
151 const static wchar_t* SETTING_SERVICE_COMMAND_SUBSCRIBE_INTERNAL = L"osp.sys.ipcserver.setting_service.command.subscribe.internal";
152 const static wchar_t* SETTING_SERVICE_COMMAND_UNSUBSCRIBE_INTERNAL = L"osp.sys.ipcserver.setting_service.command.unsubscribe.internal";
153 const static wchar_t* SETTING_SERVICE_COMMAND_EVENT_INTERNAL = L"osp.sys.ipcserver.setting_service.command.event.internal";
155 const static int SETTING_SERVICE_IPC_MSG_COMMAND = 0;
156 const static int SETTING_SERVICE_IPC_MSG_KEY = 1;
157 const static int SETTING_SERVICE_IPC_MSG_VALUE = 2;
158 const static int SETTING_SERVICE_IPC_MSG_RESULT = 1;
160 const static wchar_t* _SETTING_RESULT_SUCCESS = L"E_SUCCESS";
161 const static wchar_t* _SETTING_RESULT_INVALID_ARG = L"E_INVALID_ARG";
162 const static wchar_t* _SETTING_RESULT_PRIVILEGE_DENIED = L"E_PRIVILEGE_DENIED";
163 const static wchar_t* _SETTING_RESULT_UNSUPPORTED_OPERATION = L"E_UNSUPPORTED_OPERATION";
164 const static wchar_t* _SETTING_RESULT_OBJ_NOT_FOUND = L"E_OBJ_NOT_FOUND";
165 const static wchar_t* _SETTING_RESULT_OBJ_ALREADY_EXIST = L"E_OBJ_ALREADY_EXIST";
166 const static wchar_t* _SETTING_RESULT_IN_PROGRESS = L"E_IN_PROGRESS";
167 const static wchar_t* _SETTING_RESULT_SYSTEM = L"E_SYSTEM";
169 _SettingClientEx* _SettingClientEx::__pSettingClient = null;
171 int common_service = 1;
174 _SettingClientEx::InitSettingClient(void)
176 static _SettingClientEx settingManager;
177 __pSettingClient = &settingManager;
181 _SettingClientEx::GetInstance(void)
183 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
184 if(__pSettingClient == null)
186 pthread_once(&once_block, InitSettingClient);
188 return __pSettingClient;
191 _SettingClientEx::_SettingClientEx()
192 : __subscribed(false)
193 , __subscribedForInternal(false)
195 , __pSettingEvent(null)
196 , __pSettingEventForInternal(null)
198 result r = E_SUCCESS;
199 static String serviceId(SETTING_SERVICE_ID);
201 unique_ptr<_SettingEvent> settingEvent(new(nothrow) _SettingEvent());
202 unique_ptr<_SettingEvent> settingEventForInternal(new(nothrow) _SettingEvent());
204 r = __ipcClient.Construct(serviceId, this);
205 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to construct IPC client.");
206 r = __asyncEventList.Construct();
207 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to construct asyn event list.");
209 SysTryCatch(NID_SYS, settingEvent.get() != null && settingEventForInternal.get() != null, r = E_SYSTEM, r, "It is failed to create event instances.");
214 __pSettingEvent = settingEvent.release();
215 __pSettingEventForInternal = settingEventForInternal.release();
220 _SettingClientEx::~_SettingClientEx()
222 __subscribed = false;
223 __subscribedForInternal = false;
226 if(__pSettingEvent != null)
228 delete __pSettingEvent;
231 if(__pSettingEventForInternal != null)
233 delete __pSettingEventForInternal;
238 _SettingClientEx::ConvertCode(String code)
240 result r = E_SUCCESS;
241 if(code == _SETTING_RESULT_SUCCESS)
245 else if(code == _SETTING_RESULT_INVALID_ARG)
249 else if(code == _SETTING_RESULT_PRIVILEGE_DENIED)
251 r = E_PRIVILEGE_DENIED;
253 else if(code == _SETTING_RESULT_UNSUPPORTED_OPERATION)
255 r = E_UNSUPPORTED_OPERATION;
257 else if(code == _SETTING_RESULT_OBJ_NOT_FOUND)
261 else if(code == _SETTING_RESULT_OBJ_ALREADY_EXIST)
263 r = E_OBJ_ALREADY_EXIST;
265 else if(code == _SETTING_RESULT_IN_PROGRESS)
269 else if(code == _SETTING_RESULT_SYSTEM)
281 _SettingClientEx::ConvertKeyOspToTizen(String ospKey)
283 String tizenKey = ospKey;
285 if(tizenKey == _HOUR_FORMAT_SELECTED)
286 tizenKey = _LOCALE_TIME_FORMAT_24HOUR;
288 else if(tizenKey == _ENABLE_MOTION)
289 tizenKey = _MOTION_UI;
291 else if(tizenKey == _DATA_ROAMING_ENABLED)
292 tizenKey = _NETWORK_TELEPHONY_ROAMING;
294 else if(tizenKey == _GPS_ENABLED)
295 tizenKey = _LOCATION_GPS;
297 else if(tizenKey == _PACKET_SERVICE_ALLOWED)
298 tizenKey = _NETWORK_TELEPHONY_PACKETSERVICE;
300 else if(tizenKey == _SILENT_MODE)
301 tizenKey = _SOUND_SILENTMODE;
303 else if(tizenKey == _WPS_ENABLED)
304 tizenKey = _LOCATION_WPS;
306 else if(tizenKey == _FLIGHT_MODE_ENABLED)
307 tizenKey = _NETWORK_FLIGHTMODE;
309 else if(tizenKey == _TOUCH_VIBRATION_LEVEL)
310 tizenKey = _VIBRATOR_LEVEL;
312 else if(tizenKey == _MEDIA_SOUND_VOLUME)
313 tizenKey = _SOUND_MEDIA_VOLUME;
315 else if(tizenKey == _NOTIFICATION_SOUND_VOLUME)
316 tizenKey = _SOUND_NOTIFICATION_VOLUME;
318 else if(tizenKey == _RINGTONE_SOUND_VOLUME)
319 tizenKey = _SOUND_RINGTONE_VOLUME;
321 else if(tizenKey == _SYSTEM_SOUND_VOLUME)
322 tizenKey = _SOUND_SYSTEM_VOLUME;
324 else if(tizenKey == _COUNTRY)
325 tizenKey = _LOCALE_COUNTRY;
327 else if(tizenKey == _DATE_FORMAT)
328 tizenKey = _LOCALE_DATE_FORMAT;
330 else if(tizenKey == _DATE_TIME_FORMAT)
331 tizenKey = _LOCALE_DATETIME_FORMAT;
333 else if(tizenKey == _FONTTYPE)
334 tizenKey = _FONT_TYPE;
336 else if(tizenKey == _FONTSIZE)
337 tizenKey = _FONT_SIZE;
339 else if(tizenKey == _RINGTONE)
340 tizenKey = _SOUND_RINGTONE;
342 else if(tizenKey == _TIME_FORMAT)
343 tizenKey = _LOCALE_TIME_FORMAT;
345 else if(tizenKey == _WALLPAPER)
346 tizenKey = _SCREEN_WALLPAPER;
352 _SettingClientEx::ConvertKeyTizenToOsp(String tizenKey, String& ospKey)
354 result r = E_SUCCESS;
355 if(tizenKey == _LOCALE_TIME_FORMAT_24HOUR)
357 ospKey = _HOUR_FORMAT_SELECTED;
359 else if(tizenKey == _MOTION_UI)
361 ospKey = _ENABLE_MOTION;
363 else if(tizenKey == _NETWORK_TELEPHONY_ROAMING)
365 ospKey = _DATA_ROAMING_ENABLED;
367 else if(tizenKey == _LOCATION_GPS)
369 ospKey = _GPS_ENABLED;
371 else if(tizenKey == _NETWORK_TELEPHONY_PACKETSERVICE)
373 ospKey = _PACKET_SERVICE_ALLOWED;
375 else if(tizenKey == _SOUND_SILENTMODE)
377 ospKey = _SILENT_MODE;
379 else if(tizenKey == _LOCATION_WPS)
381 ospKey = _WPS_ENABLED;
383 else if(tizenKey == _NETWORK_FLIGHTMODE)
385 ospKey = _FLIGHT_MODE_ENABLED;
387 else if(tizenKey == _VIBRATOR_LEVEL)
389 ospKey = _TOUCH_VIBRATION_LEVEL;
391 else if(tizenKey == _SOUND_MEDIA_VOLUME)
393 ospKey = _MEDIA_SOUND_VOLUME;
395 else if(tizenKey == _SOUND_NOTIFICATION_VOLUME)
397 ospKey = _NOTIFICATION_SOUND_VOLUME;
399 else if(tizenKey == _SOUND_RINGTONE_VOLUME)
401 ospKey = _RINGTONE_SOUND_VOLUME;
403 else if(tizenKey == _SOUND_SYSTEM_VOLUME)
405 ospKey = _SYSTEM_SOUND_VOLUME;
407 else if(tizenKey == _LOCALE_COUNTRY)
411 else if(tizenKey == _LOCALE_DATE_FORMAT)
413 ospKey = _DATE_FORMAT;
415 else if(tizenKey == _LOCALE_DATETIME_FORMAT)
417 ospKey = _DATE_TIME_FORMAT;
419 else if(tizenKey == _FONT_TYPE)
423 else if(tizenKey == _FONT_SIZE)
427 else if(tizenKey == _SOUND_RINGTONE)
431 else if(tizenKey == _LOCALE_TIME_FORMAT)
433 ospKey = _TIME_FORMAT;
435 else if(tizenKey == _SCREEN_WALLPAPER)
448 _SettingClientEx::GetOnService(String commandId, String key, String& response)
450 result r = E_SUCCESS;
452 SysTryReturnResult(NID_SYS, commandId.GetLength() > 0 && key.GetLength() > 0, E_INVALID_ARG, "There are invalid parameters.");
453 String requestKey = ConvertKeyOspToTizen(key);
454 String* pResult = null;
455 String* pValue = null;
457 ArrayList requestMessages;
458 ArrayList responseMessages;
460 r = requestMessages.Construct();
461 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct request message.");
462 r = responseMessages.Construct();
463 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct response message.");
465 r = requestMessages.Add(commandId);
466 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add command id on request message.");
467 r = requestMessages.Add(requestKey);
468 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required key on request message.");
470 //unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
472 IoService_Request message(requestMessages, &responseMessages);
474 //r = __ipcClient.SendRequest(*(pMsg.get()));
475 r = __ipcClient.SendRequest(message);
476 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
478 pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT);
479 SysTryCatch(NID_SYS, pResult != null, r = E_SYSTEM, r, "There is no result code.");
480 r = ConvertCode(*pResult);
484 pValue = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_VALUE);
485 SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "There is no result value.");
490 responseMessages.RemoveAll(true);
495 _SettingClientEx::SetOnService(String commandId, String key, String value)
497 result r = E_SUCCESS;
499 SysTryReturnResult(NID_SYS, commandId.GetLength() > 0 && key.GetLength() > 0 && value.GetLength() > 0, E_INVALID_ARG, "There are invalid parameters.");
500 String requestKey = ConvertKeyOspToTizen(key);
501 String* pResult = null;
503 ArrayList requestMessages;
504 ArrayList responseMessages;
506 r = requestMessages.Construct();
507 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct request message.");
508 r = responseMessages.Construct();
509 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct response message.");
511 r = requestMessages.Add(commandId);
512 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add command id on request message.");
513 r = requestMessages.Add(requestKey);
514 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required key on request message.");
515 r = requestMessages.Add(value);
516 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add required value on request message.");
518 IoService_Request message(requestMessages, &responseMessages);
520 r = __ipcClient.SendRequest(message);
521 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
523 pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT);
524 SysTryCatch(NID_SYS, pResult != null, r = E_SYSTEM, r, "There is no result code.");
525 r = ConvertCode(*pResult);
528 responseMessages.RemoveAll(true);
533 _SettingClientEx::GetValue(const String& key, bool& value)
536 result r = GetOnService(SETTING_SERVICE_COMMAND_GET_BOOL, key, response);
538 SysLog(NID_SYS, "result is %ls.", response.GetPointer());
555 _SettingClientEx::GetValue(const String& key, int& value)
558 result r = GetOnService(SETTING_SERVICE_COMMAND_GET_INT, key, response);
562 r = Integer::Parse(response, value);
563 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to convert to integer from [%s]", response.GetPointer());
570 _SettingClientEx::GetValue(const String& key, long long& value)
572 return E_OBJ_NOT_FOUND;
576 _SettingClientEx::GetValue(const String& key, double& value)
578 return E_OBJ_NOT_FOUND;
582 _SettingClientEx::GetValue(const String& key, UuId& value)
584 return E_OBJ_NOT_FOUND;
588 _SettingClientEx::GetValue(const String& key, String& value)
591 result r = E_SUCCESS;
593 if(key == _USBMODE) //This is compatible issue. USB mode is fixed on Tizen.
595 value = _USBMODE_MTP;
599 if(key == _LANGUAGE) //This is not full compatible.
601 r = GetOnService(SETTING_SERVICE_COMMAND_GET_STRING, _LOCALE_LANGUAGE, response);
605 r = GetOnService(SETTING_SERVICE_COMMAND_GET_STRING, key, response);
613 if(key == _LANGUAGE) //This is not full compatible.
615 r = value.SubString(0, 3, value);
616 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to sub string on %ls.", value.GetPointer());
623 _SettingClientEx::GetValueForPrivilegedKey(const String& key, bool& value)
625 return E_OBJ_NOT_FOUND;
629 _SettingClientEx::SetValue(const String& key, const bool& value)
632 requestValue = Boolean::ToString(value);
633 return SetOnService(SETTING_SERVICE_COMMAND_SET_BOOL, key, requestValue);
637 _SettingClientEx::SetValue(const String& key, const int& value)
640 requestValue.Append(value);
641 return SetOnService(SETTING_SERVICE_COMMAND_SET_INT, key, requestValue);
645 _SettingClientEx::SetValue(const String& key, const String& value)
648 requestValue.Append(value);
649 return SetOnService(SETTING_SERVICE_COMMAND_SET_STRING, key, requestValue);
653 _SettingClientEx::SetValueForPrivilegedKey(const String& key, bool value)
656 requestValue = Boolean::ToString(value);
657 return SetOnService(SETTING_SERVICE_COMMAND_SET_BOOL, key, requestValue);
661 _SettingClientEx::SetValueForPrivilegedKey(const String& key, String value)
664 requestValue.Append(value);
665 return SetOnService(SETTING_SERVICE_COMMAND_SET_PRIV_STRING, key, requestValue);
670 _SettingClientEx::SetValueAsync(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
672 result r = E_SUCCESS;
675 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
677 requestValue = Boolean::ToString(value);
678 r = SetOnService(SETTING_SERVICE_COMMAND_SET_ASYNC_BOOL, key, requestValue);
684 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
685 pEvent->AddListener(*listener);
687 __asyncEventList.Add(new String(key), pEvent);
695 _SettingClientEx::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
697 result r = E_SUCCESS;
700 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
702 requestValue = Boolean::ToString(value);
703 r = SetOnService(SETTING_SERVICE_COMMAND_SET_PRIV_ASYNC_BOOL, key, requestValue);
709 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
710 pEvent->AddListener(*listener);
712 __asyncEventList.Add(new String(key), pEvent);
720 _SettingClientEx::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message)
722 IPC_BEGIN_MESSAGE_MAP(_SettingClientEx, message)
723 IPC_MESSAGE_HANDLER_EX(IoService_Data, &client, OnDataReceived)
724 IPC_END_MESSAGE_MAP_EX()
728 _SettingClientEx::OnDataReceived(const ArrayList& data)
730 result r = E_SUCCESS;
731 String* pCommandCode = (String*)data.GetAt(SETTING_SERVICE_IPC_MSG_COMMAND);
732 String* pKey = (String*)data.GetAt(SETTING_SERVICE_IPC_MSG_KEY);
733 String* pValue = null;
735 SysTryCatch(NID_SYS, pCommandCode != null && pKey != null, r = E_SYSTEM, r, "There is no valid data.");
737 SysLog(NID_SYS, "CommandCode: %ls", pCommandCode->GetPointer());
738 SysLog(NID_SYS, "Key: %ls", pKey->GetPointer());
740 if(*pCommandCode == SETTING_SERVICE_COMMAND_RESULT)
742 pValue = (String*)(data.GetAt(SETTING_SERVICE_IPC_MSG_VALUE));
743 SysTryCatch(NID_SYS, pValue != null, r = E_SYSTEM, r, "There is no valid value.");
745 r = ConvertCode(*pValue);
747 _SettingAsyncEvent* pEvent = dynamic_cast <_SettingAsyncEvent*> (__asyncEventList.GetValue(*pKey));
749 SysTryCatch(NID_SYS, pEvent != null, r = E_SYSTEM, r, "There is no reserved event.");
751 _SettingAsyncEventArg* pSettingAsyncEventArg = new (std::nothrow) _SettingAsyncEventArg;
752 SysTryCatch(NID_SYS, pSettingAsyncEventArg != null, r = E_SYSTEM, r, "There is no reserved event.");
754 pSettingAsyncEventArg->Key = *pKey;
755 pSettingAsyncEventArg->errorCode = r;
756 pEvent->Fire(*pSettingAsyncEventArg);
758 r = __asyncEventList.Remove(*pKey, true);
760 else if(*pCommandCode == SETTING_SERVICE_COMMAND_EVENT)
762 SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready.");
764 _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg();
765 pSettingEventArg->KeyName = *pKey;
767 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true)
770 r = ConvertKeyTizenToOsp(pSettingEventArg->KeyName, ospKey);
773 pSettingEventArg->KeyName = ospKey;
774 __pSettingEvent->Fire(*pSettingEventArg);
779 __pSettingEvent->Fire(*pSettingEventArg);
782 else if(*pCommandCode == SETTING_SERVICE_COMMAND_EVENT_INTERNAL)
784 SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready.");
786 _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg();
787 pSettingEventArg->KeyName = *pKey;
789 __pSettingEventForInternal->Fire(*pSettingEventArg);
793 ArrayList* pData = const_cast< ArrayList *> (&data);
794 pData->RemoveAll(true);
798 _SettingClientEx::HasKey(const String& key)
801 result r = GetOnService(SETTING_SERVICE_COMMAND_SUPPORTED, key, response);
803 SysLog(NID_SYS, "HasKey result key:%ls, %ls", key.GetPointer(), response.GetPointer());
804 if(response == L"1" && r == E_SUCCESS)
812 _SettingClientEx::ResetToFactoryDefault(void)
817 result r = GetOnService(_SETTING_COMMAND_FACTORY_RESET, value, response);
818 SysLog(NID_SYS, "Reset result is %s[%ls].", GetErrorMessage(r), response.GetPointer());
822 //For OSP_COMPAT mode
824 _SettingClientEx::SetVolume(const String& soundCategory, int level)
826 result r = SetValue(soundCategory, level);
827 if (r == E_INVALID_ARG)
831 else if(r == E_OBJ_NOT_FOUND)
835 else if(r == E_UNSUPPORTED_OPERATION)
844 _SettingClientEx::SubscribeEvent(void)
846 result r = E_SUCCESS;
847 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
848 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
849 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
851 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
852 _SettingEvent* pSettingEventForInternal = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
853 SysTryReturnResult(NID_SYS, pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
855 if(pSettingEvent->GetCount() > 0 && __subscribed == false)
857 ArrayList requestMessages;
858 ArrayList responseMessages;
860 requestMessages.Construct();
861 responseMessages.Construct();
863 String commandId(SETTING_SERVICE_COMMAND_SUBSCRIBE);
865 requestMessages.Add(commandId);
867 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
869 r = __ipcClient.SendRequest(*(pMsg.get()));
870 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
872 String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT);
873 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
874 r = ConvertCode(*pResult);
880 responseMessages.RemoveAll(true);
882 else if(pSettingEvent->GetCount() == 0 && __subscribed == true)
884 ArrayList requestMessages;
885 ArrayList responseMessages;
887 requestMessages.Construct();
888 responseMessages.Construct();
890 String commandId(SETTING_SERVICE_COMMAND_UNSUBSCRIBE);
892 requestMessages.Add(commandId);
894 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
896 r = __ipcClient.SendRequest(*(pMsg.get()));
897 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
899 String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT);
900 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
901 r = ConvertCode(*pResult);
905 __subscribed = false;
907 responseMessages.RemoveAll(true);
910 if(pSettingEventForInternal->GetCount() > 0 && __subscribedForInternal == false)
912 ArrayList requestMessages;
913 ArrayList responseMessages;
915 requestMessages.Construct();
916 responseMessages.Construct();
918 String commandId(SETTING_SERVICE_COMMAND_SUBSCRIBE_INTERNAL);
920 requestMessages.Add(commandId);
922 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
924 r = __ipcClient.SendRequest(*(pMsg.get()));
925 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
927 String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT);
928 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
929 r = ConvertCode(*pResult);
933 __subscribedForInternal = true;
935 responseMessages.RemoveAll(true);
937 else if(pSettingEventForInternal->GetCount() == 0 && __subscribedForInternal == true)
939 ArrayList requestMessages;
940 ArrayList responseMessages;
942 requestMessages.Construct();
943 responseMessages.Construct();
945 String commandId(SETTING_SERVICE_COMMAND_UNSUBSCRIBE_INTERNAL);
947 requestMessages.Add(commandId);
949 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
951 r = __ipcClient.SendRequest(*(pMsg.get()));
952 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
954 String* pResult = (String*)responseMessages.GetAt(SETTING_SERVICE_IPC_MSG_RESULT);
955 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
956 r = ConvertCode(*pResult);
960 __subscribedForInternal = false;
962 responseMessages.RemoveAll(true);
969 _SettingClientEx::AddSettingEventListener(ISettingEventListener& listener)
971 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
972 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
973 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
975 result r = pSettingEvent->AddSettingEventListener(listener);
976 if (r == E_INVALID_OPERATION)
980 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add event listener.");
982 r = SubscribeEvent();
983 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
989 _SettingClientEx::RemoveSettingEventListener(ISettingEventListener& listener)
991 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
992 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
993 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
995 result r = pSettingEvent->RemoveSettingEventListener(listener);
996 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to remove event listener.");
998 r = SubscribeEvent();
999 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1004 // Event for internal
1006 _SettingClientEx::AddSettingEventListenerForInternal(ISettingEventListener& listener)
1008 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener event is not ready.");
1009 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1010 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1012 result r = pSettingEvent->AddSettingEventListener(listener);
1013 SysLog(NID_SYS, "Add Setting event result is %s for internal.", GetErrorMessage(r));
1015 if (r == E_INVALID_OPERATION)
1020 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to add event listener.");
1022 r = SubscribeEvent();
1023 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1029 _SettingClientEx::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
1031 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
1032 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1033 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1035 result r = pSettingEvent->RemoveSettingEventListener(listener);
1036 SysLog(NID_SYS, "Remove setting event result is %s for internal.", GetErrorMessage(r));
1038 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to remove event listener.");
1040 r = SubscribeEvent();
1041 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1046 //For OSP_COMPAT mode
1048 _SettingClientEx::SetSettingEventListener(ISettingEventListener* pListener)
1050 result r = E_SUCCESS;
1051 if(__pListener != null)
1053 r = RemoveSettingEventListener(*pListener);
1054 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to unregister exist listener.");
1055 if(pListener != null)
1057 r = AddSettingEventListener(*pListener);
1058 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to register listener.");
1062 __pListener = pListener;
1067 } } // Tizen::System