Add client functions for pkg update info 68/122068/10
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 30 Mar 2017 05:31:50 +0000 (14:31 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 14 Apr 2017 02:10:46 +0000 (11:10 +0900)
- Add methods to be used to request register/unregister pkg update info

Related changes:
[pkgmgr-server] : https://review.tizen.org/gerrit/122067
[pkgmgr-info] : https://review.tizen.org/gerrit/121964

Change-Id: I2e6abbef46651967e17bfb6a12b7fed5894a6aa7
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
client/include/package-manager.h
client/src/pkgmgr.c

index 9f78be4994bf29b4abd93034acf450265d9d4278..968e2f52a4253d11c67f3b47a4d08ba00ab05dec 100644 (file)
@@ -166,6 +166,18 @@ typedef struct {
        long long ext_app_size;
 } pkg_size_info_t;
 
+typedef enum {
+       PM_UPDATEINFO_TYPE_NONE = 0,
+       PM_UPDATEINFO_TYPE_FORCE,
+       PM_UPDATEINFO_TYPE_OPTIONAL
+} pkgmgr_updateinfo_type;
+
+typedef struct {
+       char *pkgid;
+       char *version;
+       pkgmgr_updateinfo_type type;
+} pkg_update_info_t;
+
 typedef int (*pkgmgr_iter_fn)(const char *pkg_type, const char *pkgid,
                                const char *version, void *data);
 
@@ -398,6 +410,54 @@ int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
                                const char *pkgid, pkgmgr_move_type move_type,
                                pkgmgr_handler event_cb, void *data, uid_t uid);
 
+/**
+ * @brief      This API registers the update information of given packages
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  pc      pkgmgr_client
+ * @param[in]  update_info     update information
+ * @param[in]  uid     the addressee user id of the instruction
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+ * @retval     PKGMGR_R_ERROR  general error
+*/
+int pkgmgr_client_register_pkg_update_info(pkgmgr_client *pc,
+                               pkg_update_info_t *update_info);
+int pkgmgr_client_usr_register_pkg_update_info(pkgmgr_client *pc,
+                               pkg_update_info_t *update_info, uid_t uid);
+
+/**
+ * @brief      This API unregisters update information of certain package.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  pc      pkgmgr_client
+ * @param[in]  pkgid   package id
+ * @param[in]  uid     the addressee user id of the instruction
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+ * @retval     PKGMGR_R_ERROR  general error
+*/
+int pkgmgr_client_unregister_pkg_update_info(pkgmgr_client *pc, const char *pkgid);
+int pkgmgr_client_usr_unregister_pkg_update_info(pkgmgr_client *pc,
+                               const char *pkgid, uid_t uid);
+
+/**
+ * @brief      This API unregister update information of all packages.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  pc      pkgmgr_client
+ * @param[in]  uid     the addressee user id of the instruction
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+ * @retval     PKGMGR_R_ERROR  general error
+*/
+int pkgmgr_client_unregister_all_pkg_update_info(pkgmgr_client *pc);
+int pkgmgr_client_usr_unregister_all_pkg_update_info(pkgmgr_client *pc,
+                               uid_t uid);
+
 /**
  * @brief      This API activates package.
  *
index 76584f92cfc6052d9b782982282a045b78eb899a..2dc974717dd9426655be0f7e77fa026e57da55b4 100644 (file)
@@ -760,6 +760,129 @@ API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
        return cb_info->req_id;
 }
 
+API int pkgmgr_client_usr_register_pkg_update_info(pkgmgr_client *pc,
+               pkg_update_info_t *update_info, uid_t uid)
+{
+       int ret;
+       struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+       GVariant *result;
+
+       if (pc == NULL || update_info == NULL || update_info->pkgid == NULL) {
+               ERR("invalid parameter");
+               return PKGMGR_R_EINVAL;
+       }
+
+       if (client->pc_type != PC_REQUEST) {
+               ERR("client->pc_type is not PC_REQUEST");
+               return PKGMGR_R_EINVAL;
+       }
+
+       ret = pkgmgr_client_connection_send_request(client, "register_pkg_update_info",
+                       g_variant_new("(ussi)", uid, update_info->pkgid, update_info->version,
+                       update_info->type), &result);
+       if (ret != PKGMGR_R_OK) {
+               ERR("request failed: %d", ret);
+               return ret;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       if (ret != PKGMGR_R_OK) {
+               g_variant_unref(result);
+               return ret;
+       }
+       g_variant_unref(result);
+
+       return PKGMGR_R_OK;
+}
+
+API int pkgmgr_client_register_pkg_update_info(pkgmgr_client *pc,
+               pkg_update_info_t *update_info)
+{
+       return pkgmgr_client_usr_register_pkg_update_info(pc, update_info,
+                       _getuid());
+}
+
+API int pkgmgr_client_usr_unregister_pkg_update_info(pkgmgr_client *pc,
+               const char *pkgid, uid_t uid)
+{
+       int ret;
+       struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+       GVariant *result;
+
+       if (pc == NULL || pkgid == NULL) {
+               ERR("invalid parameter");
+               return PKGMGR_R_EINVAL;
+       }
+
+       if (client->pc_type != PC_REQUEST) {
+               ERR("client->pc_type is not PC_REQUEST");
+               return PKGMGR_R_EINVAL;
+       }
+
+       ret = pkgmgr_client_connection_send_request(client,
+                       "unregister_pkg_update_info",
+                       g_variant_new("(us)", uid, pkgid), &result);
+       if (ret != PKGMGR_R_OK) {
+               ERR("request failed: %d", ret);
+               return ret;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       if (ret != PKGMGR_R_OK) {
+               g_variant_unref(result);
+               return ret;
+       }
+       g_variant_unref(result);
+
+       return PKGMGR_R_OK;
+}
+
+API int pkgmgr_client_unregister_pkg_update_info(pkgmgr_client *pc,
+               const char *pkgid)
+{
+       return pkgmgr_client_usr_unregister_pkg_update_info(pc, pkgid, _getuid());
+}
+
+API int pkgmgr_client_usr_unregister_all_pkg_update_info(pkgmgr_client *pc,
+               uid_t uid)
+{
+       int ret;
+       struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+       GVariant *result;
+
+       if (pc == NULL) {
+               ERR("invalid parameter");
+               return PKGMGR_R_EINVAL;
+       }
+
+       if (client->pc_type != PC_REQUEST) {
+               ERR("client->pc_type is not PC_REQUEST");
+               return PKGMGR_R_EINVAL;
+       }
+
+       ret = pkgmgr_client_connection_send_request(client,
+                       "unregister_all_pkg_update_info",
+                       g_variant_new("(u)", uid), &result);
+       if (ret != PKGMGR_R_OK) {
+               ERR("request failed: %d", ret);
+               return ret;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       if (ret != PKGMGR_R_OK) {
+               g_variant_unref(result);
+               return ret;
+       }
+       g_variant_unref(result);
+
+       return PKGMGR_R_OK;
+}
+
+API int pkgmgr_client_unregister_all_pkg_update_info(pkgmgr_client *pc)
+{
+       return pkgmgr_client_usr_unregister_all_pkg_update_info(pc, _getuid());
+}
+
 API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type,
                const char *pkgid, uid_t uid)
 {