2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSys_SettingClient.cpp
20 * @brief This is the implementation file for _SettingClient class.
23 #include <unique_ptr.h>
25 #include "FSys_SettingClient.h"
27 #include <FBaseSysLog.h>
29 #include <FApp_AppInfo.h>
30 #include <FIo_AppServiceIpcMessages.h>
31 #include "FSys_CommunicationDispatcherClient.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";
125 static const wchar_t* _USBMODE = L"UsbMode";
126 static const wchar_t* _USBMODE_MTP = L"MTP";
128 static const wchar_t* _SETTING_SERVICE_ID = L"osp.setting.service";
129 static const wchar_t* _SETTING_SERVICE_TYPE_EVENT = L"osp.setting.service.type.event";
131 static const wchar_t* _SETTING_COMMAND_GET_BOOL = L"osp.setting.command.get.bool";
132 static const wchar_t* _SETTING_COMMAND_SET_BOOL = L"osp.setting.command.set.bool";
133 static const wchar_t* _SETTING_COMMAND_SET_BOOL_ASYNC = L"osp.setting.command.set.bool.async";
134 static const wchar_t* _SETTING_COMMAND_GET_BOOL_PRIV = L"osp.setting.command.get.bool.priv";
135 static const wchar_t* _SETTING_COMMAND_SET_BOOL_PRIV = L"osp.setting.command.set.bool.priv";
136 static const wchar_t* _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV = L"osp.setting.command.set.bool.async.priv";
138 static const wchar_t* _SETTING_COMMAND_GET_INT = L"osp.setting.command.get.int";
139 static const wchar_t* _SETTING_COMMAND_SET_INT = L"osp.setting.command.set.int";
141 static const wchar_t* _SETTING_COMMAND_GET_STRING = L"osp.setting.command.get.string";
142 static const wchar_t* _SETTING_COMMAND_SET_STRING = L"osp.setting.command.set.string";
143 static const wchar_t* _SETTING_COMMAND_SET_STRING_PRIV = L"osp.setting.command.set.string.priv";
144 static const wchar_t* _SETTING_COMMAND_SET_STRING_ASYNC = L"osp.setting.command.set.string.async";
146 static const wchar_t* _SETTING_COMMAND_ADD_EVENT = L"osp.setting.command.add.event";
147 static const wchar_t* _SETTING_COMMAND_REMOVE_EVENT = L"osp.setting.command.remove.event";
149 static const wchar_t* _SETTING_COMMAND_SUPPORTED = L"osp.setting.command.supported";
151 static const wchar_t* _SETTING_RESULT_SUCCESS = L"osp.system.result.success";
152 static const wchar_t* _SETTING_RESULT_SYSTEM = L"osp.system.result.system";
153 static const wchar_t* _SETTING_RESULT_INVALID_ARG = L"osp.system.result.invalid_arg";
154 static const wchar_t* _SETTING_RESULT_PRIVILEGE_DENIED = L"osp.system.result.privilege_denied";
155 static const wchar_t* _SETTING_RESULT_UNSUPPORTED_OPERATION = L"osp.system.result.unsupported_operation";
156 static const wchar_t* _SETTING_RESULT_OBJ_NOT_FOUND = L"osp.system.result.obj_not_found";
157 static const wchar_t* _SETTING_RESULT_OBJ_ALREADY_EXIST = L"osp.system.result.obj_already_exist";
158 static const wchar_t* _SETTING_RESULT_IN_PROGRESS = L"osp.system.result.in_progress";
160 _SettingClient* _SettingClient::__pSettingClient = null;
162 class _SettingEventArg : public IEventArg
168 class _SettingEvent : public Event
176 result AddSettingEventListener(ISettingEventListener& listener)
178 result r = AddListener(listener);
179 SysTryReturnResult(NID_SYS, __count >= 0, E_SYSTEM, "Listenr count[%d] is error.", __count);
188 result RemoveSettingEventListener(ISettingEventListener& listener)
190 result r = RemoveListener(listener);
191 SysTryReturnResult(NID_SYS, __count > 0, E_SYSTEM, "Listenr count[%d] is error.", __count);
207 virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
209 ISettingEventListener* pListener = dynamic_cast<ISettingEventListener*> (&listener);
210 const _SettingEventArg* pArg = dynamic_cast<const _SettingEventArg*>(&arg);
212 if(pListener == null || pArg == null)
214 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnt");
218 String value =pArg->KeyName;
219 pListener->OnSettingChanged(value);
223 class _SettingAsyncEventArg : public IEventArg
230 class _SettingAsyncEvent : public Event
233 virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
235 ISettingInfoSetValueAsyncResultListener* pListener = dynamic_cast<ISettingInfoSetValueAsyncResultListener*> (&listener);
236 const _SettingAsyncEventArg* pArg = dynamic_cast<const _SettingAsyncEventArg*>(&arg);
238 if(pListener == null || pArg == null)
240 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnt");
244 result r = pArg->errorCode;
245 pListener->OnResultReceivedForSetValueAsync(pArg->Key, r);
246 RemoveListener(listener);
251 _SettingClient::InitSettingClient(void)
253 static _SettingClient settingManager;
254 __pSettingClient = &settingManager;
258 _SettingClient::GetInstance(void)
260 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
261 if(__pSettingClient == null)
263 pthread_once(&once_block, InitSettingClient);
265 return __pSettingClient;
268 _SettingClient::_SettingClient()
269 : __pSettingEvent(null)
270 , __pSettingEventForInternal(null)
271 , __subscribed(false)
275 result r = E_SUCCESS;
276 static String SETTING_SERVICE_ID(_SETTING_SERVICE_ID);
278 __pSettingEvent = new (std::nothrow) _SettingEvent();
280 __pSettingEventForInternal = new (std::nothrow) _SettingEvent();
282 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
283 SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient.");
285 r = pCommunicationDispatcherClient->RegisterCommunicationListener(SETTING_SERVICE_ID, *this);
286 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient.");
288 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
290 __asyncEventList.Construct();
295 _SettingClient::~_SettingClient()
297 result r = E_SUCCESS;
298 String key(_SETTING_SERVICE_ID);
299 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
300 SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient.");
302 r = pCommunicationDispatcherClient->UnregisterCommunicationListener(key);
303 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient.");
311 _SettingClient::ConvertCode(String code)
313 result r = E_SUCCESS;
314 if(code == _SETTING_RESULT_SUCCESS)
318 else if(code == _SETTING_RESULT_INVALID_ARG)
322 else if(code == _SETTING_RESULT_PRIVILEGE_DENIED)
324 r = E_PRIVILEGE_DENIED;
326 else if(code == _SETTING_RESULT_UNSUPPORTED_OPERATION)
328 r = E_UNSUPPORTED_OPERATION;
330 else if(code == _SETTING_RESULT_OBJ_NOT_FOUND)
334 else if(code == _SETTING_RESULT_OBJ_ALREADY_EXIST)
336 r = E_OBJ_ALREADY_EXIST;
338 else if(code == _SETTING_RESULT_IN_PROGRESS)
342 else if(code == _SETTING_RESULT_SYSTEM)
354 _SettingClient::ConvertKeyOspToTizen(String ospKey)
356 String tizenKey = ospKey;
358 if(tizenKey == _HOUR_FORMAT_SELECTED)
359 tizenKey = _LOCALE_TIME_FORMAT_24HOUR;
361 else if(tizenKey == _ENABLE_MOTION)
362 tizenKey = _MOTION_UI;
364 else if(tizenKey == _DATA_ROAMING_ENABLED)
365 tizenKey = _NETWORK_TELEPHONY_ROAMING;
367 else if(tizenKey == _GPS_ENABLED)
368 tizenKey = _LOCATION_GPS;
370 else if(tizenKey == _PACKET_SERVICE_ALLOWED)
371 tizenKey = _NETWORK_TELEPHONY_PACKETSERVICE;
373 else if(tizenKey == _SILENT_MODE)
374 tizenKey = _SOUND_SILENTMODE;
376 else if(tizenKey == _WPS_ENABLED)
377 tizenKey = _LOCATION_WPS;
379 else if(tizenKey == _FLIGHT_MODE_ENABLED)
380 tizenKey = _NETWORK_FLIGHTMODE;
382 else if(tizenKey == _TOUCH_VIBRATION_LEVEL)
383 tizenKey = _VIBRATOR_LEVEL;
385 else if(tizenKey == _MEDIA_SOUND_VOLUME)
386 tizenKey = _SOUND_MEDIA_VOLUME;
388 else if(tizenKey == _NOTIFICATION_SOUND_VOLUME)
389 tizenKey = _SOUND_NOTIFICATION_VOLUME;
391 else if(tizenKey == _RINGTONE_SOUND_VOLUME)
392 tizenKey = _SOUND_RINGTONE_VOLUME;
394 else if(tizenKey == _SYSTEM_SOUND_VOLUME)
395 tizenKey = _SOUND_SYSTEM_VOLUME;
397 else if(tizenKey == _COUNTRY)
398 tizenKey = _LOCALE_COUNTRY;
400 else if(tizenKey == _DATE_FORMAT)
401 tizenKey = _LOCALE_DATE_FORMAT;
403 else if(tizenKey == _DATE_TIME_FORMAT)
404 tizenKey = _LOCALE_DATETIME_FORMAT;
406 else if(tizenKey == _FONTTYPE)
407 tizenKey = _FONT_TYPE;
409 else if(tizenKey == _FONTSIZE)
410 tizenKey = _FONT_SIZE;
412 else if(tizenKey == _RINGTONE)
413 tizenKey = _SOUND_RINGTONE;
415 else if(tizenKey == _TIME_FORMAT)
416 tizenKey = _LOCALE_TIME_FORMAT;
418 else if(tizenKey == _WALLPAPER)
419 tizenKey = _SCREEN_WALLPAPER;
425 _SettingClient::ConvertKeyTizenToOsp(String tizenKey, String& ospKey)
427 result r = E_SUCCESS;
428 if(tizenKey == _LOCALE_TIME_FORMAT_24HOUR)
430 ospKey = _HOUR_FORMAT_SELECTED;
432 else if(tizenKey == _MOTION_UI)
434 ospKey = _ENABLE_MOTION;
436 else if(tizenKey == _NETWORK_TELEPHONY_ROAMING)
438 ospKey = _DATA_ROAMING_ENABLED;
440 else if(tizenKey == _LOCATION_GPS)
442 ospKey = _GPS_ENABLED;
444 else if(tizenKey == _NETWORK_TELEPHONY_PACKETSERVICE)
446 ospKey = _PACKET_SERVICE_ALLOWED;
448 else if(tizenKey == _SOUND_SILENTMODE)
450 ospKey = _SILENT_MODE;
452 else if(tizenKey == _LOCATION_WPS)
454 ospKey = _WPS_ENABLED;
456 else if(tizenKey == _NETWORK_FLIGHTMODE)
458 ospKey = _FLIGHT_MODE_ENABLED;
460 else if(tizenKey == _VIBRATOR_LEVEL)
462 ospKey = _TOUCH_VIBRATION_LEVEL;
464 else if(tizenKey == _SOUND_MEDIA_VOLUME)
466 ospKey = _MEDIA_SOUND_VOLUME;
468 else if(tizenKey == _SOUND_NOTIFICATION_VOLUME)
470 ospKey = _NOTIFICATION_SOUND_VOLUME;
472 else if(tizenKey == _SOUND_RINGTONE_VOLUME)
474 ospKey = _RINGTONE_SOUND_VOLUME;
476 else if(tizenKey == _SOUND_SYSTEM_VOLUME)
478 ospKey = _SYSTEM_SOUND_VOLUME;
480 else if(tizenKey == _LOCALE_COUNTRY)
484 else if(tizenKey == _LOCALE_DATE_FORMAT)
486 ospKey = _DATE_FORMAT;
488 else if(tizenKey == _LOCALE_DATETIME_FORMAT)
490 ospKey = _DATE_TIME_FORMAT;
492 else if(tizenKey == _FONT_TYPE)
496 else if(tizenKey == _FONT_SIZE)
500 else if(tizenKey == _SOUND_RINGTONE)
504 else if(tizenKey == _LOCALE_TIME_FORMAT)
506 ospKey = _TIME_FORMAT;
508 else if(tizenKey == _SCREEN_WALLPAPER)
521 _SettingClient::GetOnService(String commandId, String key, String& response)
523 result r = E_SUCCESS;
524 String requestKey = ConvertKeyOspToTizen(key);
526 ArrayList requestMessages;
527 ArrayList responseMessages;
529 requestMessages.Construct();
530 responseMessages.Construct();
532 String serviceId(_SETTING_SERVICE_ID);
534 requestMessages.Add(serviceId);
535 requestMessages.Add(commandId);
536 requestMessages.Add(requestKey);
538 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
540 r = __pIpcClient->SendRequest(*pMsg);
541 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
543 String* pResult = (String*)responseMessages.GetAt(2);
544 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
545 r = ConvertCode(*pResult);
548 String* pValue = (String*)responseMessages.GetAt(3);
549 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
556 _SettingClient::SetOnService(String commandId, String key, String& value)
558 result r = E_SUCCESS;
559 String requestKey = ConvertKeyOspToTizen(key);
561 ArrayList requestMessages;
562 ArrayList responseMessages;
564 requestMessages.Construct();
565 responseMessages.Construct();
567 String serviceId(_SETTING_SERVICE_ID);
569 requestMessages.Add(serviceId);
570 requestMessages.Add(commandId);
571 requestMessages.Add(requestKey);
572 requestMessages.Add(value);
574 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
575 r = __pIpcClient->SendRequest(*pMsg);
576 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
578 String* pResult = (String*)responseMessages.GetAt(2);
579 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
580 SysLog(NID_SYS, "Result is %ls.", pResult->GetPointer());
581 r = ConvertCode(*pResult);
582 SysLog(NID_SYS, "r is %s.", GetErrorMessage(r));
588 _SettingClient::GetValue(const String& key, bool& value)
591 result r = GetOnService(_SETTING_COMMAND_GET_BOOL, key, response);
599 else if(response == L"1")
605 SysLogException(NID_SYS, E_SYSTEM, "There are wrong value [%ls].", key.GetPointer());
614 _SettingClient::GetValue(const String& key, int& value)
617 result r = GetOnService(_SETTING_COMMAND_GET_INT, key, response);
621 r = Integer::Parse(response, value);
622 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to convert to integer from [%s]", response.GetPointer());
629 _SettingClient::GetValue(const String& key, long long& value)
631 return E_OBJ_NOT_FOUND;
635 _SettingClient::GetValue(const String& key, double& value)
637 return E_OBJ_NOT_FOUND;
641 _SettingClient::GetValue(const String& key, UuId& value)
643 return E_OBJ_NOT_FOUND;
647 _SettingClient::GetValue(const String& key, String& value)
650 result r = E_SUCCESS;
652 if(key == _USBMODE) //This is compatible issue. USB mode is fixed on Tizen.
654 value = _USBMODE_MTP;
658 if(key == _LANGUAGE) //This is not full compatible.
660 r = GetOnService(_SETTING_COMMAND_GET_STRING, _LOCALE_LANGUAGE, response);
664 r = GetOnService(_SETTING_COMMAND_GET_STRING, key, response);
672 if(key == _LANGUAGE) //This is not full compatible.
674 r = value.SubString(0, 3, value);
675 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to sub string on %ls.", value.GetPointer());
682 _SettingClient::GetValueForPrivilegedKey(const String& key, bool& value)
685 result r = GetOnService(_SETTING_COMMAND_GET_BOOL_PRIV, key, response);
693 else if(response == L"1")
699 SysLogException(NID_SYS, E_SYSTEM, "There are wrong value [%ls].", key.GetPointer());
708 _SettingClient::SetValue(const String& key, const bool& value)
713 requestValue.Append("true");
717 requestValue.Append("false");
719 return SetOnService(_SETTING_COMMAND_SET_BOOL, key, requestValue);
723 _SettingClient::SetValue(const String& key, const int& value)
726 requestValue.Append(value);
727 return SetOnService(_SETTING_COMMAND_SET_INT, key, requestValue);
731 _SettingClient::SetValue(const String& key, const String& value)
734 requestValue.Append(value);
735 return SetOnService(_SETTING_COMMAND_SET_STRING, key, requestValue);
739 _SettingClient::SetValueForPrivilegedKey(const String& key, bool value)
744 requestValue.Append("true");
748 requestValue.Append("false");
750 return SetOnService(_SETTING_COMMAND_SET_BOOL_PRIV, key, requestValue);
754 _SettingClient::SetValueForPrivilegedKey(const String& key, String value)
757 requestValue.Append(value);
758 return SetOnService(_SETTING_COMMAND_SET_STRING_PRIV, key, requestValue);
763 _SettingClient::SetValueAsync(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
765 result r = E_SUCCESS;
768 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
772 requestValue.Append("true");
776 requestValue.Append("false");
779 r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC, key, requestValue);
785 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
786 pEvent->AddListener(*listener);
788 __asyncEventList.Add(new String(key), pEvent);
796 _SettingClient::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
798 result r = E_SUCCESS;
801 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
805 requestValue.Append("true");
809 requestValue.Append("false");
812 r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC_PRIV, key, requestValue);
818 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
819 pEvent->AddListener(*listener);
821 __asyncEventList.Add(new String(key), pEvent);
829 _SettingClient::OnDataReceived(const ArrayList& data)
831 result r = E_SUCCESS;
832 String* pServiceId = (String*)(data.GetAt(0));
833 String* pResponseId = (String*)(data.GetAt(1));
834 String* pKey = (String*)(data.GetAt(2));
835 String* pValue = null;
837 SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service Id.");
838 SysTryReturnVoidResult(NID_SYS, pResponseId != null, E_SYSTEM, "There is response Id.");
839 SysTryReturnVoidResult(NID_SYS, pKey != null, E_SYSTEM, "There is no key.");
841 SysLog(NID_SYS, "ServiceId: %ls, ResponseId: %ls, Key: %ls", pServiceId->GetPointer(), pResponseId->GetPointer(), pKey->GetPointer());
843 if(*pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC || *pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV
844 || *pResponseId == _SETTING_COMMAND_SET_STRING_ASYNC)
847 pValue = (String*)(data.GetAt(3));
849 SysTryReturnVoidResult(NID_SYS, pValue != null, E_SYSTEM, "There is no value.");
850 SysLog(NID_SYS, "Value: %ls", pValue->GetPointer());
852 _SettingAsyncEvent* pEvent = dynamic_cast <_SettingAsyncEvent*> (__asyncEventList.GetValue(*pKey));
853 r = ConvertCode(*pValue);
857 _SettingAsyncEventArg* pSettingAsyncEventArg = new (std::nothrow) _SettingAsyncEventArg;
858 pSettingAsyncEventArg->Key = *pKey;
859 pSettingAsyncEventArg->errorCode = r;
860 pEvent->Fire(*pSettingAsyncEventArg);
862 r = __asyncEventList.Remove(*pKey, true);
864 else if(*pResponseId == _SETTING_SERVICE_TYPE_EVENT)
866 SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready.");
868 _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg();
869 pSettingEventArg->KeyName = *pKey;
872 if(pSettingEventArg->KeyName == _LOCALE_LANGUAGE
873 || pSettingEventArg->KeyName == _LOCALE_COUNTRY
874 || pSettingEventArg->KeyName == _FONT_TYPE
875 || pSettingEventArg->KeyName == _FONT_SIZE)
877 if(__pSettingEventForInternal != null)
879 _SettingEventArg* pSettingEventArgForInternal = new (std::nothrow) _SettingEventArg();
880 pSettingEventArgForInternal->KeyName = pSettingEventArg->KeyName;
881 __pSettingEventForInternal->Fire(*pSettingEventArgForInternal);
885 SysLogException(NID_SYS, E_SYSTEM, "Internal Event is not ready.");
890 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true)
893 r = ConvertKeyTizenToOsp(pSettingEventArg->KeyName, ospKey);
896 pSettingEventArg->KeyName = ospKey;
897 __pSettingEvent->Fire(*pSettingEventArg);
902 __pSettingEvent->Fire(*pSettingEventArg);
908 _SettingClient::HasKey(const String& key)
911 result r = GetOnService(_SETTING_COMMAND_SUPPORTED, key, response);
913 SysLog(NID_SYS, "HasKey result key:%ls, %ls", key.GetPointer(), response.GetPointer());
914 if(response == L"1" && r == E_SUCCESS)
922 _SettingClient::ResetToFactoryDefault(void)
927 //For OSP_COMPAT mode
929 _SettingClient::SetVolume(const String& soundCategory, int level)
931 result r = SetValue(soundCategory, level);
932 if (r == E_INVALID_ARG)
936 else if(r == E_OBJ_NOT_FOUND)
940 else if(r == E_UNSUPPORTED_OPERATION)
949 _SettingClient::SubscribeEvent(void)
951 result r = E_SUCCESS;
952 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
953 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
954 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
956 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
957 _SettingEvent* pSettingEventForInternal = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
958 SysTryReturnResult(NID_SYS, pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
960 if(pSettingEvent->GetCount() > 0 || pSettingEventForInternal->GetCount() >0)
962 if(__subscribed == false)
964 ArrayList requestMessages;
965 ArrayList responseMessages;
967 requestMessages.Construct();
968 responseMessages.Construct();
970 String serviceId(_SETTING_SERVICE_ID);
971 String eventId(_SETTING_COMMAND_ADD_EVENT);
973 requestMessages.Add(serviceId);
974 requestMessages.Add(eventId);
976 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
978 r = __pIpcClient->SendRequest(*pMsg);
979 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
981 String* pResult = (String*)responseMessages.GetAt(2);
982 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
983 r = ConvertCode(*pResult);
991 else if(pSettingEvent->GetCount() == 0 && pSettingEventForInternal->GetCount() == 0)
993 if(__subscribed == true)
995 ArrayList requestMessages;
996 ArrayList responseMessages;
998 requestMessages.Construct();
999 responseMessages.Construct();
1001 String serviceId(_SETTING_SERVICE_ID);
1002 String eventId(_SETTING_COMMAND_REMOVE_EVENT);
1004 requestMessages.Add(serviceId);
1005 requestMessages.Add(eventId);
1007 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
1009 r = __pIpcClient->SendRequest(*pMsg);
1010 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
1012 String* pResult = (String*)responseMessages.GetAt(2);
1013 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
1014 r = ConvertCode(*pResult);
1018 __subscribed = false;
1027 _SettingClient::AddSettingEventListener(ISettingEventListener& listener)
1029 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1030 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
1031 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1033 result r = pSettingEvent->AddSettingEventListener(listener);
1034 if (r == E_INVALID_OPERATION)
1038 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add event listener.");
1040 r = SubscribeEvent();
1041 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1047 _SettingClient::RemoveSettingEventListener(ISettingEventListener& listener)
1049 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1050 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
1051 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1053 result r = pSettingEvent->RemoveSettingEventListener(listener);
1055 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to remove event listener.");
1057 r = SubscribeEvent();
1058 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1063 // Event for internal
1065 _SettingClient::AddSettingEventListenerForInternal(ISettingEventListener& listener)
1067 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener event is not ready.");
1068 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1069 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1071 result r = pSettingEvent->AddSettingEventListener(listener);
1072 if (r == E_INVALID_OPERATION)
1077 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to add event listener.");
1079 r = SubscribeEvent();
1080 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1086 _SettingClient::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
1088 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
1089 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1090 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1092 result r = pSettingEvent->RemoveSettingEventListener(listener);
1094 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to remove event listener.");
1096 r = SubscribeEvent();
1097 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1102 //For OSP_COMPAT mode
1104 _SettingClient::SetSettingEventListener(ISettingEventListener* pListener)
1106 result r = E_SUCCESS;
1107 if(__pListener != null)
1109 r = RemoveSettingEventListener(*pListener);
1110 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to unregister exist listener.");
1111 if(pListener != null)
1113 r = AddSettingEventListener(*pListener);
1114 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to register listener.");
1118 __pListener = pListener;
1123 } } // Tizen::System