Add a new API for getting the data handle 71/232171/7
authorInHong Han <inhong1.han@samsung.com>
Wed, 29 Apr 2020 01:38:55 +0000 (10:38 +0900)
committerInHong Han <inhong1.han@samsung.com>
Wed, 6 May 2020 12:00:30 +0000 (21:00 +0900)
Change-Id: Ib4a38dacd50402b07f0345137f2a23091ca842ef

client/sticker_data.c
client/sticker_dbus.c
client/sticker_dbus.h
include/sticker_data.h
server/stickerd_data_manager.c
server/stickerd_data_manager.h
server/stickerd_db_manager.c
server/stickerd_db_manager.h

index 2a64633..5b6b7ae 100644 (file)
@@ -93,6 +93,50 @@ cleanup:
         return NULL;
 }
 
+static void _free_sticker_data(sticker_data_h sticker_data)
+{
+    if (!sticker_data)
+        return;
+
+    if (sticker_data->app_id) {
+        free(sticker_data->app_id);
+        sticker_data->app_id = NULL;
+    }
+
+    if (sticker_data->uri) {
+        free(sticker_data->uri);
+        sticker_data->uri = NULL;
+    }
+
+    if (sticker_data->thumbnail) {
+        free(sticker_data->thumbnail);
+        sticker_data->thumbnail = NULL;
+    }
+
+    if (sticker_data->keyword) {
+        g_list_free_full(sticker_data->keyword, free);
+        sticker_data->keyword = NULL;
+    }
+
+    if (sticker_data->group) {
+        free(sticker_data->group);
+        sticker_data->group = NULL;
+    }
+
+    if (sticker_data->description) {
+        free(sticker_data->description);
+        sticker_data->description = NULL;
+    }
+
+    if (sticker_data->date) {
+        free(sticker_data->date);
+        sticker_data->date = NULL;
+    }
+
+    free(sticker_data);
+    sticker_data = NULL;
+}
+
 EXPORT_API int sticker_data_create(sticker_data_h *data_handle)
 {
     CHECK_STICKER_FEATURE();
@@ -215,6 +259,75 @@ EXPORT_API int sticker_data_clone(sticker_data_h origin_handle, sticker_data_h *
     return STICKER_ERROR_NONE;
 }
 
+EXPORT_API int sticker_data_get_handle(const char* uri, sticker_data_h *data_handle)
+{
+    CHECK_STICKER_FEATURE();
+
+    int ret;
+    GDBusConnection *gdbus_connection = NULL;
+    int server_watcher_id = 0;
+    int monitor_id = 0;
+    int server_monitor_id = 0;
+    int is_exist = 0;
+
+    if (!uri || uri[0] == '\0' || !data_handle)
+        return STICKER_ERROR_INVALID_PARAMETER;
+
+    struct sticker_data_s *handle = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+    if (!handle)
+        return STICKER_ERROR_OUT_OF_MEMORY;
+
+    ret = sticker_dbus_init(&gdbus_connection, &server_watcher_id, &monitor_id, &server_monitor_id, STICKER_CLIENT_LIB_PROVIDER, NULL);
+    if (ret != STICKER_ERROR_NONE) {
+        LOGE("Failed to initialize dbus : %d", ret);
+        ret = STICKER_ERROR_OPERATION_FAILED;
+        goto cleanup;
+    }
+
+    ret = sticker_dbus_check_file_exists(gdbus_connection, uri, &is_exist);
+    if (ret != STICKER_ERROR_NONE) {
+        LOGE("Failed to check file exists : %d", ret);
+        ret = STICKER_ERROR_OPERATION_FAILED;
+        goto cleanup;
+    }
+
+    if (!is_exist) {
+        LOGE("Sticker does not exist. URI : %s", uri);
+        ret = STICKER_ERROR_NO_SUCH_FILE;
+        goto cleanup;
+    }
+
+    ret = sticker_dbus_get_sticker_info_by_uri(gdbus_connection, handle, uri);
+    if (ret != STICKER_ERROR_NONE) {
+        LOGE("Failed to get sticker information : %d", ret);
+        goto cleanup;
+    }
+
+    *data_handle = handle;
+
+    ret = sticker_dbus_shutdown(gdbus_connection, &server_watcher_id, &server_monitor_id, &monitor_id, STICKER_CLIENT_LIB_PROVIDER);
+    if (ret != STICKER_ERROR_NONE)
+        LOGE("Failed to finalize dbus : %d", ret);
+
+    g_object_unref(gdbus_connection);
+
+    return STICKER_ERROR_NONE;
+
+cleanup:
+    if (handle)
+        _free_sticker_data(handle);
+
+    if (gdbus_connection) {
+        ret = sticker_dbus_shutdown(gdbus_connection, &server_watcher_id, &server_monitor_id, &monitor_id, STICKER_CLIENT_LIB_PROVIDER);
+        if (ret != STICKER_ERROR_NONE)
+            LOGE("Failed to finalize dbus : %d", ret);
+
+        g_object_unref(gdbus_connection);
+    }
+
+    return ret;
+}
+
 EXPORT_API int sticker_data_get_app_id(sticker_data_h data_handle, char **app_id)
 {
     CHECK_STICKER_FEATURE();
index 412a143..6cf0088 100644 (file)
@@ -88,6 +88,9 @@ static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIte
 
     while (g_variant_iter_loop (info_iter, "{iv}", &key, &value)) {
         switch(key) {
+            case STICKER_DATA_TYPE_INFO_ID:
+            sticker_data->sticker_info_id = g_variant_get_int32(value);
+            break;
             case STICKER_DATA_TYPE_APP_ID:
             sticker_data->app_id = g_variant_dup_string(value, NULL);
             break;
@@ -1196,4 +1199,34 @@ int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int
         g_object_unref(reply);
 
     return ret;
+}
+
+int sticker_dbus_get_sticker_info_by_uri(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, const char *uri)
+{
+    int ret;
+    GDBusMessage *reply = NULL;
+    GVariant *reply_body = NULL;
+    GVariantIter *info_iter = NULL;
+    GVariantIter *keyword_iter = NULL;
+
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "get_sticker_info_by_uri");
+    if (ret == STICKER_CLIENT_ERROR_NONE) {
+        reply_body = g_dbus_message_get_body(reply);
+        g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
+        _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
+
+        if (reply_body)
+            g_variant_unref(reply_body);
+
+        if (info_iter)
+            g_variant_iter_free(info_iter);
+
+        if (keyword_iter)
+            g_variant_iter_free(keyword_iter);
+    }
+
+    if (reply)
+        g_object_unref(reply);
+
+    return ret;
 }
\ No newline at end of file
index 4115e1d..c5643db 100644 (file)
@@ -68,6 +68,7 @@ int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connectio
 int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result);
 int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id);
 int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter);
