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_SettingClient.cpp
19 * @brief This is the implementation file for _SettingClient class.
22 #include <unique_ptr.h>
24 #include "FSys_SettingClient.h"
26 #include <FBaseSysLog.h>
28 #include <FApp_AppInfo.h>
29 #include <FIo_AppServiceIpcMessages.h>
30 #include "FSys_CommunicationDispatcherClient.h"
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Io;
40 namespace Tizen { namespace System
43 static const wchar_t* _MOTION_UI = L"http://tizen.org/setting/motion.ui";
44 static const wchar_t* _ENABLE_MOTION = L"EnableMotion";
47 static const wchar_t* _FONT_SIZE = L"http://tizen.org/setting/font.size";
48 static const wchar_t* _FONTSIZE = L"FontSize";
50 static const wchar_t* _FONT_TYPE = L"http://tizen.org/setting/font.type";
51 static const wchar_t* _FONTTYPE = L"FontType";
56 static const wchar_t* _LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
57 static const wchar_t* _COUNTRY = L"Country";
60 static const wchar_t* _LOCALE_DATE_FORMAT = L"http://tizen.org/setting/locale.date.format";
61 static const wchar_t* _DATE_FORMAT = L"DateFormat";
63 static const wchar_t* _LOCALE_TIME_FORMAT = L"http://tizen.org/setting/locale.time.format";
64 static const wchar_t* _TIME_FORMAT = L"TimeFormat";
66 static const wchar_t* _LOCALE_TIME_FORMAT_24HOUR = L"http://tizen.org/setting/locale.time.format.24hour";
67 static const wchar_t* _HOUR_FORMAT_SELECTED = L"24HourFormatSelected";
70 static const wchar_t* _LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
71 static const wchar_t* _LANGUAGE = L"Language";
74 static const wchar_t* _LOCALE_DATETIME_FORMAT = L"http://tizen.org/setting/locale.date_time.format";
75 static const wchar_t* _DATE_TIME_FORMAT = L"DateTimeFormat";
79 static const wchar_t* _LOCATION_GPS = L"http://tizen.org/setting/location.gps";
80 static const wchar_t* _GPS_ENABLED = L"GPSEnabled";
82 static const wchar_t* _LOCATION_WPS = L"http://tizen.org/setting/location.wps";
83 static const wchar_t* _WPS_ENABLED = L"WPSEnabled";
86 static const wchar_t* _NETWORK_FLIGHTMODE = L"http://tizen.org/setting/network.flight_mode";
87 static const wchar_t* _FLIGHT_MODE_ENABLED = L"FlightModeEnabled";
90 static const wchar_t* _NETWORK_TELEPHONY_PACKETSERVICE = L"http://tizen.org/setting/network.telephony.packet_service";
91 static const wchar_t* _PACKET_SERVICE_ALLOWED = L"PacketServiceAllowed";
93 static const wchar_t* _NETWORK_TELEPHONY_ROAMING = L"http://tizen.org/setting/network.telephony.roaming";
94 static const wchar_t* _DATA_ROAMING_ENABLED = L"DataRoamingEnabled";
97 static const wchar_t* _SCREEN_WALLPAPER = L"http://tizen.org/setting/screen.wallpaper";
98 static const wchar_t* _WALLPAPER = L"Wallpaper";
101 static const wchar_t* _SOUND_MEDIA_VOLUME = L"http://tizen.org/setting/sound.media.volume";
102 static const wchar_t* _MEDIA_SOUND_VOLUME = L"MediaSoundVolume";
104 static const wchar_t* _SOUND_NOTIFICATION_VOLUME = L"http://tizen.org/setting/sound.notification.volume";
105 static const wchar_t* _NOTIFICATION_SOUND_VOLUME = L"NotificationSoundVolume";
107 static const wchar_t* _SOUND_RINGTONE = L"http://tizen.org/setting/sound.ringtone";
108 static const wchar_t* _RINGTONE = L"Ringtone";
110 static const wchar_t* _SOUND_RINGTONE_VOLUME = L"http://tizen.org/setting/sound.ringtone.volume";
111 static const wchar_t* _RINGTONE_SOUND_VOLUME = L"RingtoneSoundVolume";
113 static const wchar_t* _SOUND_SYSTEM_VOLUME = L"http://tizen.org/setting/sound.system.volume";
114 static const wchar_t* _SYSTEM_SOUND_VOLUME = L"SystemSoundVolume";
116 static const wchar_t* _SOUND_SILENTMODE = L"http://tizen.org/setting/sound.silent_mode";
117 static const wchar_t* _SILENT_MODE = L"SilentMode";
120 static const wchar_t* _TOUCH_VIBRATION_LEVEL = L"TouchVibrationLevel";
121 static const wchar_t* _VIBRATOR_LEVEL = L"http://tizen.org/setting/vibrator.level";
123 static const wchar_t* _SETTING_COMMAND_FACTORY_RESET = L"osp.setting.command.factory.reset";
126 static const wchar_t* _USBMODE = L"UsbMode";
127 static const wchar_t* _USBMODE_MTP = L"MTP";
129 static const wchar_t* _SETTING_SERVICE_ID = L"osp.setting.service";
130 static const wchar_t* _SETTING_SERVICE_TYPE_EVENT = L"osp.setting.service.type.event";
132 static const wchar_t* _SETTING_COMMAND_GET_BOOL = L"osp.setting.command.get.bool";
133 static const wchar_t* _SETTING_COMMAND_SET_BOOL = L"osp.setting.command.set.bool";
134 static const wchar_t* _SETTING_COMMAND_SET_BOOL_ASYNC = L"osp.setting.command.set.bool.async";
135 static const wchar_t* _SETTING_COMMAND_GET_BOOL_PRIV = L"osp.setting.command.get.bool.priv";
136 static const wchar_t* _SETTING_COMMAND_SET_BOOL_PRIV = L"osp.setting.command.set.bool.priv";
137 static const wchar_t* _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV = L"osp.setting.command.set.bool.async.priv";
139 static const wchar_t* _SETTING_COMMAND_GET_INT = L"osp.setting.command.get.int";
140 static const wchar_t* _SETTING_COMMAND_SET_INT = L"osp.setting.command.set.int";
142 static const wchar_t* _SETTING_COMMAND_GET_STRING = L"osp.setting.command.get.string";
143 static const wchar_t* _SETTING_COMMAND_SET_STRING = L"osp.setting.command.set.string";
144 static const wchar_t* _SETTING_COMMAND_SET_STRING_PRIV = L"osp.setting.command.set.string.priv";
145 static const wchar_t* _SETTING_COMMAND_SET_STRING_ASYNC = L"osp.setting.command.set.string.async";
147 static const wchar_t* _SETTING_COMMAND_ADD_EVENT = L"osp.setting.command.add.event";
148 static const wchar_t* _SETTING_COMMAND_REMOVE_EVENT = L"osp.setting.command.remove.event";
150 static const wchar_t* _SETTING_COMMAND_SUPPORTED = L"osp.setting.command.supported";
152 static const wchar_t* _SETTING_RESULT_SUCCESS = L"osp.system.result.success";
153 static const wchar_t* _SETTING_RESULT_SYSTEM = L"osp.system.result.system";
154 static const wchar_t* _SETTING_RESULT_INVALID_ARG = L"osp.system.result.invalid_arg";
155 static const wchar_t* _SETTING_RESULT_PRIVILEGE_DENIED = L"osp.system.result.privilege_denied";
156 static const wchar_t* _SETTING_RESULT_UNSUPPORTED_OPERATION = L"osp.system.result.unsupported_operation";
157 static const wchar_t* _SETTING_RESULT_OBJ_NOT_FOUND = L"osp.system.result.obj_not_found";
158 static const wchar_t* _SETTING_RESULT_OBJ_ALREADY_EXIST = L"osp.system.result.obj_already_exist";
159 static const wchar_t* _SETTING_RESULT_IN_PROGRESS = L"osp.system.result.in_progress";
161 _SettingClient* _SettingClient::__pSettingClient = null;
163 class _SettingEventArg : public IEventArg
169 class _SettingEvent : public Event
177 result AddSettingEventListener(ISettingEventListener& listener)
179 result r = AddListener(listener);
180 SysTryReturnResult(NID_SYS, __count >= 0, E_SYSTEM, "Listenr count[%d] is error.", __count);
189 result RemoveSettingEventListener(ISettingEventListener& listener)
191 result r = RemoveListener(listener);
192 SysTryReturnResult(NID_SYS, __count > 0, E_SYSTEM, "Listenr count[%d] is error.", __count);
208 virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
210 ISettingEventListener* pListener = dynamic_cast<ISettingEventListener*> (&listener);
211 const _SettingEventArg* pArg = dynamic_cast<const _SettingEventArg*>(&arg);
213 if(pListener == null || pArg == null)
215 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnt");
219 String value =pArg->KeyName;
220 pListener->OnSettingChanged(value);
224 class _SettingAsyncEventArg : public IEventArg
231 class _SettingAsyncEvent : public Event
234 virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
236 ISettingInfoSetValueAsyncResultListener* pListener = dynamic_cast<ISettingInfoSetValueAsyncResultListener*> (&listener);
237 const _SettingAsyncEventArg* pArg = dynamic_cast<const _SettingAsyncEventArg*>(&arg);
239 if(pListener == null || pArg == null)
241 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnts [%x/%x].", pListener, pArg);
245 result r = pArg->errorCode;
246 pListener->OnResultReceivedForSetValueAsync(pArg->Key, r);
247 RemoveListener(listener);
252 _SettingClient::InitSettingClient(void)
254 static _SettingClient settingManager;
255 __pSettingClient = &settingManager;
259 _SettingClient::GetInstance(void)
261 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
262 if(__pSettingClient == null)
264 pthread_once(&once_block, InitSettingClient);
266 return __pSettingClient;
269 _SettingClient::_SettingClient()
270 : __pSettingEvent(null)
271 , __pSettingEventForInternal(null)
272 , __subscribed(false)
276 result r = E_SUCCESS;
277 static String SETTING_SERVICE_ID(_SETTING_SERVICE_ID);
279 __pSettingEvent = new (std::nothrow) _SettingEvent();
281 __pSettingEventForInternal = new (std::nothrow) _SettingEvent();
283 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
284 SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient.");
286 r = pCommunicationDispatcherClient->RegisterCommunicationListener(SETTING_SERVICE_ID, *this);
287 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient.");
289 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
291 __asyncEventList.Construct();
296 _SettingClient::~_SettingClient()
298 result r = E_SUCCESS;
299 String key(_SETTING_SERVICE_ID);
300 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
301 SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient.");
303 r = pCommunicationDispatcherClient->UnregisterCommunicationListener(key);
304 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient.");
312 _SettingClient::ConvertCode(String code)
314 result r = E_SUCCESS;
315 if(code == _SETTING_RESULT_SUCCESS)
319 else if(code == _SETTING_RESULT_INVALID_ARG)
323 else if(code == _SETTING_RESULT_PRIVILEGE_DENIED)
325 r = E_PRIVILEGE_DENIED;
327 else if(code == _SETTING_RESULT_UNSUPPORTED_OPERATION)
329 r = E_UNSUPPORTED_OPERATION;
331 else if(code == _SETTING_RESULT_OBJ_NOT_FOUND)
335 else if(code == _SETTING_RESULT_OBJ_ALREADY_EXIST)
337 r = E_OBJ_ALREADY_EXIST;
339 else if(code == _SETTING_RESULT_IN_PROGRESS)
343 else if(code == _SETTING_RESULT_SYSTEM)
355 _SettingClient::ConvertKeyOspToTizen(String ospKey)
357 String tizenKey = ospKey;
359 if(tizenKey == _HOUR_FORMAT_SELECTED)
360 tizenKey = _LOCALE_TIME_FORMAT_24HOUR;
362 else if(tizenKey == _ENABLE_MOTION)
363 tizenKey = _MOTION_UI;
365 else if(tizenKey == _DATA_ROAMING_ENABLED)
366 tizenKey = _NETWORK_TELEPHONY_ROAMING;
368 else if(tizenKey == _GPS_ENABLED)
369 tizenKey = _LOCATION_GPS;
371 else if(tizenKey == _PACKET_SERVICE_ALLOWED)
372 tizenKey = _NETWORK_TELEPHONY_PACKETSERVICE;
374 else if(tizenKey == _SILENT_MODE)
375 tizenKey = _SOUND_SILENTMODE;
377 else if(tizenKey == _WPS_ENABLED)
378 tizenKey = _LOCATION_WPS;
380 else if(tizenKey == _FLIGHT_MODE_ENABLED)
381 tizenKey = _NETWORK_FLIGHTMODE;
383 else if(tizenKey == _TOUCH_VIBRATION_LEVEL)
384 tizenKey = _VIBRATOR_LEVEL;
386 else if(tizenKey == _MEDIA_SOUND_VOLUME)
387 tizenKey = _SOUND_MEDIA_VOLUME;
389 else if(tizenKey == _NOTIFICATION_SOUND_VOLUME)
390 tizenKey = _SOUND_NOTIFICATION_VOLUME;
392 else if(tizenKey == _RINGTONE_SOUND_VOLUME)
393 tizenKey = _SOUND_RINGTONE_VOLUME;
395 else if(tizenKey == _SYSTEM_SOUND_VOLUME)
396 tizenKey = _SOUND_SYSTEM_VOLUME;
398 else if(tizenKey == _COUNTRY)
399 tizenKey = _LOCALE_COUNTRY;
401 else if(tizenKey == _DATE_FORMAT)
402 tizenKey = _LOCALE_DATE_FORMAT;
404 else if(tizenKey == _DATE_TIME_FORMAT)
405 tizenKey = _LOCALE_DATETIME_FORMAT;
407 else if(tizenKey == _FONTTYPE)
408 tizenKey = _FONT_TYPE;
410 else if(tizenKey == _FONTSIZE)
411 tizenKey = _FONT_SIZE;
413 else if(tizenKey == _RINGTONE)
414 tizenKey = _SOUND_RINGTONE;
416 else if(tizenKey == _TIME_FORMAT)
417 tizenKey = _LOCALE_TIME_FORMAT;
419 else if(tizenKey == _WALLPAPER)
420 tizenKey = _SCREEN_WALLPAPER;
426 _SettingClient::ConvertKeyTizenToOsp(String tizenKey, String& ospKey)
428 result r = E_SUCCESS;
429 if(tizenKey == _LOCALE_TIME_FORMAT_24HOUR)
431 ospKey = _HOUR_FORMAT_SELECTED;
433 else if(tizenKey == _MOTION_UI)
435 ospKey = _ENABLE_MOTION;
437 else if(tizenKey == _NETWORK_TELEPHONY_ROAMING)
439 ospKey = _DATA_ROAMING_ENABLED;
441 else if(tizenKey == _LOCATION_GPS)
443 ospKey = _GPS_ENABLED;
445 else if(tizenKey == _NETWORK_TELEPHONY_PACKETSERVICE)
447 ospKey = _PACKET_SERVICE_ALLOWED;
449 else if(tizenKey == _SOUND_SILENTMODE)
451 ospKey = _SILENT_MODE;
453 else if(tizenKey == _LOCATION_WPS)
455 ospKey = _WPS_ENABLED;
457 else if(tizenKey == _NETWORK_FLIGHTMODE)
459 ospKey = _FLIGHT_MODE_ENABLED;
461 else if(tizenKey == _VIBRATOR_LEVEL)
463 ospKey = _TOUCH_VIBRATION_LEVEL;
465 else if(tizenKey == _SOUND_MEDIA_VOLUME)
467 ospKey = _MEDIA_SOUND_VOLUME;
469 else if(tizenKey == _SOUND_NOTIFICATION_VOLUME)
471 ospKey = _NOTIFICATION_SOUND_VOLUME;
473 else if(tizenKey == _SOUND_RINGTONE_VOLUME)
475 ospKey = _RINGTONE_SOUND_VOLUME;
477 else if(tizenKey == _SOUND_SYSTEM_VOLUME)
479 ospKey = _SYSTEM_SOUND_VOLUME;
481 else if(tizenKey == _LOCALE_COUNTRY)
485 else if(tizenKey == _LOCALE_DATE_FORMAT)
487 ospKey = _DATE_FORMAT;
489 else if(tizenKey == _LOCALE_DATETIME_FORMAT)
491 ospKey = _DATE_TIME_FORMAT;
493 else if(tizenKey == _FONT_TYPE)
497 else if(tizenKey == _FONT_SIZE)
501 else if(tizenKey == _SOUND_RINGTONE)
505 else if(tizenKey == _LOCALE_TIME_FORMAT)
507 ospKey = _TIME_FORMAT;
509 else if(tizenKey == _SCREEN_WALLPAPER)
522 _SettingClient::GetOnService(String commandId, String key, String& response)
524 result r = E_SUCCESS;
525 String requestKey = ConvertKeyOspToTizen(key);
527 ArrayList requestMessages;
528 ArrayList responseMessages;
530 requestMessages.Construct();
531 responseMessages.Construct();
533 String serviceId(_SETTING_SERVICE_ID);
535 requestMessages.Add(serviceId);
536 requestMessages.Add(commandId);
537 requestMessages.Add(requestKey);
539 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
541 r = __pIpcClient->SendRequest(*(pMsg.get()));
542 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
544 String* pResult = (String*)responseMessages.GetAt(2);
545 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
546 r = ConvertCode(*pResult);
549 String* pValue = (String*)responseMessages.GetAt(3);
550 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
553 responseMessages.RemoveAll(true);
558 _SettingClient::SetOnService(String commandId, String key, String& value)
560 result r = E_SUCCESS;
561 String requestKey = ConvertKeyOspToTizen(key);
563 ArrayList requestMessages;
564 ArrayList responseMessages;
566 requestMessages.Construct();
567 responseMessages.Construct();
569 String serviceId(_SETTING_SERVICE_ID);
571 requestMessages.Add(serviceId);
572 requestMessages.Add(commandId);
573 requestMessages.Add(requestKey);
574 requestMessages.Add(value);
576 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
577 r = __pIpcClient->SendRequest(*(pMsg.get()));
578 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
580 String* pResult = (String*)responseMessages.GetAt(2);
581 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
582 SysLog(NID_SYS, "Result is %ls.", pResult->GetPointer());
583 r = ConvertCode(*pResult);
584 SysLog(NID_SYS, "r is %s.", GetErrorMessage(r));
586 responseMessages.RemoveAll(true);
591 _SettingClient::GetValue(const String& key, bool& value)
594 result r = GetOnService(_SETTING_COMMAND_GET_BOOL, key, response);
602 else if(response == L"1")
608 SysLogException(NID_SYS, E_SYSTEM, "There are wrong value [%ls].", key.GetPointer());
617 _SettingClient::GetValue(const String& key, int& value)
620 result r = GetOnService(_SETTING_COMMAND_GET_INT, key, response);
624 r = Integer::Parse(response, value);
625 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to convert to integer from [%s]", response.GetPointer());
632 _SettingClient::GetValue(const String& key, long long& value)
634 return E_OBJ_NOT_FOUND;
638 _SettingClient::GetValue(const String& key, double& value)
640 return E_OBJ_NOT_FOUND;
644 _SettingClient::GetValue(const String& key, UuId& value)
646 return E_OBJ_NOT_FOUND;
650 _SettingClient::GetValue(const String& key, String& value)
653 result r = E_SUCCESS;
655 if(key == _USBMODE) //This is compatible issue. USB mode is fixed on Tizen.
657 value = _USBMODE_MTP;
661 if(key == _LANGUAGE) //This is not full compatible.
663 r = GetOnService(_SETTING_COMMAND_GET_STRING, _LOCALE_LANGUAGE, response);
667 r = GetOnService(_SETTING_COMMAND_GET_STRING, key, response);
675 if(key == _LANGUAGE) //This is not full compatible.
677 r = value.SubString(0, 3, value);
678 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to sub string on %ls.", value.GetPointer());
685 _SettingClient::GetValueForPrivilegedKey(const String& key, bool& value)
688 result r = GetOnService(_SETTING_COMMAND_GET_BOOL_PRIV, key, response);
696 else if(response == L"1")
702 SysLogException(NID_SYS, E_SYSTEM, "There are wrong value [%ls].", key.GetPointer());
711 _SettingClient::SetValue(const String& key, const bool& value)
716 requestValue.Append("true");
720 requestValue.Append("false");
722 return SetOnService(_SETTING_COMMAND_SET_BOOL, key, requestValue);
726 _SettingClient::SetValue(const String& key, const int& value)
729 requestValue.Append(value);
730 return SetOnService(_SETTING_COMMAND_SET_INT, key, requestValue);
734 _SettingClient::SetValue(const String& key, const String& value)
737 requestValue.Append(value);
738 return SetOnService(_SETTING_COMMAND_SET_STRING, key, requestValue);
742 _SettingClient::SetValueForPrivilegedKey(const String& key, bool value)
747 requestValue.Append("true");
751 requestValue.Append("false");
753 return SetOnService(_SETTING_COMMAND_SET_BOOL_PRIV, key, requestValue);
757 _SettingClient::SetValueForPrivilegedKey(const String& key, String value)
760 requestValue.Append(value);
761 return SetOnService(_SETTING_COMMAND_SET_STRING_PRIV, key, requestValue);
766 _SettingClient::SetValueAsync(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
768 result r = E_SUCCESS;
771 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
775 requestValue.Append("true");
779 requestValue.Append("false");
782 r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC, key, requestValue);
788 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
789 pEvent->AddListener(*listener);
791 __asyncEventList.Add(new String(key), pEvent);
799 _SettingClient::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
801 result r = E_SUCCESS;
804 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
808 requestValue.Append("true");
812 requestValue.Append("false");
815 r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC_PRIV, key, requestValue);
821 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
822 pEvent->AddListener(*listener);
824 __asyncEventList.Add(new String(key), pEvent);
832 _SettingClient::OnDataReceived(const ArrayList& data)
834 result r = E_SUCCESS;
835 String* pServiceId = (String*)(data.GetAt(0));
836 String* pResponseId = (String*)(data.GetAt(1));
837 String* pKey = (String*)(data.GetAt(2));
838 String* pValue = null;
840 SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service Id.");
841 SysTryReturnVoidResult(NID_SYS, pResponseId != null, E_SYSTEM, "There is response Id.");
842 SysTryReturnVoidResult(NID_SYS, pKey != null, E_SYSTEM, "There is no key.");
844 SysLog(NID_SYS, "ServiceId: %ls, ResponseId: %ls, Key: %ls", pServiceId->GetPointer(), pResponseId->GetPointer(), pKey->GetPointer());
846 if(*pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC || *pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV
847 || *pResponseId == _SETTING_COMMAND_SET_STRING_ASYNC)
849 pValue = (String*)(data.GetAt(3));
851 SysTryReturnVoidResult(NID_SYS, pValue != null, E_SYSTEM, "There is no value.");
852 SysLog(NID_SYS, "Value: %ls", pValue->GetPointer());
854 _SettingAsyncEvent* pEvent = dynamic_cast <_SettingAsyncEvent*> (__asyncEventList.GetValue(*pKey));
855 r = ConvertCode(*pValue);
859 _SettingAsyncEventArg* pSettingAsyncEventArg = new (std::nothrow) _SettingAsyncEventArg;
860 pSettingAsyncEventArg->Key = *pKey;
861 pSettingAsyncEventArg->errorCode = r;
862 pEvent->Fire(*pSettingAsyncEventArg);
864 r = __asyncEventList.Remove(*pKey, true);
866 else if(*pResponseId == _SETTING_SERVICE_TYPE_EVENT)
868 SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready.");
870 _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg();
871 pSettingEventArg->KeyName = *pKey;
874 if(pSettingEventArg->KeyName == _LOCALE_LANGUAGE
875 || pSettingEventArg->KeyName == _LOCALE_COUNTRY
876 || pSettingEventArg->KeyName == _FONT_TYPE
877 || pSettingEventArg->KeyName == _FONT_SIZE)
879 if(__pSettingEventForInternal != null)
881 _SettingEventArg* pSettingEventArgForInternal = new (std::nothrow) _SettingEventArg();
882 pSettingEventArgForInternal->KeyName = pSettingEventArg->KeyName;
883 __pSettingEventForInternal->Fire(*pSettingEventArgForInternal);
887 SysLogException(NID_SYS, E_SYSTEM, "Internal Event is not ready.");
892 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true)
895 r = ConvertKeyTizenToOsp(pSettingEventArg->KeyName, ospKey);
898 pSettingEventArg->KeyName = ospKey;
899 __pSettingEvent->Fire(*pSettingEventArg);
904 __pSettingEvent->Fire(*pSettingEventArg);
910 _SettingClient::HasKey(const String& key)
913 result r = GetOnService(_SETTING_COMMAND_SUPPORTED, key, response);
915 SysLog(NID_SYS, "HasKey result key:%ls, %ls", key.GetPointer(), response.GetPointer());
916 if(response == L"1" && r == E_SUCCESS)
924 _SettingClient::ResetToFactoryDefault(void)
929 result r = GetOnService(_SETTING_COMMAND_FACTORY_RESET, value, response);
930 SysLog(NID_SYS, "Reset result is %s[%ls].", GetErrorMessage(r), response.GetPointer());
934 //For OSP_COMPAT mode
936 _SettingClient::SetVolume(const String& soundCategory, int level)
938 result r = SetValue(soundCategory, level);
939 if (r == E_INVALID_ARG)
943 else if(r == E_OBJ_NOT_FOUND)
947 else if(r == E_UNSUPPORTED_OPERATION)
956 _SettingClient::SubscribeEvent(void)
958 result r = E_SUCCESS;
959 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
960 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
961 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
963 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
964 _SettingEvent* pSettingEventForInternal = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
965 SysTryReturnResult(NID_SYS, pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
967 if(pSettingEvent->GetCount() > 0 || pSettingEventForInternal->GetCount() >0)
969 if(__subscribed == false)
971 ArrayList requestMessages;
972 ArrayList responseMessages;
974 requestMessages.Construct();
975 responseMessages.Construct();
977 String serviceId(_SETTING_SERVICE_ID);
978 String eventId(_SETTING_COMMAND_ADD_EVENT);
980 requestMessages.Add(serviceId);
981 requestMessages.Add(eventId);
983 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
985 r = __pIpcClient->SendRequest(*(pMsg.get()));
986 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
988 String* pResult = (String*)responseMessages.GetAt(2);
989 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
990 r = ConvertCode(*pResult);
996 responseMessages.RemoveAll(true);
999 else if(pSettingEvent->GetCount() == 0 && pSettingEventForInternal->GetCount() == 0)
1001 if(__subscribed == true)
1003 ArrayList requestMessages;
1004 ArrayList responseMessages;
1006 requestMessages.Construct();
1007 responseMessages.Construct();
1009 String serviceId(_SETTING_SERVICE_ID);
1010 String eventId(_SETTING_COMMAND_REMOVE_EVENT);
1012 requestMessages.Add(serviceId);
1013 requestMessages.Add(eventId);
1015 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
1017 r = __pIpcClient->SendRequest(*(pMsg.get()));
1018 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
1020 String* pResult = (String*)responseMessages.GetAt(2);
1021 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
1022 r = ConvertCode(*pResult);
1026 __subscribed = false;
1028 responseMessages.RemoveAll(true);
1036 _SettingClient::AddSettingEventListener(ISettingEventListener& listener)
1038 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1039 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
1040 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1042 result r = pSettingEvent->AddSettingEventListener(listener);
1043 if (r == E_INVALID_OPERATION)
1047 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add event listener.");
1049 r = SubscribeEvent();
1050 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1056 _SettingClient::RemoveSettingEventListener(ISettingEventListener& listener)
1058 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1059 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
1060 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1062 result r = pSettingEvent->RemoveSettingEventListener(listener);
1064 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to remove event listener.");
1066 r = SubscribeEvent();
1067 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1072 // Event for internal
1074 _SettingClient::AddSettingEventListenerForInternal(ISettingEventListener& listener)
1076 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener event is not ready.");
1077 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1078 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1080 result r = pSettingEvent->AddSettingEventListener(listener);
1081 SysLog(NID_SYS, "Add Setting event result is %s for internal.", GetErrorMessage(r));
1083 if (r == E_INVALID_OPERATION)
1088 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to add event listener.");
1090 r = SubscribeEvent();
1091 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1097 _SettingClient::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
1099 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
1100 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1101 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1103 result r = pSettingEvent->RemoveSettingEventListener(listener);
1104 SysLog(NID_SYS, "Remove setting event result is %s for internal.", GetErrorMessage(r));
1106 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to remove event listener.");
1108 r = SubscribeEvent();
1109 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1114 //For OSP_COMPAT mode
1116 _SettingClient::SetSettingEventListener(ISettingEventListener* pListener)
1118 result r = E_SUCCESS;
1119 if(__pListener != null)
1121 r = RemoveSettingEventListener(*pListener);
1122 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to unregister exist listener.");
1123 if(pListener != null)
1125 r = AddSettingEventListener(*pListener);
1126 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to register listener.");
1130 __pListener = pListener;
1135 } } // Tizen::System