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";
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 static const wchar_t* _SETTING_SERVICE_ID = L"osp.setting.service";
131 static const wchar_t* _SETTING_SERVICE_TYPE_EVENT = L"osp.setting.service.type.event";
133 static const wchar_t* _SETTING_COMMAND_GET_BOOL = L"osp.setting.command.get.bool";
134 static const wchar_t* _SETTING_COMMAND_SET_BOOL = L"osp.setting.command.set.bool";
135 static const wchar_t* _SETTING_COMMAND_SET_BOOL_ASYNC = L"osp.setting.command.set.bool.async";
136 static const wchar_t* _SETTING_COMMAND_GET_BOOL_PRIV = L"osp.setting.command.get.bool.priv";
137 static const wchar_t* _SETTING_COMMAND_SET_BOOL_PRIV = L"osp.setting.command.set.bool.priv";
138 static const wchar_t* _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV = L"osp.setting.command.set.bool.async.priv";
140 static const wchar_t* _SETTING_COMMAND_GET_INT = L"osp.setting.command.get.int";
141 static const wchar_t* _SETTING_COMMAND_SET_INT = L"osp.setting.command.set.int";
143 static const wchar_t* _SETTING_COMMAND_GET_STRING = L"osp.setting.command.get.string";
144 static const wchar_t* _SETTING_COMMAND_SET_STRING = L"osp.setting.command.set.string";
145 static const wchar_t* _SETTING_COMMAND_SET_STRING_PRIV = L"osp.setting.command.set.string.priv";
146 static const wchar_t* _SETTING_COMMAND_SET_STRING_ASYNC = L"osp.setting.command.set.string.async";
148 static const wchar_t* _SETTING_COMMAND_ADD_EVENT = L"osp.setting.command.add.event";
149 static const wchar_t* _SETTING_COMMAND_REMOVE_EVENT = L"osp.setting.command.remove.event";
151 static const wchar_t* _SETTING_COMMAND_SUPPORTED = L"osp.setting.command.supported";
153 static const wchar_t* _SETTING_RESULT_SUCCESS = L"osp.system.result.success";
154 static const wchar_t* _SETTING_RESULT_SYSTEM = L"osp.system.result.system";
155 static const wchar_t* _SETTING_RESULT_INVALID_ARG = L"osp.system.result.invalid_arg";
156 static const wchar_t* _SETTING_RESULT_PRIVILEGE_DENIED = L"osp.system.result.privilege_denied";
157 static const wchar_t* _SETTING_RESULT_UNSUPPORTED_OPERATION = L"osp.system.result.unsupported_operation";
158 static const wchar_t* _SETTING_RESULT_OBJ_NOT_FOUND = L"osp.system.result.obj_not_found";
159 static const wchar_t* _SETTING_RESULT_OBJ_ALREADY_EXIST = L"osp.system.result.obj_already_exist";
160 static const wchar_t* _SETTING_RESULT_IN_PROGRESS = L"osp.system.result.in_progress";
162 _SettingClient* _SettingClient::__pSettingClient = null;
164 class _SettingEventArg : public IEventArg
170 class _SettingEvent : public Event
178 result AddSettingEventListener(ISettingEventListener& listener)
180 result r = AddListener(listener);
181 SysTryReturnResult(NID_SYS, __count >= 0, E_SYSTEM, "Listenr count[%d] is error.", __count);
190 result RemoveSettingEventListener(ISettingEventListener& listener)
192 result r = RemoveListener(listener);
193 SysTryReturnResult(NID_SYS, __count > 0, E_SYSTEM, "Listenr count[%d] is error.", __count);
209 virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
211 ISettingEventListener* pListener = dynamic_cast<ISettingEventListener*> (&listener);
212 const _SettingEventArg* pArg = dynamic_cast<const _SettingEventArg*>(&arg);
214 if(pListener == null || pArg == null)
216 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnt");
220 String value =pArg->KeyName;
221 pListener->OnSettingChanged(value);
225 class _SettingAsyncEventArg : public IEventArg
232 class _SettingAsyncEvent : public Event
235 virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
237 ISettingInfoSetValueAsyncResultListener* pListener = dynamic_cast<ISettingInfoSetValueAsyncResultListener*> (&listener);
238 const _SettingAsyncEventArg* pArg = dynamic_cast<const _SettingAsyncEventArg*>(&arg);
240 if(pListener == null || pArg == null)
242 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listner or arguemnt");
246 result r = pArg->errorCode;
247 pListener->OnResultReceivedForSetValueAsync(pArg->Key, r);
248 RemoveListener(listener);
253 _SettingClient::InitSettingClient(void)
255 static _SettingClient settingManager;
256 __pSettingClient = &settingManager;
260 _SettingClient::GetInstance(void)
262 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
263 if(__pSettingClient == null)
265 pthread_once(&once_block, InitSettingClient);
267 return __pSettingClient;
270 _SettingClient::_SettingClient()
271 : __pSettingEvent(null)
272 , __pSettingEventForInternal(null)
273 , __subscribed(false)
277 result r = E_SUCCESS;
278 static String SETTING_SERVICE_ID(_SETTING_SERVICE_ID);
280 __pSettingEvent = new (std::nothrow) _SettingEvent();
282 __pSettingEventForInternal = new (std::nothrow) _SettingEvent();
284 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
285 SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient.");
287 r = pCommunicationDispatcherClient->RegisterCommunicationListener(SETTING_SERVICE_ID, *this);
288 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient.");
290 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
292 __asyncEventList.Construct();
297 _SettingClient::~_SettingClient()
299 result r = E_SUCCESS;
300 String key(_SETTING_SERVICE_ID);
301 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
302 SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient.");
304 r = pCommunicationDispatcherClient->UnregisterCommunicationListener(key);
305 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient.");
313 _SettingClient::ConvertCode(String code)
315 result r = E_SUCCESS;
316 if(code == _SETTING_RESULT_SUCCESS)
320 else if(code == _SETTING_RESULT_INVALID_ARG)
324 else if(code == _SETTING_RESULT_PRIVILEGE_DENIED)
326 r = E_PRIVILEGE_DENIED;
328 else if(code == _SETTING_RESULT_UNSUPPORTED_OPERATION)
330 r = E_UNSUPPORTED_OPERATION;
332 else if(code == _SETTING_RESULT_OBJ_NOT_FOUND)
336 else if(code == _SETTING_RESULT_OBJ_ALREADY_EXIST)
338 r = E_OBJ_ALREADY_EXIST;
340 else if(code == _SETTING_RESULT_IN_PROGRESS)
344 else if(code == _SETTING_RESULT_SYSTEM)
356 _SettingClient::ConvertKeyOspToTizen(String ospKey)
358 String tizenKey = ospKey;
360 if(tizenKey == _HOUR_FORMAT_SELECTED)
361 tizenKey = _LOCALE_TIME_FORMAT_24HOUR;
363 else if(tizenKey == _ENABLE_MOTION)
364 tizenKey = _MOTION_UI;
366 else if(tizenKey == _DATA_ROAMING_ENABLED)
367 tizenKey = _NETWORK_TELEPHONY_ROAMING;
369 else if(tizenKey == _GPS_ENABLED)
370 tizenKey = _LOCATION_GPS;
372 else if(tizenKey == _PACKET_SERVICE_ALLOWED)
373 tizenKey = _NETWORK_TELEPHONY_PACKETSERVICE;
375 else if(tizenKey == _SILENT_MODE)
376 tizenKey = _SOUND_SILENTMODE;
378 else if(tizenKey == _WPS_ENABLED)
379 tizenKey = _LOCATION_WPS;
381 else if(tizenKey == _FLIGHT_MODE_ENABLED)
382 tizenKey = _NETWORK_FLIGHTMODE;
384 else if(tizenKey == _TOUCH_VIBRATION_LEVEL)
385 tizenKey = _VIBRATOR_LEVEL;
387 else if(tizenKey == _MEDIA_SOUND_VOLUME)
388 tizenKey = _SOUND_MEDIA_VOLUME;
390 else if(tizenKey == _NOTIFICATION_SOUND_VOLUME)
391 tizenKey = _SOUND_NOTIFICATION_VOLUME;
393 else if(tizenKey == _RINGTONE_SOUND_VOLUME)
394 tizenKey = _SOUND_RINGTONE_VOLUME;
396 else if(tizenKey == _SYSTEM_SOUND_VOLUME)
397 tizenKey = _SOUND_SYSTEM_VOLUME;
399 else if(tizenKey == _COUNTRY)
400 tizenKey = _LOCALE_COUNTRY;
402 else if(tizenKey == _DATE_FORMAT)
403 tizenKey = _LOCALE_DATE_FORMAT;
405 else if(tizenKey == _DATE_TIME_FORMAT)
406 tizenKey = _LOCALE_DATETIME_FORMAT;
408 else if(tizenKey == _FONTTYPE)
409 tizenKey = _FONT_TYPE;
411 else if(tizenKey == _FONTSIZE)
412 tizenKey = _FONT_SIZE;
414 else if(tizenKey == _RINGTONE)
415 tizenKey = _SOUND_RINGTONE;
417 else if(tizenKey == _TIME_FORMAT)
418 tizenKey = _LOCALE_TIME_FORMAT;
420 else if(tizenKey == _WALLPAPER)
421 tizenKey = _SCREEN_WALLPAPER;
427 _SettingClient::ConvertKeyTizenToOsp(String tizenKey, String& ospKey)
429 result r = E_SUCCESS;
430 if(tizenKey == _LOCALE_TIME_FORMAT_24HOUR)
432 ospKey = _HOUR_FORMAT_SELECTED;
434 else if(tizenKey == _MOTION_UI)
436 ospKey = _ENABLE_MOTION;
438 else if(tizenKey == _NETWORK_TELEPHONY_ROAMING)
440 ospKey = _DATA_ROAMING_ENABLED;
442 else if(tizenKey == _LOCATION_GPS)
444 ospKey = _GPS_ENABLED;
446 else if(tizenKey == _NETWORK_TELEPHONY_PACKETSERVICE)
448 ospKey = _PACKET_SERVICE_ALLOWED;
450 else if(tizenKey == _SOUND_SILENTMODE)
452 ospKey = _SILENT_MODE;
454 else if(tizenKey == _LOCATION_WPS)
456 ospKey = _WPS_ENABLED;
458 else if(tizenKey == _NETWORK_FLIGHTMODE)
460 ospKey = _FLIGHT_MODE_ENABLED;
462 else if(tizenKey == _VIBRATOR_LEVEL)
464 ospKey = _TOUCH_VIBRATION_LEVEL;
466 else if(tizenKey == _SOUND_MEDIA_VOLUME)
468 ospKey = _MEDIA_SOUND_VOLUME;
470 else if(tizenKey == _SOUND_NOTIFICATION_VOLUME)
472 ospKey = _NOTIFICATION_SOUND_VOLUME;
474 else if(tizenKey == _SOUND_RINGTONE_VOLUME)
476 ospKey = _RINGTONE_SOUND_VOLUME;
478 else if(tizenKey == _SOUND_SYSTEM_VOLUME)
480 ospKey = _SYSTEM_SOUND_VOLUME;
482 else if(tizenKey == _LOCALE_COUNTRY)
486 else if(tizenKey == _LOCALE_DATE_FORMAT)
488 ospKey = _DATE_FORMAT;
490 else if(tizenKey == _LOCALE_DATETIME_FORMAT)
492 ospKey = _DATE_TIME_FORMAT;
494 else if(tizenKey == _FONT_TYPE)
498 else if(tizenKey == _FONT_SIZE)
502 else if(tizenKey == _SOUND_RINGTONE)
506 else if(tizenKey == _LOCALE_TIME_FORMAT)
508 ospKey = _TIME_FORMAT;
510 else if(tizenKey == _SCREEN_WALLPAPER)
523 _SettingClient::GetOnService(String commandId, String key, String& response)
525 result r = E_SUCCESS;
526 String requestKey = ConvertKeyOspToTizen(key);
528 ArrayList requestMessages;
529 ArrayList responseMessages;
531 requestMessages.Construct();
532 responseMessages.Construct();
534 String serviceId(_SETTING_SERVICE_ID);
536 requestMessages.Add(serviceId);
537 requestMessages.Add(commandId);
538 requestMessages.Add(requestKey);
540 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
542 r = __pIpcClient->SendRequest(*pMsg);
543 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
545 String* pResult = (String*)responseMessages.GetAt(2);
546 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
547 r = ConvertCode(*pResult);
550 String* pValue = (String*)responseMessages.GetAt(3);
551 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
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);
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));
590 _SettingClient::GetValue(const String& key, bool& value)
593 result r = GetOnService(_SETTING_COMMAND_GET_BOOL, key, response);
601 else if(response == L"1")
607 SysLogException(NID_SYS, E_SYSTEM, "There are wrong value [%ls].", key.GetPointer());
616 _SettingClient::GetValue(const String& key, int& value)
619 result r = GetOnService(_SETTING_COMMAND_GET_INT, key, response);
623 r = Integer::Parse(response, value);
624 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to convert to integer from [%s]", response.GetPointer());
631 _SettingClient::GetValue(const String& key, long long& value)
633 return E_OBJ_NOT_FOUND;
637 _SettingClient::GetValue(const String& key, double& value)
639 return E_OBJ_NOT_FOUND;
643 _SettingClient::GetValue(const String& key, UuId& value)
645 return E_OBJ_NOT_FOUND;
649 _SettingClient::GetValue(const String& key, String& value)
652 result r = E_SUCCESS;
654 if(key == _USBMODE) //This is compatible issue. USB mode is fixed on Tizen.
656 value = _USBMODE_MTP;
660 if(key == _LANGUAGE) //This is not full compatible.
662 r = GetOnService(_SETTING_COMMAND_GET_STRING, _LOCALE_LANGUAGE, response);
666 r = GetOnService(_SETTING_COMMAND_GET_STRING, key, response);
674 if(key == _LANGUAGE) //This is not full compatible.
676 r = value.SubString(0, 3, value);
677 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to sub string on %ls.", value.GetPointer());
684 _SettingClient::GetValueForPrivilegedKey(const String& key, bool& value)
687 result r = GetOnService(_SETTING_COMMAND_GET_BOOL_PRIV, key, response);
695 else if(response == L"1")
701 SysLogException(NID_SYS, E_SYSTEM, "There are wrong value [%ls].", key.GetPointer());
710 _SettingClient::SetValue(const String& key, const bool& value)
715 requestValue.Append("true");
719 requestValue.Append("false");
721 return SetOnService(_SETTING_COMMAND_SET_BOOL, key, requestValue);
725 _SettingClient::SetValue(const String& key, const int& value)
728 requestValue.Append(value);
729 return SetOnService(_SETTING_COMMAND_SET_INT, key, requestValue);
733 _SettingClient::SetValue(const String& key, const String& value)
736 requestValue.Append(value);
737 return SetOnService(_SETTING_COMMAND_SET_STRING, key, requestValue);
741 _SettingClient::SetValueForPrivilegedKey(const String& key, bool value)
746 requestValue.Append("true");
750 requestValue.Append("false");
752 return SetOnService(_SETTING_COMMAND_SET_BOOL_PRIV, key, requestValue);
756 _SettingClient::SetValueForPrivilegedKey(const String& key, String value)
759 requestValue.Append(value);
760 return SetOnService(_SETTING_COMMAND_SET_STRING_PRIV, key, requestValue);
765 _SettingClient::SetValueAsync(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
767 result r = E_SUCCESS;
770 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
774 requestValue.Append("true");
778 requestValue.Append("false");
781 r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC, key, requestValue);
787 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
788 pEvent->AddListener(*listener);
790 __asyncEventList.Add(new String(key), pEvent);
798 _SettingClient::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
800 result r = E_SUCCESS;
803 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
807 requestValue.Append("true");
811 requestValue.Append("false");
814 r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC_PRIV, key, requestValue);
820 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
821 pEvent->AddListener(*listener);
823 __asyncEventList.Add(new String(key), pEvent);
831 _SettingClient::OnDataReceived(const ArrayList& data)
833 result r = E_SUCCESS;
834 String* pServiceId = (String*)(data.GetAt(0));
835 String* pResponseId = (String*)(data.GetAt(1));
836 String* pKey = (String*)(data.GetAt(2));
837 String* pValue = null;
839 SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service Id.");
840 SysTryReturnVoidResult(NID_SYS, pResponseId != null, E_SYSTEM, "There is response Id.");
841 SysTryReturnVoidResult(NID_SYS, pKey != null, E_SYSTEM, "There is no key.");
843 SysLog(NID_SYS, "ServiceId: %ls, ResponseId: %ls, Key: %ls", pServiceId->GetPointer(), pResponseId->GetPointer(), pKey->GetPointer());
845 if(*pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC || *pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV
846 || *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);
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);
998 else if(pSettingEvent->GetCount() == 0 && pSettingEventForInternal->GetCount() == 0)
1000 if(__subscribed == true)
1002 ArrayList requestMessages;
1003 ArrayList responseMessages;
1005 requestMessages.Construct();
1006 responseMessages.Construct();
1008 String serviceId(_SETTING_SERVICE_ID);
1009 String eventId(_SETTING_COMMAND_REMOVE_EVENT);
1011 requestMessages.Add(serviceId);
1012 requestMessages.Add(eventId);
1014 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
1016 r = __pIpcClient->SendRequest(*pMsg);
1017 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
1019 String* pResult = (String*)responseMessages.GetAt(2);
1020 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
1021 r = ConvertCode(*pResult);
1025 __subscribed = false;
1034 _SettingClient::AddSettingEventListener(ISettingEventListener& listener)
1036 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1037 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
1038 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1040 result r = pSettingEvent->AddSettingEventListener(listener);
1041 if (r == E_INVALID_OPERATION)
1045 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add event listener.");
1047 r = SubscribeEvent();
1048 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1054 _SettingClient::RemoveSettingEventListener(ISettingEventListener& listener)
1056 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1057 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
1058 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1060 result r = pSettingEvent->RemoveSettingEventListener(listener);
1062 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to remove event listener.");
1064 r = SubscribeEvent();
1065 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1070 // Event for internal
1072 _SettingClient::AddSettingEventListenerForInternal(ISettingEventListener& listener)
1074 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener event is not ready.");
1075 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1076 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1078 result r = pSettingEvent->AddSettingEventListener(listener);
1079 if (r == E_INVALID_OPERATION)
1084 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to add event listener.");
1086 r = SubscribeEvent();
1087 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1093 _SettingClient::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
1095 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
1096 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1097 SysTryReturnResult(NID_SYS, pSettingEvent != null, E_SYSTEM, "listener event is not ready.");
1099 result r = pSettingEvent->RemoveSettingEventListener(listener);
1101 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to remove event listener.");
1103 r = SubscribeEvent();
1104 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1109 //For OSP_COMPAT mode
1111 _SettingClient::SetSettingEventListener(ISettingEventListener* pListener)
1113 result r = E_SUCCESS;
1114 if(__pListener != null)
1116 r = RemoveSettingEventListener(*pListener);
1117 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to unregister exist listener.");
1118 if(pListener != null)
1120 r = AddSettingEventListener(*pListener);
1121 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to register listener.");
1125 __pListener = pListener;
1130 } } // Tizen::System