Add a new API for retrieving group list using display type 67/227767/4
authorInHong Han <inhong1.han@samsung.com>
Mon, 16 Mar 2020 08:15:11 +0000 (17:15 +0900)
committerInHong Han <inhong1.han@samsung.com>
Wed, 18 Mar 2020 05:05:26 +0000 (05:05 +0000)
Change-Id: Ib6f92eff0014daad1b427e4e8a194dc4d9a54cf7

client/sticker_dbus.c
client/sticker_dbus.h
consumer/sticker_consumer.c
include/sticker_consumer.h
server/stickerd_data_manager.c
server/stickerd_data_manager.h
server/stickerd_db_manager.c
server/stickerd_db_manager.h

index a5190f6..cef8b8c 100644 (file)
@@ -968,4 +968,43 @@ int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connect
         g_object_unref(reply);
 
     return ret;
+}
+
+int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list)
+{
+    int ret;
+    GDBusMessage *reply = NULL;
+    GVariantIter *iter = NULL;
+    GVariant *reply_body = NULL;
+    char *group = NULL;
+
+    if (group_list == NULL) {
+        LOGE("group_list is invalid");
+        return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
+    }
+
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
+    if (ret == STICKER_CLIENT_ERROR_NONE) {
+        reply_body = g_dbus_message_get_body(reply);
+        g_variant_get(reply_body, "(a(s))", &iter);
+
+        if (!iter) {
+            LOGD("failed to get iter");
+            return STICKER_CLIENT_ERROR_OPERATION_FAILED;
+        }
+
+        while (g_variant_iter_loop (iter, "(s)", &group)) {
+            *group_list = g_list_append(*group_list, strdup((const char *)group));
+        }
+
+        g_variant_iter_free(iter);
+    }
+
+    if (reply_body)
+        g_variant_unref(reply_body);
+
+    if (reply)
+        g_object_unref(reply);
+
+    return ret;
 }
\ No newline at end of file
index f29d8ea..4ef7234 100644 (file)
@@ -59,6 +59,7 @@ int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, con
 int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int offset, int count, GVariantIter **id_iter);
 int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *app_id, const char *keyword, int offset, int count, GVariantIter **id_iter);
 int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, int offset, int count, GVariantIter **id_iter);
+int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list);
 
 #ifdef __cplusplus
 }
index 0734de1..5211f36 100644 (file)
@@ -503,4 +503,32 @@ cleanup:
         g_variant_iter_free(id_iter);
 
     return ret;
+}
+
+EXPORT_API int sticker_consumer_group_list_foreach_by_display_type(sticker_consumer_h consumer_handle, sticker_data_display_type_e type, sticker_consumer_group_list_foreach_cb callback, void *user_data)
+{
+    CHECK_STICKER_FEATURE();
+
+    int ret;
+    GList *list = NULL;
+
+    if (!consumer_handle || (type < 1) || !callback)
+        return STICKER_ERROR_INVALID_PARAMETER;
+
+    ret = sticker_dbus_get_group_list_by_display_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, &list);
+    if (ret != STICKER_ERROR_NONE) {
+        LOGE("Failed to get group list : %d", ret);
+        ret = STICKER_ERROR_OPERATION_FAILED;
+        goto cleanup;
+    }
+
+    for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) {
+        callback((const char *)tmp->data, user_data);
+    }
+
+cleanup:
+    if (list)
+        g_list_free_full(list, free);
+
+    return ret;
 }
