2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Contact: Junkyu Han <junkyu.han@samsung.com>
6 * Licensed under the Flora License, Version 1.1 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license/
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include "ttsd-worker-lib.h"
24 #include "tizen-things-lib-dbus.h"
26 #define TTSD_WORKER_DBUS_NAME "ttsd.worker.dbus"
27 #define TTSD_WORKER_DBUS_OBJECT_PATH "/ttsd_worker_dbus_object"
28 #define TTSD_WORKER_DBUS_INTERFACE "ttsd.worker.dbus"
31 GCancellable *cancellable;
32 TtsdWorkerDbus *dbus_object;
33 ttsd_worker_submit_report_completed_cb completed_cb;
34 void *completed_cb_data;
37 static dbus_h *__make_dbus_connection(void);
38 static void __destroy_dbus_connection(dbus_h *h);
39 static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpointer user_data);
41 static void __destroy_dbus_connection(dbus_h *h)
43 _D("Destory the DBus Connection");
45 g_cancellable_cancel(h->cancellable);
46 g_object_unref(h->cancellable);
49 g_object_unref(h->dbus_object);
52 static dbus_h *__make_dbus_connection(void)
57 _D("Make the DBus Connection");
59 h = g_try_malloc0(sizeof(dbus_h));
63 h->cancellable = g_cancellable_new();
65 h->dbus_object = ttsd_worker_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
66 G_DBUS_PROXY_FLAGS_NONE,
67 TTSD_WORKER_DBUS_NAME,
68 TTSD_WORKER_DBUS_OBJECT_PATH,
71 if (!h->dbus_object) {
72 _E("Fail to create the proxy object because of %s", error->message);
74 __destroy_dbus_connection(h);
81 static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
83 GError *g_error = NULL;
84 dbus_h *h = user_data;
87 const char *result = NULL;
92 _E("There's no user_data for dbus_h");
96 ret = ttsd_worker_dbus_call_ttsd_worker_submit_report_finish(h->dbus_object, &ret_val, res, &g_error);
98 _E("DBus proxy call is failed[%s]", g_error->message);
99 result = "Failed to submit report";
100 g_error_free(g_error);
103 _E("Submit report is failed");
104 result = "Failed to submit report";
106 result = "Success to submit report";
110 h->completed_cb(result, h->completed_cb_data);
112 __destroy_dbus_connection(h);
115 int ttsd_worker_submit_report(const char *report, ttsd_worker_submit_report_completed_cb completed_cb, void *user_data)
119 h = __make_dbus_connection();
121 _E("Failed to make dbus connection");
125 h->completed_cb = completed_cb;
126 h->completed_cb_data = user_data;
128 ttsd_worker_dbus_call_ttsd_worker_submit_report(h->dbus_object,
131 (GAsyncReadyCallback) __submit_completed_cb,
137 int ttsd_worker_submit_report_sync(const char *report)
140 GError *error = NULL;
142 gboolean ret = FALSE;
144 h = __make_dbus_connection();
146 _E("Failed to make dbus connection");
150 ret = ttsd_worker_dbus_call_ttsd_worker_submit_report_sync(h->dbus_object,
156 _E("DBus proxy call is failed[%s]", error->message);
161 _E("Submit report is failed");
166 __destroy_dbus_connection(h);