Support the event callback to send sticker DB changes 99/230699/2
authorInHong Han <inhong1.han@samsung.com>
Mon, 13 Apr 2020 05:24:08 +0000 (14:24 +0900)
committerInHong Han <inhong1.han@samsung.com>
Tue, 14 Apr 2020 04:34:19 +0000 (13:34 +0900)
Change-Id: I43d08448b3d67794f2ea7f7ccfdd4b8a9a9d3508

client/sticker_dbus.c
client/sticker_dbus.h
client/sticker_defs.h
consumer/sticker_consumer.c
provider/sticker_provider.c
server/stickerd_data_manager.c
server/stickerd_data_manager.h
server/stickerd_db_manager.c
server/stickerd_db_manager.h
server/stickerd_dbus.c
server/stickerd_dbus.h

index f8a4b72..412a143 100644 (file)
@@ -26,6 +26,7 @@
 #define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data")
 
 static int is_server_started = 0;
+static CLIENT_LIB last_req_lib = STICKER_CLIENT_LIB_NONE;
 
 static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
 {
@@ -74,18 +75,14 @@ static int _dbus_init(GDBusConnection **gdbus_connection)
     return STICKER_CLIENT_ERROR_NONE;
 }
 
-static void _get_sticker_info_from_gvariant(GVariant *body, sticker_data_h sticker_data)
+static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIter *keyword_iter, sticker_data_h sticker_data)
 {
     STICKER_DAT_TYPE key;
     GVariant *value = NULL;
-    GVariantIter *info_iter = NULL;
-    GVariantIter *keyword_iter = NULL;
     char *keyword = NULL;
 
-    g_variant_get(body, "(a{iv}a(s))", &info_iter, &keyword_iter);
-
     if (!info_iter || !keyword_iter) {
-        LOGD("failed to get iter");
+        LOGW("failed to get iter");
         return;
     }
 
@@ -206,6 +203,29 @@ static void _handle_sticker_consumer_cb(GDBusConnection *connection,
         return;
     }
 
+    if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) {
+        if (consumer_handle->event_cb != NULL) {
+            sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+            if (sticker_data) {
+                int event_type;
+                GVariantIter *info_iter = NULL;
+                GVariantIter *keyword_iter = NULL;
+
+                g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter);
+                _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
+                consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data);
+
+                if (info_iter)
+                    g_variant_iter_free(info_iter);
+
+                if (keyword_iter)
+                    g_variant_iter_free(keyword_iter);
+
+                _free_sticker_data(sticker_data);
+            }
+        }
+    }
+
     #if 0 // Receive the sticker information by asynchronous communication.
     if (g_strcmp0(signal_name, "send_group_list") == 0) {
         if (consumer_handle->group_foreach_cb != NULL)
@@ -446,14 +466,13 @@ static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body
     return ret;
 }
 
-static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id)
+static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib)
 {
     int ret;
     GDBusMessage *reply = NULL;
     GVariant *reply_body = NULL;
 
-    ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "sticker_service_register");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register");
     if (ret != STICKER_CLIENT_ERROR_NONE) {
         LOGE("_send_sync_message() failed : %d", ret);
         return ret;
@@ -476,7 +495,7 @@ static void _on_name_appeared(GDBusConnection *connection,
 {
     if (is_server_started == 0) {
         int *watcher_id = (int *)user_data;
-        _monitor_register(connection, watcher_id);
+        _monitor_register(connection, watcher_id, last_req_lib);
     }
 }
 
@@ -493,6 +512,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id
                       int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
 {
     int ret;
+    last_req_lib = lib;
 
     ret = _dbus_init(gdbus_connection);
     if (ret != STICKER_CLIENT_ERROR_NONE) {
@@ -506,7 +526,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id
         return ret;
     }
 
-    ret = _monitor_register(*gdbus_connection, server_watcher_id);
+    ret = _monitor_register(*gdbus_connection, server_watcher_id, lib);
     if (ret != STICKER_CLIENT_ERROR_NONE) {
         LOGE("_monitor_register() failed : %d", ret);
         return ret;
@@ -532,12 +552,12 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id
     return STICKER_CLIENT_ERROR_NONE;
 }
 
-int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id)
+int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib)
 {
     int ret;
 
     if (server_watcher_id) {
-        ret = _send_async_message(gdbus_connection, g_variant_new("(i)", *server_watcher_id), "sticker_service_unregister");
+        ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister");
         if (ret != STICKER_CLIENT_ERROR_NONE) {
             LOGE("Failed to unregister sticker service");
             return ret;
@@ -663,6 +683,7 @@ int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, c
 int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
 {
     int ret;
+    bool is_updated = false;
     GDBusMessage *reply = NULL;
     GVariant *reply_body = NULL;
     sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
@@ -675,7 +696,17 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
     ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
-        _get_sticker_info_from_gvariant(reply_body, origin_data);
+        GVariantIter *info_iter = NULL;
+        GVariantIter *keyword_iter = NULL;
+
+        g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
+        _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data);
+
+        if (info_iter)
+            g_variant_iter_free(info_iter);
+
+        if (keyword_iter)
+            g_variant_iter_free(keyword_iter);
     } else {
         LOGW("failed to get sticker info");
         free(origin_data);
@@ -721,6 +752,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
                 free(conv_path);
                 goto cleanup;
             }
+            is_updated = true;
         }
         free(conv_path);
     }
@@ -732,6 +764,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
             LOGE("failed to update sticker type");
             goto cleanup;
         }
