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 tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data")
28 static int is_server_started = 0;
30 static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
32 LOGD("name : %s, name_owner : %s", name, name_owner);
36 static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
38 LOGD("name : %s", name);
42 static int _dbus_init(GDBusConnection **gdbus_connection)
47 if (*gdbus_connection == NULL) {
48 GDBusConnection *conn = NULL;
49 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
52 LOGE("g_bus_get_sync error message = %s", error->message);
55 return STICKER_CLIENT_ERROR_IO_ERROR;
57 *gdbus_connection = conn;
60 LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
61 watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
63 G_BUS_NAME_WATCHER_FLAGS_NONE,
68 LOGD("watch_id : %d", watch_id);
70 LOGE("Failed to get identifier");
71 return STICKER_CLIENT_ERROR_IO_ERROR;
74 return STICKER_CLIENT_ERROR_NONE;
77 static void _get_sticker_info_from_gvariant(GVariant *body, sticker_data_h sticker_data)
80 GVariant *value = NULL;
81 GVariantIter *info_iter = NULL;
82 GVariantIter *keyword_iter = NULL;
85 g_variant_get(body, "(a{iv}a(s))", &info_iter, &keyword_iter);
87 if (!info_iter || !keyword_iter) {
88 LOGD("failed to get iter");
92 while (g_variant_iter_loop (info_iter, "{iv}", &key, &value)) {
94 case STICKER_DATA_TYPE_APP_ID:
95 sticker_data->app_id = g_variant_dup_string(value, NULL);
97 case STICKER_DATA_TYPE_URI_TYPE:
98 sticker_data->type = g_variant_get_int32(value);
100 case STICKER_DATA_TYPE_URI:
101 sticker_data->uri = g_variant_dup_string(value, NULL);
103 case STICKER_DATA_TYPE_THUMBNAIL:
104 sticker_data->thumbnail = g_variant_dup_string(value, NULL);
106 case STICKER_DATA_TYPE_DESCRIPTION:
107 sticker_data->description = g_variant_dup_string(value, NULL);
109 case STICKER_DATA_TYPE_GROUP:
110 sticker_data->group = g_variant_dup_string(value, NULL);
112 case STICKER_DATA_TYPE_DATE:
113 sticker_data->date = g_variant_dup_string(value, NULL);
115 case STICKER_DATA_TYPE_DISP_TYPE:
116 sticker_data->disp_type = g_variant_get_int32(value);
123 while (g_variant_iter_loop (keyword_iter, "(s)", &keyword)) {
124 sticker_data->keyword = g_list_append(sticker_data->keyword, strdup((const char *)keyword));
128 g_variant_unref(value);
130 g_variant_iter_free(info_iter);
131 g_variant_iter_free(keyword_iter);
134 static void _free_sticker_data(sticker_data_h sticker_data)
136 if (sticker_data->app_id) {
137 free(sticker_data->app_id);
138 sticker_data->app_id = NULL;
141 if (sticker_data->uri) {
142 free(sticker_data->uri);
143 sticker_data->uri = NULL;
146 if (sticker_data->thumbnail) {
147 free(sticker_data->thumbnail);
148 sticker_data->thumbnail = NULL;
151 if (sticker_data->keyword) {
152 g_list_free_full(sticker_data->keyword, free);
153 sticker_data->keyword = NULL;
156 if (sticker_data->group) {
157 free(sticker_data->group);
158 sticker_data->group = NULL;
161 if (sticker_data->description) {
162 free(sticker_data->description);
163 sticker_data->description = NULL;
166 if (sticker_data->date) {
167 free(sticker_data->date);
168 sticker_data->date = NULL;
175 static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVariant *body)
178 g_variant_get(body, "(i)", &ret);
181 provider_handle->insert_finished_cb(STICKER_ERROR_NONE, provider_handle->insert_finished_cb_user_data);
183 provider_handle->insert_finished_cb(STICKER_ERROR_OPERATION_FAILED, provider_handle->insert_finished_cb_user_data);
188 static void _handle_sticker_consumer_cb(GDBusConnection *connection,
189 const gchar *sender_name,
190 const gchar *object_path,
191 const gchar *interface_name,
192 const gchar *signal_name,
193 GVariant *parameters,
196 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
197 sticker_consumer_h consumer_handle = (sticker_consumer_h)user_data;
199 if (consumer_handle == NULL) {
200 LOGE("consumer handle is not available");
204 if (parameters == NULL) {
205 LOGE("failed to get sticker info");
209 #if 0 // Receive the sticker information by asynchronous communication.
210 if (g_strcmp0(signal_name, "send_group_list") == 0) {
211 if (consumer_handle->group_foreach_cb != NULL)
212 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
214 } else if (g_strcmp0(signal_name, "send_keyword_list") == 0) {
215 if (consumer_handle->keyword_foreach_cb != NULL)
216 _call_sticker_list_cb(consumer_handle, parameters, signal_name);
220 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
223 LOGE("failed to allocate memory");
227 _get_sticker_info_from_gvariant(parameters, sticker_data);
229 if (g_strcmp0(signal_name, "send_all_sticker_info") == 0) {
230 if (consumer_handle->data_foreach_cb != NULL)
231 consumer_handle->data_foreach_cb(sticker_data, consumer_handle->data_foreach_cb_user_data);
233 LOGW("No registered callback function");
234 } else if (g_strcmp0(signal_name, "send_sticker_info_by_keyword") == 0) {
235 if (consumer_handle->data_foreach_by_keyword_cb != NULL)
236 consumer_handle->data_foreach_by_keyword_cb(sticker_data, consumer_handle->data_foreach_by_keyword_cb_user_data);
238 LOGW("No registered callback function");
239 } else if (g_strcmp0(signal_name, "send_sticker_info_by_group") == 0) {
240 if (consumer_handle->data_foreach_by_group_cb != NULL)
241 consumer_handle->data_foreach_by_group_cb(sticker_data, consumer_handle->data_foreach_by_group_cb_user_data);
243 LOGW("No registered callback function");
244 } else if (g_strcmp0(signal_name, "send_sticker_info_by_type") == 0) {
245 if (consumer_handle->data_foreach_by_type_cb != NULL)
246 consumer_handle->data_foreach_by_type_cb(sticker_data, consumer_handle->data_foreach_by_type_cb_user_data);
248 LOGW("No registered callback function");
251 _free_sticker_data(sticker_data);
256 static void _handle_sticker_provider_cb(GDBusConnection *connection,
257 const gchar *sender_name,
258 const gchar *object_path,
259 const gchar *interface_name,
260 const gchar *signal_name,
261 GVariant *parameters,
264 LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
265 sticker_provider_h provider_handle = (sticker_provider_h)user_data;
267 if (provider_handle == NULL) {
268 LOGE("provider handle is not available");
272 if (parameters == NULL) {
273 LOGE("failed to get sticker info");
277 if (g_strcmp0(signal_name, "send_insert_result") == 0) {
278 if (provider_handle->insert_finished_cb != NULL)
279 _call_insert_finished_cb(provider_handle, parameters);
282 #if 0 // Receive the sticker information by asynchronous communication.
283 sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
286 LOGE("failed to allocate memory");
290 _get_sticker_info_from_gvariant(parameters, sticker_data);
292 if (g_strcmp0(signal_name, "send_sticker_info_by_appid") == 0) {
293 if (provider_handle->data_foreach_cb != NULL)
294 provider_handle->data_foreach_cb(sticker_data, provider_handle->data_foreach_cb_user_data);
296 LOGW("No registered callback function");
299 _free_sticker_data(sticker_data);
303 static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
305 int ret = STICKER_CLIENT_ERROR_NONE;
306 if (*monitor_id == 0) {
308 if (lib == STICKER_CLIENT_LIB_CONSUMER)
309 id = g_dbus_connection_signal_subscribe(gdbus_connection,
311 STICKER_CONSUMER_INTERFACE_NAME,
315 G_DBUS_SIGNAL_FLAGS_NONE,
316 _handle_sticker_consumer_cb,
319 else if (lib == STICKER_CLIENT_LIB_PROVIDER)
320 id = g_dbus_connection_signal_subscribe(gdbus_connection,
322 STICKER_PROVIDER_INTERFACE_NAME,
326 G_DBUS_SIGNAL_FLAGS_NONE,
327 _handle_sticker_provider_cb,
332 ret = STICKER_CLIENT_ERROR_IO_ERROR;
333 LOGE("g_dbus_connection_signal_subscribe() failed");
342 static GDBusMessage *_get_gbus_message(GVariant *body, const char *cmd)
344 GDBusMessage *message = NULL;
345 message = g_dbus_message_new_method_call(
348 STICKER_INTERFACE_NAME,
352 LOGE("Failed to create a new gdbus message");
354 g_variant_unref(body);
359 g_dbus_message_set_body(message, body);
364 static int _send_gdbus_sync_message(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
366 int ret = STICKER_CLIENT_ERROR_NONE;
369 *reply = g_dbus_connection_send_message_with_reply_sync(
372 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
379 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
381 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
382 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
383 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
389 if (g_dbus_message_to_gerror(*reply, &err)) {
390 LOGE("error message = %s, code = %d", err->message, err->code);
391 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
392 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
399 LOGD("Send a message to server(cmd : %s)", cmd);
400 return STICKER_CLIENT_ERROR_NONE;
403 static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
405 int ret = STICKER_CLIENT_ERROR_NONE;
406 GDBusMessage *msg = NULL;
408 msg = _get_gbus_message(body, cmd);
410 return STICKER_CLIENT_ERROR_IO_ERROR;
412 ret = _send_gdbus_sync_message(gdbus_connection, msg, reply, cmd);
420 static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
422 int ret = STICKER_CLIENT_ERROR_NONE;
423 GDBusMessage *msg = NULL;
426 msg = _get_gbus_message(body, cmd);
428 return STICKER_CLIENT_ERROR_IO_ERROR;
430 g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
436 ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
437 LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
439 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
440 ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
449 static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id)
452 GDBusMessage *reply = NULL;
453 GVariant *reply_body = NULL;
455 ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "sticker_service_register");
457 if (ret != STICKER_CLIENT_ERROR_NONE) {
458 LOGE("_send_sync_message() failed : %d", ret);
462 reply_body = g_dbus_message_get_body(reply);
463 g_variant_get(reply_body, "(i)", server_watcher_id);
466 g_object_unref(reply);
468 is_server_started = 1;
472 static void _on_name_appeared(GDBusConnection *connection,
474 const gchar *name_owner,
477 if (is_server_started == 0) {
478 int *watcher_id = (int *)user_data;
479 _monitor_register(connection, watcher_id);
484 static void _on_name_vanished(GDBusConnection *connection,
488 is_server_started = 0;
492 int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
493 int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
497 ret = _dbus_init(gdbus_connection);
498 if (ret != STICKER_CLIENT_ERROR_NONE) {
499 LOGE("_dbus_init() failed : %d", ret);
503 ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
504 if (ret != STICKER_CLIENT_ERROR_NONE) {
505 LOGE("_dbus_signal_init() failed : %d", ret);
509 ret = _monitor_register(*gdbus_connection, server_watcher_id);
510 if (ret != STICKER_CLIENT_ERROR_NONE) {
511 LOGE("_monitor_register() failed : %d", ret);
515 if (*server_monitor_id == 0) {
516 *server_monitor_id = g_bus_watch_name_on_connection(
519 G_BUS_NAME_WATCHER_FLAGS_NONE,
524 if (*server_monitor_id == 0) {
525 g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
527 LOGE("Failed to get identifier");
528 return STICKER_CLIENT_ERROR_IO_ERROR;
532 return STICKER_CLIENT_ERROR_NONE;
535 int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id)
539 if (server_watcher_id) {
540 ret = _send_async_message(gdbus_connection, g_variant_new("(i)", *server_watcher_id), "sticker_service_unregister");
541 if (ret != STICKER_CLIENT_ERROR_NONE) {
542 LOGE("Failed to unregister sticker service");
546 *server_watcher_id = 0;
549 if (*server_monitor_id) {
550 g_bus_unwatch_name(*server_monitor_id);
551 *server_monitor_id = 0;
555 g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
559 return STICKER_CLIENT_ERROR_NONE;
562 static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
565 LOGE("keyword doesn't exist");
569 g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
572 int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
576 GDBusMessage *reply = NULL;
577 GVariant *reply_body = NULL;
578 GVariantBuilder *info_builder;
579 GVariantBuilder *keyword_builder;
581 if (!sticker_data->app_id || (sticker_data->type < 1) || !sticker_data->uri || !sticker_data->group || !sticker_data->keyword)
582 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
584 info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
585 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_data->app_id));
586 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_data->type));
587 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_data->uri));
588 if (sticker_data->thumbnail)
589 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_data->thumbnail));
590 if (sticker_data->description)
591 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
592 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
593 g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
595 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
596 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
598 ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
599 if (ret != STICKER_CLIENT_ERROR_NONE) {
600 LOGW("Failed to save sticker info");
604 reply_body = g_dbus_message_get_body(reply);
605 g_variant_get(reply_body, "(i)", &ret_id);
606 sticker_data->sticker_info_id = ret_id;
608 LOGD("ret_id : %d", ret_id);
610 g_variant_builder_unref(info_builder);
611 g_variant_builder_unref(keyword_builder);
614 g_variant_unref(reply_body);
617 g_object_unref(reply);
622 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
626 ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
627 if (ret != STICKER_CLIENT_ERROR_NONE)
628 LOGE("failed to send json path");
633 int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id)
636 GDBusMessage *reply = NULL;
638 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
639 if (ret != STICKER_CLIENT_ERROR_NONE)
640 LOGE("failed to delete sticker info");
643 g_object_unref(reply);
648 int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri)
651 GDBusMessage *reply = NULL;
653 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "delete_sticker_info_by_uri");
654 if (ret != STICKER_CLIENT_ERROR_NONE)
655 LOGE("failed to delete sticker info");
658 g_object_unref(reply);
663 int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
666 GDBusMessage *reply = NULL;
667 GVariant *reply_body = NULL;
668 sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
671 LOGE("failed to allocate memory");
672 return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
675 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
676 if (ret == STICKER_CLIENT_ERROR_NONE) {
677 reply_body = g_dbus_message_get_body(reply);
678 _get_sticker_info_from_gvariant(reply_body, origin_data);
680 LOGW("failed to get sticker info");
683 g_object_unref(reply);
687 if (sticker_data->uri) {
689 char *conv_path = NULL;
690 if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
691 len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
692 conv_path = (char *)calloc(len, sizeof(char));
694 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
696 conv_path = strdup(sticker_data->uri);
698 if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
699 LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
701 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
702 if (ret == STICKER_CLIENT_ERROR_NONE) {
703 reply_body = g_dbus_message_get_body(reply);
704 g_variant_get(reply_body, "(i)", &is_exist);
707 LOGE("file already exists");
708 ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
713 LOGE("failed to check file exists");
718 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");
719 if (ret != STICKER_CLIENT_ERROR_NONE) {
720 LOGE("failed to update sticker uri");
728 if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
729 LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
730 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
731 if (ret != STICKER_CLIENT_ERROR_NONE) {
732 LOGE("failed to update sticker type");
737 if (sticker_data->thumbnail) {
738 int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
739 char *conv_path = (char *)calloc(len, sizeof(char));
741 snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
742 if (strcmp(conv_path, origin_data->thumbnail) != 0)
744 LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
745 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");
746 if (ret != STICKER_CLIENT_ERROR_NONE)
748 LOGE("failed to update sticker thumbnail");
757 if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
758 LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
759 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
760 if (ret != STICKER_CLIENT_ERROR_NONE) {
761 LOGE("failed to update sticker description");
766 if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
767 LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
768 ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
769 if (ret != STICKER_CLIENT_ERROR_NONE) {
770 LOGE("failed to update sticker group");
775 if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
776 LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
777 ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
778 if (ret != STICKER_CLIENT_ERROR_NONE) {
779 LOGE("failed to update sticker display type");
784 if (sticker_data->keyword) {
785 GVariantBuilder *keyword_builder;
786 keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
787 g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
788 ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
789 if (ret != STICKER_CLIENT_ERROR_NONE)
790 LOGE("failed to update sticker keyword");
791 g_variant_builder_unref(keyword_builder);
795 _free_sticker_data(origin_data);
798 g_variant_unref(reply_body);
801 g_object_unref(reply);
806 int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id)
809 GDBusMessage *reply = NULL;
810 GVariant *reply_body = NULL;
812 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
813 if (ret == STICKER_CLIENT_ERROR_NONE) {
814 reply_body = g_dbus_message_get_body(reply);
815 sticker_data->sticker_info_id = record_id;
816 _get_sticker_info_from_gvariant(reply_body, sticker_data);
819 g_variant_unref(reply_body);
823 g_object_unref(reply);
828 int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
831 GDBusMessage *reply = NULL;
832 GVariantIter *iter = NULL;
833 GVariant *reply_body = NULL;
836 if (group_list == NULL) {
837 LOGE("group_list is invalid");
838 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
841 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_list");
842 if (ret == STICKER_CLIENT_ERROR_NONE) {
843 reply_body = g_dbus_message_get_body(reply);
844 g_variant_get(reply_body, "(a(s))", &iter);
847 LOGD("failed to get iter");
848 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
851 while (g_variant_iter_loop (iter, "(s)", &group)) {
852 *group_list = g_list_append(*group_list, strdup((const char *)group));
855 g_variant_iter_free(iter);
859 g_variant_unref(reply_body);
862 g_object_unref(reply);
867 int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
870 GDBusMessage *reply = NULL;
871 GVariantIter *iter = NULL;
872 GVariant *reply_body = NULL;
873 char *keyword = NULL;
875 if (keyword_list == NULL) {
876 LOGE("keyword_list is invalid");
877 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
880 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_keyword_list");
881 if (ret == STICKER_CLIENT_ERROR_NONE) {
882 reply_body = g_dbus_message_get_body(reply);
883 g_variant_get(reply_body, "(a(s))", &iter);
886 LOGD("failed to get iter");
887 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
890 while (g_variant_iter_loop (iter, "(s)", &keyword)) {
891 *keyword_list = g_list_append(*keyword_list, strdup((const char *)keyword));
894 g_variant_iter_free(iter);
898 g_variant_unref(reply_body);
901 g_object_unref(reply);
906 int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count)
909 GDBusMessage *reply = NULL;
910 GVariant *reply_body = NULL;
912 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
913 if (ret == STICKER_CLIENT_ERROR_NONE) {
914 reply_body = g_dbus_message_get_body(reply);
915 g_variant_get(reply_body, "(i)", count);
919 g_variant_unref(reply_body);
922 g_object_unref(reply);
927 int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
930 GDBusMessage *reply = NULL;
931 GVariant *reply_body = NULL;
933 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info");
934 if (ret == STICKER_CLIENT_ERROR_NONE) {
935 reply_body = g_dbus_message_get_body(reply);
936 g_variant_get(reply_body, "(a(i))", &(*id_iter));
940 g_variant_unref(reply_body);
943 g_object_unref(reply);
948 int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
951 GDBusMessage *reply = NULL;
952 GVariant *reply_body = NULL;
954 ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
955 if (ret == STICKER_CLIENT_ERROR_NONE) {
956 reply_body = g_dbus_message_get_body(reply);
957 g_variant_get(reply_body, "(a(i))", &(*id_iter));
961 g_variant_unref(reply_body);
964 g_object_unref(reply);
969 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)
972 GDBusMessage *reply = NULL;
973 GVariant *reply_body = NULL;
975 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type");
976 if (ret == STICKER_CLIENT_ERROR_NONE) {
977 reply_body = g_dbus_message_get_body(reply);
978 g_variant_get(reply_body, "(a(i))", &(*id_iter));
982 g_variant_unref(reply_body);
985 g_object_unref(reply);
990 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)
993 GDBusMessage *reply = NULL;
994 GVariant *reply_body = NULL;
996 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group");
997 if (ret == STICKER_CLIENT_ERROR_NONE) {
998 reply_body = g_dbus_message_get_body(reply);
999 g_variant_get(reply_body, "(a(i))", &(*id_iter));
1003 g_variant_unref(reply_body);
1006 g_object_unref(reply);
1011 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)
1014 GDBusMessage *reply = NULL;
1015 GVariant *reply_body = NULL;
1017 ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword");
1018 if (ret == STICKER_CLIENT_ERROR_NONE) {
1019 reply_body = g_dbus_message_get_body(reply);
1020 g_variant_get(reply_body, "(a(i))", &(*id_iter));
1024 g_variant_unref(reply_body);
1027 g_object_unref(reply);
1032 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)
1035 GDBusMessage *reply = NULL;
1036 GVariant *reply_body = NULL;
1038 ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type");
1039 if (ret == STICKER_CLIENT_ERROR_NONE) {
1040 reply_body = g_dbus_message_get_body(reply);
1041 g_variant_get(reply_body, "(a(i))", &(*id_iter));
1045 g_variant_unref(reply_body);
1048 g_object_unref(reply);
1053 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)
1056 GDBusMessage *reply = NULL;
1057 GVariantIter *iter = NULL;
1058 GVariant *reply_body = NULL;
1061 if (group_list == NULL) {
1062 LOGE("group_list is invalid");
1063 return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
1066 ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
1067 if (ret == STICKER_CLIENT_ERROR_NONE) {
1068 reply_body = g_dbus_message_get_body(reply);
1069 g_variant_get(reply_body, "(a(s))", &iter);
1072 LOGD("failed to get iter");
1073 return STICKER_CLIENT_ERROR_OPERATION_FAILED;
1076 while (g_variant_iter_loop (iter, "(s)", &group)) {
1077 *group_list = g_list_append(*group_list, strdup((const char *)group));
1080 g_variant_iter_free(iter);
1084 g_variant_unref(reply_body);
1087 g_object_unref(reply);
1092 int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result)
1095 GDBusMessage *reply = NULL;
1096 GVariant *reply_body = NULL;
1098 ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "check_file_exists");
1099 if (ret == STICKER_CLIENT_ERROR_NONE) {
1100 reply_body = g_dbus_message_get_body(reply);
1101 g_variant_get(reply_body, "(i)", result);
1105 g_variant_unref(reply_body);
1108 g_object_unref(reply);
1113 int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id)
1116 GDBusMessage *reply = NULL;
1118 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info");
1119 if (ret != STICKER_CLIENT_ERROR_NONE)
1120 LOGE("failed to insert recent sticker info");
1123 g_object_unref(reply);
1128 int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter)
1131 GDBusMessage *reply = NULL;
1132 GVariant *reply_body = NULL;
1134 ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info");
1135 if (ret == STICKER_CLIENT_ERROR_NONE) {
1136 reply_body = g_dbus_message_get_body(reply);
1137 g_variant_get(reply_body, "(a(i))", &(*id_iter));
1141 g_variant_unref(reply_body);
1144 g_object_unref(reply);