--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(motion)
+
+# Source Lists
+SET(SRCS
+ src/shared/ctx_util_misc.cpp
+ src/shared/ctx_util_sensor.cpp
+# Gesture
+ src/gesture/gesture.cpp
+ src/gesture/motion_engine.cpp
+# Activity
+ src/activity/activity.cpp
+)
+
+# Dependencies
+SET(dependency "dlog glib-2.0 capi-base-common capi-system-info sensor")
+
+# Target lib (for backward compatibility, the below old naming is used)
+SET(target "core-context-manager")
+
+# Options
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE(FindPkgConfig)
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/shared
+ /usr/include
+ /usr/include/glib-2.0
+)
+
+ADD_DEFINITIONS(-O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed -Wl,--rpath=/usr/lib)
+
+# 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=\"CONTEXT-LIB\"")
+SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
+
+# Install
+INSTALL(TARGETS ${target} DESTINATION lib)
+INSTALL(
+ DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include/motion
+ FILES_MATCHING PATTERN "*.h"
+)
+
+SET(PC_NAME ${target})
+SET(PC_INCLUDE "/usr/include/motion")
+SET(PC_DESCRIPTION "Tizen Native Motion Recognition API")
+SET(PC_REQUIRED ${dependency})
+SET(PC_LDFLAGS -l${target})
+SET(PC_CFLAGS -I\${includedir}/motion)
+
+CONFIGURE_FILE(
+ motion.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/motion.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/motion.pc DESTINATION lib/pkgconfig)
--- /dev/null
+Copyright (c) 2014 - 2015 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) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+
+ 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
+/*
+ * motion
+ *
+ * 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_ACTIVITY_MODULE Activity Recognition
+ *
+ * @brief The activity recognition API allows applications to be notified and
+ * react when a user activity is recognized.
+ *
+ * @section CAPI_CONTEXT_ACTIVITY_MODULE_HEADER Required Header
+ * \#include <activity_recognition.h>
+ *
+ * @section CAPI_CONTEXT_ACTIVITY_MODULE_OVERVIEW Overview
+ *
+ * The activity recognition API allows to register callback functions to be called
+ * when a user activity is recognized, for example, the user starts to run.
+ *
+ * Available activity types are listed in #activity_type_e.
+ * Applications can check whether each activity type is recognizable in the current
+ * device using activity_is_supported().
+
+ \code
+ bool supported = false;
+ activity_is_supported(ACTIVITY_RUN, &supported);
+
+ if (!supported) {
+ // Not supported in the current device.
+ }
+ \endcode
+
+ * Regarding a recognizable activity,
+ * an application can set and unset a callback function as follows.
+ *
+ * First, an activity handle needs to be initialized.
+ * With the @c handle, a callback function can be registered by activity_start_recognition().
+
+ \code
+ activity_h handle;
+
+ result = activity_create(&handle);
+
+ if (result != ACTIVITY_ERROR_NONE) {
+ // An error occurred.
+ }
+
+ result = activity_start_recognition(handle, ACTIVITY_RUN, activity_cb, NULL);
+
+ if (result != ACTIVITY_ERROR_NONE) {
+ // An error occurred. Do necessary error handling here.
+ }
+ \endcode
+
+ * Note that, calling activity_start_recognition() twice on the same handle returns #ACTIVITY_ERROR_ALREADY_STARTED.
+ * If the application needs to recognize multiple activities,
+ * it needs to created multiple handles, one handle for each activity type.
+ *
+ * Once the activity recognition is started, the callback function is called
+ * if the registered activity is detected.
+ * Here is an example of the callback function.
+
+ \code
+ void activity_cb(activity_type_e type, const activity_data_h data, double timestamp, activity_error_e error, void *user_data)
+ {
+ int result;
+ activity_accuracy_e accuracy;
+
+ if (error != ACTIVITY_ERROR_NONE) {
+ // An error occurred. Do necessary error handling here.
+ return;
+ }
+
+ if (type == ACTIVITY_RUN) {
+ // More than one activities can be started using the same callback function.
+
+ result = activity_get_accuracy(data, &accuracy);
+
+ if (result != GESTURE_ERROR_NONE) {
+ // An error occurred. Do necessary error handling here.
+ return;
+ }
+
+ // ...
+ }
+ }
+ \endcode
+
+ * Finally, if the application does not need to be notified the activity event,
+ * it can be stopped as follows.
+
+ \code
+ activity_stop_recognition(handle);
+
+ // If the handle will not be used anymore, its resources needs be released explicitly.
+ activity_release(handle);
+ \endcode
+
+ * @section CAPI_CONTEXT_ACTIVITY_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ * - http://tizen.org/feature/sensor.activity_recognition
+ *
+ * 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="../org.tizen.mobile.native.appprogramming/html/ide_sdk_tools/feature_element.htm"><b>Feature Element</b>.</a>
+ *
+ */
--- /dev/null
+/*
+ * motion
+ *
+ * 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="../org.tizen.mobile.native.appprogramming/html/ide_sdk_tools/feature_element.htm"><b>Feature Element</b>.</a>
+ *
+ */
--- /dev/null
+/*
+ * motion
+ *
+ * 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_ACTIVITY_H__
+#define __TIZEN_ACTIVITY_H__
+
+/**
+ * @addtogroup CAPI_CONTEXT_ACTIVITY_MODULE
+ * @{
+ */
+
+#include <stdbool.h>
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * @brief Handle for controlling the activity recognizer
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _activity_handle_s* activity_h;
+
+/**
+ * @brief Activity data handle delivered through activity_recognition_cb()
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _activity_data_s* activity_data_h;
+
+/**
+ * @brief Error codes
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ ACTIVITY_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ ACTIVITY_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */
+ ACTIVITY_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Function not implemented */
+ ACTIVITY_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ ACTIVITY_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+ ACTIVITY_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+ ACTIVITY_ERROR_ALREADY_STARTED = TIZEN_ERROR_CONTEXT | 0x01, /**< Recognition is already started */
+ ACTIVITY_ERROR_NOT_STARTED = TIZEN_ERROR_CONTEXT | 0x02, /**< Recognition is not started */
+ ACTIVITY_ERROR_OPERATION_FAILED = TIZEN_ERROR_CONTEXT | 0x04, /**< Operation failed because of a system error */
+} activity_error_e;
+
+/**
+ * @brief Activity types
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ ACTIVITY_STATIONARY = 1, /**< Stationary */
+ ACTIVITY_WALK, /**< Walking */
+ ACTIVITY_RUN, /**< Running */
+ ACTIVITY_IN_VEHICLE, /**< In a moving vehicle */
+} activity_type_e;
+
+/**
+ * @brief Recognition accuracy
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ ACTIVITY_ACCURACY_LOW = 0, /**< Not accurate */
+ ACTIVITY_ACCURACY_MID, /**< Moderate */
+ ACTIVITY_ACCURACY_HIGH, /**< Highly accurate */
+} activity_accuracy_e;
+
+/**
+ * @brief Called when a activity is recognized.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] activity Activity recognized.
+ * @param[in] data Detailed information of the recognized activity.
+ * @param[in] timestamp The time when the activity is recognized. Epoch time in seconds.
+ * @param[in] error An error value. It can be one of the following error values:@n
+ * #ACTIVITY_ERROR_NONE, if the operation succeeded.@n
+ * #ACTIVITY_ERROR_NOT_SUPPORTED, if the activity is not supported in the current profile.@n
+ * #ACTIVITY_ERROR_OPERATION_FAILED, if the operation failed because of a system error.@n
+ * #ACTIVITY_ERROR_PERMISSION_DENIED, if the application has no permission to use this.
+ * @param[in] user_data The user data had passed to activity_start_recognition().
+ *
+ * @pre activity_start_recognition()
+ * @see activity_get_accuracy()
+ */
+typedef void(* activity_recognition_cb)(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void *user_data);
+
+/**
+ * @brief Check whether the activity is supported or not.
+ * @details Check if the given activity type is supported in the current device.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] activity Activity type to be checked.
+ * @param[out] supported @c true, if the activity is recognizable in the current device.@n
+ * @c false, otherwise.
+ *
+ * @return 0 if the @c activity is supported, otherwise a negative error value.
+ * @retval #ACTIVITY_ERROR_NONE Supported.
+ * @retval #ACTIVITY_ERROR_INVALID_PARAMETER Invalid parameter used.
+ * @retval #ACTIVITY_ERROR_NOT_SUPPORTED The @c activity is not supported.
+ * @retval #ACTIVITY_ERROR_OPERATION_FAILED Operation failed because of a system error.
+ * @retval #ACTIVITY_ERROR_PERMISSION_DENIED Does not have permission to use this.
+ */
+int activity_is_supported(activity_type_e activity, bool* supported);
+
+/**
+ * @brief Initializes an activity handle.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[out] handle Activity handle to be initialized.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACTIVITY_ERROR_NONE Successful.
+ * @retval #ACTIVITY_ERROR_INVALID_PARAMETER Invalid parameter used.
+ * @retval #ACTIVITY_ERROR_NOT_SUPPORTED Activity recognition is not supported.
+ * @retval #ACTIVITY_ERROR_OPERATION_FAILED Operation failed because of a system error, e.g., out of memory.
+ *
+ * @see activity_release()
+ */
+int activity_create(activity_h *handle);
+
+/**
+ * @brief Releases the resources occupied by the activity handle.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] handle Activity handle to be released.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACTIVITY_ERROR_NONE Successful.
+ * @retval #ACTIVITY_ERROR_INVALID_PARAMETER Invalid parameter used.
+ * @retval #ACTIVITY_ERROR_NOT_SUPPORTED Activity recognition is not supported.
+ * @retval #ACTIVITY_ERROR_OPERATION_FAILED Operation failed because of a system error.
+ *
+ * @pre activity_create()
+ */
+int activity_release(activity_h handle);
+
+/**
+ * @brief Starts to recognize an activity.
+ * @details Sets a callback function to be invoked when the activity is detected,
+ * and starts to monitor occurrences of the activity.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] handle Activity handle to be used to control the activity event.
+ * @param[in] activity Activity type to be monitored.
+ * @param[in] callback Callback function to receive activity events.
+ * @param[in] user_data User data to be passed to the callback function.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACTIVITY_ERROR_NONE Successful.
+ * @retval #ACTIVITY_ERROR_INVALID_PARAMETER Invalid parameter used.
+ * @retval #ACTIVITY_ERROR_NOT_SUPPORTED Activity recognition is not supported.
+ * @retval #ACTIVITY_ERROR_ALREADY_STARTED The @c handle is being used already.
+ * @retval #ACTIVITY_ERROR_OPERATION_FAILED Operation failed because of a system error.
+ * @retval #ACTIVITY_ERROR_PERMISSION_DENIED Does not have permission to use this.
+ *
+ * @pre activity_create()
+ * @post activity_recognition_cb()
+ * @see activity_stop_recognition()
+ */
+int activity_start_recognition(activity_h handle, activity_type_e activity, activity_recognition_cb callback, void *user_data);
+
+/**
+ * @brief Stops recognizing the activity registered to the activity handle.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] handle Activity handle to release its callback function registered.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACTIVITY_ERROR_NONE Successful.
+ * @retval #ACTIVITY_ERROR_INVALID_PARAMETER Invalid parameter used.
+ * @retval #ACTIVITY_ERROR_NOT_SUPPORTED Activity recognition is not supported.
+ * @retval #ACTIVITY_ERROR_NOT_STARTED Nothing is started using the @c handle.
+ * @retval #ACTIVITY_ERROR_OPERATION_FAILED Operation failed because of a system error.
+ */
+int activity_stop_recognition(activity_h handle);
+
+/**
+ * @brief Gets the recognition accuracy.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] data Activity data received through activity_cb().
+ * @param[out] accuracy Accuracy.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ACTIVITY_ERROR_NONE Successful.
+ * @retval #ACTIVITY_ERROR_INVALID_PARAMETER Invalid parameter used.
+ * @retval #ACTIVITY_ERROR_NOT_SUPPORTED Activity recognition is not supported.
+ * @retval #ACTIVITY_ERROR_OPERATION_FAILED Operation failed because of a system error.
+ */
+int activity_get_accuracy(const activity_data_h data, activity_accuracy_e *accuracy);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+/**
+* @}
+*/
+
+#endif // __TIZEN_ACTIVITY_H__
--- /dev/null
+/*
+ * motion
+ *
+ * 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 <stdbool.h>
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * @brief Handle for controlling the gesture recognizer
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _gesture_handle_s* gesture_h;
+
+/**
+ * @brief Gesture data handle delivered through gesture_recognition_cb()
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _gesture_data_s* gesture_data_h;
+
+/**
+ * @brief 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 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 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 Regarding the 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, /**< The gesture is not detected */
+ GESTURE_EVENT_DETECTED = 1, /**< The gesture is detected */
+
+ GESTURE_SHAKE_DETECTED = 1, /**< Shake gesture is detected */
+ GESTURE_SHAKE_FINISHED = 2, /**< Shake gesture finished */
+
+ GESTURE_SNAP_X_NEGATIVE = 1, /**< -X snap is detected */
+ GESTURE_SNAP_X_POSITIVE = 2, /**< +X snap is detected */
+ GESTURE_SNAP_Y_NEGATIVE = 3, /**< -Y snap is detected */
+ GESTURE_SNAP_Y_POSITIVE = 4, /**< +Y snap is detected */
+ GESTURE_SNAP_Z_NEGATIVE = 5, /**< -Z snap is detected */
+ GESTURE_SNAP_Z_POSITIVE = 6, /**< +Z snap is detected */
+} 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 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 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 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. It should be one of #gesture_type_e.
+ * @param[in] option Detection option. It should be one of #gesture_option_e.
+ * @param[in] callback Callback function to receive gesture events.
+ * @param[in] user_data User data to be passed to the callback function.
+ *
+ * @return 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 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 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 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
+#Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=@PC_INCLUDE@
+
+Name: @PC_NAME@
+Description: @PC_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+Name: motion
+Summary: Tizen Native Motion Recognition API
+Version: 1.1.3
+Release: 1
+Group: Framework/context
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(sensor)
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%ifarch %{arm}
+%define ARCH arm
+%else
+%define ARCH i586
+%endif
+
+%description
+Tizen Native Motion Recognition API
+
+%prep
+%setup -q
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+
+export CFLAGS+=" -Werror -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default"
+export CXXFLAGS+=" -Werror -Wextra -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wswitch-default -Wnon-virtual-dtor -Wno-c++0x-compat"
+
+#export CFLAGS+=" -Wno-array-bounds -Wno-ignored-qualifiers"
+export CFLAGS+=" -Wno-unused-parameter -Wno-empty-body"
+export CXXFLAGS+=" -Wno-unused-parameter -Wno-empty-body"
+
+export CFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow -fno-common"
+export CXXFLAGS+=" -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow"
+
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCH=%{ARCH} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{PROFILE}
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/motion
+# For backward compatibility
+ln -s ./motion.pc %{buildroot}/%{_libdir}/pkgconfig/libcore-context-manager.pc
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+%files
+%manifest packaging/motion.manifest
+%defattr(-,root,root,-)
+%{_libdir}/*.so*
+/usr/share/license/motion
+
+%package devel
+Summary: Tizen Native Motion Recognition API (Development)
+Group: Framework/context
+Requires: motion = %{version}-%{release}
+
+%description devel
+Tizen Native Motion Recognition API (Development)
+
+%post devel
+/sbin/ldconfig
+
+%postun devel
+/sbin/ldconfig
+
+%files devel
+%defattr(-,root,root,-)
+%{_includedir}/motion/*.h
+%{_libdir}/pkgconfig/*.pc
--- /dev/null
+/*
+ * motion
+ *
+ * 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.
+ *
+ */
+
+#include <ctx_types_private.h>
+#include <ctx_error.h>
+#include "activity.h"
+
+EXTAPI int activity_is_supported(activity_type_e activity, bool* supported)
+{
+ if (supported)
+ *supported = false;
+
+ return CERR_NOT_SUPPORTED;
+}
+
+EXTAPI int activity_create(activity_h *handle)
+{
+ return CERR_NOT_SUPPORTED;
+}
+
+EXTAPI int activity_release(activity_h handle)
+{
+ return CERR_NOT_SUPPORTED;
+}
+
+EXTAPI int activity_start_recognition(activity_h handle, activity_type_e activity, activity_recognition_cb callback, void *user_data)
+{
+ return CERR_NOT_SUPPORTED;
+}
+
+EXTAPI int activity_stop_recognition(activity_h handle)
+{
+ return CERR_NOT_SUPPORTED;
+}
+
+EXTAPI int activity_get_accuracy(const activity_data_h data, activity_accuracy_e *accuracy)
+{
+ return CERR_NOT_SUPPORTED;
+}
--- /dev/null
+/*
+ * motion
+ *
+ * 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 _CONTEXT_ACTIVITY_H_
+#define _CONTEXT_ACTIVITY_H_
+
+#include <activity_recognition.h>
+
+#define FEATURE_KEY_ACTIVITY "tizen.org/feature/sensor.activity_recognition"
+
+typedef struct _activity_data_s {
+ int activity;
+ int accuracy;
+} _cx_activity_data;
+
+typedef struct _activity_handle_s {
+ int req_id;
+ activity_recognition_cb callback;
+ void *user_data;
+} _cx_activity_h;
+
+#endif /* End of _CONTEXT_ACTIVITY_PRIVATE_H_ */
--- /dev/null
+/*
+ * motion
+ *
+ * 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.
+ *
+ */
+
+#include <stdlib.h>
+#include <ctx_error.h>
+#include <ctx_util_misc.h>
+#include <ctx_types_private.h>
+#include <handle_map.h>
+#include "motion_engine.h"
+#include "gesture.h"
+
+static ctx::handle_map_t<_cx_gesture_h> handle_map;
+
+void cx_gesture_deliver_data(int req_id, _cx_gesture_data data, double timestamp, int error)
+{
+ _cx_gesture_h *handle = NULL;
+
+ handle = handle_map.get_copy(req_id);
+ try_return_void_tag(handle, LOGD, "No matching handle found");
+
+ if (handle->callback) {
+ data.gesture = handle->gesture;
+ handle->callback(static_cast<gesture_type_e>(data.gesture), &data,
+ timestamp, static_cast<gesture_error_e>(error), handle->user_data);
+ }
+
+ free(handle);
+}
+
+EXTAPI int gesture_is_supported(gesture_type_e gesture, bool* supported)
+{
+ if (supported)
+ *supported = false;
+
+ ASSERT_SUPPORTED(FEATURE_KEY_GESTURE);
+ ASSERT_NULL(supported);
+
+ if (!ctx::gesture::me_check_coverage(gesture))
+ return GESTURE_ERROR_NONE;
+
+ int ret = ctx::gesture::me_is_supported(gesture);
+ if (ret == GESTURE_ERROR_NONE)
+ *supported = true;
+
+ return GESTURE_ERROR_NONE;
+}
+
+EXTAPI int gesture_create(gesture_h *handle)
+{
+ ASSERT_SUPPORTED(FEATURE_KEY_GESTURE);
+ ASSERT_HANDLE;
+
+ *handle = static_cast<gesture_h>(malloc(sizeof(_cx_gesture_h)));
+ ASSERT_ALLOC(*handle);
+
+ (*handle)->req_id = CTX_VALUE_UNDEFINED;
+ (*handle)->gesture = CTX_VALUE_UNDEFINED;
+ (*handle)->callback = NULL;
+ (*handle)->user_data = NULL;
+
+ (*handle)->me_handle = CTX_VALUE_UNDEFINED;
+ (*handle)->me_event = CTX_VALUE_UNDEFINED;
+
+ return GESTURE_ERROR_NONE;
+}
+
+EXTAPI int gesture_release(gesture_h handle)
+{
+ ASSERT_SUPPORTED(FEATURE_KEY_GESTURE);
+ ASSERT_HANDLE;
+ gesture_stop_recognition(handle);
+ free(handle);
+ return GESTURE_ERROR_NONE;
+}
+
+EXTAPI 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_KEY_GESTURE);
+ if (gesture == GESTURE_WRIST_UP) {
+ ASSERT_SUPPORTED(FEATURE_KEY_WRISTUP);
+ }
+ ASSERT_HANDLE;
+ ASSERT_NULL(callback);
+
+ if (handle_map.find(handle->req_id) != NULL) {
+ LOGW("The handle is being used");
+ return GESTURE_ERROR_ALREADY_STARTED;
+ }
+
+ handle->gesture = gesture;
+ handle->user_data = user_data;
+ handle->callback = callback;
+
+ int ret;
+
+ if (ctx::gesture::me_check_coverage(gesture)) {
+ ret = ctx::gesture::me_start(handle, gesture, option);
+ } else {
+ ret = GESTURE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (ret == GESTURE_ERROR_NONE)
+ handle_map.insert(handle->req_id, handle);
+
+ return ret;
+}
+
+EXTAPI int gesture_stop_recognition(gesture_h handle)
+{
+ ASSERT_SUPPORTED(FEATURE_KEY_GESTURE);
+ ASSERT_HANDLE;
+ int ret = GESTURE_ERROR_NOT_STARTED;
+
+ if (handle_map.find(handle->req_id) != NULL) {
+ if (ctx::gesture::me_check_coverage(handle->gesture))
+ ctx::gesture::me_stop(handle);
+
+ handle_map.remove(handle->req_id);
+ ret = GESTURE_ERROR_NONE;
+ }
+
+ handle->req_id = CTX_VALUE_UNDEFINED;
+ handle->gesture = CTX_VALUE_UNDEFINED;
+ handle->callback = NULL;
+ handle->user_data = NULL;
+
+ return ret;
+}
+
+EXTAPI int gesture_get_event(const gesture_data_h data, gesture_event_e *event)
+{
+ ASSERT_SUPPORTED(FEATURE_KEY_GESTURE);
+ ASSERT_NULL(data);
+ ASSERT_NULL(event);
+
+ if (data->gesture == GESTURE_TILT)
+ return GESTURE_ERROR_NOT_SUPPORTED;
+
+ *event = static_cast<gesture_event_e>(data->event);
+
+ return GESTURE_ERROR_NONE;
+}
+
+EXTAPI int gesture_get_tilt(const gesture_data_h data, int *x, int *y)
+{
+ ASSERT_SUPPORTED(FEATURE_KEY_GESTURE);
+ ASSERT_NULL(data);
+ ASSERT_NULL(x);
+ ASSERT_NULL(y);
+
+ if (data->gesture != GESTURE_TILT)
+ return GESTURE_ERROR_NOT_SUPPORTED;
+
+ *x = data->tilt_x;
+ *y = data->tilt_y;
+
+ return GESTURE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * motion
+ *
+ * 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 _CONTEXT_GESTURE_H_
+#define _CONTEXT_GESTURE_H_
+
+#include <gesture_recognition.h>
+
+#define FEATURE_KEY_GESTURE "tizen.org/feature/sensor.gesture_recognition"
+#define FEATURE_KEY_WRISTUP "tizen.org/feature/sensor.wrist_up"
+
+typedef struct _gesture_data_s {
+ int gesture;
+ int event;
+ int tilt_x;
+ int tilt_y;
+} _cx_gesture_data;
+
+typedef struct _gesture_handle_s {
+ int req_id;
+ int gesture;
+ gesture_recognition_cb callback;
+ void *user_data;
+
+ int me_handle; // Handle for motion-engine in sensor-fw
+ int me_event; // Event enum for motion-engine in sensor-fw
+
+} _cx_gesture_h;
+
+void cx_gesture_deliver_data(int req_id, _cx_gesture_data data, double timestamp, int error);
+
+#endif /* End of _CONTEXT_GESTURE_PRIVATE_H_ */
--- /dev/null
+/*
+ * motion
+ *
+ * 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.
+ *
+ */
+
+#include <ctx_error.h>
+#include <ctx_types_private.h>
+#include <ctx_util_misc.h>
+#include <ctx_util_sensor.h>
+#include "gesture.h"
+#include "motion_engine.h"
+
+static int convert_shake_data(int value)
+{
+ switch (value) {
+ case MOTION_ENGIEN_SHAKE_NONE:
+ return GESTURE_EVENT_NONE;
+
+ case MOTION_ENGIEN_SHAKE_DETECTION:
+ case MOTION_ENGIEN_SHAKE_CONTINUING:
+ return GESTURE_SHAKE_DETECTED;
+
+ case MOTION_ENGIEN_SHAKE_FINISH:
+ case MOTION_ENGINE_SHAKE_BREAK:
+ return GESTURE_SHAKE_FINISHED;
+
+ default:
+ return CTX_VALUE_UNDEFINED;
+ }
+}
+
+static int convert_face_down_data(int value)
+{
+ switch (value) {
+ case MOTION_ENGIEN_TOP_TO_BOTTOM_NONE:
+ return GESTURE_EVENT_NONE;
+
+ case MOTION_ENGIEN_TOP_TO_BOTTOM_DETECTION:
+ return GESTURE_EVENT_DETECTED;
+
+ default:
+ return CTX_VALUE_UNDEFINED;
+ }
+}
+
+static void me_sensor_event_extract_int(unsigned int event_type, sensor_data_t *event_data, _cx_gesture_data *gesture_data)
+{
+ gesture_data->event = event_data->values[0];
+
+ switch (event_type) {
+ case MOTION_ENGINE_EVENT_SHAKE:
+ case MOTION_ENGINE_EVENT_SHAKE_ALWAYS_ON:
+ gesture_data->event = convert_shake_data(gesture_data->event);
+ return;
+
+ case MOTION_ENGINE_EVENT_TOP_TO_BOTTOM:
+ gesture_data->event = convert_face_down_data(gesture_data->event);
+ return;
+
+ default:
+ return;
+ }
+}
+
+static void me_sensor_event_extract_tilt(sensor_data_t *event_data, _cx_gesture_data *gesture_data)
+{
+ try_return_void_tag(event_data->value_count >= 2, LOGW, "Invalid data count (%d)", event_data->value_count);
+ gesture_data->tilt_x = event_data->values[0];
+ gesture_data->tilt_y = event_data->values[1];
+}
+
+static bool me_sensor_extract_data(unsigned int event_type, sensor_data_t *event_data, _cx_gesture_data *gesture_data)
+{
+ if (event_type == MOTION_ENGINE_EVENT_TILT) {
+ me_sensor_event_extract_tilt(event_data, gesture_data);
+
+ } else {
+ me_sensor_event_extract_int(event_type, event_data, gesture_data);
+ }
+
+ return true;
+}
+
+static void me_sensor_event_cb(sensor_t sensor, unsigned int sensor_event_type, sensor_data_t *sensor_event_data, void *user_data)
+{
+ try_return_void(user_data);
+
+ int64_t ts = ctx::time::get_utc(NULL, NULL);
+ int req_id = (int)user_data;
+ LOGD("Received data for ReqId %d", req_id);
+
+ _cx_gesture_data data;
+
+ if (!me_sensor_extract_data(sensor_event_type, sensor_event_data, &data)) {
+ LOGE("Failed to extract motion data from sensor event");
+ return;
+ }
+
+ cx_gesture_deliver_data(req_id, data, ts/1000.0L, GESTURE_ERROR_NONE);
+}
+
+static int get_event_type(int motion)
+{
+ switch (motion) {
+ // Mobile Lite Profile
+ case GESTURE_SHAKE:
+ return MOTION_ENGINE_EVENT_SHAKE;
+
+ // Mobile Full Profile
+ case GESTURE_DOUBLE_TAP:
+ return MOTION_ENGINE_EVENT_DOUBLETAP;
+
+ case GESTURE_MOVE_TO_EAR:
+ return MOTION_ENGINE_EVENT_DIRECT_CALL;
+
+ case GESTURE_NO_MOVE:
+ return MOTION_ENGINE_EVENT_NO_MOVE;
+
+ case GESTURE_PICK_UP:
+ return MOTION_ENGINE_EVENT_SMART_RELAY;
+
+ case GESTURE_SNAP:
+ return MOTION_ENGINE_EVENT_SNAP;
+
+ case GESTURE_TILT:
+ return MOTION_ENGINE_EVENT_TILT;
+
+ case GESTURE_TURN_FACE_DOWN:
+ return MOTION_ENGINE_EVENT_TOP_TO_BOTTOM;
+
+ default:
+ return CTX_VALUE_UNDEFINED;
+ }
+}
+
+static int get_me_option(int mode)
+{
+ if (mode == GESTURE_OPTION_DEFAULT) {
+ return SENSOR_OPTION_DEFAULT;
+
+ } else if (mode == GESTURE_OPTION_ALWAYS_ON) {
+ return SENSOR_OPTION_ALWAYS_ON;
+ }
+
+ return CTX_VALUE_UNDEFINED;
+}
+
+bool ctx::gesture::me_check_coverage(int motion)
+{
+ switch (motion) {
+ case GESTURE_SHAKE:
+ case GESTURE_DOUBLE_TAP:
+ case GESTURE_MOVE_TO_EAR:
+ case GESTURE_NO_MOVE:
+ case GESTURE_PICK_UP:
+ case GESTURE_SNAP:
+ case GESTURE_TILT:
+ case GESTURE_TURN_FACE_DOWN:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+int ctx::gesture::me_is_supported(int motion)
+{
+ int handle = -1, res;
+ int ev_type = get_event_type(motion);
+ res = ctx::sensor::connect(&handle, MOTION_SENSOR, ev_type, SENSOR_OPTION_DEFAULT, me_sensor_event_cb, NULL);
+ ctx::sensor::disconnect(&handle, MOTION_SENSOR, ev_type);
+
+ return res;
+}
+
+int ctx::gesture::me_start(_cx_gesture_h *handle, int gesture, int option)
+{
+ int req_id = ctx::generate_rid();
+ int ev_type = get_event_type(gesture);
+ int me_opt = get_me_option(option);
+
+ try_return_result(me_opt != CTX_VALUE_UNDEFINED, GESTURE_ERROR_INVALID_PARAMETER);
+
+ int res = ctx::sensor::connect(&handle->me_handle, MOTION_SENSOR, ev_type, me_opt, me_sensor_event_cb, (void*)req_id);
+ try_return_result(!IS_FAILED(res), res);
+
+ LOGI("Started MotionEngine Event %d (Gesture %d)", ev_type, gesture);
+
+ handle->req_id = req_id;
+ handle->me_event = ev_type;
+
+ return GESTURE_ERROR_NONE;
+}
+
+int ctx::gesture::me_stop(_cx_gesture_h *handle)
+{
+ LOGI("Stopping MotionEngine Event %d", handle->me_event);
+
+ ctx::sensor::disconnect(&handle->me_handle, MOTION_SENSOR, handle->me_event);
+
+ handle->me_handle = CTX_VALUE_UNDEFINED;
+ handle->me_event = CTX_VALUE_UNDEFINED;
+
+ return GESTURE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * motion
+ *
+ * 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 _CX_GESTURE_MOTION_ENGINE_H_
+#define _CX_GESTURE_MOTION_ENGINE_H_
+
+#include <stdbool.h>
+#include "gesture.h"
+
+namespace ctx { namespace gesture{
+
+ bool me_check_coverage(int gesture);
+ int me_is_supported(int gesture);
+ int me_start(_cx_gesture_h *handle, int gesture, int mode);
+ int me_stop(_cx_gesture_h *handle);
+
+} } /* namespace ctx::gesture */
+
+#endif /* End of _CX_GESTURE_MOTION_ENGINE_H_ */
--- /dev/null
+/*
+ * motion
+ *
+ * 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_CONTEXT_ERROR_H__
+#define __TIZEN_CONTEXT_ERROR_H__
+
+#include <tizen_error.h>
+
+#define CERR_NONE TIZEN_ERROR_NONE /* Successful */
+#define CERR_INVALID_PARAMETER TIZEN_ERROR_INVALID_PARAMETER /* Invalid function parameter */
+#define CERR_INVALID_OPERATION TIZEN_ERROR_INVALID_OPERATION /* Function not implemented */
+#define CERR_OUT_OF_MEMORY TIZEN_ERROR_OUT_OF_MEMORY /* Out of memory */
+#define CERR_PERMISSION_DENIED TIZEN_ERROR_PERMISSION_DENIED /* Permission denied */
+#define CERR_NOT_SUPPORTED TIZEN_ERROR_NOT_SUPPORTED /* Not supported */
+#define CERR_ALREADY_STARTED (TIZEN_ERROR_CONTEXT | 0x01) /* Already started */
+#define CERR_NOT_STARTED (TIZEN_ERROR_CONTEXT | 0x02) /* Not started */
+#define CERR_OPERATION_FAILED (TIZEN_ERROR_CONTEXT | 0x04) /* Operation failed because of a system error */
+
+#endif // __TIZEN_CONTEXT_ERROR_H__
--- /dev/null
+/*
+ * motion
+ *
+ * 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 __CONTEXT_TYPES_PRIVATE_H__
+#define __CONTEXT_TYPES_PRIVATE_H__
+
+#include <dlog.h>
+#include <ctx_error.h>
+
+#define EXTAPI __attribute__ ((visibility("default")))
+
+#define ASSERT_SUPPORTED(feature) \
+ do { \
+ int __result = ctx::is_supported(feature); \
+ if (__result != CERR_NONE) return __result; \
+ } while (0)
+
+#define try_return_result_tag(cond, ret, tag, fmt, arg...) \
+ do { if (!(cond)) { tag(fmt, ##arg); return ret; } } while (0)
+
+#define try_return_void_tag(cond, tag, fmt, arg...) \
+ do { if (!(cond)) { tag(fmt, ##arg); return; } } while (0)
+
+#define try_catch_tag(cond, tag, fmt, arg...) \
+ do { if (!(cond)) { tag(fmt, ##arg); goto CATCH; } } while (0)
+
+#define try_return_result(cond, ret) \
+ do { if (!(cond)) { return ret; } } while (0)
+
+#define try_return_void(cond) \
+ do { if (!(cond)) { return; } } while (0)
+
+#define try_catch(cond) \
+ do { if (!(cond)) { goto CATCH; } } while (0)
+
+#define assert_invalid_param(cond) \
+ do { if (!(cond)) { return CERR_INVALID_PARAMETER; } } while (0)
+
+#define IS_FAILED(X) ((X) != CERR_NONE)
+
+#define CTX_VALUE_UNDEFINED -1
+
+#define ASSERT_HANDLE try_return_result_tag(handle, CERR_INVALID_PARAMETER, LOGE, "handle cannot be null")
+#define ASSERT_ALLOC(X) try_return_result_tag(X, CERR_OPERATION_FAILED, LOGE, "Memory allocation failed")
+#define ASSERT_NULL(X) try_return_result_tag(X, CERR_INVALID_PARAMETER, LOGE, "Parameter null")
+
+#endif /* __CONTEXT_TYPES_PRIVATE_H__ */
--- /dev/null
+/*
+ * motion
+ *
+ * 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.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/time.h>
+#include <glib.h>
+#include <system_info.h>
+#include <ctx_types_private.h>
+#include "ctx_error.h"
+#include "ctx_util_misc.h"
+
+int ctx::generate_rid()
+{
+ static GMutex rid_mutex;
+ static int rid = 0;
+ int ret = 0;
+
+ g_mutex_lock(&rid_mutex);
+
+ if (++rid < 0)
+ rid = 1;
+
+ ret = rid;
+
+ g_mutex_unlock(&rid_mutex);
+
+ return ret;
+}
+
+int ctx::is_supported(const char* feature)
+{
+ bool supported = false;
+ int ret = system_info_get_platform_bool(feature, &supported);
+
+ if (ret == CERR_NONE && !supported) {
+ SLOGD("Not Supported: %s", feature);
+ return CERR_NOT_SUPPORTED;
+ } else if (ret != CERR_NONE) {
+ SLOGE("Getting system info failed: %#x", ret);
+ return CERR_OPERATION_FAILED;
+ }
+
+ return CERR_NONE;
+}
+
+int64_t ctx::time::get_utc(int64_t* ymd, int64_t* hms)
+{
+ struct timeval now;
+ struct tm tm_now;
+ int64_t timestamp;
+ int64_t hms_now;
+
+ gettimeofday(&now, NULL);
+ timestamp = now.tv_sec * 1000LL + now.tv_usec / 1000;
+
+ if (ymd || hms) {
+ time_t now_sec = now.tv_sec;
+ gmtime_r(&now_sec, &tm_now);
+ hms_now = ((tm_now.tm_hour * 60 + tm_now.tm_min) * 60 + tm_now.tm_sec) * 1000LL + now.tv_usec / 1000;
+
+ if (hms)
+ *hms = hms_now;
+
+ if (ymd)
+ *ymd = timestamp - hms_now;
+ }
+
+ return timestamp;
+}
--- /dev/null
+/*
+ * motion
+ *
+ * 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 __CONTEXT_UTIL_MISC_H__
+#define __CONTEXT_UTIL_MISC_H__
+
+#include <sys/types.h>
+
+namespace ctx {
+
+ int generate_rid(void);
+ int is_supported(const char* feature);
+
+ namespace time {
+
+ int64_t get_utc(int64_t* ymd, int64_t* hms);
+
+ } /* namespace ctx::util */
+
+} /* namespace ctx */
+
+#endif /* __CONTEXT_UTIL_MISC_H__ */
--- /dev/null
+/*
+ * motion
+ *
+ * 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.
+ *
+ */
+
+#include <ctx_error.h>
+#include "ctx_types_private.h"
+#include "ctx_util_sensor.h"
+
+#define NUM_CONNECT_TRIAL 2
+
+int ctx::sensor::connect(int *handle, sensor_type_t sensor, unsigned int event, int option, sensor_cb_t cb, void *user_data)
+{
+ sensor_t sen = sensord_get_sensor(sensor);
+
+ for (int i=0; i < NUM_CONNECT_TRIAL && *handle < 0; ++i) {
+ LOGD("Trial #%d to connect to Sensor %d", i+1, sensor);
+ *handle = sensord_connect(sen);
+ }
+
+ try_return_result_tag(*handle>=0, CERR_NOT_SUPPORTED, SLOGE, "Failed to connect Sensor %d", sensor);
+
+ bool supported = false;
+ try_return_result_tag(sensord_is_supported_event_type(sen, event, &supported), CERR_OPERATION_FAILED, SLOGE, "sensord_is_supported_event_type() failed");
+ try_return_result_tag(supported, CERR_NOT_SUPPORTED, SLOGD, "Sensor Event %d is not supported.", event);
+
+ if (!sensord_register_event(*handle, event, 0, 0, cb, user_data)) {
+ LOGE("Failed to register Sensor Event %d", event);
+ sensord_disconnect(*handle);
+ *handle = -1;
+ return CERR_NOT_SUPPORTED;
+ }
+
+ if (!sensord_start(*handle, option)) {
+ LOGE("Failed to start Sensor %d", sensor);
+ sensord_unregister_event(*handle, event);
+ sensord_disconnect(*handle);
+ *handle = -1;
+ return CERR_OPERATION_FAILED;
+ }
+
+ LOGI("Sensor %d (Event %#x) started (Option: %d)", sensor, event, option);
+ return CERR_NONE;
+}
+
+void ctx::sensor::disconnect(int *handle, sensor_type_t sensor, unsigned int event)
+{
+ try_return_void(*handle >= 0);
+
+ sensord_unregister_event(*handle, event);
+ sensord_stop(*handle);
+ sensord_disconnect(*handle);
+
+ *handle = -1;
+
+ LOGI("Sensor %d (Event %#x) stopped", sensor, event);
+}
--- /dev/null
+/*
+ * motion
+ *
+ * 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 __CONTEXT_UTIL_SENSOR_H__
+#define __CONTEXT_UTIL_SENSOR_H__
+
+#include <sensor_internal.h>
+
+namespace ctx { namespace sensor {
+
+ int connect(int *handle, sensor_type_t sensor, unsigned int event, int option, sensor_cb_t cb, void *user_data);
+ void disconnect(int *handle, sensor_type_t sensor, unsigned int event);
+
+} } /* namespace ctx::sensor */
+
+#endif /* __CONTEXT_UTIL_SENSOR_H__ */
+
--- /dev/null
+/*
+ * motion
+ *
+ * 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 _CONTEXT_HANDLE_LIST_H_
+#define _CONTEXT_HANDLE_LIST_H_
+
+#include <map>
+#include <glib.h>
+#include "ctx_types_private.h"
+
+namespace ctx {
+
+template <typename _handle_t>
+class handle_map_t
+{
+private:
+ std::map<int, _handle_t*> _map;
+ GMutex _mutex;
+
+public:
+ handle_map_t() {}
+ ~handle_map_t() {}
+
+ void insert(int rid, _handle_t *h);
+ void remove(int rid);
+
+ _handle_t* find(int rid);
+ _handle_t* get_copy(int rid);
+
+}; /* class handle_map_t */
+
+} /* namesapce ctx */
+
+template <typename _handle_t>
+void ctx::handle_map_t<_handle_t>::insert(int rid, _handle_t *h)
+{
+ g_mutex_lock(&_mutex);
+
+ _map[rid] = h;
+
+ g_mutex_unlock(&_mutex);
+}
+
+template <typename _handle_t>
+void ctx::handle_map_t<_handle_t>::remove(int rid)
+{
+ g_mutex_lock(&_mutex);
+
+ _map.erase(rid);
+
+ g_mutex_unlock(&_mutex);
+}
+
+template <typename _handle_t>
+_handle_t* ctx::handle_map_t<_handle_t>::find(int rid)
+{
+ _handle_t *h = NULL;
+
+ g_mutex_lock(&_mutex);
+
+ typename std::map<int, _handle_t*>::iterator it = _map.find(rid);
+ if (it != _map.end())
+ h = it->second;
+
+ g_mutex_unlock(&_mutex);
+
+ return h;
+}
+
+template <typename _handle_t>
+_handle_t* ctx::handle_map_t<_handle_t>::get_copy(int rid)
+{
+ _handle_t *copy = static_cast<_handle_t*>(malloc(sizeof(_handle_t)));
+ try_return_result_tag(copy, NULL, LOGE, "Memory allocation failed");
+
+ g_mutex_lock(&_mutex);
+
+ typename std::map<int, _handle_t*>::iterator it = _map.find(rid);
+ if (it != _map.end()) {
+ *copy = *(it->second);
+ } else {
+ free(copy);
+ copy = NULL;
+ }
+
+ g_mutex_unlock(&_mutex);
+
+ return copy;
+}
+
+#endif /* _CONTEXT_HANDLE_LIST_H_ */