Fix build error in sticker-receiver
[platform/core/uifw/capi-ui-sticker.git] / consumer / sticker_consumer.c
index 8602652..4f51fb5 100644 (file)
@@ -17,6 +17,7 @@
 #include <dlog.h>
 #include <gio/gio.h>
 #include <dbus/dbus.h>
+#include <app_common.h>
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <cynara-session.h>
@@ -77,7 +78,7 @@ static int _cynara_initialize()
 {
     int ret = cynara_initialize(&p_cynara, NULL);
     if (ret != CYNARA_API_SUCCESS)
-        LOGE("Failed to cynara initialize");
+        LOGE("Failed to cynara initialize"); //LCOV_EXCL_LINE
 
     return ret;
 }
@@ -109,7 +110,7 @@ static int _check_privilege(const char *uid, const char *privilege)
         free(session);
 
     if (ret != CYNARA_API_ACCESS_ALLOWED) {
-        LOGE("Access denied. The result of cynara_check() : %d.", ret);
+        LOGE("Access denied. The result of cynara_check() : %d.", ret); //LCOV_EXCL_LINE
         return -1;
     }
 
@@ -133,7 +134,7 @@ static int _sticker_check_privilege() {
 
     snprintf(uid, 16, "%d", getuid());
     if (_check_privilege(uid, STICKER_PRIVILEGE_MEDIASTORAGE) < 0) {
-        LOGE("Permission is denied");
+        LOGE("Permission is denied"); //LCOV_EXCL_LINE
         ret = STICKER_ERROR_PERMISSION_DENIED;
     }
 
@@ -158,12 +159,23 @@ EXPORT_API int sticker_consumer_create(sticker_consumer_h *consumer_handle)
     if (!consumer_struct)
         return STICKER_ERROR_OUT_OF_MEMORY;
 
+    ret = app_get_id(&consumer_struct->app_id);
+    if (ret != APP_ERROR_NONE) {
+        //LCOV_EXCL_START
+        LOGE("Failed to get app_id : %d", ret);
+        free(consumer_struct);
+        return STICKER_ERROR_OPERATION_FAILED;
+        //LCOV_EXCL_STOP
+    }
+
     ret = sticker_dbus_init(&consumer_struct->gdbus_connection, &consumer_struct->server_watcher_id,
         &consumer_struct->monitor_id, &consumer_struct->server_monitor_id, STICKER_CLIENT_LIB_CONSUMER, (void *)consumer_struct);
     if (ret != STICKER_ERROR_NONE) {
+        //LCOV_EXCL_START
         LOGE("Failed to initialize dbus : %d", ret);
         free(consumer_struct);
         return STICKER_ERROR_OPERATION_FAILED;
+        //LCOV_EXCL_STOP
     }
 
     *consumer_handle = consumer_struct;
@@ -181,16 +193,23 @@ EXPORT_API int sticker_consumer_destroy(sticker_consumer_h consumer_handle)
 
     LOGD("consumer_handle : %p", consumer_handle);
     ret = sticker_dbus_shutdown(consumer_handle->gdbus_connection, &consumer_handle->server_watcher_id,
-                                &consumer_handle->server_monitor_id, &consumer_handle->monitor_id);
+                                &consumer_handle->server_monitor_id, &consumer_handle->monitor_id, STICKER_CLIENT_LIB_CONSUMER);
     if (ret != STICKER_ERROR_NONE) {
+        //LCOV_EXCL_START
         LOGE("Failed to finalize dbus : %d", ret);
         free(consumer_handle);
         return STICKER_ERROR_OPERATION_FAILED;
+        //LCOV_EXCL_STOP
     }
 
     if (consumer_handle->gdbus_connection)
         g_object_unref(consumer_handle->gdbus_connection);
 
+    if (consumer_handle->app_id) {
+        free(consumer_handle->app_id);
+        consumer_handle->app_id = NULL;
+    }
+
     free(consumer_handle);
 
     return STICKER_ERROR_NONE;
