2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "sticker_dbus.h"
24 #define LOG_TAG "STICKER_DBUS"
26 #define STICKER_DIRECTORY "/opt/usr/share/sticker-data"
28 static int is_server_started = 0;
29 static CLIENT_LIB last_req_lib = STICKER_CLIENT_LIB_NONE;
31 static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
33 LOGD("name : %s, name_owner : %s", name, name_owner);
37 static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
39 LOGD("name : %s", name);
43 static int _dbus_init(GDBusConnection **gdbus_connection)
48 if (*gdbus_connection == NULL) {
49 GDBusConnection *conn = NULL;
50 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
54 LOGE("g_bus_get_sync error message = %s", error->message);
58 return STICKER_CLIENT_ERROR_IO_ERROR;
60 *gdbus_connection = conn;
63 LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
64 watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
66 G_BUS_NAME_WATCHER_FLAGS_NONE,
71 LOGD("watch_id : %d", watch_id);
73 LOGE("Failed to get identifier"); //LCOV_EXCL_LINE
74 return STICKER_CLIENT_ERROR_IO_ERROR;
77 return STICKER_CLIENT_ERROR_NONE;
80 static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIter *keyword_iter, sticker_data_h sticker_data)
83 GVariant *value = NULL;
86 if (!info_iter || !keyword_iter) {
87 LOGW("failed to get iter");
91 while (g_variant_iter_loop (info_iter, "{iv}", &key, &value)) {
93 case STICKER_DATA_TYPE_INFO_ID:
94 sticker_data->sticker_info_id = g_variant_get_int32(value);
96 case STICKER_DATA_TYPE_APP_ID:
97 sticker_data->app_id = g_variant_dup_string(value, NULL);
99 case STICKER_DATA_TYPE_URI_TYPE:
100 sticker_data->type = g_variant_get_int32(value);
102 case STICKER_DATA_TYPE_URI:
103 sticker_data->uri = g_variant_dup_string(value, NULL);
105 case STICKER_DATA_TYPE_THUMBNAIL:
106 sticker_data->thumbnail = g_variant_dup_string(value, NULL);
108 case STICKER_DATA_TYPE_DESCRIPTION:
109 sticker_data->description = g_variant_dup_string(value, NULL);
111 case STICKER_DATA_TYPE_GROUP:
112 sticker_data->group = g_variant_dup_string(value, NULL);
114 case STICKER_DATA_TYPE_DATE:
115 sticker_data->date = g_variant_dup_string(value, NULL);
117 case STICKER_DATA_TYPE_DISP_TYPE:
118 sticker_data->disp_type = g_variant_get_int32(value);
125 while (g_variant_iter_loop (keyword_iter, "(s)", &keyword)) {
126 sticker_data->keyword = g_list_append(sticker_data->keyword, strdup((const char *)keyword));
130 g_variant_unref(value);
132 g_variant_iter_free(info_iter);
133 g_variant_iter_free(keyword_iter);
136 static void _free_sticker_data(sticker_data_h sticker_data)
138 if (sticker_data->app_id) {
139 free(sticker_data->app_id);
140 sticker_data->app_id = NULL;
143 if (sticker_data->uri) {
144 free(sticker_data->uri);
145 sticker_data->uri = NULL;
148 if (sticker_data->thumbnail) {
149 free(sticker_data->thumbnail);
150 sticker_data->thumbnail = NULL;
153 if (sticker_data->keyword) {
154 g_list_free_full(sticker_data->keyword, free);
155 sticker_data->keyword = NULL;
158 if (sticker_data->group) {
159 free(sticker_data->group);
160 sticker_data->group = NULL;
163 if (sticker_data->description) {
164 free(sticker_data->description);
165 sticker_data->description = NULL;
168 if (sticker_data->date) {
169 free(sticker_data->date);
170 sticker_data->date = NULL;
177 static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVariant *body)
180 g_variant_get(body, "(i)", &ret);
183 provider_handle->insert_finished_cb(STICKER_ERROR_NONE, provider_handle->insert_finished_cb_user_data);
185 provider_handle->insert_finished_cb(STICKER_ERROR_OPERATION_FAILED, provider_handle->insert_finished_cb_user_data);
190 static void _handle_sticker_consumer_cb(GDBusConnection *connection,
191 const gchar *sender_name,
192 const gchar *object_path,
193 const gchar *interface_name,
194 const gchar *signal_name,
195 GVariant *parameters,
198 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
199 sticker_consumer_h consumer_handle = (sticker_consumer_h)user_data;
201 if (consumer_handle == NULL) {
202 LOGE("consumer handle is not available");
206 if (parameters == NULL) {
207 LOGE("failed to get sticker info");
211 if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) {
212 if (consumer_handle->event_cb != NULL) {
213 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
216 GVariantIter *info_iter = NULL;
217 GVariantIter *keyword_iter = NULL;
219 g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter);
220 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
221 consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data);
224 g_variant_iter_free(info_iter);
227 g_variant_iter_free(keyword_iter);
229 _free_sticker_data(sticker_data);
234 #if 0 // Receive the sticker information by asynchronous communication.
235 if (g_strcmp0(signal_name, "send_group_list") == 0) {
236 if (consumer_handle->group_foreach_cb != NULL)
237 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
239 } else if (g_strcmp0(signal_name, "send_keyword_list") == 0) {
240 if (consumer_handle->keyword_foreach_cb != NULL)
241 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
245 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
248 LOGE("failed to allocate memory");
252 _get_sticker_info_from_gvariant(parameters, sticker_data);
254 if (g_strcmp0(signal_name, "send_all_sticker_info") == 0) {
255 if (consumer_handle->data_foreach_cb != NULL)
256 consumer_handle->data_foreach_cb(sticker_data, consumer_handle->data_foreach_cb_user_data);
258 LOGW("No registered callback function");
259 } else if (g_strcmp0(signal_name, "send_sticker_info_by_keyword") == 0) {
260 if (consumer_handle->data_foreach_by_keyword_cb != NULL)
261 consumer_handle->data_foreach_by_keyword_cb(sticker_data, consumer_handle->data_foreach_by_keyword_cb_user_data);
263 LOGW("No registered callback function");
264 } else if (g_strcmp0(signal_name, "send_sticker_info_by_group") == 0) {
265 if (consumer_handle->data_foreach_by_group_cb != NULL)
266 consumer_handle->data_foreach_by_group_cb(sticker_data, consumer_handle->data_foreach_by_group_cb_user_data);
268 LOGW("No registered callback function");
269 } else if (g_strcmp0(signal_name, "send_sticker_info_by_type") == 0) {
270 if (consumer_handle->data_foreach_by_type_cb != NULL)
271 consumer_handle->data_foreach_by_type_cb(sticker_data, consumer_handle->data_foreach_by_type_cb_user_data);
273 LOGW("No registered callback function");
276 _free_sticker_data(sticker_data);
281 static void _handle_sticker_provider_cb(GDBusConnection *connection,
282 const gchar *sender_name,
283 const gchar *object_path,
284 const gchar *interface_name,
285 const gchar *signal_name,
286 GVariant *parameters,
289 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
290 sticker_provider_h provider_handle = (sticker_provider_h)user_data;
292 if (provider_handle == NULL) {
293 LOGE("provider handle is not available");
297 if (parameters == NULL) {
298 LOGE("failed to get sticker info");
302 if (g_strcmp0(signal_name, "send_insert_result") == 0) {
303 if (provider_handle->insert_finished_cb != NULL)
304 _call_insert_finished_cb(provider_handle, parameters);
307 #if 0 // Receive the sticker information by asynchronous communication.
308 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
311 LOGE("failed to allocate memory");
315 _get_sticker_info_from_gvariant(parameters, sticker_data);
317 if (g_strcmp0(signal_name, "send_sticker_info_by_appid") == 0) {
318 if (provider_handle->data_foreach_cb != NULL)
319 provider_handle->data_foreach_cb(sticker_data, provider_handle->data_foreach_cb_user_data);
321 LOGW("No registered callback function");
324 _free_sticker_data(sticker_data);
328 static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
330 int ret = STICKER_CLIENT_ERROR_NONE;
331 if (*monitor_id == 0) {
333 if (lib == STICKER_CLIENT_LIB_CONSUMER)
334 id = g_dbus_connection_signal_subscribe(gdbus_connection,
336 STICKER_CONSUMER_INTERFACE_NAME,
340 G_DBUS_SIGNAL_FLAGS_NONE,
341 _handle_sticker_consumer_cb,
344 else if (lib == STICKER_CLIENT_LIB_PROVIDER)
345 id = g_dbus_connection_signal_subscribe(gdbus_connection,
347 STICKER_PROVIDER_INTERFACE_NAME,
351 G_DBUS_SIGNAL_FLAGS_NONE,
352 _handle_sticker_provider_cb,
358 ret = STICKER_CLIENT_ERROR_IO_ERROR;
359 LOGE("g_dbus_connection_signal_subscribe() failed");
369 static GDBusMessage *_get_gdbus_message(GVariant *body, const char *cmd)
371 GDBusMessage *message = NULL;
372 message = g_dbus_message_new_method_call(
375 STICKER_INTERFACE_NAME,
380 LOGE("Failed to create a new gdbus message");
382 g_variant_unref(body);
388 g_dbus_message_set_body(message, body);
393 static int _send_gdbus_sync_message(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
395 int ret = STICKER_CLIENT_ERROR_NONE;
398 *reply = g_dbus_connection_send_message_with_reply_sync(
401 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
409 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
411 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
412 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
413 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
420 if (g_dbus_message_to_gerror(*reply, &err)) {
422 LOGE("error message = %s, code = %d", err->message, err->code);
423 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
424 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
432 LOGD("Send a message to server(cmd : %s)", cmd);
433 return STICKER_CLIENT_ERROR_NONE;
436 static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
438 int ret = STICKER_CLIENT_ERROR_NONE;
439 GDBusMessage *msg = NULL;
441 msg = _get_gdbus_message(body, cmd);
443 return STICKER_CLIENT_ERROR_IO_ERROR;
445 ret = _send_gdbus_sync_message(gdbus_connection, msg, reply, cmd);
453 static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
455 int ret = STICKER_CLIENT_ERROR_NONE;
456 GDBusMessage *msg = NULL;
459 msg = _get_gdbus_message(body, cmd);
461 return STICKER_CLIENT_ERROR_IO_ERROR;
463 g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
470 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
471 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
473 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
474 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
484 static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib)
487 GDBusMessage *reply = NULL;
488 GVariant *reply_body = NULL;
490 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register");
491 if (ret != STICKER_CLIENT_ERROR_NONE) {
492 LOGE("_send_sync_message() failed : %d", ret);
496 reply_body = g_dbus_message_get_body(reply);
497 g_variant_get(reply_body, "(i)", server_watcher_id);
500 g_object_unref(reply);
502 is_server_started = 1;
506 static void _on_name_appeared(GDBusConnection *connection,
508 const gchar *name_owner,
511 if (is_server_started == 0) {
512 int *watcher_id = (int *)user_data;
513 _monitor_register(connection, watcher_id, last_req_lib);
518 static void _on_name_vanished(GDBusConnection *connection,
522 is_server_started = 0;
526 int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
527 int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
532 ret = _dbus_init(gdbus_connection);
533 if (ret != STICKER_CLIENT_ERROR_NONE) {
535 LOGE("_dbus_init() failed : %d", ret);
540 ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
541 if (ret != STICKER_CLIENT_ERROR_NONE) {
543 LOGE("_dbus_signal_init() failed : %d", ret);
548 ret = _monitor_register(*gdbus_connection, server_watcher_id, lib);
549 if (ret != STICKER_CLIENT_ERROR_NONE) {
551 LOGE("_monitor_register() failed : %d", ret);
556 if (*server_monitor_id == 0) {
557 *server_monitor_id = g_bus_watch_name_on_connection(
560 G_BUS_NAME_WATCHER_FLAGS_NONE,
565 if (*server_monitor_id == 0) {
567 g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
569 LOGE("Failed to get identifier");
570 return STICKER_CLIENT_ERROR_IO_ERROR;
575 return STICKER_CLIENT_ERROR_NONE;
578 int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib)
582 if (server_watcher_id) {
583 ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister");
584 if (ret != STICKER_CLIENT_ERROR_NONE) {
585 LOGE("Failed to unregister sticker service");
589 *server_watcher_id = 0;
592 if (*server_monitor_id) {
593 g_bus_unwatch_name(*server_monitor_id);
594 *server_monitor_id = 0;
598 g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
602 return STICKER_CLIENT_ERROR_NONE;
605 static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
608 LOGE("keyword doesn't exist");
612 g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
615 int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
619 GDBusMessage *reply = NULL;
620 GVariant *reply_body = NULL;
621 GVariantBuilder *info_builder;
622 GVariantBuilder *keyword_builder;
624 if (!sticker_data->app_id || (sticker_data->type < 1) || !sticker_data->uri || !sticker_data->group || !sticker_data->keyword)
625 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
627 info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
628 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_data->app_id));
629 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_data->type));
630 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_data->uri));
631 if (sticker_data->thumbnail)
632 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_data->thumbnail));
633 if (sticker_data->description)
634 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
635 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
636 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
638 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
639 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
641 ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
642 if (ret != STICKER_CLIENT_ERROR_NONE) {
643 LOGW("Failed to save sticker info");
647 reply_body = g_dbus_message_get_body(reply);
648 g_variant_get(reply_body, "(i)", &ret_id);
649 sticker_data->sticker_info_id = ret_id;
651 LOGD("ret_id : %d", ret_id);
653 g_variant_builder_unref(info_builder);
654 g_variant_builder_unref(keyword_builder);
657 g_variant_unref(reply_body);
660 g_object_unref(reply);
665 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
669 ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
670 if (ret != STICKER_CLIENT_ERROR_NONE)
671 LOGE("failed to send json path");
676 int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id)
679 GDBusMessage *reply = NULL;
681 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
682 if (ret != STICKER_CLIENT_ERROR_NONE)
683 LOGE("failed to delete sticker info");
686 g_object_unref(reply);
691 int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri)
694 GDBusMessage *reply = NULL;
696 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "delete_sticker_info_by_uri");
697 if (ret != STICKER_CLIENT_ERROR_NONE)
698 LOGE("failed to delete sticker info");
701 g_object_unref(reply);
706 int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
709 bool is_updated = false;
710 GDBusMessage *reply = NULL;
711 GVariant *reply_body = NULL;
712 sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
715 LOGE("failed to allocate memory");
716 return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
719 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
720 if (ret == STICKER_CLIENT_ERROR_NONE) {
721 reply_body = g_dbus_message_get_body(reply);
722 GVariantIter *info_iter = NULL;
723 GVariantIter *keyword_iter = NULL;
725 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
726 _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data);
729 g_variant_iter_free(info_iter);
732 g_variant_iter_free(keyword_iter);
734 LOGW("failed to get sticker info");
737 g_object_unref(reply);
741 if (sticker_data->uri) {
743 char *conv_path = NULL;
744 if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
745 len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
746 conv_path = (char *)calloc(len, sizeof(char));
748 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
750 conv_path = strdup(sticker_data->uri);
752 if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
753 LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
755 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
756 if (ret == STICKER_CLIENT_ERROR_NONE) {
757 reply_body = g_dbus_message_get_body(reply);
758 g_variant_get(reply_body, "(i)", &is_exist);
761 LOGE("file already exists");
762 ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
767 LOGE("failed to check file exists");
772 ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri");
773 if (ret != STICKER_CLIENT_ERROR_NONE) {
774 LOGE("failed to update sticker uri");
783 if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
784 LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
785 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
786 if (ret != STICKER_CLIENT_ERROR_NONE) {
787 LOGE("failed to update sticker type");
793 if (sticker_data->thumbnail) {
794 int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
795 char *conv_path = (char *)calloc(len, sizeof(char));
797 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
798 if (strcmp(conv_path, origin_data->thumbnail) != 0)
800 LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
801 ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
802 if (ret != STICKER_CLIENT_ERROR_NONE)
804 LOGE("failed to update sticker thumbnail");
814 if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
815 LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
816 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
817 if (ret != STICKER_CLIENT_ERROR_NONE) {
818 LOGE("failed to update sticker description");
824 if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
825 LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
826 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
827 if (ret != STICKER_CLIENT_ERROR_NONE) {
828 LOGE("failed to update sticker group");
834 if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
835 LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
836 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
837 if (ret != STICKER_CLIENT_ERROR_NONE) {
838 LOGE("failed to update sticker display type");
844 if (sticker_data->keyword) {
845 GVariantBuilder *keyword_builder;
846 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
847 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
848 ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
849 if (ret != STICKER_CLIENT_ERROR_NONE)
850 LOGE("failed to update sticker keyword");
853 g_variant_builder_unref(keyword_builder);
857 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event");
860 _free_sticker_data(origin_data);
863 g_variant_unref(reply_body);
866 g_object_unref(reply);
871 int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id)
874 GDBusMessage *reply = NULL;
875 GVariant *reply_body = NULL;
876 GVariantIter *info_iter = NULL;
877 GVariantIter *keyword_iter = NULL;
879 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
880 if (ret == STICKER_CLIENT_ERROR_NONE) {
881 reply_body = g_dbus_message_get_body(reply);
882 sticker_data->sticker_info_id = record_id;
884 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
885 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
888 g_variant_unref(reply_body);
891 g_variant_iter_free(info_iter);
894 g_variant_iter_free(keyword_iter);
898 g_object_unref(reply);
903 int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
906 GDBusMessage *reply = NULL;
907 GVariantIter *iter = NULL;
908 GVariant *reply_body = NULL;
911 if (group_list == NULL) {
912 LOGE("group_list is invalid");
913 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
916 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_list");
917 if (ret == STICKER_CLIENT_ERROR_NONE) {
918 reply_body = g_dbus_message_get_body(reply);
919 g_variant_get(reply_body, "(a(s))", &iter);
922 LOGD("failed to get iter");
923 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
926 while (g_variant_iter_loop (iter, "(s)", &group)) {
927 *group_list = g_list_append(*group_list, strdup((const char *)group));
930 g_variant_iter_free(iter);
934 g_variant_unref(reply_body);
937 g_object_unref(reply);
942 int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
945 GDBusMessage *reply = NULL;
946 GVariantIter *iter = NULL;
947 GVariant *reply_body = NULL;
948 char *keyword = NULL;
950 if (keyword_list == NULL) {
951 LOGE("keyword_list is invalid");
952 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
955 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_keyword_list");
956 if (ret == STICKER_CLIENT_ERROR_NONE) {
957 reply_body = g_dbus_message_get_body(reply);
958 g_variant_get(reply_body, "(a(s))", &iter);
961 LOGD("failed to get iter");
962 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
965 while (g_variant_iter_loop (iter, "(s)", &keyword)) {
966 *keyword_list = g_list_append(*keyword_list, strdup((const char *)keyword));
969 g_variant_iter_free(iter);
973 g_variant_unref(reply_body);
976 g_object_unref(reply);
981 int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count)
984 GDBusMessage *reply = NULL;
985 GVariant *reply_body = NULL;
987 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
988 if (ret == STICKER_CLIENT_ERROR_NONE) {
989 reply_body = g_dbus_message_get_body(reply);
990 g_variant_get(reply_body, "(i)", count);
994 g_variant_unref(reply_body);
997 g_object_unref(reply);
1002 int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
1005 GDBusMessage *reply = NULL;
1006 GVariant *reply_body = NULL;
1008 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info");
1009 if (ret == STICKER_CLIENT_ERROR_NONE) {
1010 reply_body = g_dbus_message_get_body(reply);
1011 g_variant_get(reply_body, "(a(i))", id_iter);
1015 g_variant_unref(reply_body);
1018 g_object_unref(reply);
1023 int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
1026 GDBusMessage *reply = NULL;
1027 GVariant *reply_body = NULL;
1029 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
1030 if (ret == STICKER_CLIENT_ERROR_NONE) {
1031 reply_body = g_dbus_message_get_body(reply);
1032 g_variant_get(reply_body, "(a(i))", id_iter);
1036 g_variant_unref(reply_body);
1039 g_object_unref(reply);
1044 int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter)
1047 GDBusMessage *reply = NULL;
1048 GVariant *reply_body = NULL;
1050 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type");
1051 if (ret == STICKER_CLIENT_ERROR_NONE) {
1052 reply_body = g_dbus_message_get_body(reply);
1053 g_variant_get(reply_body, "(a(i))", id_iter);
1057 g_variant_unref(reply_body);
1060 g_object_unref(reply);
1065 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)
1068 GDBusMessage *reply = NULL;
1069 GVariant *reply_body = NULL;
1071 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group");
1072 if (ret == STICKER_CLIENT_ERROR_NONE) {
1073 reply_body = g_dbus_message_get_body(reply);
1074 g_variant_get(reply_body, "(a(i))", id_iter);
1078 g_variant_unref(reply_body);
1081 g_object_unref(reply);
1086 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)
1089 GDBusMessage *reply = NULL;
1090 GVariant *reply_body = NULL;
1092 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword");
1093 if (ret == STICKER_CLIENT_ERROR_NONE) {
1094 reply_body = g_dbus_message_get_body(reply);
1095 g_variant_get(reply_body, "(a(i))", id_iter);
1099 g_variant_unref(reply_body);
1102 g_object_unref(reply);
1107 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)
1110 GDBusMessage *reply = NULL;
1111 GVariant *reply_body = NULL;
1113 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type");
1114 if (ret == STICKER_CLIENT_ERROR_NONE) {
1115 reply_body = g_dbus_message_get_body(reply);
1116 g_variant_get(reply_body, "(a(i))", id_iter);
1120 g_variant_unref(reply_body);
1123 g_object_unref(reply);
1128 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)
1131 GDBusMessage *reply = NULL;
1132 GVariantIter *iter = NULL;
1133 GVariant *reply_body = NULL;
1136 if (group_list == NULL) {
1137 LOGE("group_list is invalid");
1138 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
1141 ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
1142 if (ret == STICKER_CLIENT_ERROR_NONE) {
1143 reply_body = g_dbus_message_get_body(reply);
1144 g_variant_get(reply_body, "(a(s))", &iter);
1147 LOGD("failed to get iter");
1148 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
1151 while (g_variant_iter_loop (iter, "(s)", &group)) {
1152 *group_list = g_list_append(*group_list, strdup((const char *)group));
1155 g_variant_iter_free(iter);
1159 g_variant_unref(reply_body);
1162 g_object_unref(reply);
1167 int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result)
1170 GDBusMessage *reply = NULL;
1171 GVariant *reply_body = NULL;
1173 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "check_file_exists");
1174 if (ret == STICKER_CLIENT_ERROR_NONE) {
1175 reply_body = g_dbus_message_get_body(reply);
1176 g_variant_get(reply_body, "(i)", result);
1180 g_variant_unref(reply_body);
1183 g_object_unref(reply);
1188 int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id)
1191 GDBusMessage *reply = NULL;
1193 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info");
1194 if (ret != STICKER_CLIENT_ERROR_NONE)
1195 LOGE("failed to insert recent sticker info");
1198 g_object_unref(reply);
1203 int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter)
1206 GDBusMessage *reply = NULL;
1207 GVariant *reply_body = NULL;
1209 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info");
1210 if (ret == STICKER_CLIENT_ERROR_NONE) {
1211 reply_body = g_dbus_message_get_body(reply);
1212 g_variant_get(reply_body, "(a(i))", id_iter);
1216 g_variant_unref(reply_body);
1219 g_object_unref(reply);
1224 int sticker_dbus_get_sticker_info_by_uri(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, const char *uri)
1227 GDBusMessage *reply = NULL;
1228 GVariant *reply_body = NULL;
1229 GVariantIter *info_iter = NULL;
1230 GVariantIter *keyword_iter = NULL;
1232 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "get_sticker_info_by_uri");
1233 if (ret == STICKER_CLIENT_ERROR_NONE) {
1234 reply_body = g_dbus_message_get_body(reply);
1235 g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
1236 _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
1239 g_variant_unref(reply_body);
1242 g_variant_iter_free(info_iter);
1245 g_variant_iter_free(keyword_iter);
1249 g_object_unref(reply);