2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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.
19 #include "GestureSensor.h"
21 #define FEATURE_GESTURE "tizen.org/feature/sensor.gesture_recognition"
23 #define GESTURE_FIRST GESTURE_DOUBLE_TAP
24 #define GESTURE_LAST GESTURE_WRIST_UP
25 #define IS_VALID_GESTURE(X) (GESTURE_FIRST <= (X) && (X) <= GESTURE_LAST)
27 using namespace gesture;
29 struct _gesture_handle_s {
30 GestureSensor *sensor;
33 EXPORT_API int gesture_is_supported(gesture_type_e gesture, bool* supported)
38 ASSERT_SUPPORTED(FEATURE_GESTURE);
40 ASSERT_NOT_NULL(supported);
41 IF_FAIL_RETURN(IS_VALID_GESTURE(gesture), ERR_INVALID_PARAMETER);
43 *supported = GestureSensor::isSupported(gesture);
48 EXPORT_API int gesture_create(gesture_h *handle)
50 ASSERT_SUPPORTED(FEATURE_GESTURE);
52 ASSERT_NOT_NULL(handle);
54 _gesture_handle_s *hdl = static_cast<gesture_h>(malloc(sizeof(_gesture_handle_s)));
55 IF_FAIL_RETURN_TAG(hdl, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
57 hdl->sensor = new(std::nothrow) GestureSensor();
58 if (hdl->sensor == NULL) {
59 _E("Memory allocation failed");
61 return ERR_OPERATION_FAILED;
69 EXPORT_API int gesture_release(gesture_h handle)
71 ASSERT_SUPPORTED(FEATURE_GESTURE);
73 ASSERT_NOT_NULL(handle);
75 delete handle->sensor;
82 EXPORT_API int gesture_start_recognition(gesture_h handle, gesture_type_e gesture, gesture_option_e option, gesture_recognition_cb callback, void *user_data)
84 ASSERT_SUPPORTED(FEATURE_GESTURE);
86 ASSERT_NOT_NULL(handle);
87 ASSERT_NOT_NULL(callback);
88 IF_FAIL_RETURN(IS_VALID_GESTURE(gesture), ERR_INVALID_PARAMETER);
90 if (option == GESTURE_OPTION_DEFAULT) {
91 handle->sensor->setPowerSave(true);
92 } else if (option == GESTURE_OPTION_ALWAYS_ON) {
93 handle->sensor->setPowerSave(false);
95 return ERR_INVALID_PARAMETER;
98 if (!handle->sensor->setGesture(gesture)) {
99 return GESTURE_ERROR_NOT_SUPPORTED;
102 handle->sensor->setCallback(callback);
103 handle->sensor->setUserData(user_data);
105 if (!handle->sensor->start()) {
106 return ERR_OPERATION_FAILED;
113 EXPORT_API int gesture_stop_recognition(gesture_h handle)
115 ASSERT_SUPPORTED(FEATURE_GESTURE);
117 ASSERT_NOT_NULL(handle);
119 IF_FAIL_RETURN(handle->sensor->stop(), GESTURE_ERROR_NOT_STARTED);
125 EXPORT_API int gesture_get_event(const gesture_data_h data, gesture_event_e *event)
127 ASSERT_SUPPORTED(FEATURE_GESTURE);
129 ASSERT_NOT_NULL(data);
130 ASSERT_NOT_NULL(event);
132 if (data->gesture == GESTURE_TILT)
133 return GESTURE_ERROR_NOT_SUPPORTED;
135 *event = static_cast<gesture_event_e>(data->event);
141 EXPORT_API int gesture_get_tilt(const gesture_data_h data, int *x, int *y)
143 ASSERT_SUPPORTED(FEATURE_GESTURE);
145 ASSERT_NOT_NULL(data);
149 if (data->gesture != GESTURE_TILT)
150 return ERR_NOT_SUPPORTED;