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);
762 _SettingClient::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
764 result r = E_SUCCESS;
767 SysTryReturnResult(NID_SYS, __asyncEventList.ContainsKey(key) == false, E_IN_PROGRESS, "Required key[%ls] is already in progress.", key.GetPointer());
771 requestValue.Append("true");
775 requestValue.Append("false");
778 r = SetOnService(_SETTING_COMMAND_SET_BOOL_ASYNC_PRIV, key, requestValue);
782 _SettingAsyncEvent* pEvent = new (std::nothrow) _SettingAsyncEvent();
783 pEvent->AddListener(*listener);
785 __asyncEventList.Add(new String(key), pEvent);
792 _SettingClient::OnDataReceived(const ArrayList& data)
794 result r = E_SUCCESS;
795 String* pServiceId = (String*)(data.GetAt(0));
796 String* pResponseId = (String*)(data.GetAt(1));
797 String* pKey = (String*)(data.GetAt(2));
798 String* pValue = null;
800 SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service Id.");
801 SysTryReturnVoidResult(NID_SYS, pResponseId != null, E_SYSTEM, "There is response Id.");
802 SysTryReturnVoidResult(NID_SYS, pKey != null, E_SYSTEM, "There is no key.");
804 SysLog(NID_SYS, "ServiceId: %ls, ResponseId: %ls, Key: %ls", pServiceId->GetPointer(), pResponseId->GetPointer(), pKey->GetPointer());
806 if(*pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC || *pResponseId == _SETTING_COMMAND_SET_BOOL_ASYNC_PRIV
807 || *pResponseId == _SETTING_COMMAND_SET_STRING_ASYNC)
810 pValue = (String*)(data.GetAt(3));
812 SysTryReturnVoidResult(NID_SYS, pValue != null, E_SYSTEM, "There is no value.");
813 SysLog(NID_SYS, "Value: %ls", pValue->GetPointer());
815 _SettingAsyncEvent* pEvent = dynamic_cast <_SettingAsyncEvent*> (__asyncEventList.GetValue(*pKey));
816 r = ConvertCode(*pValue);
820 _SettingAsyncEventArg* pSettingAsyncEventArg = new (std::nothrow) _SettingAsyncEventArg;
821 pSettingAsyncEventArg->Key = *pKey;
822 pSettingAsyncEventArg->errorCode = r;
823 pEvent->Fire(*pSettingAsyncEventArg);
825 r = __asyncEventList.Remove(*pKey, true);
827 else if(*pResponseId == _SETTING_SERVICE_TYPE_EVENT)
829 SysTryReturnVoidResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "Event is not ready.");
831 _SettingEventArg* pSettingEventArg = new (std::nothrow) _SettingEventArg();
832 pSettingEventArg->KeyName = *pKey;
835 if(pSettingEventArg->KeyName == _LOCALE_LANGUAGE
836 || pSettingEventArg->KeyName == _LOCALE_COUNTRY
837 || pSettingEventArg->KeyName == _FONT_TYPE
838 || pSettingEventArg->KeyName == _FONT_SIZE)
840 if(__pSettingEventForInternal != null)
842 _SettingEventArg* pSettingEventArgForInternal = new (std::nothrow) _SettingEventArg();
843 pSettingEventArgForInternal->KeyName = pSettingEventArg->KeyName;
844 __pSettingEventForInternal->Fire(*pSettingEventArgForInternal);
848 SysLogException(NID_SYS, E_SYSTEM, "Internal Event is not ready.");
853 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true)
856 r = ConvertKeyTizenToOsp(pSettingEventArg->KeyName, ospKey);
859 pSettingEventArg->KeyName = ospKey;
860 __pSettingEvent->Fire(*pSettingEventArg);
865 __pSettingEvent->Fire(*pSettingEventArg);
871 _SettingClient::HasKey(const String& key)
874 result r = GetOnService(_SETTING_COMMAND_SUPPORTED, key, response);
876 if(response == L"1" && r == E_SUCCESS)
884 _SettingClient::ResetToFactoryDefault(void)
889 //For OSP_COMPAT mode
891 _SettingClient::SetVolume(const String& soundCategory, int level)
893 result r = SetValue(soundCategory, level);
894 if (r == E_INVALID_ARG)
898 else if(r == E_OBJ_NOT_FOUND)
902 else if(r == E_UNSUPPORTED_OPERATION)
911 _SettingClient::SubscribeEvent(void)
913 result r = E_SUCCESS;
914 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener list is not ready.");
915 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
917 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
918 _SettingEvent* pSettingEventForInternal = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
920 if(pSettingEvent->GetCount() > 0 || pSettingEventForInternal->GetCount() >0)
922 if(__subscribed == false)
924 ArrayList requestMessages;
925 ArrayList responseMessages;
927 requestMessages.Construct();
928 responseMessages.Construct();
930 String serviceId(_SETTING_SERVICE_ID);
931 String eventId(_SETTING_COMMAND_ADD_EVENT);
933 requestMessages.Add(serviceId);
934 requestMessages.Add(eventId);
936 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
938 r = __pIpcClient->SendRequest(*pMsg);
939 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
941 String* pResult = (String*)responseMessages.GetAt(2);
942 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
943 r = ConvertCode(*pResult);
951 else if(pSettingEvent->GetCount() == 0 && pSettingEventForInternal->GetCount() == 0)
953 if(__subscribed == true)
955 ArrayList requestMessages;
956 ArrayList responseMessages;
958 requestMessages.Construct();
959 responseMessages.Construct();
961 String serviceId(_SETTING_SERVICE_ID);
962 String eventId(_SETTING_COMMAND_REMOVE_EVENT);
964 requestMessages.Add(serviceId);
965 requestMessages.Add(eventId);
967 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
969 r = __pIpcClient->SendRequest(*pMsg);
970 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
972 String* pResult = (String*)responseMessages.GetAt(2);
973 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
974 r = ConvertCode(*pResult);
978 __subscribed = false;
987 _SettingClient::AddSettingEventListener(ISettingEventListener& listener)
989 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener list is not ready.");
990 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
991 result r = pSettingEvent->AddSettingEventListener(listener);
992 if (r == E_INVALID_OPERATION)
996 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add event listener.");
998 r = SubscribeEvent();
999 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1005 _SettingClient::RemoveSettingEventListener(ISettingEventListener& listener)
1007 SysTryReturnResult(NID_SYS, __pSettingEvent != null, E_SYSTEM, "listener list is not ready.");
1008 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEvent);
1009 result r = pSettingEvent->RemoveSettingEventListener(listener);
1011 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to remove event listener.");
1013 r = SubscribeEvent();
1014 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1019 // Event for internal
1021 _SettingClient::AddSettingEventListenerForInternal(ISettingEventListener& listener)
1023 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
1024 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1025 result r = pSettingEvent->AddSettingEventListener(listener);
1026 if (r == E_INVALID_OPERATION)
1031 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to add event listener.");
1033 r = SubscribeEvent();
1034 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to add event listener.");
1040 _SettingClient::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
1042 SysTryReturnResult(NID_SYS, __pSettingEventForInternal != null, E_SYSTEM, "listener list is not ready.");
1043 _SettingEvent* pSettingEvent = dynamic_cast<_SettingEvent*> (__pSettingEventForInternal);
1044 result r = pSettingEvent->RemoveSettingEventListener(listener);
1046 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to remove event listener.");
1048 r = SubscribeEvent();
1049 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to request to remove event listener.");
1054 //For OSP_COMPAT mode
1056 _SettingClient::SetSettingEventListener(ISettingEventListener* pListener)
1058 result r = E_SUCCESS;
1059 if(__pListener != null)
1061 r = RemoveSettingEventListener(*pListener);
1062 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to unregister exist listener.");
1063 if(pListener != null)
1065 r = AddSettingEventListener(*pListener);
1066 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to register listener.");
1070 __pListener = pListener;
1075 } } // Tizen::System