Modify dbus library 87/178987/3
authorjunkyu han <junkyu.han@samsung.com>
Tue, 15 May 2018 07:10:14 +0000 (16:10 +0900)
committerjunkyu han <junkyu.han@samsung.com>
Tue, 15 May 2018 10:04:51 +0000 (19:04 +0900)
Change-Id: I2e67b0436fef5b22a6630eaad4a013bb15eca8fb

daemon/CMakeLists.txt
daemon/include/ttd-worker-interface.h
daemon/src/tizen-things-daemon-dbus.xml
daemon/src/tizen-things-daemon.c
daemon/src/ttd-worker-interface.c
lib/CMakeLists.txt
lib/include/ttsd-worker-lib.h
lib/src/tizen-things-lib-dbus.xml
lib/src/ttsd-worker-lib.c

index c3840cf..add707d 100644 (file)
@@ -25,19 +25,7 @@ EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
                 ${CMAKE_SOURCE_DIR}/daemon/src/tizen-things-daemon-dbus.xml \\
                 ")
 
-SET(DAEMON_SOURCE
-       src/tizen-things-daemon.c
-       src/tizen-things-daemon-dbus.c
-       src/ttd-cloud-conn-state.c
-       src/ttd-cmd.c
-       src/ttd-conn-mgr.c
-       src/ttd-http.c
-       src/ttd-log.c
-       src/ttd-parse-cmd.c
-       src/ttd-queue.c
-       src/ttd-task.c
-       src/ttd-worker-handle.c
-       src/ttd-worker-interface.c)
+FILE(GLOB DAEMON_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
 
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Winline -g -fno-builtin-malloc -fPIE")
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fstack-protector-all -D_FORTIFY_SOURCE=2")
index 8235517..cc9dede 100644 (file)
@@ -17,9 +17,9 @@
 #ifndef __TT_DAEMON_WORKER_INTERFACE_H__
 #define __TT_DAEMON_WORKER_INTERFACE_H__
 
-typedef struct _worker_interface_h worker_interface_h;
+typedef struct _worker_interface_h *worker_interface_h;
 
-int ttd_worker_interface_init(worker_interface_h **h);
-void ttd_worker_interface_fini(worker_interface_h *h);
+int ttd_worker_interface_init(worker_interface_h *h);
+void ttd_worker_interface_fini(worker_interface_h h);
 
 #endif /* __TT_DAEMON_WORKER_INTERFACE_H__ */
index d553f86..91b6ee2 100644 (file)
@@ -11,6 +11,7 @@
 
                <method name="ttsd_worker_submit_report">
                        <arg type="s" name="report" direction="in"/>
+                       <arg type="i" name="ret" direction="out"/>
                </method>
 
                <!-- We don't need to signals, because of aul_launch -->
index 025b1f0..e725d97 100644 (file)
@@ -38,7 +38,7 @@
 typedef struct __ttd_data {
        GMainLoop *mainloop;
        GThreadPool *thread_pool;
-       worker_interface_h *worker_itf_h;
+       worker_interface_h worker_itf_h;
 } ttd_data;
 
 static gboolean __daemon_job_handler(gpointer data);
index 9d828ab..dc4cb41 100644 (file)
@@ -31,33 +31,52 @@ struct _worker_interface_h {
 
 static gboolean __received_from_worker(TtsdWorkerDbus *obj, GDBusMethodInvocation *context, gchar *report, void *user_data)
 {
+       int ret = 0;
        _D("Report[%s] is arrived from worker", report);
 
-       g_assert(obj != NULL);
-       g_assert(context != NULL);
-       g_assert(report != NULL);
+       if (!obj) {
+               _E("Dbus object is NULL");
+               ret = -1;
+               return FALSE;
+       }
+
+       if (!context) {
+               _E("Invocation is NULL");
+               ret = -1;
+               return FALSE;
+       }
 
-       ttsd_worker_dbus_complete_ttsd_worker_submit_report(obj, context);
+       if (!report) {
+               _E("Report is NULL");
+               ret = -1;
+               return FALSE;
+       }
 
-       /* Put report into queue */
+       ttsd_worker_dbus_complete_ttsd_worker_submit_report(obj, context, ret);
 
        return FALSE;
 }
 
 static void __on_name_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
-       _D("DBus name[%s] is acquired", name);
+       _D("On Name[%s] is acquired", name);
+}
+
+static void __on_name_lost_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       _D("On Name[%s] is lost", name);
 }
 
 static void __on_bus_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
        gulong ret = 0;
+       _D("On Bus acquired[%s]", name);
 
        if (!user_data) {
                _E("DBus handle is not delivered, something wrong");
                return;
        }
