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 {
27 VibrationSupport::VibrationSupport(): m_initialized(false),
33 VibrationSupport::~VibrationSupport()
35 Assert(!m_initialized);
38 void VibrationSupport::initialize(void)
40 LogDebug("initialize");
41 initializeVibration();
44 void VibrationSupport::deinitialize(void)
46 LogDebug("deinitialize");
50 int ret = haptic_close(m_handle);
52 if( HAPTIC_ERROR_NONE == ret )
54 m_initialized = false;
55 LogDebug("deinitialize success");
60 LogDebug("deinitialize failed - error code : " << ret);
65 void VibrationSupport::startVibration(const long vibrationTime)
67 LogDebug("startVibration called");
69 if ( m_initialized == false )
71 if ( initializeVibration() == false )
77 int time = static_cast<int>(vibrationTime);
78 int ret = haptic_vibrate_monotone(m_handle, time, &m_effect_handle);
80 if( HAPTIC_ERROR_NONE == ret )
82 LogDebug("haptic_vibrate_monotone success");
86 LogDebug("haptic_vibrate_monotone failed - error code : " << ret);
92 void VibrationSupport::stopVibration(void)
94 LogDebug("stopVibration called");
95 if ( m_initialized == false )
100 int ret = haptic_stop_all_effects(m_handle);
102 if( HAPTIC_ERROR_NONE == ret )
104 LogDebug("haptic_stop_all_effects success");
108 LogDebug("haptic_stop_all_effects failed - error code : " << ret);
114 bool VibrationSupport::initializeVibration(void)
116 LogDebug("initializeVibration called");
119 if ( m_initialized == false )
121 haptic_device_h handle = NULL;
122 int ret = haptic_open(HAPTIC_DEVICE_0, &handle);
124 if ( ret == HAPTIC_ERROR_NONE )
126 LogDebug("initializeVibration success");
127 m_initialized = true;
132 LogDebug("initializeVibration failed - error code : " << ret);
133 m_initialized = false;
138 return m_initialized;
141 } // namespace ViewModule