Re(Add Libarary for DBus communication) because of excepted review 25/176325/6
authorjunkyu han <junkyu.han@samsung.com>
Wed, 18 Apr 2018 10:31:14 +0000 (19:31 +0900)
committerjunkyu han <junkyu.han@samsung.com>
Sat, 21 Apr 2018 09:37:30 +0000 (18:37 +0900)
Change-Id: I6ae98cfa0267864107b000287c872f1ad1e88460

daemon/CMakeLists.txt
daemon/src/tizen-things-daemon.c
daemon/tizen-things-daemon-dbus.xml [new file with mode: 0644]
lib/CMakeLists.txt
lib/include/log.h [new file with mode: 0644]
lib/include/things-service-lib.h [deleted file]
lib/include/ttsd-worker-lib.h [new file with mode: 0644]
lib/src/things-service-lib.c [deleted file]
lib/src/ttsd-worker-lib.c [new file with mode: 0644]
packaging/tizen-things-daemon.service
packaging/tizen-things-daemon.spec

index 378732c..d329efd 100644 (file)
@@ -3,9 +3,9 @@ SET(DAEMON tizen-things-daemon)
 
 INCLUDE(FindPkgConfig)
 pkg_check_modules(DAEMON_PKGS REQUIRED
-       glib-2.0
-       dlog
        libtzplatform-config
+       gio-2.0
+       gio-unix-2.0
 )
 
 FOREACH (flag ${DAEMON_PKGS_CFLAGS})
@@ -20,9 +20,21 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,now -Wl,-z,relro")
 
-#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
-ADD_EXECUTABLE(${DAEMON} ${DAEMON_SOURCE})
+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)
 TARGET_LINK_LIBRARIES(${DAEMON} ${DAEMON_PKGS_LDFLAGS} -lm)
 
 # Install