-       worker_interface_h *h = user_data;
+       worker_interface_h h = user_data;
 
        h->m_server = g_dbus_object_manager_server_new(TTSD_DBUS_OBJECT_PATH);
        if (!h->m_server) {
@@ -91,26 +110,41 @@ static void __on_bus_acquired_cb(GDBusConnection *connection, const gchar *name,
        g_dbus_object_manager_server_set_connection(h->m_server, connection);
 }
 
-int ttd_worker_interface_init(worker_interface_h **h)
+int ttd_worker_interface_init(worker_interface_h *h)
 {
-       *h = (worker_interface_h *)calloc(1, sizeof(worker_interface_h));
-       if (!*h) {
+       worker_interface_h _h = NULL;
+
+       if (!h) {
+               _E("Worker Interface handler is NULL");
+               return -1;
+       }
+
+       _h = g_try_malloc0(sizeof(worker_interface_h));
+       if (!_h) {
                _E("Failed to allocate memory for dbus handle");
                return -1;
        }
 
-       (*h)->owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, TTSD_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE,
-                       __on_bus_acquired_cb, __on_name_acquired_cb, NULL, *h, NULL);
-       if (!(*h)->owner_id) {
+       _h->owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+                       TTSD_DBUS_NAME,
+                       G_BUS_NAME_OWNER_FLAGS_NONE,
+                       __on_bus_acquired_cb,
+                       __on_name_acquired_cb,
+                       __on_name_lost_cb,
+                       _h,
+                       NULL);
+       if (!_h->owner_id) {
                _E("Failed to get identifier for dbus");
-               g_free(*h);
+               g_free(_h);
                return -1;
        }
 
+       *h = _h;
+
        return 0;
 }
 
-void ttd_worker_interface_fini(worker_interface_h *h)
+void ttd_worker_interface_fini(worker_interface_h h)
 {
        if (!h) {
                _E("Worker interface handle is NULL");
index 931483f..5edd4fb 100644 (file)
@@ -28,9 +28,7 @@ EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
 
 INCLUDE_DIRECTORIES(${INCLUDE_DIR})
 
-SET(LIB_TTS_SOURCE
-       src/tizen-things-lib-dbus.c
-       src/ttsd-worker-lib.c)
+FILE(GLOB LIB_TTS_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
 
 ADD_LIBRARY(${LIB} SHARED ${LIB_TTS_SOURCE})
 TARGET_LINK_LIBRARIES(${LIB} ${LIB_TTS_LDFLAGS})
index 7bf8f9b..0d4dba9 100644 (file)
@@ -22,6 +22,6 @@
 typedef void(*ttsd_worker_submit_report_completed_cb)(const char *result, void *user_data);
 
 int ttsd_worker_submit_report(const char *report, ttsd_worker_submit_report_completed_cb completed_cb, void *completed_cb_data);
-int ttsd_worker_submit_report_sync(const char *report, ttsd_worker_submit_report_completed_cb completed_cb, void *completed_cb_data);
+int ttsd_worker_submit_report_sync(const char *report);
 
 #endif /* __TTSD_WORKER_LIB_H__ */
index d553f86..91b6ee2 100644 (file)
@@ -11,6 +11,7 @@
 
                <method name="ttsd_worker_submit_report">
                        <arg type="s" name="report" direction="in"/>
+                       <arg type="i" name="ret" direction="out"/>
                </method>
 
                <!-- We don't need to signals, because of aul_launch -->
index 93f2ac4..fe81165 100644 (file)
@@ -56,7 +56,7 @@ static dbus_h *__make_dbus_connection(void)
 
        _D("Make the DBus Connection");
 
-       h = malloc(sizeof(dbus_h));
+       h = g_try_malloc0(sizeof(dbus_h));
        if (!h)
                return NULL;
 
@@ -82,6 +82,7 @@ static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpo
 {
        GError *g_error = NULL;
        dbus_h *h = user_data;
+       gint ret_val = -1;
        gboolean ret = FALSE;
        const char *result = NULL;
 
@@ -92,13 +93,18 @@ static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpo
                return;
        }
 
-       ret = ttsd_worker_dbus_call_ttsd_worker_submit_report_finish(h->dbus_object, res, &g_error);
+       ret = ttsd_worker_dbus_call_ttsd_worker_submit_report_finish(h->dbus_object, &ret_val, res, &g_error);
        if (!ret) {
                _E("DBus proxy call is failed[%s]", g_error->message);
                result = "Failed to submit report";
                g_error_free(g_error);
-       } else
-               result = "Success to submit report";
+       } else {
+               if (ret_val < 0) {
+                       _E("Submit report is failed");
+                       result = "Failed to submit report";
+               } else
+                       result = "Success to submit report";
+       }
 
        if (h->completed_cb)
                h->completed_cb(result, h->completed_cb_data);
@@ -128,12 +134,12 @@ int ttsd_worker_submit_report(const char *report, ttsd_worker_submit_report_comp
        return 0;
 }
 
-int ttsd_worker_submit_report_sync(const char *report, ttsd_worker_submit_report_completed_cb completed_cb, void *user_data)
+int ttsd_worker_submit_report_sync(const char *report)
 {
        dbus_h *h = NULL;
        GError *error = NULL;
+       gint ret_val = -1;
        gboolean ret = FALSE;
-       const char *result = NULL;
 
        h = __make_dbus_connection();
        if (!h) {
@@ -141,20 +147,21 @@ int ttsd_worker_submit_report_sync(const char *report, ttsd_worker_submit_report
                return -1;
        }
 
-       h->completed_cb = completed_cb;
-       h->completed_cb_data = user_data;
-
-       ret = ttsd_worker_dbus_call_ttsd_worker_submit_report_sync(h->dbus_object, report, h->cancellable, &error);
+       ret = ttsd_worker_dbus_call_ttsd_worker_submit_report_sync(h->dbus_object,
+                       report,
+                       &ret_val,
+                       h->cancellable,
+                       &error);
        if (!ret) {
                _E("DBus proxy call is failed[%s]", error->message);
                g_error_free(error);
-               result = "Failed to submit report";
                return -1;
-       } else
-               result = "Success to submit report";
-
-       if (h->completed_cb)
-               h->completed_cb(result, h->completed_cb_data);
+       } else {
+               if (ret_val < 0) {
+                       _E("Submit report is failed");
+                       return -1;
+               }
+       }
 
        __destroy_dbus_connection(h);