From f730eed310831186d128c9b7d5331bcf143a6730 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Fri, 14 Aug 2020 15:59:05 +0900 Subject: [PATCH] [ACR-1585][gesture][Add changes in gesture.h] - Add APIs to set and unset error callback Change-Id: Idb5a113ee6f69788386c0119e1baf451d762fb17 Signed-off-by: sooyeon.kim --- client/gesture.c | 44 ++++++++++++++++- client/gesture_client_dbus.c | 20 ++++++-- client/gesture_client_dbus.h | 2 +- client/gesture_main.h | 13 +++-- doc/uix_gesture_doc.h | 4 +- include/gesture.h | 115 +++++++++++++++++++++++++++++++++---------- include/gesture_common.h | 11 ++++- server/gestured_dbus.c | 29 ++++++----- 8 files changed, 184 insertions(+), 54 deletions(-) diff --git a/client/gesture.c b/client/gesture.c index d6f8d47..96fe1be 100644 --- a/client/gesture.c +++ b/client/gesture.c @@ -281,6 +281,10 @@ EXPORT_API int hand_gesture_start_recognition(hand_gesture_h handle, hand_gestur int ret = HAND_GESTURE_ERROR_NONE; + /* Set recognition callback and userdata in the handle */ + handle->recog_cb = callback; + handle->recog_user_data = user_data; + hand_gesture_data_h gesture_data = (hand_gesture_data_h)calloc(1, sizeof(struct hand_gesture_data_s)); if (!gesture_data) { return HAND_GESTURE_ERROR_OUT_OF_MEMORY; @@ -309,6 +313,10 @@ EXPORT_API int hand_gesture_stop_recognition(hand_gesture_h handle) return HAND_GESTURE_ERROR_OPERATION_FAILED; } + /* Unset recognition callback and userdata in the handle */ + handle->recog_cb = NULL; + handle->recog_user_data = NULL; + return HAND_GESTURE_ERROR_NONE; } @@ -332,7 +340,7 @@ EXPORT_API int hand_gesture_get_engine_info(hand_gesture_h handle, char** engine int ret = HAND_GESTURE_ERROR_NONE; - ret = gesture_client_dbus_engine_get_info(handle->gdbus_connection, engine_app_id, engine_name); + ret = gesture_client_dbus_get_engine_info(handle->gdbus_connection, engine_app_id, engine_name); if (ret != HAND_GESTURE_ERROR_NONE) { LOGE("Failed to get engine info : %d", ret); return HAND_GESTURE_ERROR_OPERATION_FAILED; @@ -340,3 +348,37 @@ EXPORT_API int hand_gesture_get_engine_info(hand_gesture_h handle, char** engine LOGD("[engineInfo] hand_gesture_get_engine_info : engine_app_id = %s, engine_name = %s", *engine_app_id, *engine_name); return ret; } + +EXPORT_API int hand_gesture_set_error_cb(hand_gesture_h handle, hand_gesture_error_cb callback, void *user_data) +{ + CHECK_GESTURE_FEATURE(); + ASSERT_NOT_NULL(handle); + + ASSERT_NOT_NULL(callback); + + LOGD("[DEBUG] Set error_cb"); + + int ret = HAND_GESTURE_ERROR_NONE; + + handle->error_cb = callback; + handle->error_user_data = user_data; + + + return ret; +} + +EXPORT_API int hand_gesture_unset_error_cb(hand_gesture_h handle) +{ + CHECK_GESTURE_FEATURE(); + ASSERT_NOT_NULL(handle); + + LOGD("[DEBUG] Unset error_cb"); + + int ret = HAND_GESTURE_ERROR_NONE; + + handle->error_cb = NULL; + handle->error_user_data = NULL; + + + return ret; +} diff --git a/client/gesture_client_dbus.c b/client/gesture_client_dbus.c index 0683bf0..91b139d 100644 --- a/client/gesture_client_dbus.c +++ b/client/gesture_client_dbus.c @@ -133,10 +133,24 @@ static void _handle_gesture_cb(GDBusConnection *connection, g_gesture_data->event = levent; g_gesture_data->detected_Count = lcount; - g_callback(gesture_type, g_gesture_data, 0, HAND_GESTURE_ERROR_NONE, user_data); +// g_callback(gesture_type, g_gesture_data, 0, HAND_GESTURE_ERROR_NONE, user_data); + if (_handle->recog_cb) { + LOGD("[CLIENT DBUS] Send recognition result. gesture_type(%d)", gesture_type); + _handle->recog_cb(_handle, gesture_type, 0, HAND_GESTURE_ERROR_NONE, _handle->recog_user_data); + } } else if (g_strcmp0(signal_name, GESTURE_CLIENT_SIGNAL_GET_ERROR) == 0) { - + int error; + char* err_msg = NULL; + g_variant_get(parameters, "(is)", &error, err_msg); + LOGD("[CLIENT DBUS] error(%d)", error); + + if (_handle->error_cb) { + LOGD("[CLIENT DBUS] Send error"); + _handle->error_cb(_handle, (hand_gesture_error_e)error, err_msg, _handle->error_user_data); + } else { + LOGW("[CLIENT DBUS] There is no error callback"); + } } else if (g_strcmp0(signal_name, GESTURE_CLIENT_SIGNAL_GET_MOTION_STATUS) == 0) { @@ -639,7 +653,7 @@ int gesture_client_dbus_is_support_gesture_type(GDBusConnection *gdbus_connectio } -int gesture_client_dbus_engine_get_info(GDBusConnection *gdbus_connection, char** engine_app_id, char** engine_name) +int gesture_client_dbus_get_engine_info(GDBusConnection *gdbus_connection, char** engine_app_id, char** engine_name) { int ret; GDBusMessage *reply = NULL; diff --git a/client/gesture_client_dbus.h b/client/gesture_client_dbus.h index fde91b3..b3666be 100644 --- a/client/gesture_client_dbus.h +++ b/client/gesture_client_dbus.h @@ -45,7 +45,7 @@ int gesture_client_dbus_stop_recognition(GDBusConnection *gdbus_connection); int gesture_client_dbus_foreach_result_time(GDBusConnection *gdbus_connection); int gesture_client_dbus_foreach_supported_type(GDBusConnection *gdbus_connection); int gesture_client_dbus_is_support_gesture_type(GDBusConnection *gdbus_connection, hand_gesture_type_e gesture, bool* supported); -int gesture_client_dbus_engine_get_info(GDBusConnection *gdbus_connection, char** engine_app_id, char** engine_name); +int gesture_client_dbus_get_engine_info(GDBusConnection *gdbus_connection, char** engine_app_id, char** engine_name); #ifdef __cplusplus } diff --git a/client/gesture_main.h b/client/gesture_main.h index 3cbe67e..c35f331 100644 --- a/client/gesture_main.h +++ b/client/gesture_main.h @@ -29,10 +29,15 @@ extern "C" #endif struct hand_gesture_s { - GDBusConnection *gdbus_connection; - guint server_watcher_id; - int monitor_id; - int server_monitor_id; + GDBusConnection *gdbus_connection; + guint server_watcher_id; + int monitor_id; + int server_monitor_id; + + hand_gesture_recognition_cb recog_cb; + void* recog_user_data; + hand_gesture_error_cb error_cb; + void* error_user_data; }; #ifdef __cplusplus diff --git a/doc/uix_gesture_doc.h b/doc/uix_gesture_doc.h index 7def9e3..042d0dd 100644 --- a/doc/uix_gesture_doc.h +++ b/doc/uix_gesture_doc.h @@ -36,13 +36,11 @@ * 4. Stop recognizing
* 5. Destroy a handle
* The Gesture API also notifies you (by callback mechanism) when the input gesture is recognized. - * An application should register a callback function to receive the recognized results with gesture_client_start_recognition(). + * An application should register a callback function to receive the recognized results with hand_gesture_start_recognition(). * * @section CAPI_UIX_GESTURE_MODULE_FEATURE Related Features * This API is related with the following features:
- * - http://tizen.org/feature/sensor.accelerometer
* - http://tizen.org/feature/sensor.gesture_recognition
- * - http://tizen.org/feature/sensor.gyroscope
* It is recommended to design feature related codes in your application for reliability.
* 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.
* 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.
diff --git a/include/gesture.h b/include/gesture.h index 65ce9a8..6b4f13e 100644 --- a/include/gesture.h +++ b/include/gesture.h @@ -23,7 +23,7 @@ extern "C" { #endif -/** +/* * @file gesture.h * @brief This file contains hand gesture's APIs. */ @@ -43,30 +43,52 @@ typedef struct hand_gesture_s *hand_gesture_h; * @brief Called when a gesture is detected. * * @since_tizen @if WEARABLE 6.0 @endif + * @remarks The @a handle is managed by the platform and will be released when hand_gesture_destroy() is called. * - * @param[in] gesture Gesture type detected - * @param[in] data Detailed information of the detected gesture.@n - * hand_gesture_get_event() or gesture_get_tilt() can be used to extract the information from @c data. + * @param[in] handle A gesture handle + * @param[in] gesture A gesture type detected * @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 * #HAND_GESTURE_ERROR_NONE, if the operation succeeded.@n * #HAND_GESTURE_ERROR_NOT_SUPPORTED, if the gesture is not supported in the current profile.@n * #HAND_GESTURE_ERROR_OPERATION_FAILED, if the operation failed because of a system error.@n * #HAND_GESTURE_ERROR_PERMISSION_DENIED, if the application has no permission to use this. - * @param[in] user_data The user data had passed to hand_gesture_start_recognition() + * @param[in] user_data The user data is passed to hand_gesture_start_recognition() * - * @pre hand_gesture_start_recognition() + * @see hand_gesture_start_recognition() */ -typedef void(* hand_gesture_recognition_cb)(hand_gesture_type_e gesture, const hand_gesture_data_h data, double timestamp, hand_gesture_error_e error, void *user_data); +typedef void(* hand_gesture_recognition_cb)(hand_gesture_h handle, hand_gesture_type_e gesture, double timestamp, hand_gesture_error_e error, void *user_data); /** - * @brief Checks whether the gesture is supported or not. + * @brief Called when an error is occurred. + * + * @since_tizen @if WEARABLE 6.0 @endif + * @remarks The @a handle is the same object for which the callback was set. + * The @a handle is available until hand_gesture_destroy() is called. + * The @a msg is managed by the platform and will be released when invoking this callback function is finished. + * + * @param[in] handle A gesture handle + * @param[in] error An error value. It can be one of the following error values: @n + * #HAND_GESTURE_ERROR_INVALID_PARAMETER, + * #HAND_GESTURE_ERROR_INVALID_OPERATION, + * #HAND_GESTURE_ERROR_OUT_OF_MEMORY, + * #HAND_GESTURE_ERROR_OPERATION_FAILED + * @param[in] msg An error message from gesture engine service + * @param[in] user_data The user data is passed to hand_gesture_set_error_cb() + * + * @see hand_gesture_set_error_cb() + * @see hand_gesture_unset_error_cb() + */ +typedef void(* hand_gesture_error_cb)(hand_gesture_h handle, hand_gesture_error_e error, const char* msg, void *user_data); + +/** + * @brief Checks whether a gesture is supported or not. * @details Check if the given gesture type is supported in the current device. * * @since_tizen @if WEARABLE 6.0 @endif * - * @param[in] handle The gesture handle - * @param[in] gesture Gesture type to be checked + * @param[in] handle A gesture handle + * @param[in] gesture A gesture type to be checked * @param[out] supported @c true if the gesture is recognizable in the current device,@n * @c false otherwise * @@ -86,7 +108,7 @@ int hand_gesture_is_supported_type(hand_gesture_h handle, hand_gesture_type_e ge * @privilege %http://tizen.org/privilege/appmanager.launch * @remarks If the function succeeds, @a handle must be released with hand_gesture_destroy(). * - * @param[out] handle The gesture handle + * @param[out] handle A gesture handle * * @return 0 on success, otherwise a negative error value * @retval #HAND_GESTURE_ERROR_NONE Successful @@ -95,6 +117,7 @@ int hand_gesture_is_supported_type(hand_gesture_h handle, hand_gesture_type_e ge * @retval #HAND_GESTURE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #HAND_GESTURE_ERROR_OUT_OF_MEMORY Out of memory * @retval #HAND_GESTURE_ERROR_OPERATION_FAILED Operation failed + * * @see hand_gesture_destroy() */ int hand_gesture_create(hand_gesture_h *handle); @@ -104,30 +127,32 @@ int hand_gesture_create(hand_gesture_h *handle); * * @since_tizen @if WEARABLE 6.0 @endif * - * @param[in] handle The gesture handle + * @param[in] handle A gesture handle * * @return 0 on success, otherwise a negative error value * @retval #HAND_GESTURE_ERROR_NONE Successful * @retval #HAND_GESTURE_ERROR_NOT_SUPPORTED Not supported * @retval #HAND_GESTURE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #HAND_GESTURE_ERROR_OPERATION_FAILED Operation failed + * * @see hand_gesture_create() */ int hand_gesture_destroy(hand_gesture_h handle); /** - * @brief Sets the option for gesture recognition. + * @brief Sets an option for gesture recognition. * * @since_tizen @if WEARABLE 6.0 @endif + * @remarks If you would like to set a gesture option, you should call this function before hand_gesture_start_recognition() is invoked. \n + * If you do not call this function, #HAND_GESTURE_OPTION_DEFAULT will be set as the default option. * - * @param[in] handle Gesture handle to be used to control the gesture event - * @param[in] option Detection option + * @param[in] handle A gesture handle used to control the gesture event + * @param[in] option An option for detecting gestures * * @return @c 0 on success, otherwise a negative error value * @retval #HAND_GESTURE_ERROR_NONE Successful * @retval #HAND_GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported * @retval #HAND_GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used - * @retval #HAND_GESTURE_ERROR_ALREADY_STARTED The @c handle is being used already * @retval #HAND_GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error * * @see hand_gesture_start_recognition() @@ -142,10 +167,10 @@ int hand_gesture_set_option(hand_gesture_h handle, hand_gesture_option_e option) * @privlevel public * @privilege %http://tizen.org/privilege/appmanager.launch * - * @param[in] handle Gesture handle to be used to control the gesture event - * @param[in] gesture Gesture type to be monitored - * @param[in] callback Callback function to receive gesture events - * @param[in] user_data User data to be passed to the callback function + * @param[in] handle A gesture handle used to control the gesture event + * @param[in] gesture A gesture type to be monitored + * @param[in] callback A callback function to receive gesture events + * @param[in] user_data A user data to be passed to the callback function * * @return @c 0 on success, otherwise a negative error value * @retval #HAND_GESTURE_ERROR_NONE Successful @@ -153,6 +178,7 @@ int hand_gesture_set_option(hand_gesture_h handle, hand_gesture_option_e option) * @retval #HAND_GESTURE_ERROR_PERMISSION_DENIED Permission denied * @retval #HAND_GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used * @retval #HAND_GESTURE_ERROR_ALREADY_STARTED The @c handle is being used already + * @retval #HAND_GESTURE_ERROR_OUT_OF_MEMORY Out of memory * @retval #HAND_GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error * * @pre hand_gesture_create() @@ -167,7 +193,7 @@ int hand_gesture_start_recognition(hand_gesture_h handle, hand_gesture_type_e ge * * @since_tizen @if WEARABLE 6.0 @endif * - * @param[in] handle Gesture handle to release its callback function registered + * @param[in] handle A gesture handle * * @return @c 0 on success, otherwise a negative error value * @retval #HAND_GESTURE_ERROR_NONE Successful @@ -179,25 +205,62 @@ int hand_gesture_start_recognition(hand_gesture_h handle, hand_gesture_type_e ge int hand_gesture_stop_recognition(hand_gesture_h handle); /** - * @brief Gets the gesture engine information. + * @brief Gets a gesture engine information. * * @since_tizen @if WEARABLE 6.0 @endif * @remarks The @a engine_app_id and the @a engine_name should be released using free(). * - * @param[in] handle Gesture handle to release its callback function registered - * @param[out] engine_app_id The gesture engine app ID - * @param[out] engine_name The gesture engine name + * @param[in] handle A gesture handle + * @param[out] engine_app_id A gesture engine app ID + * @param[out] engine_name A gesture engine name * * @return @c 0 on success, otherwise a negative error value * @retval #HAND_GESTURE_ERROR_NONE Successful * @retval #HAND_GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported * @retval #HAND_GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used - * @retval #HAND_GESTURE_ERROR_NOT_STARTED Nothing is started using the @c handle * @retval #HAND_GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error */ int hand_gesture_get_engine_info(hand_gesture_h handle, char** engine_app_id, char** engine_name); /** + * @brief Sets a callback function to be invoked when an error is occurred. + * + * @since_tizen @if WEARABLE 6.0 @endif + * + * @param[in] handle A gesture handle + * @param[in] callback A callback function invoked when an error is occurred + * @param[in] user_data A user data to be passed to the callback function + * + * @return @c 0 on success, otherwise a negative error value + * @retval #HAND_GESTURE_ERROR_NONE Successful + * @retval #HAND_GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported + * @retval #HAND_GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used + * @retval #HAND_GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error + * + * @see hand_gesture_error_cb() + * @see hand_gesture_unset_error_cb() + */ +int hand_gesture_set_error_cb(hand_gesture_h handle, hand_gesture_error_cb callback, void *user_data); + +/** + * @brief Unsets a callback function to be invoked when an error is occurred. + * + * @since_tizen @if WEARABLE 6.0 @endif + * + * @param[in] handle A gesture handle + * + * @return @c 0 on success, otherwise a negative error value + * @retval #HAND_GESTURE_ERROR_NONE Successful + * @retval #HAND_GESTURE_ERROR_NOT_SUPPORTED Gesture recognition is not supported + * @retval #HAND_GESTURE_ERROR_INVALID_PARAMETER Invalid parameter used + * @retval #HAND_GESTURE_ERROR_OPERATION_FAILED Operation failed because of a system error + * + * @see hand_gesture_set_error_cb() + */ +int hand_gesture_unset_error_cb(hand_gesture_h handle); + + +/** * @} */ diff --git a/include/gesture_common.h b/include/gesture_common.h index 491e5d7..0aaf39a 100644 --- a/include/gesture_common.h +++ b/include/gesture_common.h @@ -28,12 +28,17 @@ extern "C" { #define TIZEN_ERROR_GESTURE -0x03090000 #endif -/** +/* * @file gesture_common.h * @brief This file contains gesture's common struct info. */ /** + * @addtogroup CAPI_UIX_GESTURE_MODULE + * @{ + */ + +/** * @brief Delivery through hand_gesture_recognition_cb() of gesture data handle. * @since_tizen @if WEARABLE 6.0 @endif */ @@ -79,6 +84,10 @@ typedef enum { } hand_gesture_option_e; +/** + * @} + */ + #ifdef __cplusplus } #endif diff --git a/server/gestured_dbus.c b/server/gestured_dbus.c index 9a9169c..539a202 100644 --- a/server/gestured_dbus.c +++ b/server/gestured_dbus.c @@ -282,32 +282,32 @@ int gestured_send_dbus_message(GVariant *body, const char *sender, char *cmd, CL LOGD("cmd = %s", cmd); LOGD("=========================="); #endif - if (!g_dbus_connection_emit_signal(_gdbus_connection, + if (!g_dbus_connection_emit_signal(_gdbus_connection, bus_name, GESTURE_OBJECT_PATH, interface, cmd, body, &err)) { - if (err != NULL) { - LOGE("Failed to send dbus message : %s", err->message); - g_error_free(err); - } + if (err != NULL) { + LOGE("Failed to send dbus message : %s", err->message); + g_error_free(err); + } - return GESTURED_ERROR_IO_ERROR; - } + return GESTURED_ERROR_IO_ERROR; + } } } else { if (!g_dbus_connection_emit_signal(_gdbus_connection, - bus_name, - GESTURE_OBJECT_PATH, - interface, - cmd, - body, - &err)) { + bus_name, + GESTURE_OBJECT_PATH, + interface, + cmd, + body, + &err)) { if (err != NULL) { LOGE("Failed to send dbus message : %s", err->message); - g_error_free(err); + g_error_free(err); } return GESTURED_ERROR_IO_ERROR; @@ -477,7 +477,6 @@ int gestured_register_dbus_interface(void) " " " " " " -// " " " " " " -- 2.7.4