Add api related with resource copy callback's handle param 02/262702/6
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 17 Aug 2021 05:21:45 +0000 (14:21 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Wed, 18 Aug 2021 08:56:21 +0000 (17:56 +0900)
[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 <ilho159.kim@samsung.com>
client/include/package-manager.h
client/src/pkgmgr.c
client/src/pkgmgr_client_connection.c
installer/pkgmgr_installer.c
installer/pkgmgr_installer.h
types/include/package-manager-types.h

index 840dc08..4064d91 100644 (file)
@@ -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);
+
 /** @} */
 
 
index 5b812ad..9478271 100644 (file)
@@ -40,6 +40,7 @@
 #include <tzplatform_config.h>
 
 #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;
+}
index be882bc..8f20b46 100644 (file)
@@ -24,6 +24,7 @@
 #include <gio/gio.h>
 
 #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,
index e709431..30936f7 100644 (file)
@@ -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 <pkgmgr-info.h>
 
@@ -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;
index 3340ecf..e133dd6 100644 (file)
@@ -1236,7 +1236,7 @@ int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade);
 #include <pkgmgr_installer.h>
 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
 }
index 062bb43..19bbf1f 100644 (file)
@@ -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