Modify lib interface to use code-gen 14/178814/2
authorjunkyu han <junkyu.han@samsung.com>
Mon, 14 May 2018 06:34:37 +0000 (15:34 +0900)
committerjunkyu han <junkyu.han@samsung.com>
Tue, 15 May 2018 04:34:38 +0000 (13:34 +0900)
Change-Id: I633b1eda044755c66c6301d4b20ac8a5bd7ea04c

daemon/CMakeLists.txt
daemon/src/tizen-things-daemon-dbus.xml [moved from daemon/tizen-things-daemon-dbus.xml with 68% similarity]
daemon/src/ttd-worker-interface.c
lib/CMakeLists.txt
lib/include/ttsd-worker-lib.h
lib/src/tizen-things-lib-dbus.xml [new file with mode: 0644]
lib/src/ttsd-worker-lib.c

index 8f7f30e..c3840cf 100644 (file)
@@ -18,7 +18,26 @@ FOREACH (flag ${DAEMON_PKGS_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-FILE(GLOB DAEMON_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
+FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
+EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
+                " \\
+                --generate-c-code ${CMAKE_SOURCE_DIR}/daemon/src/tizen-things-daemon-dbus \\
+                ${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)
 
 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")
@@ -28,19 +47,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,now -Wl,-z,relro")
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
-ADD_CUSTOM_COMMAND(
-       WORKING_DIRECTORY
-       OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tizen-things-daemon-dbus.c
-       COMMAND gdbus-codegen
-                       --generate-c-code tizen-things-daemon-dbus
-                       --c-generate-object-manager
-                       --generate-docbook generated-docs
-                       ${CMAKE_CURRENT_SOURCE_DIR}/tizen-things-daemon-dbus.xml
-                       COMMENT "Generating GDBus .c/.h")
-
-
-
-ADD_EXECUTABLE(${DAEMON} ${DAEMON_SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/tizen-things-daemon-dbus.c)
+ADD_EXECUTABLE(${DAEMON} ${DAEMON_SOURCE})
 TARGET_LINK_LIBRARIES(${DAEMON} ${DAEMON_PKGS_LDFLAGS} -lm)
 
 # Install
similarity index 68%
rename from daemon/tizen-things-daemon-dbus.xml
rename to daemon/src/tizen-things-daemon-dbus.xml
index 9632f45..d553f86 100644 (file)
@@ -9,14 +9,8 @@
 
                <!-- Method definitions -->
 
-               <method name="ttsd_worker_submit_report_async">
-                       <arg type="s" name="report" direction="in"/>
-                       <arg type="i" name="ret" direction="out"/>
-               </method>
-
                <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 fe1ac06..9d828ab 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #include <glib.h>
-#include "../tizen-things-daemon-dbus.h"
+#include "tizen-things-daemon-dbus.h"
 
 #include "ttd-log.h"
 #include "ttd-worker-interface.h"
@@ -33,7 +33,11 @@ static gboolean __received_from_worker(TtsdWorkerDbus *obj, GDBusMethodInvocatio
 {
        _D("Report[%s] is arrived from worker", report);
 
-       ttsd_worker_dbus_complete_ttsd_worker_submit_report_async(obj, context, 0);
+       g_assert(obj != NULL);
+       g_assert(context != NULL);
+       g_assert(report != NULL);
+
+       ttsd_worker_dbus_complete_ttsd_worker_submit_report(obj, context);
 
        /* Put report into queue */
 
@@ -47,7 +51,6 @@ static void __on_name_acquired_cb(GDBusConnection *connection, const gchar *name
 
 static void __on_bus_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
-       GDBusInterfaceSkeleton *ttsd_intf_sk = NULL;
        gulong ret = 0;
 
        if (!user_data) {
@@ -70,8 +73,7 @@ static void __on_bus_acquired_cb(GDBusConnection *connection, const gchar *name,
                return;
        }
 
-       ttsd_intf_sk = G_DBUS_INTERFACE_SKELETON(h->dbus_obj);
-       if (!g_dbus_interface_skeleton_export(ttsd_intf_sk,
+       if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(h->dbus_obj),
                                connection, TTSD_DBUS_OBJECT_PATH, NULL)) {
                _E("Failed to export interface with object path");
                ttd_worker_interface_fini(h);
@@ -86,14 +88,6 @@ static void __on_bus_acquired_cb(GDBusConnection *connection, const gchar *name,
                return;
        }
 
-       ret = g_signal_connect(h->dbus_obj, "handle-ttsd-worker-submit-report-async",
-                       G_CALLBACK (__received_from_worker), h);
-       if (!ret) {
-               _E("Failed to connect handle: submit-report-async");
-               ttd_worker_interface_fini(h);
-               return;
-       }
-
        g_dbus_object_manager_server_set_connection(h->m_server, connection);
 }
 
index bf1cdae..931483f 100644 (file)
@@ -8,6 +8,7 @@ SET(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
 INCLUDE(FindPkgConfig)
 pkg_check_modules(LIB_TTS_PKGS REQUIRED
        glib-2.0
+       gio-unix-2.0
        dlog
 )
 
@@ -18,9 +19,19 @@ ENDFOREACH(flag)
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Winline -g")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${INSTALL_LIB_DIR}")
 
-FILE(GLOB LIB_TTS_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
+FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
+EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
+                " \\
+                --generate-c-code ${CMAKE_SOURCE_DIR}/lib/src/tizen-things-lib-dbus \\
+                ${CMAKE_SOURCE_DIR}/lib/src/tizen-things-lib-dbus.xml \\
+                ")
+
 INCLUDE_DIRECTORIES(${INCLUDE_DIR})
 
+SET(LIB_TTS_SOURCE
+       src/tizen-things-lib-dbus.c
+       src/ttsd-worker-lib.c)
+
 ADD_LIBRARY(${LIB} SHARED ${LIB_TTS_SOURCE})
 TARGET_LINK_LIBRARIES(${LIB} ${LIB_TTS_LDFLAGS})
 
index 0a24338..7bf8f9b 100644 (file)
@@ -21,7 +21,7 @@
 
 typedef void(*ttsd_worker_submit_report_completed_cb)(const char *result, void *user_data);
 
-int ttsd_worker_submit_report_async(const char *report, ttsd_worker_submit_report_completed_cb completed_cb, void *completed_cb_data);
-int ttsd_worker_submit_report(const char *report);
+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);
 
 #endif /* __TTSD_WORKER_LIB_H__ */
diff --git a/lib/src/tizen-things-lib-dbus.xml b/lib/src/tizen-things-lib-dbus.xml
new file mode 100644 (file)
index 0000000..d553f86
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="0.1" encoding="UTF-8" ?>
+
+<!DOCTYPE node PUBLIC
+       "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
+       "http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
+
+<node>
+       <interface name="ttsd.worker.dbus">
+
+               <!-- Method definitions -->
+
+               <method name="ttsd_worker_submit_report">
+                       <arg type="s" name="report" direction="in"/>
+               </method>
+
+               <!-- We don't need to signals, because of aul_launch -->
+       </interface>
+</node>
+
index 093c75c..93f2ac4 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "log.h"
 #include "ttsd-worker-lib.h"
+#include "tizen-things-lib-dbus.h"
 
 #define TTSD_WORKER_DBUS_NAME "ttsd.worker.dbus"
 #define TTSD_WORKER_DBUS_OBJECT_PATH "/ttsd_worker_dbus_object"
@@ -28,8 +29,7 @@
 
 typedef struct {
        GCancellable *cancellable;
-       GDBusConnection *client_bus;
-       GDBusProxy *client_bus_proxy;
+       TtsdWorkerDbus *dbus_object;
        ttsd_worker_submit_report_completed_cb completed_cb;
        void *completed_cb_data;
 } dbus_h;
@@ -45,12 +45,8 @@ static void __destroy_dbus_connection(dbus_h *h)
                g_cancellable_cancel(h->cancellable);
                g_object_unref(h->cancellable);
        }
-       if (h->client_bus_proxy) {
-               g_object_unref(h->client_bus_proxy);
-       }
-       if (h->client_bus) {
-               g_object_unref(h->client_bus);
-       }
+       if (h->dbus_object)
+               g_object_unref(h->dbus_object);
 }
 
 static dbus_h *__make_dbus_connection(void)
@@ -66,38 +62,27 @@ static dbus_h *__make_dbus_connection(void)
 
        h->cancellable = g_cancellable_new();
 
-       h->client_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, h->cancellable, &error);
-       if (!h->client_bus) {
-               if (error)
-                       _E("Couldn't connect to the System bus[%s]", error->message);
-               goto ERROR;
-       }
-
-       h->client_bus_proxy = g_dbus_proxy_new_sync(h->client_bus, G_DBUS_PROXY_FLAGS_NONE,
-                       NULL, TTSD_WORKER_DBUS_NAME, TTSD_WORKER_DBUS_OBJECT_PATH,
-                       TTSD_WORKER_DBUS_INTERFACE, h->cancellable, &error);
-       if (!h->client_bus_proxy) {
-               if (error)
-                       _E("Fail to create the proxy object because of %s", error->message);
-               goto ERROR;
+       h->dbus_object = ttsd_worker_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+                       G_DBUS_PROXY_FLAGS_NONE,
+                       TTSD_WORKER_DBUS_NAME,
+                       TTSD_WORKER_DBUS_OBJECT_PATH,
+                       h->cancellable,
+                       &error);
+       if (!h->dbus_object) {
+               _E("Fail to create the proxy object because of %s", error->message);
+               g_error_free(error);
+               __destroy_dbus_connection(h);
+               return NULL;
        }
 
        return h;
-
-ERROR:
-       if (error)
-               g_error_free(error);
-
-       __destroy_dbus_connection(h);
-
-       return NULL;
 }
 
 static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
        GError *g_error = NULL;
-       GVariant *g_var;
        dbus_h *h = user_data;
+       gboolean ret = FALSE;
        const char *result = NULL;
 
        _D("Send completed");
@@ -107,15 +92,13 @@ static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpo
                return;
        }
 
-       g_var = g_dbus_proxy_call_finish(h->client_bus_proxy, res, &g_error);
-       if (g_error) {
+       ret = ttsd_worker_dbus_call_ttsd_worker_submit_report_finish(h->dbus_object, 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 {
+       } else
                result = "Success to submit report";
-               g_variant_unref(g_var);
-       }
 
        if (h->completed_cb)
                h->completed_cb(result, h->completed_cb_data);
@@ -123,7 +106,7 @@ static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpo
        __destroy_dbus_connection(h);
 }
 
-int ttsd_worker_submit_report_async(const char *report, ttsd_worker_submit_report_completed_cb completed_cb, void *user_data)
+int ttsd_worker_submit_report(const char *report, ttsd_worker_submit_report_completed_cb completed_cb, void *user_data)
 {
        dbus_h *h = NULL;
 
@@ -136,15 +119,21 @@ int ttsd_worker_submit_report_async(const char *report, ttsd_worker_submit_repor
        h->completed_cb = completed_cb;
        h->completed_cb_data = user_data;
 
-       g_dbus_proxy_call(h->client_bus_proxy, "ttsd_worker_submit_report_async", g_variant_new("(s)", report), G_DBUS_CALL_FLAGS_NONE, -1, h->cancellable, (GAsyncReadyCallback) __submit_completed_cb, h);
+       ttsd_worker_dbus_call_ttsd_worker_submit_report(h->dbus_object,
+                       report,
+                       h->cancellable,
+                       (GAsyncReadyCallback) __submit_completed_cb,
+                       h);
 
        return 0;
 }
 
-int ttsd_worker_submit_report(const char *report)
+int ttsd_worker_submit_report_sync(const char *report, ttsd_worker_submit_report_completed_cb completed_cb, void *user_data)
 {
        dbus_h *h = NULL;
-       GError *g_error = NULL;
+       GError *error = NULL;
+       gboolean ret = FALSE;
+       const char *result = NULL;
 
        h = __make_dbus_connection();
        if (!h) {
@@ -152,14 +141,20 @@ int ttsd_worker_submit_report(const char *report)
                return -1;
        }
 
-       g_dbus_proxy_call_sync(h->client_bus_proxy, "ttsd_worker_submit_report",
-                       g_variant_new("(s)", report), G_DBUS_CALL_FLAGS_NONE, -1, h->cancellable, &g_error);
+       h->completed_cb = completed_cb;
+       h->completed_cb_data = user_data;
 
-       if (g_error) {
-               _E("DBus proxy call is failed[%s]", g_error->message);
-               g_error_free(g_error);
+       ret = ttsd_worker_dbus_call_ttsd_worker_submit_report_sync(h->dbus_object, report, 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);
 
        __destroy_dbus_connection(h);