index 6651435..33e53e7 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-
 int main(int argc, char* argv[])
 {
 
diff --git a/daemon/tizen-things-daemon-dbus.xml b/daemon/tizen-things-daemon-dbus.xml
new file mode 100644 (file)
index 0000000..91b6ee2
--- /dev/null
@@ -0,0 +1,20 @@
+<?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"/>
+                       <arg type="i" name="ret" direction="out"/>
+               </method>
+
+               <!-- We don't need to signals, because of aul_launch -->
+       </interface>
+</node>
+
index bf1cdae..9b558a8 100644 (file)
@@ -8,6 +8,8 @@ SET(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
 INCLUDE(FindPkgConfig)
 pkg_check_modules(LIB_TTS_PKGS REQUIRED
        glib-2.0
+       dbus-1
+       gio-2.0
        dlog
 )
 
diff --git a/lib/include/log.h b/lib/include/log.h
new file mode 100644 (file)
index 0000000..97ff652
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TT_DAEMON_SYS_INFO_LOG_H__
+#define __TT_DAEMON_SYS_INFO_LOG_H__
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "TTSD_LIB"
+
+#if !defined(_V)
+#define _V(fmt, arg...) dlog_print(DLOG_VERBOSE, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#if !defined(_D)
+#define _D(fmt, arg...) dlog_print(DLOG_DEBUG, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#if !defined(_I)
+#define _I(fmt, arg...) dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#if !defined(_W)
+#define _W(fmt, arg...) dlog_print(DLOG_WARN, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#if !defined(_E)
+#define _E(fmt, arg...) dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
+#endif
+
+#define retvm_if(expr, val, fmt, arg...) do { \
+       if (expr) { \
+               _E(fmt, ##arg); \
+               _E("(%s) -> %s() return", #expr, __FUNCTION__); \
+               return val; \
+       } \
+} while (0)
+
+#define retv_if(expr, val) do { \
+       if (expr) { \
+               _E("(%s) -> %s() return", #expr, __FUNCTION__); \
+               return (val); \
+       } \
+} while (0)
+
+#define retm_if(expr, fmt, arg...) do { \
+       if (expr) { \
+               _E(fmt, ##arg); \
+               _E("(%s) -> %s() return", #expr, __FUNCTION__); \
+               return; \
+       } \
+} while (0)
+
+#define ret_if(expr) do { \
+       if (expr) { \
+               _E("(%s) -> %s() return", #expr, __FUNCTION__); \
+               return; \
+       } \
+} while (0)
+
+#define goto_if(expr, val) do { \
+       if (expr) { \
+               _E("(%s) -> goto", #expr); \
+               goto val; \
+       } \
+} while (0)
+
+#define break_if(expr) { \
+       if (expr) { \
+               _E("(%s) -> break", #expr); \
+               break; \
+       } \
+}
+
+#define continue_if(expr) { \
+       if (expr) { \
+               _E("(%s) -> continue", #expr); \
+               continue; \
+       } \
+}
+
+#endif /* __TT_DAEMON_SYS_INFO_LOG_H__ */
diff --git a/lib/include/things-service-lib.h b/lib/include/things-service-lib.h
deleted file mode 100644 (file)
index b7c6afc..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __TT_SERVICE_LIB_H__
-#define __TT_SERVICE_LIB_H__
-
-int test_API(void);
-
-#endif /* __TT_SERVICE_LIB_H__ */
diff --git a/lib/include/ttsd-worker-lib.h b/lib/include/ttsd-worker-lib.h
new file mode 100644 (file)
index 0000000..26c5e96
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TTSD_WORKER_LIB_H__
+#define __TTSD_WORKER_LIB_H__
+
+int ttsd_worker_submit_report(char *report);
+
+#endif /* __TTSD_WORKER_LIB_H__ */
diff --git a/lib/src/things-service-lib.c b/lib/src/things-service-lib.c
deleted file mode 100644 (file)
index 4160424..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <glib.h>
-
-int test_API(void)
-{
-       return 0;
-}
diff --git a/lib/src/ttsd-worker-lib.c b/lib/src/ttsd-worker-lib.c
new file mode 100644 (file)
index 0000000..2503008
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "log.h"
+#include "ttsd-worker-lib.h"
+
+#define TTSD_WORKER_DBUS_NAME "ttsd.worker.dbus"
+#define TTSD_WORKER_DBUS_OBJECT_PATH "/ttsd_worker_dbus_object"
+#define TTSD_WORKER_DBUS_INTERFACE "ttsd.worker.dbus"
+
+typedef struct {
+       GCancellable *cancellable;
+       GDBusConnection *client_bus;
+       GDBusProxy *client_bus_proxy;
+} dbus_h;
+
+static dbus_h *__make_dbus_connection(void);
+static void __destroy_dbus_connection(dbus_h *h);
+
+static void __destroy_dbus_connection(dbus_h *h)
+{
+       _D("Destory the DBus Connection");
+       if (h->cancellable) {
+               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);
+       }
+}
+
+static dbus_h *__make_dbus_connection(void)
+{
+       dbus_h *h = NULL;
+       GError *error = NULL;
+
+       _D("Make the DBus Connection");
+
+       h = malloc(sizeof(dbus_h));
+       if (!h)
+               return NULL;
+
+       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;
+       }
+
+       return h;
+
+ERROR:
+       if (error)
+               g_error_free(error);
+
+       __destroy_dbus_connection(h);
+
+       return NULL;
+}
+
+int ttsd_worker_submit_report(char *report)
+{
+       dbus_h *h = NULL;
+       GError *g_error = NULL;
+
+       h = __make_dbus_connection();
+       if (!h) {
+               _E("Failed to make dbus connection");
+               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);
+
+       if (g_error) {
+               _E("DBus proxy call is failed[%s]", g_error->message);
+               g_error_free(g_error);
+               return -1;
+       }
+
+       __destroy_dbus_connection(h);
+
+       return 0;
+}
index 8e8a064..353e7cd 100644 (file)
@@ -1,5 +1,5 @@
 [Unit]
-Description=Things Daemon
+Description=Things Service Daemon
 
 [Service]
 Type=idle
index b7daff6..8c31b84 100644 (file)
@@ -7,7 +7,7 @@ Release:    1
 License:    Flora-1.1
 Provides:   %{name} = %{version}-%{release}
 Source0:    %{name}-%{version}.tar.gz
-Source1:       %{name}.service
+Source1:    %{name}.service
 
 BuildRequires: cmake
 
@@ -16,6 +16,8 @@ BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(ecore)
 BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(gio-unix-2.0)
 BuildRequires: pkgconfig(libtzplatform-config)
 
 %description