Fix invalid licenses
[platform/framework/web/crosswalk-tizen.git] / src / runtime / vibration_manager.cc
1 /*
2  * Copyright (c) 2015 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
18 #include "runtime/vibration_manager.h"
19
20 #include <dd-haptic.h>
21
22 #include "common/logger.h"
23
24
25 namespace wrt {
26 namespace platform {
27
28 class VibrationImpl : public VibrationManager {
29  public:
30   VibrationImpl();
31   virtual ~VibrationImpl();
32   virtual void Start(int ms);
33   virtual void Stop();
34  private:
35   bool Initialize();
36   // haptic_devce_h was declared as int
37   haptic_device_h handle_;
38 };
39
40
41 VibrationImpl::VibrationImpl()
42     : handle_(0) {
43 }
44
45 VibrationImpl::~VibrationImpl() {
46   if (handle_ != 0) {
47     haptic_close(handle_);
48     handle_ = 0;
49   }
50 }
51
52 bool VibrationImpl::Initialize() {
53   if (handle_ != 0)
54     return true;
55
56   int ret = haptic_open(HAPTIC_DEVICE_0, &handle_);
57   if (ret != HAPTIC_ERROR_NONE) {
58     LOGGER(ERROR) << "Fail to open haptic device";
59     handle_ = 0;
60     return false;
61   }
62   return true;
63 }
64
65 void VibrationImpl::Start(int ms) {
66   if (Initialize()) {
67     haptic_vibrate_monotone(handle_, ms, NULL);
68   }
69 }
70
71 void VibrationImpl::Stop() {
72   if (Initialize()) {
73     haptic_stop_all_effects(handle_);
74   }
75 }
76
77 VibrationManager* VibrationManager::GetInstance() {
78   static VibrationImpl instance;
79   return &instance;
80 }
81
82
83 }  // namespace platform
84 }  // namespace wrt
85
86