From: Jihoon Kim Date: Fri, 8 Mar 2019 08:28:59 +0000 (+0900) Subject: Add API to send autofill error X-Git-Tag: accepted/tizen/unified/20190313.151533~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F201100%2F4;p=platform%2Fcore%2Fuifw%2Fautofill.git Add API to send autofill error Change-Id: Ic73ade01e57e8b2855c897c418103fde5c9571b9 Signed-off-by: Jihoon Kim --- diff --git a/client/autofill.c b/client/autofill.c index e45baa4..e8985d3 100644 --- a/client/autofill.c +++ b/client/autofill.c @@ -180,6 +180,44 @@ static void __auth_info_recv_cb(void *user_data, rpc_port_autofill_auth_info_h a autofill_auth_info_destroy(aih); } + +static void __error_info_recv_cb(void *user_data, rpc_port_autofill_error_info_h error_info_h) +{ + autofill_error_info_h eih = NULL; + autofill_h ah = user_data; + + int error_code = 0; + char *app_id = NULL; + char *error_message = NULL; + + autofill_error_info_create(&eih); + + rpc_port_autofill_error_info_get_app_id(error_info_h, &app_id); + rpc_port_autofill_error_info_get_error_code(error_info_h, &error_code); + rpc_port_autofill_error_info_get_error_message(error_info_h, &error_message); + + autofill_error_info_set_app_id(eih, app_id); + autofill_error_info_set_error_code(eih, error_code); + autofill_error_info_set_error_message(eih, error_message); + + LOGD("error code : %d, message : %s", error_code, error_message); + + if (app_id) + free(app_id); + + if (error_message) + free(error_message); + + if (ah) { + if (ah->autofill_error_info_received_cb) + ah->autofill_error_info_received_cb(ah, eih, ah->autofill_error_info_data); + } + else { + LOGW("no user data"); + } + + autofill_error_info_destroy(eih); +} //LCOV_EXCL_STOP static void __on_connected(rpc_port_proxy_AutofillAppPort_h h, void *user_data) @@ -195,8 +233,9 @@ static void __on_connected(rpc_port_proxy_AutofillAppPort_h h, void *user_data) LOGI("connected"); rpc_port_AutofillAppPort_autofill_fill_response_received_cb_h fill_response_received_cb = rpc_port_AutofillAppPort_autofill_fill_response_received_cb_create(__fill_response_recv_cb, false, ah); rpc_port_AutofillAppPort_autofill_auth_info_received_cb_h auth_info_received_cb = rpc_port_AutofillAppPort_autofill_auth_info_received_cb_create(__auth_info_recv_cb, false, ah); + rpc_port_AutofillAppPort_autofill_error_info_received_cb_h error_info_received_cb = rpc_port_AutofillAppPort_autofill_error_info_received_cb_create(__error_info_recv_cb, false, ah); - int r = rpc_port_proxy_AutofillAppPort_invoke_Register(h, ah->context_id, auth_info_received_cb, fill_response_received_cb); + int r = rpc_port_proxy_AutofillAppPort_invoke_Register(h, ah->context_id, auth_info_received_cb, fill_response_received_cb, error_info_received_cb); if (r != 0) LOGW("[ERROR] Failed to invoke Register"); @@ -269,6 +308,7 @@ EXPORT_API int autofill_destroy(autofill_h ah) ah->connection_callback = NULL; ah->autofill_fill_response_received_cb = NULL; ah->autofill_auth_info_received_cb = NULL; + ah->autofill_error_info_received_cb = NULL; if (ah->rpc_h) { rpc_port_proxy_AutofillAppPort_destroy(ah->rpc_h); @@ -401,3 +441,29 @@ EXPORT_API int autofill_commit(autofill_h ah, autofill_save_view_info_h vi) return AUTOFILL_ERROR_NONE; } } + +EXPORT_API int autofill_error_info_set_received_cb(autofill_h ah, autofill_error_info_received_cb callback, void *user_data) +{ + if (!ah || !callback) { + LOGW("[ERROR] Invalid parameter"); + return AUTOFILL_ERROR_INVALID_PARAMETER; + } + + ah->autofill_error_info_received_cb = callback; + ah->autofill_error_info_data = user_data; + + return AUTOFILL_ERROR_NONE; +} + +EXPORT_API int autofill_error_info_unset_received_cb(autofill_h ah) +{ + if (!ah) { + LOGW("[ERROR] Invalid parameter"); + return AUTOFILL_ERROR_INVALID_PARAMETER; + } + + ah->autofill_error_info_received_cb = NULL; + ah->autofill_error_info_data = NULL; + + return AUTOFILL_ERROR_NONE; +} \ No newline at end of file diff --git a/include/autofill.h b/include/autofill.h index ab05b07..0f6b920 100644 --- a/include/autofill.h +++ b/include/autofill.h @@ -85,6 +85,18 @@ typedef void (*autofill_fill_response_received_cb)(autofill_h ah, autofill_fill_ typedef void (*autofill_auth_info_received_cb)(autofill_h ah, autofill_auth_info_h auth_info, void *user_data); /** + * @brief Called when receiving the error information. + * @since_tizen 5.5 + * @remarks @a ah should not be freed and can be used only in the callback. + * @remarks @a error_info should not be freed and can be used only in the callback. + * @param[in] ah The autofill handle + * @param[in] error_info The autofill error information handle + * @param[in] user_data The user data passed from the callback function + * @see autofill_error_info_set_received_cb() + */ +typedef void (*autofill_error_info_received_cb)(autofill_h ah, autofill_error_info_h error_info, void *user_data); + +/** * @brief Creates a handle for autofill. * @since_tizen 5.5 * @remarks If the function succeeds, @a ah handle must be released with autofill_destroy(). @@ -205,6 +217,30 @@ int autofill_fill_response_unset_received_cb(autofill_h ah); int autofill_commit(autofill_h ah, autofill_save_view_info_h vi); /** + * @brief Sets the callback to receive the error information. + * @since_tizen 5.5 + * @param[in] ah The autofill handle + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + * @see autofill_error_info_unset_received_cb() + */ +int autofill_error_info_set_received_cb(autofill_h ah, autofill_error_info_received_cb callback, void *user_data); + +/** + * @brief Unsets the callback to receive the error information. + * @since_tizen 5.5 + * @param[in] ah The autofill handle + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + * @see autofill_error_info_set_received_cb() + */ +int autofill_error_info_unset_received_cb(autofill_h ah); + +/** * @} */ diff --git a/include/autofill_common.h b/include/autofill_common.h index ae0601a..fb57863 100644 --- a/include/autofill_common.h +++ b/include/autofill_common.h @@ -105,6 +105,12 @@ typedef struct autofill_save_item_s *autofill_save_item_h; typedef struct autofill_save_view_info_s *autofill_save_view_info_h; /** + * @brief The autofill error information handle. + * @since_tizen 5.5 + */ +typedef struct autofill_error_info_s *autofill_error_info_h; + +/** * @brief Called for each autofill information in view info. * @since_tizen 5.5 * @remarks @a item should not be freed and can be used only in the callback. @@ -1100,6 +1106,98 @@ int autofill_save_item_set_value(autofill_save_item_h it, const char *value); int autofill_save_item_get_value(autofill_save_item_h it, char **value); /** + * @brief Creates autofill error information. + * @since_tizen 5.5 + * @remarks If the function succeeds, @a ei handle must be released with autofill_error_info_destroy(). + * @param[out] ei The autofill error information handle + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #AUTOFILL_ERROR_OUT_OF_MEMORY Out of memory + */ +int autofill_error_info_create(autofill_error_info_h *ei); + +/** + * @brief Destroys autofill error information. + * @since_tizen 5.5 + * @param[in] ei The autofill error information handle + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + */ +int autofill_error_info_destroy(autofill_error_info_h ei); + +/** + * @brief Sets the app id in autofill error information. + * @since_tizen 5.5 + * @param[in] ei The autofill error information handle + * @param[in] app_id The app ID + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + */ +int autofill_error_info_set_app_id(autofill_error_info_h ei, const char *app_id); + +/** + * @brief Gets the app id in autofill error information. + * @since_tizen 5.5 + * @remarks @a app_id must be released using free(). + * @param[in] ei The autofill error information handle + * @param[out] app_id The app ID + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #AUTOFILL_ERROR_OPERATION_FAILED Operation failure + */ +int autofill_error_info_get_app_id(autofill_error_info_h ei, char **app_id); + +/** + * @brief Sets the error code in autofill error information. + * @since_tizen 5.5 + * @param[in] ei The autofill error information handle + * @param[in] error_code The autofill error code + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + */ +int autofill_error_info_set_error_code(autofill_error_info_h ei, autofill_error_e error_code); + +/** + * @brief Gets the error code in autofill error information. + * @since_tizen 5.5 + * @param[in] ei The autofill error information handle + * @param[out] error_code The autofill error code + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + */ +int autofill_error_info_get_error_code(autofill_error_info_h ei, autofill_error_e *error_code); + +/** + * @brief Sets the error message in autofill error information. + * @since_tizen 5.5 + * @param[in] ei The autofill error information handle + * @param[in] error_message The autofill error message + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + */ +int autofill_error_info_set_error_message(autofill_error_info_h ei, const char *error_message); + +/** + * @brief Gets the error message in autofill error information. + * @since_tizen 5.5 + * @remarks @a error_message must be released using free(). + * @param[in] ei The autofill error information handle + * @param[out] error_message The autofill error message + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #AUTOFILL_ERROR_OPERATION_FAILED Operation failure + */ +int autofill_error_info_get_error_message(autofill_error_info_h ei, char **error_message); + +/** * @} */ diff --git a/include/autofill_error.h b/include/autofill_error.h index 6ad20e4..676ed5e 100644 --- a/include/autofill_error.h +++ b/include/autofill_error.h @@ -43,6 +43,9 @@ typedef enum { AUTOFILL_ERROR_NOT_INITIALIZED = TIZEN_ERROR_AUTOFILL | 0x0001, /**< Not initialized */ AUTOFILL_ERROR_OPERATION_FAILED = TIZEN_ERROR_AUTOFILL | 0x0002, /**< Operation failed */ AUTOFILL_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + AUTOFILL_ERROR_AUTHENTICATION_FAILED = TIZEN_ERROR_AUTOFILL | 0x0003, /**< Authentication failed */ + AUTOFILL_ERROR_COMMIT_FAILED = TIZEN_ERROR_AUTOFILL | 0x0004, /**< Failed to save autofill data */ + AUTOFILL_ERROR_FILL_RESPONSE_FAILED = TIZEN_ERROR_AUTOFILL | 0x0005, /**< Failed to response fill request */ } autofill_error_e; /** diff --git a/include/autofill_private.h b/include/autofill_private.h index 6a465cb..363cf85 100644 --- a/include/autofill_private.h +++ b/include/autofill_private.h @@ -36,6 +36,9 @@ struct autofill_s { autofill_auth_info_received_cb autofill_auth_info_received_cb; void *autofill_auth_info_data; + + autofill_error_info_received_cb autofill_error_info_received_cb; + void *autofill_error_info_data; }; struct autofill_view_info_s { diff --git a/include/autofill_service.h b/include/autofill_service.h index c5283d7..8d7d36e 100644 --- a/include/autofill_service.h +++ b/include/autofill_service.h @@ -189,6 +189,17 @@ int autofill_service_set_terminate_received_cb(autofill_service_terminate_receiv int autofill_service_unset_terminate_received_cb(void); /** + * @brief Sends error to the autofill client. + * @since_tizen 5.5 + * @param[in] context_id The autofill context identification value of an associated autofill client handle + * @param[in] h The autofill error info handle + * @return 0 on success, otherwise a negative error value + * @retval #AUTOFILL_ERROR_NONE No error + * @retval #AUTOFILL_ERROR_INVALID_PARAMETER Invalid parameter + */ +int autofill_service_send_error_info(int context_id, autofill_error_info_h h); + +/** * @} */ diff --git a/service_lib/autofill_service.c b/service_lib/autofill_service.c index b064dd9..8113909 100644 --- a/service_lib/autofill_service.c +++ b/service_lib/autofill_service.c @@ -48,12 +48,14 @@ static void *g_autofill_service_terminate_received_data = NULL; rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h g_auth_info_cb; rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h g_fill_response_received_cb; +rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h g_send_error_cb; typedef struct { char *app_id; rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h auth_info_cb; rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_received_cb; + rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h send_error_cb; } autofill_svc_s; static GList *__client_list = NULL; @@ -264,7 +266,8 @@ static void __terminate_received_cb(rpc_port_stub_AutofillSvcPort_context_h cont static autofill_svc_s *__create_client(const char *app_id, rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h auth_info_cb, - rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_received_cb) + rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_received_cb, + rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h send_error_cb) { LOGD(""); autofill_svc_s *handle; @@ -300,6 +303,14 @@ static autofill_svc_s *__create_client(const char *app_id, return NULL; } + rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_clone(send_error_cb, &handle->send_error_cb); + if (!handle->send_error_cb) { + LOGE("Out of memory"); + free(handle->app_id); + free(handle); + return NULL; + } + return handle; } @@ -317,6 +328,9 @@ static void __destroy_client(gpointer data) if (handle->fill_response_received_cb) rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_destroy(handle->fill_response_received_cb); + if (handle->send_error_cb) + rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_destroy(handle->send_error_cb); + if (handle->app_id) free(handle->app_id); @@ -351,7 +365,11 @@ static void __message_terminate(rpc_port_stub_AutofillSvcPort_context_h context, free(sender); } -static int __message_register(rpc_port_stub_AutofillSvcPort_context_h context, rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h auth_info_cb, rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_received_cb, void *user_data) +static int __message_register(rpc_port_stub_AutofillSvcPort_context_h context, + rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h auth_info_cb, + rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_received_cb, + rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h send_error_cb, + void *user_data) { LOGD(""); char *sender = NULL; @@ -363,7 +381,7 @@ static int __message_register(rpc_port_stub_AutofillSvcPort_context_h context, r LOGD("sender(%s)", sender); autofill_svc_s *client; - client = __create_client(sender, auth_info_cb, fill_response_received_cb); + client = __create_client(sender, auth_info_cb, fill_response_received_cb, send_error_cb); free(sender); if (!client) @@ -371,8 +389,7 @@ static int __message_register(rpc_port_stub_AutofillSvcPort_context_h context, r rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_clone(auth_info_cb, &g_auth_info_cb); rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_clone(fill_response_received_cb, &g_fill_response_received_cb); - - LOGD("auth info : %p, fill response : %p", g_auth_info_cb, g_fill_response_received_cb); + rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_clone(send_error_cb, &g_send_error_cb); __client_list = g_list_append(__client_list, client); @@ -664,3 +681,38 @@ EXPORT_API int autofill_service_unset_terminate_received_cb(void) return AUTOFILL_ERROR_NONE; } + +EXPORT_API int autofill_service_send_error_info(int context_id, autofill_error_info_h h) +{ + char *app_id = NULL; + char *error_message = NULL; + autofill_error_e error_code; + rpc_port_autofill_svc_error_info_h error_info_h = NULL; + + if (!h) { + LOGW("[ERROR] Invalid parameter"); + return AUTOFILL_ERROR_INVALID_PARAMETER; + } + + autofill_error_info_get_app_id(h, &app_id); + autofill_error_info_get_error_code(h, &error_code); + autofill_error_info_get_error_message(h, &error_message); + + /* create error info */ + rpc_port_autofill_svc_error_info_create(&error_info_h); + rpc_port_autofill_svc_error_info_set_app_id(error_info_h, app_id); + rpc_port_autofill_svc_error_info_set_error_code(error_info_h, error_code); + rpc_port_autofill_svc_error_info_set_error_message(error_info_h, error_message); + + int ret = rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_invoke(g_send_error_cb, context_id, error_info_h); + + if (app_id) + free(app_id); + + if (error_message) + free(error_message); + + rpc_port_autofill_svc_error_info_destroy(error_info_h); + + return ret; +} \ No newline at end of file diff --git a/tidl/autofill.tidl b/tidl/autofill.tidl index 6f4ccac..c44c301 100644 --- a/tidl/autofill.tidl +++ b/tidl/autofill.tidl @@ -51,10 +51,17 @@ struct autofill_fill_response { list response_groups; } +struct autofill_error_info { + string app_id; + int error_code; + string error_message; +} + interface AutofillAppPort { void autofill_auth_info_received_cb(autofill_auth_info auth_info) delegate; void autofill_fill_response_received_cb(autofill_fill_response response) delegate; - int Register(int context_id, autofill_auth_info_received_cb auth_info_cb, autofill_fill_response_received_cb fill_response_cb); + void autofill_error_info_received_cb(autofill_error_info error_info) delegate; + int Register(int context_id, autofill_auth_info_received_cb auth_info_cb, autofill_fill_response_received_cb fill_response_cb, autofill_error_info_received_cb error_info_cb); void Unregister(int context_id) async; int request_auth_info(int context_id, autofill_view_info vi); diff --git a/tidl/autofill_service.tidl b/tidl/autofill_service.tidl index 311a411..bd89003 100644 --- a/tidl/autofill_service.tidl +++ b/tidl/autofill_service.tidl @@ -53,10 +53,17 @@ struct autofill_svc_fill_response { list response_groups; } +struct autofill_svc_error_info { + string app_id; + int error_code; + string error_message; +} + interface AutofillSvcPort { void autofill_svc_auth_info_cb(int context_id, autofill_svc_auth_info auth_info) delegate; void autofill_svc_fill_response_cb(int context_id, autofill_svc_fill_response response) delegate; - int Register(autofill_svc_auth_info_cb auth_info_cb, autofill_svc_fill_response_cb fill_response_cb); + void autofill_svc_send_error_cb(int context_id, autofill_svc_error_info error_info) delegate; + int Register(autofill_svc_auth_info_cb auth_info_cb, autofill_svc_fill_response_cb fill_response_cb, autofill_svc_send_error_cb send_error_cb); void Unregister() async; void request_auth_info(int context_id, autofill_svc_view_info vi) async;