@@ -208,7 +227,7 @@ EXPORT_API int sticker_consumer_data_foreach_all(sticker_consumer_h consumer_han
     if (!consumer_handle || (offset < 0) || (count <= 0) || !result || !callback)
         return STICKER_ERROR_INVALID_PARAMETER;
 
-    ret = sticker_dbus_get_all_sticker_info(consumer_handle->gdbus_connection, offset, count, &id_iter);
+    ret = sticker_dbus_get_all_sticker_info(consumer_handle->gdbus_connection, consumer_handle->app_id, offset, count, &id_iter);
     if (ret != STICKER_ERROR_NONE) {
         LOGE("Failed to get all sticker information : %d", ret);
         ret = STICKER_ERROR_OPERATION_FAILED;
@@ -256,7 +275,7 @@ EXPORT_API int sticker_consumer_data_foreach_by_keyword(sticker_consumer_h consu
     if (!consumer_handle || (offset < 0) || (count <= 0) || !result || !keyword || !callback)
         return STICKER_ERROR_INVALID_PARAMETER;
 
-    ret = sticker_dbus_get_sticker_info_by_keyword(consumer_handle->gdbus_connection, keyword, offset, count, &id_iter);
+    ret = sticker_dbus_get_sticker_info_by_keyword(consumer_handle->gdbus_connection, consumer_handle->app_id, keyword, offset, count, &id_iter);
     if (ret != STICKER_ERROR_NONE) {
         LOGE("Failed to get sticker information by keyword : %d", ret);
         ret = STICKER_ERROR_OPERATION_FAILED;
@@ -304,7 +323,7 @@ EXPORT_API int sticker_consumer_data_foreach_by_group(sticker_consumer_h consume
     if (!consumer_handle || (offset < 0) || (count <= 0) || !result || !group || !callback)
         return STICKER_ERROR_INVALID_PARAMETER;
 
-    ret = sticker_dbus_get_sticker_info_by_group(consumer_handle->gdbus_connection, group, offset, count, &id_iter);
+    ret = sticker_dbus_get_sticker_info_by_group(consumer_handle->gdbus_connection, consumer_handle->app_id, group, offset, count, &id_iter);
     if (ret != STICKER_ERROR_NONE) {
         LOGE("Failed to get sticker information by group : %d", ret);
         ret = STICKER_ERROR_OPERATION_FAILED;
@@ -352,9 +371,9 @@ EXPORT_API int sticker_consumer_data_foreach_by_type(sticker_consumer_h consumer
     if (!consumer_handle || (offset < 0) || (count <= 0) || !result || (type < 1) || !callback)
         return STICKER_ERROR_INVALID_PARAMETER;
 
-    ret = sticker_dbus_get_sticker_info_by_type(consumer_handle->gdbus_connection, type, offset, count, &id_iter);
+    ret = sticker_dbus_get_sticker_info_by_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, offset, count, &id_iter);
     if (ret != STICKER_ERROR_NONE) {
-        LOGE("Failed to get sticker information by group : %d", ret);
+        LOGE("Failed to get sticker information by uri type : %d", ret);
         ret = STICKER_ERROR_OPERATION_FAILED;
         goto cleanup;
     }
@@ -398,7 +417,7 @@ EXPORT_API int sticker_consumer_group_list_foreach_all(sticker_consumer_h consum
     if (!consumer_handle || !callback)
         return STICKER_ERROR_INVALID_PARAMETER;
 
-    ret = sticker_dbus_get_group_list(consumer_handle->gdbus_connection, &list);
+    ret = sticker_dbus_get_group_list(consumer_handle->gdbus_connection, consumer_handle->app_id, &list);
     if (ret != STICKER_ERROR_NONE) {
         LOGE("Failed to get group list : %d", ret);
         ret = STICKER_ERROR_OPERATION_FAILED;
@@ -426,7 +445,7 @@ EXPORT_API int sticker_consumer_keyword_list_foreach_all(sticker_consumer_h cons
     if (!consumer_handle || !callback)
         return STICKER_ERROR_INVALID_PARAMETER;
 
-    ret = sticker_dbus_get_keyword_list(consumer_handle->gdbus_connection, &list);
+    ret = sticker_dbus_get_keyword_list(consumer_handle->gdbus_connection, consumer_handle->app_id, &list);
     if (ret != STICKER_ERROR_NONE) {
         LOGE("Failed to get keyword list : %d", ret);
         ret = STICKER_ERROR_OPERATION_FAILED;
@@ -443,3 +462,171 @@ cleanup:
 
     return ret;
 }
+
+EXPORT_API 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)
+{
+    CHECK_STICKER_FEATURE();
+
+    int ret;
+    int info_id;
+    int sticker_count = 0;
+    GVariantIter *id_iter = NULL;
+
+    if (!consumer_handle || (offset < 0) || (count <= 0) || !result || (type < 1) || !callback)
+        return STICKER_ERROR_INVALID_PARAMETER;
+
+    ret = sticker_dbus_get_sticker_info_by_display_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, offset, count, &id_iter);
+    if (ret != STICKER_ERROR_NONE) {
+        LOGE("Failed to get sticker information by display type : %d", ret);
+        ret = STICKER_ERROR_OPERATION_FAILED;
+        goto cleanup;
+    }
+
+    if (id_iter) {
+        while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
+            sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+            if (!sticker_data) {
+                ret = STICKER_ERROR_OUT_OF_MEMORY;
+                goto cleanup;
+            }
+
+            ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
+            if (ret == STICKER_ERROR_NONE) {
+                sticker_count++;
+                callback(sticker_data, user_data);
+                _free_sticker_data(sticker_data);
+            } else {
+                _free_sticker_data(sticker_data);
+                goto cleanup;
+            }
+        }
+    }
+
+    *result = sticker_count;
+
+cleanup:
+    if (id_iter)
+        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;
+}
+
+EXPORT_API int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker_data_h data_handle)
+{
+    CHECK_STICKER_FEATURE();
+
+    int ret;
+
+    if (!consumer_handle || !data_handle || (data_handle->sticker_info_id <= 0) || !data_handle->uri)
+        return STICKER_ERROR_INVALID_PARAMETER;
+
+    ret = sticker_dbus_insert_recent_sticker_info(consumer_handle->gdbus_connection, data_handle->sticker_info_id);
+    if (ret != STICKER_ERROR_NONE) {
+        LOGE("Failed to add recent sticker information : %d", ret);
+        return STICKER_ERROR_OPERATION_FAILED;
+    }
+
+    return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data)
+{
+    CHECK_STICKER_FEATURE();
+
+    int ret;
+    int info_id;
+    int sticker_count = 0;
+    GVariantIter *id_iter = NULL;
+
+    if (!consumer_handle || (count <= 0) || !result || !callback)
+        return STICKER_ERROR_INVALID_PARAMETER;
+
+    ret = sticker_dbus_get_recent_sticker_list(consumer_handle->gdbus_connection, count, &id_iter);
+    if (ret != STICKER_ERROR_NONE) {
+        LOGE("Failed to get recent sticker information : %d", ret);
+        ret = STICKER_ERROR_OPERATION_FAILED;
+        goto cleanup;
+    }
+
+    if (id_iter) {
+        while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
+            sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+            if (!sticker_data) {
+                ret = STICKER_ERROR_OUT_OF_MEMORY;
+                goto cleanup;
+            }
+
+            ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
+            if (ret == STICKER_ERROR_NONE) {
+                sticker_count++;
+                callback(sticker_data, user_data);
+                _free_sticker_data(sticker_data);
+            } else {
+                _free_sticker_data(sticker_data);
+                goto cleanup;
+            }
+        }
+    }
+
+    *result = sticker_count;
+
+cleanup:
+    if (id_iter)
+        g_variant_iter_free(id_iter);
+
+    return ret;
+}
+
+EXPORT_API int sticker_consumer_set_event_cb(sticker_consumer_h consumer_handle, sticker_consumer_event_cb callback, void *user_data)
+{
+    CHECK_STICKER_FEATURE();
+
+    if (!consumer_handle || !callback)
+        return STICKER_ERROR_INVALID_PARAMETER;
+
+    consumer_handle->event_cb = callback;
+    consumer_handle->event_cb_user_data = user_data;
+
+    return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_consumer_unset_event_cb(sticker_consumer_h consumer_handle)
+{
+    CHECK_STICKER_FEATURE();
+
+    if (!consumer_handle)
+        return STICKER_ERROR_INVALID_PARAMETER;
+
+    consumer_handle->event_cb = NULL;
+    consumer_handle->event_cb_user_data = NULL;
+
+    return STICKER_ERROR_NONE;
+}
\ No newline at end of file