+int sticker_dbus_get_sticker_info_by_uri(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, const char *uri);
 
 #ifdef __cplusplus
 }
index 2a59af1..4f75071 100644 (file)
@@ -119,6 +119,23 @@ int sticker_data_destroy(sticker_data_h data_handle);
 int sticker_data_clone(sticker_data_h origin_handle, sticker_data_h *target_handle);
 
 /**
+ * @brief Gets the sticker data handle for the given URI.
+ * @since_tizen 5.5
+ * @remarks If the function succeeds, @a data_handle must be released with sticker_data_destroy().
+ * @param[in] uri The URI of the sticker data handle
+ * @param[out] data_handle The sticker data handle for the given sticker URI
+ * @return 0 on success, otherwise a negative error value
+ * @retval #STICKER_ERROR_NONE Successful
+ * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported
+ * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STICKER_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed
+ * @retval #STICKER_ERROR_NO_SUCH_FILE A sticker with given @a uri does not exist
+ * @see sticker_data_destroy()
+ */
+int sticker_data_get_handle(const char* uri, sticker_data_h *data_handle);
+
+/**
  * @brief Gets the name of the sticker provider application from sticker data handle.
  * @since_tizen 5.5
  * @remarks @a app_id must be released using free().
index 0e40774..c731971 100644 (file)
@@ -164,6 +164,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con
         ret = stickerd_get_recent_sticker_info(parameters, &reply_body);
     } else if (g_strcmp0(method_name, "send_update_event") == 0) {
         ret = stickerd_send_update_event(parameters, &reply_body);
+    } else if (g_strcmp0(method_name, "get_sticker_info_by_uri") == 0) {
+        ret = stickerd_get_sticker_info_by_uri(parameters, &reply_body);
     }
 
     if (ret == STICKERD_SERVER_ERROR_NONE) {
@@ -345,6 +347,12 @@ int stickerd_register_dbus_interface(void)
             "        <method name='send_update_event'>"
             "          <arg type='i' name='record_id' direction='in'/>"
             "        </method>"
+
+            "        <method name='get_sticker_info_by_uri'>"
+            "          <arg type='s' name='uri' direction='in'/>"
+            "          <arg type='a{iv}' name='sticker_info' direction='out'/>"
+            "          <arg type='a(s)' name='keyword_list' direction='out'/>"
+            "        </method>"
             "  </interface>"
             "  </node>";
 
@@ -1776,4 +1784,57 @@ int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body)
     }
 
     return ret;
+}
+
+int stickerd_get_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body)
+{
+    int ret;
+    char *uri = NULL;
+    GVariantBuilder *info_builder;
+    GVariantBuilder *keyword_builder;
+
+    g_variant_get(parameters, "(&s)", &uri);
+
+    sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
+
+    if (!sticker_info)
+        return STICKERD_SERVER_ERROR_OUT_OF_MEMORY;
+
+    ret = stickerd_db_get_sticker_info_by_uri(uri, sticker_info);
+    if (ret != STICKERD_SERVER_ERROR_NONE) {
+        LOGE("Failed to get sticker info");
+        ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+        goto cleanup;
+    }
+
+    info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_INFO_ID, g_variant_new_int32(sticker_info->record_id));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_info->app_id));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_info->type));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_info->uri));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_info->thumbnail));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_info->description));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_info->group));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DATE, g_variant_new_string((const gchar *)sticker_info->date));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_info->display_type));
+
+    keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+    g_list_foreach(sticker_info->keyword, (GFunc) _set_keyword_builder, keyword_builder);
+
+    *reply_body = g_variant_new("(a{iv}a(s))", info_builder, keyword_builder);
+    g_variant_builder_unref(info_builder);
+    g_variant_builder_unref(keyword_builder);
+
+    if (*reply_body == NULL) {
+        LOGE("Failed to create reply_body");
+        ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+    }
+
+cleanup:
+    if (sticker_info) {
+        _free_sticker_data(sticker_info);
+        sticker_info = NULL;
+    }
+
+    return ret;
 }
\ No newline at end of file
index 6b54c68..e6ac7e7 100644 (file)
@@ -51,6 +51,7 @@ int stickerd_check_file_exists(GVariant *parameters, GVariant **reply_body);
 int stickerd_insert_recent_sticker_info(GVariant *parameters, GVariant **reply_body);
 int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body);
 int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body);
+int stickerd_get_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body);
 
 #ifdef __cplusplus
 }
index 6e3ace3..b13c2ee 100644 (file)
@@ -1016,7 +1016,6 @@ cleanup:
 int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info)
 {
     int ret;
-    int record_id;
     sqlite3 *db = NULL;
     sqlite3_stmt *stmt = NULL;
 
@@ -1038,7 +1037,7 @@ int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info
         goto cleanup;
     }
 
-    record_id = sticker_info->display_type = sqlite3_column_int(stmt, 0);
+    sticker_info->record_id = sqlite3_column_int(stmt, 0);
 
     const unsigned char *tmp_app_id = sqlite3_column_text(stmt, 1);
     if (tmp_app_id)
@@ -1077,7 +1076,7 @@ int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info
         goto cleanup;
     }
 
-    sqlite3_bind_int(stmt, 1, record_id);
+    sqlite3_bind_int(stmt, 1, sticker_info->record_id);
 
     while (sqlite3_step(stmt) == SQLITE_ROW) {
         const unsigned char *keyword = sqlite3_column_text(stmt, 0);
index 83bf132..53c1e42 100644 (file)
@@ -38,6 +38,7 @@ typedef enum {
 } sticker_info_db_type;
 
 typedef struct {
+    int record_id;
     char *app_id;
     int  type;
     char *uri;