${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")
#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__ */
<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 -->
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);
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) {
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");
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})
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__ */
<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 -->
_D("Make the DBus Connection");
- h = malloc(sizeof(dbus_h));
+ h = g_try_malloc0(sizeof(dbus_h));
if (!h)
return NULL;
{
GError *g_error = NULL;
dbus_h *h = user_data;
+ gint ret_val = -1;
gboolean ret = FALSE;
const char *result = NULL;
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);
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) {
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);