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_SettingVibrationProvider.cpp
19 * @brief This is the implementation for the _SettingVibrationProvider class.
22 #include <runtime_info.h>
23 #include <haptic/haptic.h>
27 #include <FBaseSysLog.h>
30 #include "FSys_SettingInfo.h"
31 #include "FSys_SettingVibrationProvider.h"
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Io;
38 namespace Tizen { namespace System
40 static const wchar_t* _VIBRATOR = L"http://tizen.org/setting/vibrator";
41 static const wchar_t* _VIBRATOR_LEVEL = L"http://tizen.org/setting/vibrator.level";
42 static const wchar_t* _VIBRATOR_LEVEL_NOTIFICATION = L"http://tizen.org/setting/vibrator.level.notification";
44 _SettingVibrationProvider::_SettingVibrationProvider()
46 int errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, SettingEventVConf, null);
49 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL event listener");
52 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, SettingEventVConf, null);
55 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT event listener");
58 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, SettingEventVConf, null);
61 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_DEFAULT_MEM_CAMERA_INT event listener");
66 _SettingVibrationProvider::~_SettingVibrationProvider()
68 int errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, SettingEventVConf);
71 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL event listener");
74 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, SettingEventVConf);
77 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT event listener");
80 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, SettingEventVConf);
83 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT event listener");
88 _SettingVibrationProvider::GetValue(const String& key, bool& value)
92 result r = E_OBJ_NOT_FOUND;
96 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
98 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &enabled);
99 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL vconf.");
100 value = enabled ? true : false;
106 _SettingVibrationProvider::SetValue(const String& key, const bool value)
109 result r = E_OBJ_NOT_FOUND;
110 haptic_device_h __hapticHandle;
114 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
118 errorCode = haptic_open(HAPTIC_DEVICE_0, &__hapticHandle);
119 SysTryReturnResult(NID_SYS, errorCode == HAPTIC_ERROR_NONE, E_SYSTEM, "It is failed to open haptic library.");
120 haptic_stop_all_effects(__hapticHandle);
121 errorCode = haptic_close(__hapticHandle);
122 SysTryReturnResult(NID_SYS, errorCode == HAPTIC_ERROR_NONE, E_SYSTEM, "It is failed to close haptic library.");
123 __hapticHandle = null;
125 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, value);
126 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL vconf.");
132 _SettingVibrationProvider::GetValue(const String& key, int& value)
136 result r = E_OBJ_NOT_FOUND;
138 if(key == _VIBRATOR_LEVEL)
140 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
143 errorCode = vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &level);
144 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT vconf");
147 else if (key == _VIBRATOR_LEVEL_NOTIFICATION)
149 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
152 int errorCode = vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &level);
153 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT vconf");
160 _SettingVibrationProvider::SetValue(const String& key, const int value)
163 result r = E_OBJ_NOT_FOUND;
164 if(key == _VIBRATOR_LEVEL)
166 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
169 SysTryReturnResult(NID_SYS, value >= 0 && value <= 5, E_INVALID_ARG, "Speicified value is not valid");
170 errorCode = vconf_set_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, value);
171 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT vconf");
173 else if(key == _VIBRATOR_LEVEL_NOTIFICATION)
175 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
178 SysTryReturnResult(NID_SYS, value >= 0 && value <= 5, E_INVALID_ARG, "Speicified value is not valid");
179 errorCode = vconf_set_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, value);
180 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT vconf");
186 _SettingVibrationProvider::HasKey(const Tizen::Base::String& key)
189 if(key == _VIBRATOR_LEVEL_NOTIFICATION
190 || key == _VIBRATOR_LEVEL
199 _SettingVibrationProvider::SettingEventVConf(keynode_t* node, void* userData)
203 if (strcmp(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, vconf_keynode_get_name(node)) == 0)
205 settingKey.Append(_VIBRATOR);
207 else if (strcmp(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, vconf_keynode_get_name(node)) == 0)
209 settingKey.Append(_VIBRATOR_LEVEL);
211 else if (strcmp(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, vconf_keynode_get_name(node)) == 0)
213 settingKey.Append(_VIBRATOR_LEVEL_NOTIFICATION);
220 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
221 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
223 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
224 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());