+        is_updated = true;
     }
 
     if (sticker_data->thumbnail) {
@@ -749,6 +782,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
                     free(conv_path);
                     goto cleanup;
                 }
+                is_updated = true;
             }
             free(conv_path);
         }
@@ -761,6 +795,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
             LOGE("failed to update sticker description");
             goto cleanup;
         }
+        is_updated = true;
     }
 
     if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
@@ -770,6 +805,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
             LOGE("failed to update sticker group");
             goto cleanup;
         }
+        is_updated = true;
     }
 
     if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
@@ -779,6 +815,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
             LOGE("failed to update sticker display type");
             goto cleanup;
         }
+        is_updated = true;
     }
 
     if (sticker_data->keyword) {
@@ -788,9 +825,14 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
         ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
         if (ret != STICKER_CLIENT_ERROR_NONE)
             LOGE("failed to update sticker keyword");
+        else
+            is_updated = true;
         g_variant_builder_unref(keyword_builder);
     }
 
+    if (is_updated)
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event");
+
 cleanup:
     _free_sticker_data(origin_data);
 
@@ -808,15 +850,25 @@ int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection
     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("(i)", record_id), &reply, "get_sticker_info");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         sticker_data->sticker_info_id = record_id;
-        _get_sticker_info_from_gvariant(reply_body, sticker_data);
+
+        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)
index a6d5437..4115e1d 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <glib.h>
 #include <gio/gio.h>
 #include <dbus/dbus.h>
@@ -47,7 +48,7 @@ enum sticker_client_error {
 
 int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
                       int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data);
-int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id);
+int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib);
 int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data);
 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path);
 int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id);
index 01cae60..69167ec 100644 (file)
@@ -69,6 +69,12 @@ typedef enum {
     STICKER_DATA_TYPE_DISP_TYPE,
 } STICKER_DAT_TYPE;
 
+typedef enum {
+    STICKER_EVENT_TYPE_INSERT,
+    STICKER_EVENT_TYPE_DELETE,
+    STICKER_EVENT_TYPE_UPDATE,
+} STICKER_EVENT_TYPE;
+
 #ifdef __cplusplus
 }
 #endif
index 1c9de90..91de924 100644 (file)
@@ -189,7 +189,7 @@ 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) {
         LOGE("Failed to finalize dbus : %d", ret);
         free(consumer_handle);
index 98f1005..b16db5e 100644 (file)
@@ -107,7 +107,7 @@ EXPORT_API int sticker_provider_destroy(sticker_provider_h provider_handle)
 
     LOGD("provider_handle : %p", provider_handle);
     ret = sticker_dbus_shutdown(provider_handle->gdbus_connection, &provider_handle->server_watcher_id,
-                                &provider_handle->server_monitor_id, &provider_handle->monitor_id);
+                                &provider_handle->server_monitor_id, &provider_handle->monitor_id, STICKER_CLIENT_LIB_PROVIDER);
     if (ret != STICKER_ERROR_NONE) {
         LOGE("Failed to finalize dbus : %d", ret);
         free(provider_handle);
@@ -151,7 +151,6 @@ EXPORT_API int sticker_provider_insert_data(sticker_provider_h provider_handle,
         else
             return STICKER_ERROR_OPERATION_FAILED;
     }
-
     return STICKER_ERROR_NONE;
 }
 
index d82b2cf..23c09e0 100644 (file)
@@ -44,6 +44,7 @@
 
 static GHashTable *_monitoring_hash = NULL;
 static char error_buffer[MAX_ERROR_BUFFER];
+static GList *consumer_list = NULL;
 extern GMainLoop *main_loop;
 
 static void _check_watcher_exist()
