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.
19 #include "ttd-worker-interface.h"
20 #include "common-worker-inf-def.h"
21 #include "common-worker-inf-dbus.h"
23 struct _worker_interface_h {
25 GDBusObjectManagerServer *m_server;
26 TtdWorkerDbus *dbus_obj;
30 __received_from_worker(TtdWorkerDbus *obj,
31 GDBusMethodInvocation *context,
41 ttd_worker_dbus_complete_ttd_worker_submit_report(obj, context, ret);
44 static void __on_name_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
46 _D("On Name[%s] is acquired", name);
49 static void __on_name_lost_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
51 _D("On Name[%s] is lost", name);
54 static void __on_bus_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
57 _D("On Bus acquired[%s]", name);
60 _E("DBus handle is not delivered, something wrong");
63 worker_interface_h h = user_data;
65 h->m_server = g_dbus_object_manager_server_new(TTD_WORKER_DBUS_OBJECT_PATH);
67 _E("Failed to create dbus server");
68 ttd_worker_interface_fini(h);
72 h->dbus_obj = ttd_worker_dbus_skeleton_new();
74 _E("Failed to create dbus skeleton");
75 ttd_worker_interface_fini(h);
79 if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(h->dbus_obj),
80 connection, TTD_WORKER_DBUS_OBJECT_PATH, NULL)) {
81 _E("Failed to export interface with object path");
82 ttd_worker_interface_fini(h);
86 ret = g_signal_connect(h->dbus_obj, "handle-ttd-worker-submit-report",
87 G_CALLBACK (__received_from_worker), h);
89 _E("Failed to connect handle: submit-report");
90 ttd_worker_interface_fini(h);
94 g_dbus_object_manager_server_set_connection(h->m_server, connection);
97 int ttd_worker_interface_init(worker_interface_h *h)
99 worker_interface_h _h = NULL;
102 _E("Worker Interface handler is NULL");
106 _h = g_try_malloc0(sizeof(worker_interface_h));
108 _E("Failed to allocate memory for dbus handle");
112 _h->owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
113 TTD_WORKER_DBUS_NAME,
114 G_BUS_NAME_OWNER_FLAGS_NONE,
115 __on_bus_acquired_cb,
116 __on_name_acquired_cb,
121 _E("Failed to get identifier for dbus");
131 void ttd_worker_interface_fini(worker_interface_h h)
134 _E("Worker interface handle is NULL");
139 g_object_unref(h->dbus_obj);
142 g_bus_unown_name(h->owner_id);
145 g_object_unref(h->m_server);