2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 * @file view_logic_vibration_support.cpp
18 * @author Jihoon Chung (jihoon.chung@samsung.com)
21 #include "view_logic_vibration_support.h"
22 #include <dpl/log/log.h>
25 namespace ViewModule {
26 VibrationSupport::VibrationSupport() : m_initialized(false),
31 VibrationSupport::~VibrationSupport()
33 Assert(!m_initialized);
36 void VibrationSupport::initialize(void)
38 LogDebug("initialize");
39 initializeVibration();
42 void VibrationSupport::deinitialize(void)
44 LogDebug("deinitialize");
47 int ret = haptic_close(m_handle);
49 if (HAPTIC_ERROR_NONE == ret) {
50 m_initialized = false;
51 LogDebug("deinitialize success");
54 LogDebug("deinitialize failed - error code : " << ret);
59 void VibrationSupport::startVibration(const long vibrationTime)
61 LogDebug("startVibration called");
63 if (m_initialized == false) {
64 if (initializeVibration() == false) {
69 int time = static_cast<int>(vibrationTime);
70 int ret = haptic_vibrate_monotone(m_handle, time, &m_effect_handle);
72 if (HAPTIC_ERROR_NONE == ret) {
73 LogDebug("haptic_vibrate_monotone success");
75 LogDebug("haptic_vibrate_monotone failed - error code : " << ret);
81 void VibrationSupport::stopVibration(void)
83 LogDebug("stopVibration called");
84 if (m_initialized == false) {
88 int ret = haptic_stop_all_effects(m_handle);
90 if (HAPTIC_ERROR_NONE == ret) {
91 LogDebug("haptic_stop_all_effects success");
93 LogDebug("haptic_stop_all_effects failed - error code : " << ret);
99 bool VibrationSupport::initializeVibration(void)
101 LogDebug("initializeVibration called");
103 if (m_initialized == false) {
104 haptic_device_h handle = NULL;
105 int ret = haptic_open(HAPTIC_DEVICE_0, &handle);
107 if (ret == HAPTIC_ERROR_NONE) {
108 LogDebug("initializeVibration success");
109 m_initialized = true;
112 LogDebug("initializeVibration failed - error code : " << ret);
113 m_initialized = false;
118 return m_initialized;
120 } // namespace ViewModule