@@ -52,6 +53,8 @@ static void _check_watcher_exist()
         LOGD("Terminate sticker daemon");
         g_hash_table_destroy(_monitoring_hash);
         _monitoring_hash = NULL;
+        g_list_free_full(consumer_list, free);
+        consumer_list = NULL;
         g_main_loop_quit(main_loop);
     }
 }
@@ -77,6 +80,9 @@ static void _on_name_vanished(GDBusConnection *connection,
             delete_monitoring_list(&_monitoring_hash, info->bus_name, info->watcher_id);
         }
 
+        if (g_list_find(consumer_list, info->bus_name))
+            consumer_list = g_list_remove(consumer_list, info->bus_name);
+
         if (info->bus_name)
             free(info->bus_name);
         free(info);
@@ -95,14 +101,17 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con
     if (_monitoring_hash == NULL)
         _monitoring_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
 
+    if (consumer_list == NULL)
+        consumer_list = g_list_alloc();
+
     GVariant *reply_body = NULL;
     int ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
 
     if (g_strcmp0(method_name, "sticker_service_register") == 0) {
         ret = stickerd_server_register(parameters, &reply_body, sender,
-            _on_name_appeared, _on_name_vanished, &_monitoring_hash);
+            _on_name_appeared, _on_name_vanished, &_monitoring_hash, &consumer_list);
     } else if (g_strcmp0(method_name, "sticker_service_unregister") == 0) {
-        ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash);
+        ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash, &consumer_list);
     } else if (g_strcmp0(method_name, "insert_sticker_info") == 0) {
         ret = stickerd_insert_sticker_info(parameters, &reply_body);
     } else if  (g_strcmp0(method_name, "update_sticker_info_by_json") == 0) {
@@ -153,6 +162,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con
         ret = stickerd_insert_recent_sticker_info(parameters, &reply_body);
     } else if (g_strcmp0(method_name, "get_recent_sticker_info") == 0) {
         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);
     }
 
     if (ret == STICKERD_SERVER_ERROR_NONE) {
@@ -178,10 +189,12 @@ int stickerd_register_dbus_interface(void)
             "  <node>"
             "  <interface name='org.tizen.sticker_service'>"
             "        <method name='sticker_service_register'>"
+            "          <arg type='i' name='lib_type' direction='in'/>"
             "          <arg type='i' name='watcher_id' direction='out'/>"
             "        </method>"
 
             "        <method name='sticker_service_unregister'>"
+            "          <arg type='i' name='lib_type' direction='in'/>"
             "          <arg type='i' name='watcher_id' direction='in'/>"
             "        </method>"
 
@@ -328,6 +341,10 @@ 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='send_update_event'>"
+            "          <arg type='i' name='record_id' direction='in'/>"
+            "        </method>"
             "  </interface>"
             "  </node>";
 
@@ -538,6 +555,70 @@ cleanup:
     }
 }
 
+static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
+{
+    if (!keyword) {
+        LOGE("keyword doesn't exist");
+        return;
+    }
+
+    g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
+}
+
+static GVariant* _get_sticker_g_variant(STICKER_EVENT_TYPE type, sticker_info_db *sticker_info)
+{
+    GVariantBuilder *info_builder;
+    GVariantBuilder *keyword_builder;
+
+    info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
+    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);
+
+    GVariant *body = g_variant_new("(ia{iv}a(s))", (int)type, info_builder, keyword_builder);
+    g_variant_builder_unref(info_builder);
+    g_variant_builder_unref(keyword_builder);
+
+    if (body)
+        return body;
+    else
+        return NULL;
+}
+
+void _get_consumer_busname(gpointer data, gpointer user_data)
+{
+    if (data == NULL)
+        return;
+
+    int ret;
+    char *cmd = "send_sticker_changed_event";
+    char *sender = (char *)data;
+    GVariant *body = (GVariant *)user_data;
+
+    ret = stickerd_send_dbus_message(body, sender, cmd, STICKER_CLIENT_LIB_CONSUMER);
+    if (ret != STICKERD_SERVER_ERROR_NONE)
+        LOGE("Failed to send sticker changed event");
+}
+
+static void _send_sticker_changed_event(STICKER_EVENT_TYPE type, sticker_info_db *sticker_info)
+{
+    GVariant *body = _get_sticker_g_variant(type, sticker_info);
+
+    if (body)
+        g_list_foreach(consumer_list, _get_consumer_busname, body);
+
+    if (body)
+        g_variant_unref(body);
+}
+
 int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body)
 {
     int ret;
@@ -635,7 +716,8 @@ int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body)
     if (*reply_body == NULL) {
         LOGE("Failed to create reply_body");
         ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
-    }
+    } else
+        _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info);
 
 cleanup:
     if (value)
