Add a code for removing sticker data 48/227048/2
authorInHong Han <inhong1.han@samsung.com>
Mon, 9 Mar 2020 08:16:35 +0000 (17:16 +0900)
committerInHong Han <inhong1.han@samsung.com>
Mon, 9 Mar 2020 08:20:24 +0000 (17:20 +0900)
Change-Id: I70ba9a3ec0f887a8c6eaf4e144d7754cf56739ce

receiver/inc/sticker_info.h
receiver/src/ft.cpp
receiver/src/sticker_info.cpp

index 7cf88fe..bda6616 100644 (file)
@@ -4,5 +4,6 @@
 void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc);
 int create_sticker_provider_handle(void);
 void destroy_sticker_provider_handle(void);
+void delete_sticker_data(const char *fileName);
 
 #endif /* __STICKER_INF_H__ */
index c8d83eb..fae0991 100644 (file)
@@ -446,11 +446,14 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in
                 string file_name = string(json_filename ? json_filename : "");
 
                 if (file_len > 0) {
-                    LOGD("fileName : %s, len : %d", file_name.c_str(), file_len);
+                    LOGD("Add file : %s, len : %d", file_name.c_str(), file_len);
                     total_file_count++;
                 } else {
-                    // Delete sticker
-                    LOGD("fileName : %s, len : %d", file_name.c_str(), file_len);
+                    LOGD("Delete file : %s, len : %d", file_name.c_str(), file_len);
+                    if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
+                        delete_sticker_data(file_name.c_str());
+                        destroy_sticker_provider_handle();
+                    }
                 }
             }
         }
index a391fc2..1ac2247 100644 (file)
@@ -3,10 +3,14 @@
 #include <app_common.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <iostream>
 
 #include "log.h"
 
+using namespace std;
+
 static sticker_provider_h sticker_provider = NULL;
+static bool need_to_retrive = false;
 
 sticker_data_h
 set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword,
@@ -106,3 +110,47 @@ void destroy_sticker_provider_handle(void)
     sticker_provider_destroy(sticker_provider);
     sticker_provider = NULL;
 }
+
+static void _sticker_foreach_cb(sticker_data_h data_handle, void *user_data)
+{
+    int ret;
+    char *del_file = (char *)user_data;
+    sticker_data_uri_type_e type;
+    char *uri = NULL;
+
+    if (!need_to_retrive)
+        return;
+
+    ret = sticker_data_get_uri(data_handle, &type, &uri);
+    if (ret != STICKER_ERROR_NONE)
+        LOGE("Failed to get sticker uri");
+
+    int result = (string(uri)).find(del_file);
+    if (result >= 0) {
+        LOGI("Delete sticker (%s)", uri);
+        need_to_retrive = false;
+
+        ret = sticker_provider_delete_data(sticker_provider, data_handle);
+        if (ret != STICKER_ERROR_NONE)
+            LOGE("Failed to delete sticker");
+    }
+}
+
+void delete_sticker_data(const char *fileName)
+{
+    int ret;
+    int offset = 0;
+    int count = 0;
+    int result = 0;
+    need_to_retrive = true;
+
+    while (result == count && need_to_retrive) {
+        count = 20;
+        ret = sticker_provider_data_foreach_all(sticker_provider, offset, count, &result, _sticker_foreach_cb, (void *)fileName);
+        offset += result;
+        if (ret != STICKER_ERROR_NONE) {
+            LOGE("Failed to retrieve sticker");
+            return;
+        }
+    }
+}
\ No newline at end of file