From 93fbd6105378aca0bc2f936ab845d1deca0767fd Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 2 Jun 2015 16:48:07 +0900 Subject: [PATCH 2/8] Migrate from 2.3 activity/gesture recognition API Change-Id: I7342faac42177a760c9950b28c047bcc2979340e Signed-off-by: Mu-Woong Lee --- .gitignore | 1 + CMakeLists.txt | 67 ++++++++++ LICENSE | 203 +++++++++++++++++++++++++++++++ doc/activity_recognition_doc.h | 126 +++++++++++++++++++ doc/gesture_recognition_doc.h | 149 +++++++++++++++++++++++ include/activity_recognition.h | 223 ++++++++++++++++++++++++++++++++++ include/gesture_recognition.h | 269 +++++++++++++++++++++++++++++++++++++++++ motion.pc.in | 13 ++ packaging/motion.manifest | 5 + packaging/motion.spec | 87 +++++++++++++ src/activity/activity.cpp | 55 +++++++++ src/activity/activity.h | 38 ++++++ src/gesture/gesture.cpp | 174 ++++++++++++++++++++++++++ src/gesture/gesture.h | 48 ++++++++ src/gesture/motion_engine.cpp | 219 +++++++++++++++++++++++++++++++++ src/gesture/motion_engine.h | 35 ++++++ src/shared/ctx_error.h | 35 ++++++ src/shared/ctx_types_private.h | 63 ++++++++++ src/shared/ctx_util_misc.cpp | 87 +++++++++++++ src/shared/ctx_util_misc.h | 38 ++++++ src/shared/ctx_util_sensor.cpp | 71 +++++++++++ src/shared/ctx_util_sensor.h | 33 +++++ src/shared/handle_map.h | 107 ++++++++++++++++ 23 files changed, 2146 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 doc/activity_recognition_doc.h create mode 100644 doc/gesture_recognition_doc.h create mode 100644 include/activity_recognition.h create mode 100644 include/gesture_recognition.h create mode 100644 motion.pc.in create mode 100644 packaging/motion.manifest create mode 100644 packaging/motion.spec create mode 100644 src/activity/activity.cpp create mode 100644 src/activity/activity.h create mode 100644 src/gesture/gesture.cpp create mode 100644 src/gesture/gesture.h create mode 100644 src/gesture/motion_engine.cpp create mode 100644 src/gesture/motion_engine.h create mode 100644 src/shared/ctx_error.h create mode 100644 src/shared/ctx_types_private.h create mode 100644 src/shared/ctx_util_misc.cpp create mode 100644 src/shared/ctx_util_misc.h create mode 100644 src/shared/ctx_util_sensor.cpp create mode 100644 src/shared/ctx_util_sensor.h create mode 100644 src/shared/handle_map.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a01ee28 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0bb3793 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,67 @@ +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) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5b25701 --- /dev/null +++ b/LICENSE @@ -0,0 +1,203 @@ +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. diff --git a/doc/activity_recognition_doc.h b/doc/activity_recognition_doc.h new file mode 100644 index 0000000..ba22e7d --- /dev/null +++ b/doc/activity_recognition_doc.h @@ -0,0 +1,126 @@ +/* + * 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 + * + * @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 Feature Element. + * + */ diff --git a/doc/gesture_recognition_doc.h b/doc/gesture_recognition_doc.h new file mode 100644 index 0000000..3444820 --- /dev/null +++ b/doc/gesture_recognition_doc.h @@ -0,0 +1,149 @@ +/* + * 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 + * + * @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 Feature Element. + * + */ diff --git a/include/activity_recognition.h b/include/activity_recognition.h new file mode 100644 index 0000000..e908d87 --- /dev/null +++ b/include/activity_recognition.h @@ -0,0 +1,223 @@ +/* + * 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 +#include + +#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__ diff --git a/include/gesture_recognition.h b/include/gesture_recognition.h new file mode 100644 index 0000000..e4f2de0 --- /dev/null +++ b/include/gesture_recognition.h @@ -0,0 +1,269 @@ +/* + * 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 +#include + +#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__ diff --git a/motion.pc.in b/motion.pc.in new file mode 100644 index 0000000..50edac1 --- /dev/null +++ b/motion.pc.in @@ -0,0 +1,13 @@ +#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} diff --git a/packaging/motion.manifest b/packaging/motion.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/packaging/motion.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/motion.spec b/packaging/motion.spec new file mode 100644 index 0000000..c5de290 --- /dev/null +++ b/packaging/motion.spec @@ -0,0 +1,87 @@ +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 diff --git a/src/activity/activity.cpp b/src/activity/activity.cpp new file mode 100644 index 0000000..020a1cf --- /dev/null +++ b/src/activity/activity.cpp @@ -0,0 +1,55 @@ +/* + * 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 +#include +#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; +} diff --git a/src/activity/activity.h b/src/activity/activity.h new file mode 100644 index 0000000..c802c90 --- /dev/null +++ b/src/activity/activity.h @@ -0,0 +1,38 @@ +/* + * 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 + +#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_ */ diff --git a/src/gesture/gesture.cpp b/src/gesture/gesture.cpp new file mode 100644 index 0000000..2c34c85 --- /dev/null +++ b/src/gesture/gesture.cpp @@ -0,0 +1,174 @@ +/* + * 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 +#include +#include +#include +#include +#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(data.gesture), &data, + timestamp, static_cast(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(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(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; +} diff --git a/src/gesture/gesture.h b/src/gesture/gesture.h new file mode 100644 index 0000000..d2dde88 --- /dev/null +++ b/src/gesture/gesture.h @@ -0,0 +1,48 @@ +/* + * 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 + +#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_ */ diff --git a/src/gesture/motion_engine.cpp b/src/gesture/motion_engine.cpp new file mode 100644 index 0000000..ded6a60 --- /dev/null +++ b/src/gesture/motion_engine.cpp @@ -0,0 +1,219 @@ +/* + * 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 +#include +#include +#include +#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; +} diff --git a/src/gesture/motion_engine.h b/src/gesture/motion_engine.h new file mode 100644 index 0000000..82f8003 --- /dev/null +++ b/src/gesture/motion_engine.h @@ -0,0 +1,35 @@ +/* + * 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 +#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_ */ diff --git a/src/shared/ctx_error.h b/src/shared/ctx_error.h new file mode 100644 index 0000000..4fca642 --- /dev/null +++ b/src/shared/ctx_error.h @@ -0,0 +1,35 @@ +/* + * 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 + +#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__ diff --git a/src/shared/ctx_types_private.h b/src/shared/ctx_types_private.h new file mode 100644 index 0000000..570989c --- /dev/null +++ b/src/shared/ctx_types_private.h @@ -0,0 +1,63 @@ +/* + * 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 +#include + +#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__ */ diff --git a/src/shared/ctx_util_misc.cpp b/src/shared/ctx_util_misc.cpp new file mode 100644 index 0000000..affa491 --- /dev/null +++ b/src/shared/ctx_util_misc.cpp @@ -0,0 +1,87 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#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; +} diff --git a/src/shared/ctx_util_misc.h b/src/shared/ctx_util_misc.h new file mode 100644 index 0000000..e15d207 --- /dev/null +++ b/src/shared/ctx_util_misc.h @@ -0,0 +1,38 @@ +/* + * 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 + +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__ */ diff --git a/src/shared/ctx_util_sensor.cpp b/src/shared/ctx_util_sensor.cpp new file mode 100644 index 0000000..4077fbb --- /dev/null +++ b/src/shared/ctx_util_sensor.cpp @@ -0,0 +1,71 @@ +/* + * 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 +#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); +} diff --git a/src/shared/ctx_util_sensor.h b/src/shared/ctx_util_sensor.h new file mode 100644 index 0000000..70a8ded --- /dev/null +++ b/src/shared/ctx_util_sensor.h @@ -0,0 +1,33 @@ +/* + * 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 + +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__ */ + diff --git a/src/shared/handle_map.h b/src/shared/handle_map.h new file mode 100644 index 0000000..75d9b2b --- /dev/null +++ b/src/shared/handle_map.h @@ -0,0 +1,107 @@ +/* + * 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 +#include +#include "ctx_types_private.h" + +namespace ctx { + +template +class handle_map_t +{ +private: + std::map _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 +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 +void ctx::handle_map_t<_handle_t>::remove(int rid) +{ + g_mutex_lock(&_mutex); + + _map.erase(rid); + + g_mutex_unlock(&_mutex); +} + +template +_handle_t* ctx::handle_map_t<_handle_t>::find(int rid) +{ + _handle_t *h = NULL; + + g_mutex_lock(&_mutex); + + typename std::map::iterator it = _map.find(rid); + if (it != _map.end()) + h = it->second; + + g_mutex_unlock(&_mutex); + + return h; +} + +template +_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::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_ */ -- 2.7.4 From 0a9a1292350a85f85001c4672673a5aa4dec99cb Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Fri, 5 Jun 2015 13:26:16 +0900 Subject: [PATCH 3/8] Build error fix for 64bit env. Change-Id: Ie02f0227398be20471ef9edd7b171deae453f4a8 Signed-off-by: Mu-Woong Lee --- src/gesture/motion_engine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gesture/motion_engine.cpp b/src/gesture/motion_engine.cpp index ded6a60..fb2ae38 100644 --- a/src/gesture/motion_engine.cpp +++ b/src/gesture/motion_engine.cpp @@ -100,7 +100,7 @@ static void me_sensor_event_cb(sensor_t sensor, unsigned int sensor_event_type, try_return_void(user_data); int64_t ts = ctx::time::get_utc(NULL, NULL); - int req_id = (int)user_data; + int req_id = *static_cast(user_data); LOGD("Received data for ReqId %d", req_id); _cx_gesture_data data; @@ -189,18 +189,18 @@ int ctx::gesture::me_is_supported(int motion) 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); + handle->req_id = ctx::generate_rid(); + 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); + int res = ctx::sensor::connect(&handle->me_handle, MOTION_SENSOR, ev_type, me_opt, me_sensor_event_cb, &(handle->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; -- 2.7.4 From eb395d930a9ae4c55e2ecad7f79dc8029ecb9cf3 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Fri, 5 Jun 2015 22:24:27 +0900 Subject: [PATCH 4/8] Updated build script for 64bit support Change-Id: I14a1decb4e5c5202e78cfaec2827d78b0b11b3bf Signed-off-by: Mu-Woong --- CMakeLists.txt | 16 ++++++++-------- motion.pc.in | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bb3793..0f50d5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(motion) +INCLUDE(GNUInstallDirs) # Source Lists SET(SRCS @@ -19,17 +20,13 @@ SET(dependency "dlog glib-2.0 capi-base-common capi-system-info sensor") 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) +ADD_DEFINITIONS(-O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed) # Build pkg_check_modules(pkgs REQUIRED ${dependency}) @@ -46,14 +43,17 @@ SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) # Install -INSTALL(TARGETS ${target} DESTINATION lib) +INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include/motion FILES_MATCHING PATTERN "*.h" ) +SET(VERSION ${FULLVER}) +SET(PC_PREFIX ${CMAKE_INSTALL_PREFIX}) SET(PC_NAME ${target}) -SET(PC_INCLUDE "/usr/include/motion") +SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") +SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/motion") SET(PC_DESCRIPTION "Tizen Native Motion Recognition API") SET(PC_REQUIRED ${dependency}) SET(PC_LDFLAGS -l${target}) @@ -64,4 +64,4 @@ CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/motion.pc @ONLY ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/motion.pc DESTINATION lib/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/motion.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/motion.pc.in b/motion.pc.in index 50edac1..71c14c4 100644 --- a/motion.pc.in +++ b/motion.pc.in @@ -1,8 +1,8 @@ #Package Information for pkg-config -prefix=@PREFIX@ -exec_prefix=/usr -libdir=/usr/lib +prefix=@PC_PREFIX@ +exec_prefix=@PC_PREFIX@ +libdir=@PC_LIBDIR@ includedir=@PC_INCLUDE@ Name: @PC_NAME@ -- 2.7.4 From 7c119579cd43f43a25a883e3ae1e8bf1923ffb83 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Sat, 20 Jun 2015 15:54:17 +0900 Subject: [PATCH 5/8] Change include directory path Change-Id: If22eb727ea5505b67412c2b4625442784acc4acc Signed-off-by: Mu-Woong --- CMakeLists.txt | 14 +++++++------- packaging/motion.spec | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f50d5d..21b3e92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ SET(SRCS src/activity/activity.cpp ) -# Dependencies +SET(inc_subdir "context-service") SET(dependency "dlog glib-2.0 capi-base-common capi-system-info sensor") # Target lib (for backward compatibility, the below old naming is used) @@ -45,7 +45,7 @@ SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) # Install INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) INSTALL( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include/motion + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${inc_subdir} FILES_MATCHING PATTERN "*.h" ) @@ -53,15 +53,15 @@ SET(VERSION ${FULLVER}) SET(PC_PREFIX ${CMAKE_INSTALL_PREFIX}) SET(PC_NAME ${target}) SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") -SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/motion") +SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${inc_subdir}") SET(PC_DESCRIPTION "Tizen Native Motion Recognition API") SET(PC_REQUIRED ${dependency}) SET(PC_LDFLAGS -l${target}) -SET(PC_CFLAGS -I\${includedir}/motion) +SET(PC_CFLAGS -I\${includedir}/${inc_subdir}) CONFIGURE_FILE( - motion.pc.in - ${CMAKE_CURRENT_SOURCE_DIR}/motion.pc + ${PROJECT_NAME}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/motion.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/packaging/motion.spec b/packaging/motion.spec index c5de290..ebad3a4 100644 --- a/packaging/motion.spec +++ b/packaging/motion.spec @@ -51,9 +51,9 @@ rm -rf %{buildroot} %make_install mkdir -p %{buildroot}/usr/share/license -cp LICENSE %{buildroot}/usr/share/license/motion +cp LICENSE %{buildroot}/usr/share/license/%{name} # For backward compatibility -ln -s ./motion.pc %{buildroot}/%{_libdir}/pkgconfig/libcore-context-manager.pc +ln -s ./%{name}.pc %{buildroot}/%{_libdir}/pkgconfig/libcore-context-manager.pc %post /sbin/ldconfig @@ -62,15 +62,15 @@ ln -s ./motion.pc %{buildroot}/%{_libdir}/pkgconfig/libcore-context-manager.pc /sbin/ldconfig %files -%manifest packaging/motion.manifest +%manifest packaging/%{name}.manifest %defattr(-,root,root,-) %{_libdir}/*.so* -/usr/share/license/motion +/usr/share/license/%{name} %package devel Summary: Tizen Native Motion Recognition API (Development) Group: Framework/context -Requires: motion = %{version}-%{release} +Requires: %{name} = %{version}-%{release} %description devel Tizen Native Motion Recognition API (Development) @@ -83,5 +83,5 @@ Tizen Native Motion Recognition API (Development) %files devel %defattr(-,root,root,-) -%{_includedir}/motion/*.h +%{_includedir}/*/*.h %{_libdir}/pkgconfig/*.pc -- 2.7.4 From 81445090ac8d8e00343b94a6a59e6a8ac18f0633 Mon Sep 17 00:00:00 2001 From: Mu-Woong Date: Thu, 17 Sep 2015 13:37:25 +0900 Subject: [PATCH 6/8] Gesture: reorganize the namespace of motion_engine Change-Id: I3b7b99ac7235fb4c2c8bd14e140bc0023d9f2d9e Signed-off-by: Mu-Woong --- include/gesture_recognition.h | 20 ++++++++++---------- src/gesture/gesture.cpp | 22 ++++++++++++---------- src/gesture/motion_engine.cpp | 8 ++++---- src/gesture/motion_engine.h | 12 ++++++------ 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/include/gesture_recognition.h b/include/gesture_recognition.h index e4f2de0..65b3f2a 100644 --- a/include/gesture_recognition.h +++ b/include/gesture_recognition.h @@ -94,18 +94,18 @@ typedef enum { * @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_EVENT_NONE = 0, /**< Detected nothing */ + GESTURE_EVENT_DETECTED = 1, /**< Detected the gesture */ - GESTURE_SHAKE_DETECTED = 1, /**< Shake gesture is detected */ - GESTURE_SHAKE_FINISHED = 2, /**< Shake gesture finished */ + GESTURE_SHAKE_DETECTED = 1, /**< Shake gesture started */ + GESTURE_SHAKE_FINISHED = 2, /**< Shake gesture stopped */ - 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_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; /** diff --git a/src/gesture/gesture.cpp b/src/gesture/gesture.cpp index 2c34c85..f609090 100644 --- a/src/gesture/gesture.cpp +++ b/src/gesture/gesture.cpp @@ -25,6 +25,8 @@ #include "motion_engine.h" #include "gesture.h" +using namespace ctx::gesture; + 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) @@ -51,14 +53,14 @@ EXTAPI int gesture_is_supported(gesture_type_e gesture, bool* supported) ASSERT_SUPPORTED(FEATURE_KEY_GESTURE); ASSERT_NULL(supported); - if (!ctx::gesture::me_check_coverage(gesture)) - return GESTURE_ERROR_NONE; + int ret = GESTURE_ERROR_NONE; - int ret = ctx::gesture::me_is_supported(gesture); - if (ret == GESTURE_ERROR_NONE) - *supported = true; + if (motion_engine::check_coverage(gesture)) { + ret = motion_engine::is_supported(gesture); + *supported = (ret == GESTURE_ERROR_NONE); + } - return GESTURE_ERROR_NONE; + return ret; } EXTAPI int gesture_create(gesture_h *handle) @@ -109,8 +111,8 @@ EXTAPI int gesture_start_recognition(gesture_h handle, gesture_type_e gesture, g int ret; - if (ctx::gesture::me_check_coverage(gesture)) { - ret = ctx::gesture::me_start(handle, gesture, option); + if (motion_engine::check_coverage(gesture)) { + ret = motion_engine::start(handle, gesture, option); } else { ret = GESTURE_ERROR_INVALID_PARAMETER; } @@ -128,8 +130,8 @@ EXTAPI int gesture_stop_recognition(gesture_h 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); + if (motion_engine::check_coverage(handle->gesture)) + motion_engine::stop(handle); handle_map.remove(handle->req_id); ret = GESTURE_ERROR_NONE; diff --git a/src/gesture/motion_engine.cpp b/src/gesture/motion_engine.cpp index fb2ae38..1c01997 100644 --- a/src/gesture/motion_engine.cpp +++ b/src/gesture/motion_engine.cpp @@ -159,7 +159,7 @@ static int get_me_option(int mode) return CTX_VALUE_UNDEFINED; } -bool ctx::gesture::me_check_coverage(int motion) +bool ctx::gesture::motion_engine::check_coverage(int motion) { switch (motion) { case GESTURE_SHAKE: @@ -177,7 +177,7 @@ bool ctx::gesture::me_check_coverage(int motion) } } -int ctx::gesture::me_is_supported(int motion) +int ctx::gesture::motion_engine::is_supported(int motion) { int handle = -1, res; int ev_type = get_event_type(motion); @@ -187,7 +187,7 @@ int ctx::gesture::me_is_supported(int motion) return res; } -int ctx::gesture::me_start(_cx_gesture_h *handle, int gesture, int option) +int ctx::gesture::motion_engine::start(_cx_gesture_h *handle, int gesture, int option) { int ev_type = get_event_type(gesture); int me_opt = get_me_option(option); @@ -206,7 +206,7 @@ int ctx::gesture::me_start(_cx_gesture_h *handle, int gesture, int option) return GESTURE_ERROR_NONE; } -int ctx::gesture::me_stop(_cx_gesture_h *handle) +int ctx::gesture::motion_engine::stop(_cx_gesture_h *handle) { LOGI("Stopping MotionEngine Event %d", handle->me_event); diff --git a/src/gesture/motion_engine.h b/src/gesture/motion_engine.h index 82f8003..36f3ec7 100644 --- a/src/gesture/motion_engine.h +++ b/src/gesture/motion_engine.h @@ -23,13 +23,13 @@ #include #include "gesture.h" -namespace ctx { namespace gesture{ +namespace ctx { namespace gesture { namespace motion_engine { - 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); + bool check_coverage(int gesture); + int is_supported(int gesture); + int start(_cx_gesture_h *handle, int gesture, int mode); + int stop(_cx_gesture_h *handle); -} } /* namespace ctx::gesture */ +} } } #endif /* End of _CX_GESTURE_MOTION_ENGINE_H_ */ -- 2.7.4 From 46fde31ccebd7f5b69c04d8bfa3b7c7ffc65610d Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Fri, 15 Jan 2016 10:53:51 +0900 Subject: [PATCH 7/8] Fix broken links in doxygen Signed-off-by: Somin Kim (cherry picked from commit 65df40631616e6fc5b5a1726e9402bbf72f04a70) Signed-off-by: Mu-Woong Lee Change-Id: I5247c35e258fa503457a6b994a413440d04f7247 --- doc/activity_recognition_doc.h | 2 +- doc/gesture_recognition_doc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/activity_recognition_doc.h b/doc/activity_recognition_doc.h index ba22e7d..f7c822f 100644 --- a/doc/activity_recognition_doc.h +++ b/doc/activity_recognition_doc.h @@ -121,6 +121,6 @@ * * 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 Feature Element. + * More details on featuring your application can be found from Feature Element. * */ diff --git a/doc/gesture_recognition_doc.h b/doc/gesture_recognition_doc.h index 3444820..4432482 100644 --- a/doc/gesture_recognition_doc.h +++ b/doc/gesture_recognition_doc.h @@ -144,6 +144,6 @@ * * 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 Feature Element. + * More details on featuring your application can be found from Feature Element. * */ -- 2.7.4 From c878386cd5f931496d2d6a25b14763cddcd34807 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 6 Apr 2016 18:58:21 +0900 Subject: [PATCH 8/8] Clean-up build scripts Change-Id: Ie83e9cb07e2cb0c0c7a7c58715c39a561285e69f Signed-off-by: Mu-Woong Lee --- CMakeLists.txt | 25 +++++++++---------------- packaging/motion.spec | 50 +++++++++++++++++++++++--------------------------- 2 files changed, 32 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21b3e92..c2049b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,22 +2,14 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(motion) INCLUDE(GNUInstallDirs) +# Target lib (for backward compatibility, the below old naming is used) +SET(target "core-context-manager") + # 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 -) +FILE(GLOB_RECURSE SRCS src/*.cpp) SET(inc_subdir "context-service") -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") +SET(dependency "glib-2.0 dlog capi-base-common capi-system-info sensor") # Options INCLUDE(FindPkgConfig) @@ -26,7 +18,8 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/src/shared ) -ADD_DEFINITIONS(-O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed) +ADD_DEFINITIONS(-O2 -Wall -fPIC -fdata-sections -ffunction-sections -fvisibility=hidden) +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC -Wl,--as-needed -Wl,--gc-section -Wl,--print-gc-section") # Build pkg_check_modules(pkgs REQUIRED ${dependency}) @@ -43,7 +36,7 @@ SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) # Install -INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR}) INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${inc_subdir} FILES_MATCHING PATTERN "*.h" @@ -51,7 +44,7 @@ INSTALL( SET(VERSION ${FULLVER}) SET(PC_PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(PC_NAME ${target}) +SET(PC_NAME ${PROJECT_NAME}) SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${inc_subdir}") SET(PC_DESCRIPTION "Tizen Native Motion Recognition API") diff --git a/packaging/motion.spec b/packaging/motion.spec index ebad3a4..d0eb8d8 100644 --- a/packaging/motion.spec +++ b/packaging/motion.spec @@ -1,25 +1,21 @@ Name: motion Summary: Tizen Native Motion Recognition API -Version: 1.1.3 +Version: 1.1.4 Release: 1 -Group: Framework/context +Group: Service/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(dlog) +BuildRequires: pkgconfig(capi-base-common) 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 @@ -29,21 +25,27 @@ Tizen Native Motion Recognition API %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+=" -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-parameter" +export CXXFLAGS+=" -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-parameter" -#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+=" -Wno-empty-body -fomit-frame-pointer -fno-optimize-sibling-calls" +export CXXFLAGS+=" -Wno-empty-body -fomit-frame-pointer -fno-optimize-sibling-calls" -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+=" -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow" +export CXXFLAGS+=" -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" +export CFLAGS+=" -fno-common" +export CXXFLAGS+=" -Wnon-virtual-dtor" +export CXXFLAGS+=" -std=c++11 -Wno-c++11-compat" -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCH=%{ARCH} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{PROFILE} +#export CFLAGS+=" -Wcast-qual" +#export CXXFLAGS+=" -Wcast-qual" + +#export CFLAGS+=" -DTIZEN_ENGINEER_MODE" +#export CXXFLAGS+=" -DTIZEN_ENGINEER_MODE" +#export FFLAGS+=" -DTIZEN_ENGINEER_MODE" + +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} make %{?jobs:-j%jobs} %install @@ -75,12 +77,6 @@ Requires: %{name} = %{version}-%{release} %description devel Tizen Native Motion Recognition API (Development) -%post devel -/sbin/ldconfig - -%postun devel -/sbin/ldconfig - %files devel %defattr(-,root,root,-) %{_includedir}/*/*.h -- 2.7.4