@@ -794,7 +876,8 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_
             if (ret != STICKERD_SERVER_ERROR_NONE) {
                 LOGE("Failed to insert sticker info");
                 ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
-            }
+            } else
+                _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info);
 
 free_memory:
             free(sticker_info);
@@ -833,10 +916,20 @@ int stickerd_del_sticker_info(GVariant *parameters, GVariant **reply_body)
 
     g_variant_get(parameters, "(i)", &record_id);
 
+    sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
+    if (sticker_info)
+        stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info);
+
     ret = stickerd_db_delete_sticker_info(record_id);
     if (ret != STICKERD_SERVER_ERROR_NONE) {
         LOGE("Failed to delete sticker info");
         return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+    } else {
+        if (sticker_info && sticker_info->uri) {
+            _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info);
+            free(sticker_info);
+            sticker_info = NULL;
+        }
     }
 
     return ret;
@@ -855,10 +948,20 @@ int stickerd_del_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body
 
     g_variant_get(parameters, "(&s)", &uri);
 
+    sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
+    if (sticker_info)
+        stickerd_db_get_sticker_info_by_uri(uri, sticker_info);
+
     ret = stickerd_db_delete_sticker_info_by_uri(uri);
     if (ret != STICKERD_SERVER_ERROR_NONE) {
         LOGE("Failed to delete sticker info");
         return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+    } else {
+        if (sticker_info && sticker_info->uri) {
+            _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info);
+            free(sticker_info);
+            sticker_info = NULL;
+        }
     }
 
     return ret;
@@ -1040,16 +1143,6 @@ int stickerd_update_sticker_keyword(GVariant *parameters, GVariant **reply_body)
     return ret;
 }
 
-static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
-{
-    if (!keyword) {
-        LOGE("keyword doesn't exist");
-        return;
-    }
-
-    g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
-}
-
 int stickerd_get_sticker_info(GVariant *parameters, GVariant **reply_body)
 {
     int ret;
@@ -1628,4 +1721,30 @@ int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body
         g_variant_builder_unref(id_builder);
 
     return ret;
+}
+
+int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body)
+{
+    int ret = STICKERD_SERVER_ERROR_NONE;
+    int record_id;
+
+    *reply_body = g_variant_new("()");
+    if (*reply_body == NULL) {
+        LOGE("Failed to create reply_body");
+        return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+    }
+
+    g_variant_get(parameters, "(i)", &record_id);
+
+    sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
+    if (sticker_info) {
+        ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info);
+        if (ret == STICKERD_SERVER_ERROR_NONE) {
+            _send_sticker_changed_event(STICKER_EVENT_TYPE_UPDATE, sticker_info);
+            free(sticker_info);
+            sticker_info = NULL;
+        }
+    }
+
+    return ret;
 }
\ No newline at end of file
index ea90752..6b54c68 100644 (file)
@@ -50,6 +50,7 @@ int stickerd_update_sticker_disp_type(GVariant *parameters, GVariant **reply_bod
 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);
 
 #ifdef __cplusplus
 }
index 9536c65..ecf8f33 100644 (file)
 #define STICKER_DB_CHECK_FILE_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_info WHERE uri = ? LIMIT 1)"
 #define STICKER_DB_CHECK_RECENT_HISTORY_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_recent_history_info WHERE sticker_info_id = ? LIMIT 1)"
 #define STICKER_DB_GET_RECENT_HISTORY "SELECT sticker_info_id FROM sticker_recent_history_info ORDER BY datetime(timestamp) DESC LIMIT ?"
