revise gcov option on rpm spec
[platform/core/api/motion.git] / src / GestureSensor.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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 "GestureSensor.h"
19
20 using namespace motion;
21
22 //LCOV_EXCL_START
23 GestureSensor::GestureSensor() :
24         __gestureType(static_cast<gesture_type_e>(UNDEFINED)),
25         __callback(NULL),
26         __userData(NULL),
27         __sensorAdapter(this)
28 {
29 }
30
31 GestureSensor::~GestureSensor()
32 {
33 }
34
35 bool GestureSensor::setGesture(gesture_type_e type)
36 {
37         sensor_type_t sensor = __toSensor(type);
38         IF_FAIL_RETURN(sensor != UNKNOWN_SENSOR, false);
39
40         __gestureType = type;
41         __sensorAdapter.setSensor(sensor);
42         return true;
43 }
44
45 void GestureSensor::setPowerSave(bool ps)
46 {
47         __sensorAdapter.setPowerSave(ps);
48 }
49
50 void GestureSensor::setCallback(gesture_recognition_cb cb)
51 {
52         __callback = cb;
53 }
54
55 void GestureSensor::setUserData(void* data)
56 {
57         __userData = data;
58 }
59
60 bool GestureSensor::start()
61 {
62         return __sensorAdapter.start();
63 }
64
65 bool GestureSensor::stop()
66 {
67         return __sensorAdapter.stop();
68 }
69
70 bool GestureSensor::isSupported(gesture_type_e type)
71 {
72         sensor_type_t sensor = __toSensor(type);
73         IF_FAIL_RETURN(sensor != UNKNOWN_SENSOR, false);
74
75         return SensorAdapter::isSupported(sensor);
76 }
77
78 void GestureSensor::onEvent(double timestamp, float* values, int accuracy)
79 {
80         _gesture_data_s data;
81         data.gesture = __gestureType;
82
83         /* TODO: This is the default form.
84            For each sensor, this part needs to adapt accordingly */
85         data.event = static_cast<int>(values[0]);
86
87         __callback(__gestureType, &data, timestamp, static_cast<gesture_error_e>(ERR_NONE), __userData);
88 }
89
90 sensor_type_t GestureSensor::__toSensor(gesture_type_e type)
91 {
92         switch (type) {
93         case GESTURE_PICK_UP:
94                 return GESTURE_MOVEMENT_SENSOR;
95         case GESTURE_WRIST_UP:
96                 return GESTURE_WRIST_UP_SENSOR;
97         default:
98                 return UNKNOWN_SENSOR;
99         }
100 }
101 //LCOV_EXCL_STOP