typedef void pkgmgr_client;
typedef void pkgmgr_info;
+typedef void *pkgmgr_res_cb_info_h;
typedef struct {
long long data_size;
typedef void (*pkgmgr_total_pkg_size_info_receive_cb)(pkgmgr_client *pc,
const pkg_size_info_t *size_info, void *user_data);
+typedef void (*pkgmgr_res_request_cb)(uid_t target_uid, int req_id,
+ const char *pkgid, const char *request_type, const char *status,
+ pkgmgr_res_cb_info_h handle, void *user_data);
+
typedef enum {
PC_REQUEST = 0,
PC_LISTENING,
*/
int pkgmgr_client_usr_migrate_external_image(pkgmgr_client *pc, const char *pkgid, uid_t uid);
+/**
+ * @brief Add resource path to copy
+ *
+ * This API adds path for resource copy request.\n
+ *
+ * @param[in] pc The pointer to pkgmgr_client instance
+ * @param[in] src_path Path of a resource that client want to copy
+ * @param[in] dest_path Destination path to copy source path, if dest_path is null it will be set to root path of the package's sharing resource directory
+ * @return 0 if success, error code(<0) if fail\n
+ * @retval PKGMGR_R_OK success
+ * @retval PKGMGR_R_EINVAL invalid argument
+ * @retval PKGMGR_R_ENOMEM out of memory
+ */
+int pkgmgr_client_add_res_copy_path(pkgmgr_client *pc, const char *src_path, const char *dest_path);
+
+/**
+ * @brief This API copy resources.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in] pc pkgmgr_client
+ * @param[in] event_cb user callback
+ * @param[in] data user data
+ * @return request_id (>0) if success, error code(<0) if fail\n
+ * @retval PKGMGR_R_OK success
+ * @retval PKGMGR_R_ECOMM communication error
+ * @retval PKGMGR_R_EINVAL invalid argument
+ * @retval PKGMGR_R_ENOMEM out of memory
+ * @retval PKGMGR_R_EPRIV privilege denied
+*/
+int pkgmgr_client_res_copy(pkgmgr_client *pc, pkgmgr_res_request_cb event_cb, void *user_data);
+
+/**
+ * @brief Add resource path to remove
+ *
+ * This API adds path for resource remove request.\n
+ *
+ * @param[in] pc The pointer to pkgmgr_client instance
+ * @param[in] res_path Path of a copied resource that client want to remove
+ * @return 0 if success, error code(<0) if fail\n
+ * @retval PKGMGR_R_OK success
+ * @retval PKGMGR_R_EINVAL invalid argument
+ * @retval PKGMGR_R_ENOMEM out of memory
+ */
+int pkgmgr_client_add_res_remove_path(pkgmgr_client *pc, const char *res_path);
+
+/**
+ * @brief This API removes resources.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in] pc pkgmgr_client
+ * @param[in] event_cb user callback
+ * @param[in] data user data
+ * @return request_id (>0) if success, error code(<0) if fail\n
+ * @retval PKGMGR_R_OK success
+ * @retval PKGMGR_R_ECOMM communication error
+ * @retval PKGMGR_R_EINVAL invalid argument
+ * @retval PKGMGR_R_ENOMEM out of memory
+ * @retval PKGMGR_R_EPRIV privilege denied
+*/
+int pkgmgr_client_res_remove(pkgmgr_client *pc, pkgmgr_res_request_cb event_cb, void *user_data);
+
+/**
+ * @brief This API uninstall copied resources of the package.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in] pc pkgmgr_client
+ * @param[in] pkgid package id
+ * @param[in] event_cb user callback
+ * @param[in] user_data user data
+ * @return request_id (>0) if success, error code(<0) if fail\n
+ * @retval PKGMGR_R_OK success
+ * @retval PKGMGR_R_ECOMM communication error
+ * @retval PKGMGR_R_EINVAL invalid argument
+ * @retval PKGMGR_R_ENOMEM out of memory
+ * @retval PKGMGR_R_EPRIV privilege denied
+ */
+int pkgmgr_client_res_uninstall(pkgmgr_client *pc, const char *pkgid, pkgmgr_res_request_cb event_cb, void *user_data);
+int pkgmgr_client_res_usr_uninstall(pkgmgr_client *pc, const char *pkgid, pkgmgr_res_request_cb event_cb, void *user_data, uid_t uid);
+
/** @} */
return cb_info;
}
+static struct cb_info *__create_res_request_cb_info(
+ struct pkgmgr_client_t *client,
+ pkgmgr_res_request_cb res_request_cb,
+ void *data, const char *req_key)
+{
+ struct cb_info *cb_info;
+
+ cb_info = calloc(1, sizeof(struct cb_info));
+ if (cb_info == NULL) {
+ ERR("out of memory");
+ return NULL;
+ }
+
+ cb_info->client = client;
+ cb_info->res_request_cb = res_request_cb;
+ cb_info->data = data;
+ cb_info->req_id = _get_internal_request_id();
+ if (req_key == NULL)
+ return cb_info;
+
+ cb_info->req_key = strdup(req_key);
+ if (cb_info->req_key == NULL) {
+ ERR("out of memory");
+ free(cb_info);
+ return NULL;
+ }
+
+ return cb_info;
+}
+
static struct cb_info *__create_size_info_cb_info(
struct pkgmgr_client_t *client,
pkgmgr_pkg_size_info_receive_cb size_info_cb,
pkgmgr_client_connection_disconnect(client);
if (client->tep_path)
free(client->tep_path);
+ if (client->res_copy_builder)
+ g_variant_builder_unref(client->res_copy_builder);
+ if (client->res_remove_builder)
+ g_variant_builder_unref(client->res_remove_builder);
free(client);
return PKGMGR_R_OK;
return ret;
}
+
+API int pkgmgr_client_add_res_copy_path(pkgmgr_client *pc,
+ const char *src_path, const char *dest_path)
+{
+ struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+
+ if (pc == NULL || src_path == NULL) {
+ ERR("invalid parameter");
+ return PKGMGR_R_EINVAL;
+ }
+
+ if (client->res_copy_builder == NULL) {
+ client->res_copy_builder =
+ g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
+ if (client->res_copy_builder == NULL) {
+ ERR("out of memory");
+ return PKGMGR_R_ENOMEM;
+ }
+ }
+
+ g_variant_builder_add(client->res_copy_builder, "(ss)",
+ src_path, dest_path ? dest_path : "");
+
+ return PKGMGR_R_OK;
+}
+
+API int pkgmgr_client_res_copy(pkgmgr_client *pc,
+ pkgmgr_res_request_cb event_cb, void *user_data)
+{
+ GVariant *result;
+ int ret;
+ char *req_key = NULL;
+ struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+ struct cb_info *cb_info;
+
+ if (pc == NULL || event_cb == NULL) {
+ ERR("invalid parameter");
+ return PKGMGR_R_EINVAL;
+ }
+
+ ret = pkgmgr_client_connection_send_request(client,
+ "res_copy",
+ g_variant_new("(a(ss))",
+ client->res_copy_builder), &result);
+ if (ret != PKGMGR_R_OK) {
+ ERR("request failed: %d", ret);
+ return ret;
+ }
+
+ g_variant_get(result, "(i&s)", &ret, &req_key);
+ if (req_key == NULL) {
+ g_variant_unref(result);
+ return PKGMGR_R_ECOMM;
+ }
+ if (ret != PKGMGR_R_OK) {
+ g_variant_unref(result);
+ return ret;
+ }
+
+ cb_info = __create_res_request_cb_info(client,
+ event_cb, user_data, req_key);
+ g_variant_unref(result);
+ if (cb_info == NULL)
+ return PKGMGR_R_ENOMEM;
+
+ ret = pkgmgr_client_connection_set_callback(client, cb_info);
+ if (ret != PKGMGR_R_OK) {
+ __free_cb_info(cb_info);
+ return ret;
+ }
+ client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
+
+ return cb_info->req_id;
+}
+
+API int pkgmgr_client_add_res_remove_path(pkgmgr_client *pc,
+ const char *res_path)
+{
+ struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+
+ if (pc == NULL || res_path == NULL) {
+ ERR("invalid parameter");
+ return PKGMGR_R_EINVAL;
+ }
+
+ if (client->res_remove_builder == NULL) {
+ client->res_remove_builder =
+ g_variant_builder_new(G_VARIANT_TYPE("as"));
+ if (client->res_remove_builder == NULL) {
+ ERR("out of memory");
+ return PKGMGR_R_ENOMEM;
+ }
+ }
+
+ g_variant_builder_add(client->res_remove_builder, "s", res_path);
+
+ return PKGMGR_R_OK;
+}
+
+API int pkgmgr_client_res_remove(pkgmgr_client *pc,
+ pkgmgr_res_request_cb event_cb, void *user_data)
+{
+ GVariant *result;
+ int ret;
+ char *req_key = NULL;
+ struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+ struct cb_info *cb_info;
+
+ if (pc == NULL || event_cb == NULL) {
+ ERR("invalid parameter");
+ return PKGMGR_R_EINVAL;
+ }
+
+ ret = pkgmgr_client_connection_send_request(client,
+ "res_remove",
+ g_variant_new("(as)",
+ client->res_remove_builder), &result);
+ if (ret != PKGMGR_R_OK) {
+ ERR("request failed: %d", ret);
+ return ret;
+ }
+
+ g_variant_get(result, "(i&s)", &ret, &req_key);
+ if (req_key == NULL) {
+ g_variant_unref(result);
+ return PKGMGR_R_ECOMM;
+ }
+ if (ret != PKGMGR_R_OK) {
+ g_variant_unref(result);
+ return ret;
+ }
+
+ cb_info = __create_res_request_cb_info(client,
+ event_cb, user_data, req_key);
+ g_variant_unref(result);
+ if (cb_info == NULL)
+ return PKGMGR_R_ENOMEM;
+
+ ret = pkgmgr_client_connection_set_callback(client, cb_info);
+ if (ret != PKGMGR_R_OK) {
+ __free_cb_info(cb_info);
+ return ret;
+ }
+ client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
+
+ return cb_info->req_id;
+}
+
+API int pkgmgr_client_res_uninstall(pkgmgr_client *pc, const char *pkgid,
+ pkgmgr_res_request_cb event_cb, void *user_data)
+{
+ return pkgmgr_client_res_usr_uninstall(pc, pkgid, event_cb,
+ user_data, _getuid());
+}
+
+API int pkgmgr_client_res_usr_uninstall(pkgmgr_client *pc, const char *pkgid,
+ pkgmgr_res_request_cb event_cb, void *user_data, uid_t uid)
+{
+ GVariant *result;
+ int ret = PKGMGR_R_ECOMM;
+ char *req_key = NULL;
+ struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc;
+ struct cb_info *cb_info;
+
+ if (pc == NULL || pkgid == NULL || event_cb == NULL) {
+ ERR("invalid parameter");
+ return PKGMGR_R_EINVAL;
+ }
+
+ ret = pkgmgr_client_connection_send_request(client,
+ "res_uninstall",
+ g_variant_new("(us)", uid, pkgid), &result);
+ if (ret != PKGMGR_R_OK) {
+ ERR("request failed: %d", ret);
+ return ret;
+ }
+
+ g_variant_get(result, "(i&s)", &ret, &req_key);
+ if (req_key == NULL) {
+ g_variant_unref(result);
+ return PKGMGR_R_ECOMM;
+ }
+ if (ret != PKGMGR_R_OK) {
+ g_variant_unref(result);
+ return ret;
+ }
+
+ cb_info = __create_res_request_cb_info(client,
+ event_cb, user_data, req_key);
+ g_variant_unref(result);
+ if (cb_info == NULL)
+ return PKGMGR_R_ENOMEM;
+
+ ret = pkgmgr_client_connection_set_callback(client, cb_info);
+ if (ret != PKGMGR_R_OK) {
+ __free_cb_info(cb_info);
+ return ret;
+ }
+ client->cb_info_list = g_list_append(client->cb_info_list, cb_info);
+
+ return cb_info->req_id;
+}