+#define STICKER_DB_GET_STICKER_INFO_BY_URI "SELECT * FROM sticker_info WHERE uri = ?"
 
 typedef enum
 {
@@ -1004,4 +1005,88 @@ cleanup:
     sqlite3_close(db);
 
     return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
+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;
+
+    db = _db_open();
+    if (!db)
+        return STICKERD_SERVER_ERROR_DB_FAILED;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_GET_STICKER_INFO_BY_URI, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to get sticker information : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_text(stmt, 1, uri, -1, SQLITE_TRANSIENT);
+
+    ret = sqlite3_step(stmt);
+    if (ret == SQLITE_ERROR) {
+        LOGE("sqlite3_step() failed : ret(%d)", ret);
+        goto cleanup;
+    }
+
+    record_id = sticker_info->display_type = sqlite3_column_int(stmt, 0);
+
+    const unsigned char *tmp_app_id = sqlite3_column_text(stmt, 1);
+    if (tmp_app_id)
+        sticker_info->app_id = strdup((const char *)tmp_app_id);
+
+    sticker_info->type = sqlite3_column_int(stmt, 2);
+
+    const unsigned char *tmp_uri = sqlite3_column_text(stmt, 3);
+    if (tmp_uri)
+        sticker_info->uri = strdup((const char *)tmp_uri);
+
+    const unsigned char *tmp_thumbnail = sqlite3_column_text(stmt, 4);
+    if (tmp_thumbnail)
+        sticker_info->thumbnail = strdup((const char *)tmp_thumbnail);
+
+    const unsigned char *tmp_description = sqlite3_column_text(stmt, 5);
+    if (tmp_description)
+        sticker_info->description = strdup((const char *)tmp_description);
+
+    const unsigned char *tmp_group = sqlite3_column_text(stmt, 6);
+    if (tmp_group)
+        sticker_info->group = strdup((const char *)tmp_group);
+
+    const unsigned char *tmp_date = sqlite3_column_text(stmt, 7);
+    if (tmp_date)
+        sticker_info->date = strdup((const char *)tmp_date);
+
+    sticker_info->display_type = sqlite3_column_int(stmt, 8);
+
+    sqlite3_finalize(stmt);
+    stmt = NULL;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_GET_KEYWORD_INFO_BY_RECORD_ID, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to get sticker keyword : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_int(stmt, 1, record_id);
+
+    while (sqlite3_step(stmt) == SQLITE_ROW) {
+        const unsigned char *keyword = sqlite3_column_text(stmt, 0);
+        if (keyword)
+            sticker_info->keyword = g_list_append(sticker_info->keyword, strdup((const char *)keyword));
+    }
+
+    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 38e13b5..83bf132 100644 (file)
@@ -62,6 +62,7 @@ int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *
 int stickerd_db_get_group_list_by_display_type(GVariantBuilder *builder, char *app_id, int disp_type);
 int stickerd_db_check_file_exists(int *result, char *uri);
 int stickerd_db_insert_recent_sticker_info(int record_id);
+int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info);
 
 #ifdef __cplusplus
 }
index 6184033..d125daf 100644 (file)
@@ -32,13 +32,16 @@ static GDBusConnection *_gdbus_connection;
 extern GMainLoop *main_loop;
 
 int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const gchar *sender, GBusNameAppearedCallback name_appeared_handler,
-        GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash)
+        GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash, GList **consumer_list)
 {
     int ret = STICKERD_SERVER_ERROR_NONE;
     char *m_info_bus_name = NULL;
     char *list_bus_name = NULL;
     monitoring_info_s *m_info = NULL;
     GList *monitoring_list = NULL;
+    int c_lib;
+
+    g_variant_get(parameters, "(i)", &c_lib);
 
     if (reply_body == NULL)
         return STICKERD_SERVER_ERROR_INVALID_PARAMETER;
@@ -80,6 +83,9 @@ int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const
         goto cleanup;
     }
 
+    if ((CLIENT_LIB)c_lib == STICKER_CLIENT_LIB_CONSUMER)
+        *consumer_list = g_list_append(*consumer_list, strdup((const char *)sender));
+
     LOGD("sender: %s, watcher: %d", sender, m_info->watcher_id);
     monitoring_list = g_list_append(monitoring_list, list_bus_name);
     if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(m_info->watcher_id)) == NULL)
@@ -104,11 +110,15 @@ cleanup:
     return ret;
 }
 
-int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash)
+int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash, GList **consumer_list)
 {
     int watcher_id = 0;
+    int c_lib;
+
+    g_variant_get(parameters, "(ii)", &c_lib, &watcher_id);
 
-    g_variant_get(parameters, "(i)", &watcher_id);
+    if ((CLIENT_LIB)c_lib == STICKER_CLIENT_LIB_CONSUMER)
+        *consumer_list = g_list_remove(*consumer_list, sender);
 
     if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(watcher_id)) != NULL) {
         g_bus_unwatch_name(watcher_id);
index e8ad143..2f684ae 100644 (file)
@@ -31,8 +31,8 @@ typedef struct monitoring_info {
 } monitoring_info_s;
 
 int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const gchar *sender, GBusNameAppearedCallback name_appeared_handler,
-    GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash);
-int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash);
+    GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash, GList **consumer_list);
+int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash, GList **consumer_list);
 int stickerd_server_register_dbus_interface(char *introspection_xml, GDBusInterfaceVTable interface_vtable);
 int delete_monitoring_list(GHashTable **monitoring_hash, const char *sender, int monitoring_id);
 int stickerd_send_dbus_message(GVariant *body, const char *dest, char *cmd, CLIENT_LIB lib);