2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
18 #include "tizen-things-daemon-dbus.h"
21 #include "ttd-worker-interface.h"
23 #define TTSD_DBUS_OBJECT_PATH "/ttsd_worker_dbus_object"
24 #define TTSD_DBUS_NAME "ttsd.worker.dbus"
26 struct _worker_interface_h {
28 GDBusObjectManagerServer *m_server;
29 TtsdWorkerDbus *dbus_obj;
32 static gboolean __received_from_worker(TtsdWorkerDbus *obj, GDBusMethodInvocation *context, gchar *report, void *user_data)
34 _D("Report[%s] is arrived from worker", report);
36 g_assert(obj != NULL);
37 g_assert(context != NULL);
38 g_assert(report != NULL);
40 ttsd_worker_dbus_complete_ttsd_worker_submit_report(obj, context);
42 /* Put report into queue */
47 static void __on_name_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
49 _D("DBus name[%s] is acquired", name);
52 static void __on_bus_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
57 _E("DBus handle is not delivered, something wrong");
60 worker_interface_h *h = user_data;
62 h->m_server = g_dbus_object_manager_server_new(TTSD_DBUS_OBJECT_PATH);
64 _E("Failed to create dbus server");
65 ttd_worker_interface_fini(h);
69 h->dbus_obj = ttsd_worker_dbus_skeleton_new();
71 _E("Failed to create dbus skeleton");
72 ttd_worker_interface_fini(h);
76 if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(h->dbus_obj),
77 connection, TTSD_DBUS_OBJECT_PATH, NULL)) {
78 _E("Failed to export interface with object path");
79 ttd_worker_interface_fini(h);
83 ret = g_signal_connect(h->dbus_obj, "handle-ttsd-worker-submit-report",
84 G_CALLBACK (__received_from_worker), h);
86 _E("Failed to connect handle: submit-report");
87 ttd_worker_interface_fini(h);
91 g_dbus_object_manager_server_set_connection(h->m_server, connection);
94 int ttd_worker_interface_init(worker_interface_h **h)
96 *h = (worker_interface_h *)calloc(1, sizeof(worker_interface_h));
98 _E("Failed to allocate memory for dbus handle");
102 (*h)->owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, TTSD_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE,
103 __on_bus_acquired_cb, __on_name_acquired_cb, NULL, *h, NULL);
104 if (!(*h)->owner_id) {
105 _E("Failed to get identifier for dbus");
113 void ttd_worker_interface_fini(worker_interface_h *h)
116 _E("Worker interface handle is NULL");
121 g_object_unref(h->dbus_obj);
124 g_bus_unown_name(h->owner_id);
127 g_object_unref(h->m_server);