Set mime type for bundle in case of mmsto, sms
[platform/framework/web/wrt.git] / src / view / common / view_logic_vibration_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    view_logic_vibration_support.cpp
18  * @author  Jihoon Chung (jihoon.chung@samsung.com)
19  */
20
21 #include "view_logic_vibration_support.h"
22 #include <dpl/log/log.h>
23 #include <haptic.h>
24
25 namespace ViewModule {
26
27
28 namespace {
29 const int WRT_HAPTIC_DEVICE_ID = 0;
30 }
31
32 VibrationSupport::VibrationSupport(): m_initialized(false)
33 {
34 }
35
36 VibrationSupport::~VibrationSupport()
37 {
38     Assert(!m_initialized);
39 }
40
41 void VibrationSupport::initialize(void)
42 {
43     LogDebug("initialize");
44     initializeVibration();
45 }
46
47 void VibrationSupport::deinitialize(void)
48 {
49     LogDebug("deinitialize");
50     int ret = haptic_deinitialize();
51
52     if (HAPTIC_ERROR_NOT_INITIALIZED == ret) {
53         LogDebug("not initialized");
54         m_initialized = false;
55     } else if (HAPTIC_ERROR_NONE == ret) {
56         LogDebug("success");
57         m_initialized = false;
58     } else {
59         LogDebug("deinitialize failed");
60     }
61 }
62
63 void VibrationSupport::startVibration(const long vibrationTime)
64 {
65     LogDebug("startVibration called");
66
67     if (!m_initialized) {
68         if (!initializeVibration()) {
69             return;
70         }
71     }
72     int time = static_cast<int>(vibrationTime);
73     if (HAPTIC_ERROR_NONE != haptic_vibrate_monotone(WRT_HAPTIC_DEVICE_ID,
74                                                      time,
75                                                      HAPTIC_LEVEL_AUTO))
76     {
77         LogDebug("haptic_vibrate_monotone failed.");
78     }
79     return;
80 }
81
82 void VibrationSupport::stopVibration(void)
83 {
84     LogDebug("stopVibration called");
85     if (!m_initialized) {
86         return;
87     }
88
89     if (HAPTIC_ERROR_NONE != haptic_stop_device(WRT_HAPTIC_DEVICE_ID)) {
90         LogDebug("haptic_stop_device failed");
91     }
92     return;
93 }
94
95 bool VibrationSupport::initializeVibration(void)
96 {
97     LogDebug("initializeVibration called");
98     if (HAPTIC_ERROR_NONE == haptic_initialize()) {
99         m_initialized = true;
100         return true;
101     } else {
102         LogDebug("haptic_initialize failed");
103         return false;
104     }
105 }
106
107 } // namespace ViewModule