From c6e9b006bbf576c45b20f4d92fcbbef3d3ea061e Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Tue, 17 Aug 2021 14:21:45 +0900 Subject: [PATCH] Add api related with resource copy callback's handle param [Added] pkgmgr_res_event_info_new pkgmgr_res_event_info_free pkgmgr_res_event_info_set_error_code pkgmgr_res_event_info_get_error_code Change-Id: I56af93b1a0a4eb789d839d82f087de30fc7dc358 Signed-off-by: Ilho Kim --- client/include/package-manager.h | 55 +++++++++++++++++++++++++++++++---- client/src/pkgmgr.c | 53 +++++++++++++++++++++++++++++++++ client/src/pkgmgr_client_connection.c | 23 ++++++++++++--- installer/pkgmgr_installer.c | 23 +++++++++++---- installer/pkgmgr_installer.h | 6 ++-- types/include/package-manager-types.h | 4 +++ 6 files changed, 146 insertions(+), 18 deletions(-) diff --git a/client/include/package-manager.h b/client/include/package-manager.h index 840dc08..4064d91 100644 --- a/client/include/package-manager.h +++ b/client/include/package-manager.h @@ -159,7 +159,7 @@ typedef enum _pkgmgr_return_val { typedef void pkgmgr_client; typedef void pkgmgr_info; -typedef void *pkgmgr_res_event_info_h; +typedef void pkgmgr_res_event_info; typedef struct { long long data_size; @@ -182,10 +182,6 @@ typedef struct { pkgmgr_updateinfo_type type; } pkg_update_info_t; -typedef struct { - char *pkgid; -} pkgmgr_res_event_info_t; - typedef int (*pkgmgr_iter_fn)(const char *pkg_type, const char *pkgid, const char *version, void *data); @@ -205,7 +201,7 @@ typedef void (*pkgmgr_total_pkg_size_info_receive_cb)(pkgmgr_client *pc, typedef void (*pkgmgr_res_copy_handler)(uid_t target_uid, int req_id, const char *pkgid, const char *request_type, const char *status, - pkgmgr_res_event_info_h handle, void *user_data); + pkgmgr_res_event_info *handle, void *user_data); typedef enum { PC_REQUEST = 0, @@ -1305,6 +1301,53 @@ int pkgmgr_client_res_remove(pkgmgr_client *pc, pkgmgr_res_copy_handler event_cb int pkgmgr_client_res_uninstall(pkgmgr_client *pc, const char *pkgid, pkgmgr_res_copy_handler event_cb, void *user_data); int pkgmgr_client_res_usr_uninstall(pkgmgr_client *pc, const char *pkgid, pkgmgr_res_copy_handler event_cb, void *user_data, uid_t uid); +/** + * @brief This API creates resource event info. + * + * This API is for package-manager client application.\n + * + * @return resource event info object + * @retval NULL on failure creating an object +*/ +pkgmgr_res_event_info *pkgmgr_res_event_info_new(); + +/** + * @brief This API delete resource event info. + * + * This API is for package-manager client application.\n + * + * @param[in] info resource event info + * @return Operation result; + * @retval PKGMGR_R_OK success + * @retval PKGMGR_R_EINVAL invalid argument + * @retval PKGMGR_R_ERROR internal error +*/ +int pkgmgr_res_event_info_free(pkgmgr_res_event_info *info); + +/** + * @brief This API gets the error code from resource callback handle + * + * This API is for package-manager client application.\n + * + * @param[in] handle resource event information handle + * @param[in] error_code error code about resource event + * @retval PKGMGR_R_OK success + * @retval PKGMGR_R_EINVAL invalid argument +*/ +int pkgmgr_res_event_info_set_error_code(pkgmgr_res_event_info *handle, int error_code); + +/** + * @brief This API gets the error code from resource callback handle + * + * This API is for package-manager client application.\n + * + * @param[in] handle resource event information handle + * @param[out] error_code error code about resource event + * @retval PKGMGR_R_OK success + * @retval PKGMGR_R_EINVAL invalid argument +*/ +int pkgmgr_res_event_info_get_error_code(pkgmgr_res_event_info *handle, int *error_code); + /** @} */ diff --git a/client/src/pkgmgr.c b/client/src/pkgmgr.c index 5b812ad..9478271 100644 --- a/client/src/pkgmgr.c +++ b/client/src/pkgmgr.c @@ -40,6 +40,7 @@ #include #include "package-manager.h" +#include "package-manager-types.h" #include "pkgmgr_client_debug.h" #include "pkgmgr_client_internal.h" @@ -2993,3 +2994,55 @@ API int pkgmgr_client_res_usr_uninstall(pkgmgr_client *pc, const char *pkgid, return cb_info->req_id; } + +API pkgmgr_res_event_info *pkgmgr_res_event_info_new() +{ + pkgmgr_res_event_info_t *info; + + info = calloc(1, sizeof(pkgmgr_res_event_info_t)); + if (info == NULL) { + ERR("out of memory"); + return NULL; + } + + return (pkgmgr_res_event_info *)info; +} + +API int pkgmgr_res_event_info_free(pkgmgr_res_event_info *info) +{ + pkgmgr_res_event_info_t *event_info = + (pkgmgr_res_event_info_t *)info; + + if (event_info == NULL) { + ERR("invalid argument"); + return PKGMGR_R_EINVAL; + } + + free(event_info); + + return PKGMGR_R_OK; +} + +API int pkgmgr_res_event_info_set_error_code(pkgmgr_res_event_info *handle, int error_code) +{ + pkgmgr_res_event_info_t *info = handle; + if (info == NULL) { + ERR("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + info->error_code = error_code; + return PKGMGR_R_OK; +} + +API int pkgmgr_res_event_info_get_error_code(pkgmgr_res_event_info *handle, int *error_code) +{ + pkgmgr_res_event_info_t *info = handle; + if (info == NULL || error_code == NULL) { + ERR("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + *error_code = info->error_code; + return PKGMGR_R_OK; +} diff --git a/client/src/pkgmgr_client_connection.c b/client/src/pkgmgr_client_connection.c index be882bc..8f20b46 100644 --- a/client/src/pkgmgr_client_connection.c +++ b/client/src/pkgmgr_client_connection.c @@ -24,6 +24,7 @@ #include #include "package-manager.h" +#include "package-manager-types.h" #include "pkgmgr_client_debug.h" #include "pkgmgr_client_internal.h" #include "../../installer/pkgmgr_installer.h" @@ -246,22 +247,36 @@ static void __handle_res_copy_event_signal(const gchar *signal_name, char *status = NULL; struct cb_info *cb_info = (struct cb_info *)user_data; int signal_type; + GVariant *extra_param = NULL; + pkgmgr_res_event_info_t event_info; if (!cb_info->res_copy_event_cb) return; - g_variant_get(parameters, "(u&s&s&s)", &target_uid, &req_id, &pkgid, &status); + g_variant_get(parameters, "(u&s&s&sv)", &target_uid, &req_id, &pkgid, &status, &extra_param); + if (!g_variant_type_equal(G_VARIANT_TYPE("(i)"), + g_variant_get_type(extra_param))) { + ERR("invalid extra parameter"); + g_variant_unref(extra_param); + return; + } if (cb_info->req_key) { - if (strcmp(cb_info->req_key, req_id) != 0) + if (strcmp(cb_info->req_key, req_id) != 0) { + g_variant_unref(extra_param); return; + } } else { signal_type = __get_signal_type(signal_name); - if (signal_type < 0 || !(cb_info->status_type & signal_type)) + if (signal_type < 0 || !(cb_info->status_type & signal_type)) { + g_variant_unref(extra_param); return; + } } + g_variant_get(extra_param, "(i)", &event_info.error_code); cb_info->res_copy_event_cb(target_uid, cb_info->req_id, pkgid, signal_name, - status, NULL, cb_info->data); + status, &event_info, cb_info->data); + g_variant_unref(extra_param); } static void __signal_handler(GDBusConnection *conn, const gchar *sender_name, diff --git a/installer/pkgmgr_installer.c b/installer/pkgmgr_installer.c index e709431..30936f7 100644 --- a/installer/pkgmgr_installer.c +++ b/installer/pkgmgr_installer.c @@ -40,6 +40,7 @@ #include "pkgmgr_installer_debug.h" #include "pkgmgr_installer_info.h" #include "pkgmgr_installer_error.h" +#include "package-manager-types.h" #include @@ -1254,9 +1255,16 @@ API int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade) { return 0; } +static GVariant *__get_gvariant_from_event_info(pkgmgr_res_event_info *event_info) +{ + pkgmgr_res_event_info_t *info = event_info; + + return g_variant_new("(i)", info->error_code); +} + API int pkgmgr_installer_send_res_copy_signal(pkgmgr_installer *pi, const char *pkgid, const char *status, - pkgmgr_res_event_info_h event_info) + pkgmgr_res_event_info *event_info) { char *sid; const char *signal_name; @@ -1280,8 +1288,11 @@ API int pkgmgr_installer_send_res_copy_signal(pkgmgr_installer *pi, if (g_dbus_connection_emit_signal(pi->conn, NULL, PKGMGR_INSTALLER_DBUS_OBJECT_PATH, PKGMGR_INSTALLER_DBUS_INTERFACE, signal_name, - g_variant_new("(usss)", pi->target_uid, sid, - pkgid, status), &err) != TRUE) { + g_variant_new("(usssv)", pi->target_uid, sid, + pkgid, status, + __get_gvariant_from_event_info( + event_info)), + &err) != TRUE) { ERR("failed to send dbus signal"); if (err) { ERR("err: %s", err->message); @@ -1295,7 +1306,7 @@ API int pkgmgr_installer_send_res_copy_signal(pkgmgr_installer *pi, API int pkgmgr_installer_send_res_copy_signal_for_uid(pkgmgr_installer *pi, uid_t uid, const char *pkgid, const char *status, - pkgmgr_res_event_info_h event_info) + pkgmgr_res_event_info *event_info) { char *sid; size_t data_len; @@ -1327,7 +1338,9 @@ API int pkgmgr_installer_send_res_copy_signal_for_uid(pkgmgr_installer *pi, name_size = strlen(signal_name) + 1; data_len += name_size; - gv = g_variant_new("(usss)", pi->target_uid, sid, pkgid, status); + gv = g_variant_new("(usssv)", pi->target_uid, sid, + pkgid, status, + __get_gvariant_from_event_info(event_info)); if (gv == NULL) { ERR("failed to create GVariant instance"); return -1; diff --git a/installer/pkgmgr_installer.h b/installer/pkgmgr_installer.h index 3340ecf..e133dd6 100644 --- a/installer/pkgmgr_installer.h +++ b/installer/pkgmgr_installer.h @@ -1236,7 +1236,7 @@ int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade); #include void send_res_copy_singal(uid_t uid, int request_type, const char *session_id, const char *pkgid, const char *status, - pkgmgr_res_event_info_h event_info) + pkgmgr_res_event_info *event_info) { pkgmgr_installer *pi; int r = 0; @@ -1257,7 +1257,7 @@ void send_res_copy_singal(uid_t uid, int request_type, const char *session_id, */ int pkgmgr_installer_send_res_copy_signal(pkgmgr_installer *pi, const char *pkgid, const char *status, - pkgmgr_res_event_info_h event_info); + pkgmgr_res_event_info *event_info); /** @brief Send a signal of the resource copy event status @@ -1274,7 +1274,7 @@ int pkgmgr_installer_send_res_copy_signal(pkgmgr_installer *pi, */ int pkgmgr_installer_send_res_copy_signal_for_uid(pkgmgr_installer *pi, uid_t uid, const char *pkgid, const char *status, - pkgmgr_res_event_info_h event_info); + pkgmgr_res_event_info *event_info); #ifdef __cplusplus } diff --git a/types/include/package-manager-types.h b/types/include/package-manager-types.h index 062bb43..19bbf1f 100644 --- a/types/include/package-manager-types.h +++ b/types/include/package-manager-types.h @@ -125,6 +125,10 @@ typedef struct _package_manager_pkg_detail_info_t { GList *dependency_list; } package_manager_pkg_detail_info_t; +typedef struct _pkgmgr_res_event_info_t { + int error_code; +} pkgmgr_res_event_info_t; + /** @} */ #ifdef __cplusplus -- 2.7.4