\ No newline at end of file
index f7d7533..ac2428e 100644 (file)
@@ -262,6 +262,23 @@ int sticker_consumer_keyword_list_foreach_all(sticker_consumer_h consumer_handle
 int sticker_consumer_data_foreach_by_display_type(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_data_display_type_e type, sticker_consumer_data_foreach_cb callback, void *user_data);
 
 /**
+ * @brief Retrieves all group name in the sticker database using display type.
+ * @since_tizen 5.5
+ * @param[in] consumer_handle The sticker consumer handle
+ * @param[in] type The display type of the sticker for getting sticker data
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @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_OPERATION_FAILED Operation failed
+ * @post This function invokes sticker_consumer_group_list_foreach_cb() repeatedly for getting data.
+ * @see sticker_consumer_group_list_foreach_cb()
+ */
+int sticker_consumer_group_list_foreach_by_display_type(sticker_consumer_h consumer_handle, sticker_data_display_type_e type, sticker_consumer_group_list_foreach_cb callback, void *user_data);
+
+/**
  * @}
  */
 
index 4b1e479..9b344d4 100644 (file)
@@ -141,6 +141,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con
         ret = stickerd_get_sticker_info_by_keyword(parameters, &reply_body);
     } else if (g_strcmp0(method_name, "get_sticker_info_by_disp_type") == 0) {
         ret = stickerd_get_sticker_info_by_display_type(parameters, &reply_body);
+    } else if (g_strcmp0(method_name, "get_group_list_by_disp_type") == 0) {
+        ret = stickerd_get_group_list_by_disp_type(parameters, &reply_body);
     }
 
     if (ret == STICKERD_SERVER_ERROR_NONE) {
@@ -286,6 +288,12 @@ int stickerd_register_dbus_interface(void)
             "          <arg type='i' name='count' direction='in'/>"
             "          <arg type='a(i)' name='id_list' direction='out'/>"
             "        </method>"
+
+            "        <method name='get_group_list_by_disp_type'>"
+            "          <arg type='s' name='app_id' direction='in'/>"
+            "          <arg type='i' name='disp_type' direction='in'/>"
+            "          <arg type='a(s)' name='group_list' direction='out'/>"
+            "        </method>"
             "  </interface>"
             "  </node>";
 
@@ -1396,4 +1404,32 @@ int stickerd_get_sticker_info_by_display_type(GVariant *parameters, GVariant **r
         g_variant_builder_unref(id_builder);
 
     return ret;
+}
+
+int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_body)
+{
+    int ret;
+    GVariantBuilder *builder = NULL;
+    char *app_id = NULL;
+    int disp_type;
+
+    g_variant_get(parameters, "(&si)", &app_id, &disp_type);
+
+    builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+    ret = stickerd_db_get_group_list_by_display_type(builder, app_id, disp_type);
+    if (ret != STICKERD_SERVER_ERROR_NONE) {
+        LOGE("Failed to get sticker group list");
+        g_variant_builder_unref(builder);
+        return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+    }
+
+    *reply_body = g_variant_new("(a(s))", builder);
+    g_variant_builder_unref(builder);
+
+    if (*reply_body == NULL) {
+        LOGE("Failed to create reply_body");
+        return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+    }
+
+    return ret;
 }
\ No newline at end of file
index 246d616..0c4c979 100644 (file)
@@ -44,6 +44,7 @@ int stickerd_get_sticker_info_by_type(GVariant *parameters, GVariant **reply_bod
 int stickerd_get_sticker_info_by_group(GVariant *parameters, GVariant **reply_body);
 int stickerd_get_sticker_info_by_keyword(GVariant *parameters, GVariant **reply_body);
 int stickerd_get_sticker_info_by_display_type(GVariant *parameters, GVariant **reply_body);
+int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_body);
 
 #ifdef __cplusplus
 }
index dcbf279..bc172e2 100644 (file)
@@ -82,6 +82,7 @@
 #define STICKER_DB_GET_RECORD_ID_BY_GROUP "SELECT sticker_info_id from sticker_info WHERE group_name = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?"
 #define STICKER_DB_GET_RECORD_ID_BY_KEYWORD "SELECT sticker_info_id FROM sticker_keyword_info WHERE keyword = ? INTERSECT SELECT sticker_info_id from sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?"
 #define STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE "SELECT sticker_info_id FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?"
+#define STICKER_DB_GET_GROUP_LIST_BY_DISP_TYPE "SELECT DISTINCT group_name FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?))"
 
 typedef enum
 {
@@ -735,4 +736,41 @@ cleanup:
     sqlite3_close(db);
 
     return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
+int stickerd_db_get_group_list_by_display_type(GVariantBuilder *builder, char *app_id, int disp_type)
+{
+    int ret;
+    sqlite3 *db = NULL;
+    sqlite3_stmt *stmt = NULL;
+
+    db = _db_open();
+    if (!db)
+        return STICKERD_SERVER_ERROR_DB_FAILED;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_GET_GROUP_LIST_BY_DISP_TYPE, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to get group list : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_int(stmt, 1, disp_type);
+    sqlite3_bind_text(stmt, 2, app_id, -1, SQLITE_TRANSIENT);
+
+    while (sqlite3_step(stmt) == SQLITE_ROW) {
+        const unsigned char *group = sqlite3_column_text(stmt, 0);
+        if (group)
+            g_variant_builder_add(builder, "(s)", strdup((const char *)group));
+    }
+
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_NONE;
+
+cleanup:
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_DB_FAILED;
 }
\ No newline at end of file
index 51953bb..2ef2fd5 100644 (file)
@@ -57,6 +57,7 @@ int stickerd_db_get_group_list(GVariantBuilder *builder, char *app_id);
 int stickerd_db_get_keyword_list(GVariantBuilder *builder, char *app_id);
 int stickerd_db_get_sticker_count(int *count, char *app_id);
 int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *data, char *app_id, int offset, int count);
+int stickerd_db_get_group_list_by_display_type(GVariantBuilder *builder, char *app_id, int disp_type);
 
 #ifdef __cplusplus
 }