--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(capi-context-gesture)
+INCLUDE(GNUInstallDirs)
+
+SET(target ${PROJECT_NAME})
+
+# Source Lists
+FILE(GLOB SRCS src/*.cpp)
+
+SET(inc_subdir "context-service")
+SET(dependency "glib-2.0 dlog capi-base-common capi-system-info sensor")
+
+# Options
+INCLUDE(FindPkgConfig)
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+)
+
+ADD_DEFINITIONS(-O2 -Wall -fPIC -flto -fdata-sections -ffunction-sections -fvisibility=hidden)
+ADD_DEFINITIONS(-fdiagnostics-color)
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC -Wl,--as-needed -Wl,--gc-sections -Wl,--print-gc-sections")
+SET(CMAKE_VERBOSE_MAKEFILE OFF)
+
+# Build
+pkg_check_modules(pkgs REQUIRED ${dependency})
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${target} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${target} ${pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS})
+SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"CAPI-GESTURE\"")
+SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
+
+# Install
+INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
+INSTALL(
+ DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${inc_subdir}
+ FILES_MATCHING PATTERN "*.h"
+)
+
+SET(VERSION ${FULLVER})
+SET(PC_PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(PC_NAME ${PROJECT_NAME})
+SET(PC_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
+SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${inc_subdir}")
+SET(PC_DESCRIPTION "Tizen C Native Gesture Recognition API")
+SET(PC_REQUIRED ${dependency})
+SET(PC_LDFLAGS -l${target})
+
+CONFIGURE_FILE(
+ ${PROJECT_NAME}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
--- /dev/null
+Copyright (c) 2014 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright (c) [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
--- /dev/null
+#Package Information for pkg-config
+
+prefix=@PC_PREFIX@
+exec_prefix=@PC_PREFIX@
+libdir=@PC_LIBDIR@
+includedir=@PC_INCLUDE@
+
+Name: @PC_NAME@
+Description: @PC_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
--- /dev/null
+/*
+ * gesture
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @ingroup CAPI_CONTEXT_FRAMEWORK
+ * @defgroup CAPI_CONTEXT_GESTURE_MODULE Gesture Recognition
+ *
+ * @brief The gesture recognition API allows applications to be notified and
+ * react when the user performs a gesture.
+ *
+ * @section CAPI_CONTEXT_GESTURE_MODULE_HEADER Required Header
+ * \#include <gesture_recognition.h>
+ *
+ * @section CAPI_CONTEXT_GESTURE_MODULE_OVERVIEW Overview
+ *
+ *
+ * The gesture recognition API allows to register callback functions to be called
+ * when the user performs meaningful gestures listed in #gesture_type_e, for example,
+ * shaking the device.
+ *
+ * Regardless of the gesture types,
+ * the overall process of using the gesture recognition API is as follows.
+ *
+ * If necessary, applications can check whether a gesture type is supported in the current device in advance.
+ * Note that, some gestures may not be supported in some devices, if the devices do not have necessary sensors.
+
+ \code
+ bool supported = false;
+ gesture_is_supported(GESTURE_SHAKE, &supported);
+
+ if (!supported) {
+ // Not supported in the current device.
+ }
+ \endcode
+
+ * If the gesture type is supported, to use the recognition engine,
+ * an @c handle for the gesture recognition needs to be initialized first.
+
+ \code
+ gesture_h handle;
+
+ result = gesture_create(&handle);
+
+ if (result != GESTURE_ERROR_NONE) {
+ // An error occurred.
+ }
+ \endcode
+
+ * With the @c handle initialized, a callback function,
+ * which will be called when a specified gesture is detected,
+ * is registered by using gesture_start_recognition().
+
+ \code
+ result = gesture_start_recognition(handle, GESTURE_SHAKE, GESTURE_OPTION_DEFAULT, gesture_cb, NULL);
+
+ if (result != GESTURE_ERROR_NONE) {
+ // An error occurred. Do necessary error handling here.
+ }
+ \endcode
+
+ * Then the callback function @c gesture_cb will be called whenever the shake gesture is detected.
+ *
+ * Note that, calling gesture_start_recognition() twice on the same handle returns #GESTURE_ERROR_ALREADY_STARTED.
+ * If it needs to recognize another gesture using the same handle,
+ * the started recognition session should be stopped and restarted with the new gesture type.
+ * Otherwise, the application needs to created multiple handles, one handle for each gesture needed.
+ *
+ * An example callback function is as follows.
+
+ \code
+ void gesture_cb(gesture_type_e type, const gesture_data_h data, double timestamp, gesture_error_e error, void *user_data)
+ {
+ int result;
+ gesture_event_e event;
+
+ if (error != GESTURE_ERROR_NONE) {
+ // An error occurred. Do necessary error handling here.
+ return;
+ }
+
+ if (type == GESTURE_SHAKE) {
+ // More than one gestures can be started using the same callback function.
+
+ result = gesture_get_event(data, &event);
+
+ if (result != GESTURE_ERROR_NONE) {
+ // An error occurred. Do necessary error handling here.
+ return;
+ }
+
+ if (event == GESTURE_SHAKE_DETECTED) {
+ // Shake gesture is started
+
+ } else if (event == GESTURE_SHAKE_FINISHED) {
+ // Shake gesture is stopped
+ }
+ }
+ }
+ \endcode
+
+ * As we started gesture recognition with #GESTURE_SHAKE,
+ * gesture_get_event() returns either #GESTURE_SHAKE_DETECTED or #GESTURE_SHAKE_FINISHED
+ * as it has two different states, the gesture is started, or finished.
+ * Most of the gesture types, however, simply provide #GESTURE_EVENT_DETECTED.
+ * In such cases, #GESTURE_EVENT_NONE may not be delivered at all.
+ *
+ * If #GESTURE_TILT is started, within the callback function,
+ * gesture_get_tilt() can be used to extract the tilting degrees.
+ *
+ * Finally, if the application does not need to be notified the gesture event,
+ * it can be stopped as follows.
+
+ \code
+ gesture_stop_recognition(handle);
+
+ // If the handle will not be used anymore, its resources needs be released explicitly.
+ gesture_release(handle);
+ \endcode
+
+ * @section CAPI_CONTEXT_GESTURE_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ * - http://tizen.org/feature/sensor.gesture_recognition\n
+ * - http://tizen.org/feature/sensor.wrist_up
+ *
+ * It is recommended to design feature related code in your application for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ */
--- /dev/null
+/*
+ * gesture
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_GESTURE_H__
+#define __TIZEN_GESTURE_H__
+
+/**
+ * @addtogroup CAPI_CONTEXT_GESTURE_MODULE
+ * @{
+ */
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * @brief The gesture recognizer controlling handle.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _gesture_handle_s* gesture_h;
+
+/**
+ * @brief Delivery through gesture_recognition_cb() of gesture data handle.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _gesture_data_s* gesture_data_h;
+
+/**
+ * @brief Enumeration for error codes.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ GESTURE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ GESTURE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */
+ GESTURE_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Function not implemented */
+ GESTURE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ GESTURE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+ GESTURE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+ GESTURE_ERROR_ALREADY_STARTED = TIZEN_ERROR_CONTEXT | 0x01, /**< Recognition is already started */
+ GESTURE_ERROR_NOT_STARTED = TIZEN_ERROR_CONTEXT | 0x02, /**< Recognition is not started */
+ GESTURE_ERROR_OPERATION_FAILED = TIZEN_ERROR_CONTEXT | 0x04, /**< Operation failed because of a system error */
+} gesture_error_e;
+
+/**
+ * @brief Enumeration for gesture types.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ GESTURE_DOUBLE_TAP = 1, /**< The mobile device is tapped twice */
+ GESTURE_MOVE_TO_EAR, /**< The mobile device is moved near to an ear */
+ GESTURE_NO_MOVE, /**< The mobile device is being stopped for a while */
+ GESTURE_PICK_UP, /**< The mobile device is picked up */
+ GESTURE_SHAKE, /**< The mobile device is quickly moved back and forth */
+ GESTURE_SNAP, /**< The mobile device is moved along an axis and back */
+ GESTURE_TILT, /**< The mobile device is tilted */
+ GESTURE_TURN_FACE_DOWN, /**< The mobile device is flipped from face to back */
+ GESTURE_WRIST_UP, /**< The wearable device is moved and faced up */
+} gesture_type_e;
+
+/**
+ * @brief Enumeration for gesture recognition option.
+ * @details If the default option is used, the system tries to reduce power consumption.
+ * For example, the recognition engine may stop detecting gestures if the display is turned off.
+ * Using #GESTURE_OPTION_ALWAYS_ON disables such power-saving functionalities.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ GESTURE_OPTION_DEFAULT = 0, /**< Running in the default setting */
+ GESTURE_OPTION_ALWAYS_ON = 1, /**< Trying to detect gestures always */
+} gesture_option_e;
+
+/**
+ * @brief Enumeration for gesture event types.
+ * @details With regards to type of the gesture, gesture_get_event() returns one of the followings.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ GESTURE_EVENT_NONE = 0, /**< Detected nothing */
+ GESTURE_EVENT_DETECTED = 1, /**< Detected the gesture */
+
+ GESTURE_SHAKE_DETECTED = 1, /**< Shake gesture started */
+ GESTURE_SHAKE_FINISHED = 2, /**< Shake gesture stopped */
+
+ GESTURE_SNAP_X_NEGATIVE = 1, /**< Detected -X snap */
+ GESTURE_SNAP_X_POSITIVE = 2, /**< Detected +X snap */
+ GESTURE_SNAP_Y_NEGATIVE = 3, /**< Detected -Y snap */
+ GESTURE_SNAP_Y_POSITIVE = 4, /**< Detected +Y snap */
+ GESTURE_SNAP_Z_NEGATIVE = 5, /**< Detected -Z snap */
+ GESTURE_SNAP_Z_POSITIVE = 6, /**< Detected +Z snap */
+} gesture_event_e;
+
+/**
+ * @brief Called when a gesture is detected.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] gesture Gesture type detected
+ * @param[in] data Detailed information of the detected gesture.@n
+ * gesture_get_event() or gesture_get_tilt()
+ * can be used to extract the information from @c data.
+ * @param[in] timestamp The time when the gesture is detected. Epoch time in seconds.
+ * @param[in] error An error value. It can be one of the following error values:@n
+ * #GESTURE_ERROR_NONE, if the operation succeeded.@n
+ * #GESTURE_ERROR_NOT_SUPPORTED, if the gesture is not supported in the current profile.@n
+ * #GESTURE_ERROR_OPERATION_FAILED, if the operation failed because of a system error.@n
+ * #GESTURE_ERROR_PERMISSION_DENIED, if the application has no permission to use this.
+ * @param[in] user_data The user data had passed to gesture_start_recognition()
+ *
+ * @pre gesture_start_recognition()
+ */
+typedef void(* gesture_recognition_cb)(gesture_type_e gesture, const gesture_data_h data, double timestamp, gesture_error_e error, void *user_data);
+
+/**
+ * @brief Check whether the gesture is supported or not.
+ * @details Check if the given gesture type is supported in the current device.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] gesture Gesture type to be checked
+ * @param[out] supported @c true if the gesture is recognizable in the current device,@n
+ * @c false otherwise
+ *
+ * @return @c 0 if the @c gesture is supported, otherwise a negative error value
+ * @retval #GESTURE_ERROR_NONE Supported
+ * @retval #GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used
+ * @retval #GESTURE_ERROR_NOT_SUPPORTED The @c gesture is not supported
+ * @retval #GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error
+ * @retval #GESTURE_ERROR_PERMISSION_DENIED Does not have permission to use this
+ */
+int gesture_is_supported(gesture_type_e gesture, bool* supported);
+
+/**
+ * @brief Initializes a gesture handle.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[out] handle Gesture handle to be initialized
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #GESTURE_ERROR_NONE Successful
+ * @retval #GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used
+ * @retval #GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported
+ * @retval #GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error, e.g., out of memory
+ *
+ * @see gesture_release()
+ */
+int gesture_create(gesture_h *handle);
+
+/**
+ * @brief Releases the resources occupied by the gesture handle.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] handle Gesture handle to be released
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #GESTURE_ERROR_NONE Successful
+ * @retval #GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used
+ * @retval #GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported
+ * @retval #GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error
+ *
+ * @pre gesture_create()
+ */
+int gesture_release(gesture_h handle);
+
+/**
+ * @brief Starts to recognize a gesture.
+ * @details Sets a callback function to be invoked when the gesture is detected,
+ * and starts to monitor occurrences of the gesture.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] handle Gesture handle to be used to control the gesture event
+ * @param[in] gesture Gesture type to be monitored
+ * @param[in] option Detection option
+ * @param[in] callback Callback function to receive gesture events
+ * @param[in] user_data User data to be passed to the callback function
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #GESTURE_ERROR_NONE Successful
+ * @retval #GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used
+ * @retval #GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported
+ * @retval #GESTURE_ERROR_ALREADY_STARTED The @c handle is being used already
+ * @retval #GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error
+ * @retval #GESTURE_ERROR_PERMISSION_DENIED Does not have permission to use this
+ *
+ * @pre gesture_create()
+ * @post gesture_recognition_cb()
+ * @see gesture_stop_recognition()
+ */
+int gesture_start_recognition(gesture_h handle, gesture_type_e gesture, gesture_option_e option, gesture_recognition_cb callback, void *user_data);
+
+/**
+ * @brief Stops recognizing the gesture registered to the gesture handle.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] handle Gesture handle to release its callback function registered
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #GESTURE_ERROR_NONE Successful
+ * @retval #GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used
+ * @retval #GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported
+ * @retval #GESTURE_ERROR_NOT_STARTED Nothing is started using the @c handle
+ * @retval #GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error
+ */
+int gesture_stop_recognition(gesture_h handle);
+
+/**
+ * @brief Gets the gesture event from the gesture data received.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] data Gesture data received through a callback function
+ * @param[out] event Gesture event data
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #GESTURE_ERROR_NONE Successful
+ * @retval #GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used
+ * @retval #GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported
+ * @retval #GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error
+ */
+int gesture_get_event(const gesture_data_h data, gesture_event_e *event);
+
+/**
+ * @brief Gets the tilting degrees from #GESTURE_TILT data received.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] data Tilt gesture data received through a callback function
+ * @param[out] x Tilting degree on X-axis
+ * @param[out] y Tilting degree on Y-axis
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #GESTURE_ERROR_NONE Successful
+ * @retval #GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used
+ * @retval #GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported
+ * @retval #GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error
+ */
+int gesture_get_tilt(const gesture_data_h data, int *x, int *y);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+/**
+* @}
+*/
+
+#endif // __TIZEN_GESTURE_H__
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+Name: capi-context-gesture
+Summary: Tizen Native Gesture Recognition API
+Version: 2.0.2
+Release: 1
+Group: Service/Context
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(sensor)
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+# Backward compatibility
+Provides: gesture
+Provides: libcore-context-manager.so.1
+
+%description
+Tizen Native Gesture Recognition API
+
+%prep
+%setup -q
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+
+export CXXFLAGS+=" -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-parameter"
+export CXXFLAGS+=" -Wno-empty-body -fomit-frame-pointer -fno-optimize-sibling-calls"
+export CXXFLAGS+=" -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow"
+export CXXFLAGS+=" -Wnon-virtual-dtor"
+
+%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version}
+make %{?_smp_mflags}
+
+%install
+%make_install
+
+# For backward compatibility
+ln -s %{name}.pc %{buildroot}/%{_libdir}/pkgconfig/gesture.pc
+ln -s %{name}.pc %{buildroot}/%{_libdir}/pkgconfig/libcore-context-manager.pc
+ln -s lib%{name}.so.%{version} %{buildroot}/%{_libdir}/libcore-context-manager.so.1
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+%files
+%manifest packaging/%{name}.manifest
+%{_libdir}/*.so.*
+%license LICENSE
+
+%package devel
+Summary: Tizen Native Gesture Recognition API (Development)
+Group: Framework/context
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+Tizen Native Gesture Recognition API (Development)
+
+%files devel
+%{_includedir}/*/*.h
+%{_libdir}/*.so
+%{_libdir}/pkgconfig/*.pc
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include "GestureSensor.h"
+
+#define FEATURE_GESTURE "tizen.org/feature/sensor.gesture_recognition"
+
+#define GESTURE_FIRST GESTURE_DOUBLE_TAP
+#define GESTURE_LAST GESTURE_WRIST_UP
+#define IS_VALID_GESTURE(X) (GESTURE_FIRST <= (X) && (X) <= GESTURE_LAST)
+
+using namespace gesture;
+
+struct _gesture_handle_s {
+ GestureSensor *sensor;
+};
+
+EXPORT_API int gesture_is_supported(gesture_type_e gesture, bool* supported)
+{
+ if (supported)
+ *supported = false;
+
+ ASSERT_SUPPORTED(FEATURE_GESTURE);
+ //LCOV_EXCL_START
+ ASSERT_NOT_NULL(supported);
+ IF_FAIL_RETURN(IS_VALID_GESTURE(gesture), ERR_INVALID_PARAMETER);
+
+ *supported = GestureSensor::isSupported(gesture);
+ return ERR_NONE;
+ //LCOV_EXCL_STOP
+}
+
+EXPORT_API int gesture_create(gesture_h *handle)
+{
+ ASSERT_SUPPORTED(FEATURE_GESTURE);
+ //LCOV_EXCL_START
+ ASSERT_NOT_NULL(handle);
+
+ _gesture_handle_s *hdl = static_cast<gesture_h>(malloc(sizeof(_gesture_handle_s)));
+ IF_FAIL_RETURN_TAG(hdl, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
+
+ hdl->sensor = new(std::nothrow) GestureSensor();
+ if (hdl->sensor == NULL) {
+ _E("Memory allocation failed");
+ free(hdl);
+ return ERR_OPERATION_FAILED;
+ }
+
+ *handle = hdl;
+ return ERR_NONE;
+ //LCOV_EXCL_STOP
+}
+
+EXPORT_API int gesture_release(gesture_h handle)
+{
+ ASSERT_SUPPORTED(FEATURE_GESTURE);
+ //LCOV_EXCL_START
+ ASSERT_NOT_NULL(handle);
+
+ delete handle->sensor;
+ free(handle);
+
+ return ERR_NONE;
+ //LCOV_EXCL_STOP
+}
+
+EXPORT_API int gesture_start_recognition(gesture_h handle, gesture_type_e gesture, gesture_option_e option, gesture_recognition_cb callback, void *user_data)
+{
+ ASSERT_SUPPORTED(FEATURE_GESTURE);
+ //LCOV_EXCL_START
+ ASSERT_NOT_NULL(handle);
+ ASSERT_NOT_NULL(callback);
+ IF_FAIL_RETURN(IS_VALID_GESTURE(gesture), ERR_INVALID_PARAMETER);
+
+ if (option == GESTURE_OPTION_DEFAULT) {
+ handle->sensor->setPowerSave(true);
+ } else if (option == GESTURE_OPTION_ALWAYS_ON) {
+ handle->sensor->setPowerSave(false);
+ } else {
+ return ERR_INVALID_PARAMETER;
+ }
+
+ if (!handle->sensor->setGesture(gesture)) {
+ return GESTURE_ERROR_NOT_SUPPORTED;
+ }
+
+ handle->sensor->setCallback(callback);
+ handle->sensor->setUserData(user_data);
+
+ if (!handle->sensor->start()) {
+ return ERR_OPERATION_FAILED;
+ }
+
+ return ERR_NONE;
+ //LCOV_EXCL_STOP
+}
+
+EXPORT_API int gesture_stop_recognition(gesture_h handle)
+{
+ ASSERT_SUPPORTED(FEATURE_GESTURE);
+ //LCOV_EXCL_START
+ ASSERT_NOT_NULL(handle);
+
+ IF_FAIL_RETURN(handle->sensor->stop(), GESTURE_ERROR_NOT_STARTED);
+
+ return ERR_NONE;
+ //LCOV_EXCL_STOP
+}
+
+EXPORT_API int gesture_get_event(const gesture_data_h data, gesture_event_e *event)
+{
+ ASSERT_SUPPORTED(FEATURE_GESTURE);
+ //LCOV_EXCL_START
+ ASSERT_NOT_NULL(data);
+ ASSERT_NOT_NULL(event);
+
+ if (data->gesture == GESTURE_TILT)
+ return GESTURE_ERROR_NOT_SUPPORTED;
+
+ *event = static_cast<gesture_event_e>(data->event);
+
+ return ERR_NONE;
+ //LCOV_EXCL_STOP
+}
+
+EXPORT_API int gesture_get_tilt(const gesture_data_h data, int *x, int *y)
+{
+ ASSERT_SUPPORTED(FEATURE_GESTURE);
+ //LCOV_EXCL_START
+ ASSERT_NOT_NULL(data);
+ ASSERT_NOT_NULL(x);
+ ASSERT_NOT_NULL(y);
+
+ if (data->gesture != GESTURE_TILT)
+ return ERR_NOT_SUPPORTED;
+
+ *x = data->tilt_x;
+ *y = data->tilt_y;
+
+ return ERR_NONE;
+ //LCOV_EXCL_STOP
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "GestureSensor.h"
+
+using namespace gesture;
+
+//LCOV_EXCL_START
+GestureSensor::GestureSensor() :
+ __gestureType(static_cast<gesture_type_e>(UNDEFINED)),
+ __callback(NULL),
+ __userData(NULL),
+ __sensorAdapter(this)
+{
+}
+
+GestureSensor::~GestureSensor()
+{
+}
+
+bool GestureSensor::setGesture(gesture_type_e type)
+{
+ sensor_type_t sensor = __toSensor(type);
+ IF_FAIL_RETURN(sensor != UNKNOWN_SENSOR, false);
+
+ __gestureType = type;
+ __sensorAdapter.setSensor(sensor);
+ return true;
+}
+
+void GestureSensor::setPowerSave(bool ps)
+{
+ __sensorAdapter.setPowerSave(ps);
+}
+
+void GestureSensor::setCallback(gesture_recognition_cb cb)
+{
+ __callback = cb;
+}
+
+void GestureSensor::setUserData(void* data)
+{
+ __userData = data;
+}
+
+bool GestureSensor::start()
+{
+ return __sensorAdapter.start();
+}
+
+bool GestureSensor::stop()
+{
+ return __sensorAdapter.stop();
+}
+
+bool GestureSensor::isSupported(gesture_type_e type)
+{
+ sensor_type_t sensor = __toSensor(type);
+ IF_FAIL_RETURN(sensor != UNKNOWN_SENSOR, false);
+
+ return SensorAdapter::isSupported(sensor);
+}
+
+void GestureSensor::onEvent(double timestamp, float* values, int accuracy)
+{
+ _gesture_data_s data;
+ data.gesture = __gestureType;
+
+ /* TODO: This is the default form.
+ For each sensor, this part needs to adapt accordingly */
+ data.event = static_cast<int>(values[0]);
+
+ __callback(__gestureType, &data, timestamp, static_cast<gesture_error_e>(ERR_NONE), __userData);
+}
+
+sensor_type_t GestureSensor::__toSensor(gesture_type_e type)
+{
+ switch (type) {
+ case GESTURE_PICK_UP:
+ return GESTURE_MOVEMENT_SENSOR;
+ case GESTURE_WRIST_UP:
+ return GESTURE_WRIST_UP_SENSOR;
+ default:
+ return UNKNOWN_SENSOR;
+ }
+}
+//LCOV_EXCL_STOP
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __GESTURE_SENSOR_H__
+#define __GESTURE_SENSOR_H__
+
+#include <gesture_recognition.h>
+#include "SensorAdapter.h"
+
+struct _gesture_data_s {
+ int gesture;
+ int event;
+ int tilt_x;
+ int tilt_y;
+};
+
+namespace gesture {
+
+ class GestureSensor : public ISensorListener {
+ public:
+ GestureSensor();
+ ~GestureSensor();
+
+ bool setGesture(gesture_type_e type);
+ void setPowerSave(bool ps);
+ void setCallback(gesture_recognition_cb cb);
+ void setUserData(void* data);
+
+ bool start();
+ bool stop();
+
+ static bool isSupported(gesture_type_e type);
+
+ private:
+ void onEvent(double timestamp, float* values, int accuracy);
+
+ static sensor_type_t __toSensor(gesture_type_e type);
+
+ gesture_type_e __gestureType;
+ gesture_recognition_cb __callback;
+ void *__userData;
+ SensorAdapter __sensorAdapter;
+ };
+
+}
+
+#endif /* __GESTURE_SENSOR_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __I_SENSOR_LISTENER_H__
+#define __I_SENSOR_LISTENER_H__
+
+namespace gesture {
+
+ class ISensorListener {
+ public:
+ virtual ~ISensorListener() {}
+ virtual void onEvent(double timestamp, float* values, int accuracy) = 0;
+ };
+
+}
+
+#endif /* __I_SENSOR_LISTENER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <time.h>
+#include <sys/time.h>
+#include "SensorAdapter.h"
+
+#define SENSOR_EVENT(X) (((int)(X) << 16) | 0x01)
+
+using namespace gesture;
+
+SensorAdapter::SensorAdapter(ISensorListener* listener) :
+ __sensorHandle(-1),
+ __sensorType(UNKNOWN_SENSOR),
+ __powerSave(true),
+ __listener(listener)
+{
+}
+
+SensorAdapter::~SensorAdapter()
+{
+ stop();
+}
+
+//LCOV_EXCL_START
+void SensorAdapter::setSensor(sensor_type_t type)
+{
+ __sensorType = type;
+}
+
+void SensorAdapter::setPowerSave(bool ps)
+{
+ __powerSave = ps;
+
+ if (__sensorHandle < 0)
+ return;
+
+ sensord_set_attribute_int(__sensorHandle, SENSORD_ATTRIBUTE_PAUSE_POLICY,
+ __powerSave ? SENSORD_PAUSE_ALL : SENSORD_PAUSE_NONE);
+}
+
+void SensorAdapter::setAttribute(int key, int value)
+{
+ IF_FAIL_VOID_TAG(__sensorHandle >= 0, _W, "Sensor not started");
+ sensord_set_attribute_int(__sensorHandle, key, value);
+}
+
+bool SensorAdapter::start()
+{
+ int err;
+ sensor_t sensor;
+
+ err = sensord_get_default_sensor(__sensorType, &sensor);
+ IF_FAIL_RETURN_TAG(err == 0, false, _E, "Getting sensor failed (%d)", err);
+
+ __sensorHandle = sensord_connect(sensor);
+ IF_FAIL_RETURN_TAG(__sensorHandle >= 0, false, _E, "Connection failed");
+
+ if (!sensord_register_event(__sensorHandle, SENSOR_EVENT(__sensorType), 0, 0, __eventCb, this)) {
+ _E("Event registration failed");
+ sensord_disconnect(__sensorHandle);
+ __sensorHandle = -1;
+ return false;
+ }
+
+ if (!sensord_start(__sensorHandle, __powerSave ? SENSOR_OPTION_DEFAULT : SENSOR_OPTION_ALWAYS_ON)) {
+ _E("Starting failed");
+ sensord_unregister_event(__sensorHandle, SENSOR_EVENT(__sensorType));
+ sensord_disconnect(__sensorHandle);
+ __sensorHandle = -1;
+ return false;
+ }
+
+ return true;
+}
+
+bool SensorAdapter::stop()
+{
+ IF_FAIL_RETURN(__sensorHandle >= 0, false);
+
+ sensord_stop(__sensorHandle);
+ sensord_unregister_event(__sensorHandle, SENSOR_EVENT(__sensorType));
+ sensord_disconnect(__sensorHandle);
+ __sensorHandle = -1;
+
+ return true;
+}
+
+bool SensorAdapter::isSupported(sensor_type_t type)
+{
+ sensor_t sensor = sensord_get_sensor(type);
+ return (sensor != NULL);
+}
+
+double SensorAdapter::__getEpoch(unsigned long long monotonic)
+{
+ struct timespec ts;
+ struct timeval tv;
+ double timeDiff;
+ double timestamp;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ timeDiff = (ts.tv_sec * 1000000000.0 + ts.tv_nsec) / 1000000.0 - monotonic / 1000.0;
+
+ gettimeofday(&tv, NULL);
+ timestamp = tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0 - timeDiff;
+ return timestamp;
+}
+
+void SensorAdapter::__onEvent(sensor_data_t *eventData)
+{
+ double timestamp = __getEpoch(eventData->timestamp);
+ __listener->onEvent(timestamp / 1000.0, eventData->values, eventData->accuracy);
+}
+
+void SensorAdapter::__eventCb(sensor_t sensor, unsigned int eventType, sensor_data_t *eventData, void *cbData)
+{
+ SensorAdapter *instance = static_cast<SensorAdapter*>(cbData);
+ instance->__onEvent(eventData);
+}
+//LCOV_EXCL_STOP
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __GESTURE_SENSOR_ADAPTER_H__
+#define __GESTURE_SENSOR_ADAPTER_H__
+
+#include <sensor_internal.h>
+#include "TypesInternal.h"
+#include "ISensorListener.h"
+
+namespace gesture {
+
+ class SensorAdapter {
+ public:
+ SensorAdapter(ISensorListener* listener);
+ ~SensorAdapter();
+
+ void setSensor(sensor_type_t type);
+ void setPowerSave(bool ps);
+ void setAttribute(int key, int value);
+
+ bool start();
+ bool stop();
+
+ static bool isSupported(sensor_type_t type);
+
+ private:
+ double __getEpoch(unsigned long long monotonic);
+ void __onEvent(sensor_data_t* eventData);
+
+ static void __eventCb(sensor_t sensor, unsigned int eventType, sensor_data_t *eventData, void *cbData);
+
+ int __sensorHandle;
+ sensor_type_t __sensorType;
+ bool __powerSave;
+ ISensorListener *__listener;
+ };
+
+}
+
+#endif /* __GESTURE_SENSOR_ADAPTER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <system_info.h>
+#include "TypesInternal.h"
+
+int gesture::isSupported(const char *feature)
+{
+ bool supported = false;
+ int ret = system_info_get_platform_bool(feature, &supported);
+
+ if (ret == ERR_NONE && !supported) {
+ _W("Not Supported: %s", feature);
+ return ERR_NOT_SUPPORTED;
+ } else if (ret != ERR_NONE) {
+ _E("Getting system info failed: %#x", ret);
+ return ERR_OPERATION_FAILED;
+ }
+
+ return ERR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _GESTURE_TYPES_INTERNAL_H_
+#define _GESTURE_TYPES_INTERNAL_H_
+
+#include <tizen.h>
+#include <dlog.h>
+#include <new>
+
+#define UNDEFINED -1
+
+#define ERR_NONE TIZEN_ERROR_NONE
+#define ERR_INVALID_PARAMETER TIZEN_ERROR_INVALID_PARAMETER
+#define ERR_INVALID_OPERATION TIZEN_ERROR_INVALID_OPERATION
+#define ERR_OUT_OF_MEMORY TIZEN_ERROR_OUT_OF_MEMORY
+#define ERR_PERMISSION_DENIED TIZEN_ERROR_PERMISSION_DENIED
+#define ERR_NOT_SUPPORTED TIZEN_ERROR_NOT_SUPPORTED
+#define ERR_NO_DATA TIZEN_ERROR_NO_DATA
+#define ERR_ALREADY_STARTED (TIZEN_ERROR_CONTEXT | 0x01)
+#define ERR_NOT_STARTED (TIZEN_ERROR_CONTEXT | 0x02)
+#define ERR_OUT_OF_RANGE (TIZEN_ERROR_CONTEXT | 0x03)
+#define ERR_OPERATION_FAILED (TIZEN_ERROR_CONTEXT | 0x04)
+#define ERR_RULE_ENABLED (TIZEN_ERROR_CONTEXT | 0x05)
+#define ERR_RULE_NOT_ENABLED (TIZEN_ERROR_CONTEXT | 0x06)
+#define ERR_INVALID_RULE (TIZEN_ERROR_CONTEXT | 0x07)
+#define ERR_RULE_NOT_EXIST (TIZEN_ERROR_CONTEXT | 0x08)
+#define ERR_INVALID_DATA ERR_INVALID_RULE
+#define ERR_DATA_EXIST (TIZEN_ERROR_CONTEXT | 0X09)
+
+/* Logging and Error Handling */
+#define _I SLOGI
+#define _D SLOGD
+#define _W SLOGW
+#define _E SLOGE
+#define _SI SECURE_SLOGI
+#define _SD SECURE_SLOGD
+#define _SW SECURE_LOGW
+#define _SE SECURE_SLOGE
+
+#define IF_FAIL_RETURN_TAG(cond, ret, tag, fmt, arg...) \
+ do { if (!(cond)) { tag(fmt, ##arg); return ret; } } while (0)
+
+#define IF_FAIL_RETURN(cond, ret) \
+ do { if (!(cond)) { return ret; } } while (0)
+
+#define IF_FAIL_VOID_TAG(cond, tag, fmt, arg...) \
+ do { if (!(cond)) { tag(fmt, ##arg); return; } } while (0)
+
+#define IF_FAIL_VOID(cond) \
+ do { if (!(cond)) { return; } } while (0)
+
+#define IF_FAIL_CATCH_TAG(cond, tag, fmt, arg...) \
+ do { if (!(cond)) { tag(fmt, ##arg); goto CATCH; } } while (0)
+
+#define IF_FAIL_CATCH(cond) \
+ do { if (!(cond)) { goto CATCH; } } while (0)
+
+#define IS_FAILED(X) ((X) != ERR_NONE)
+
+#define ASSERT_ALLOC(X) IF_FAIL_RETURN_TAG(X, ERR_OUT_OF_MEMORY, _E, "Memory allocation failed")
+#define ASSERT_NOT_NULL(X) IF_FAIL_RETURN_TAG(X, ERR_INVALID_PARAMETER, _E, "Parameter null")
+
+#define ASSERT_SUPPORTED(feature) \
+ do { \
+ int __result = gesture::isSupported(feature); \
+ if (__result != ERR_NONE) return __result; \
+ } while (0)
+
+namespace gesture {
+ int isSupported(const char *feature);
+}
+
+#endif /* _GESTURE_TYPES_INTERNAL_H_ */