summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Kolodziejski <m.kolodziejs@samsung.com>2018-07-13 19:03:08 +0200
committerMichal Kolodziejski <m.kolodziejs@samsung.com>2018-07-16 13:45:28 +0200
commit6470182364f780033db8fa401ad5b3da31251d06 (patch)
tree763b2c74e1ebf410055c762ce773a29a1db324c8
parent13ff103f7a36b0f059ac8da01ffa4682c8febcba (diff)
downloadttsd-worker-task-6470182364f780033db8fa401ad5b3da31251d06.tar.gz
ttsd-worker-task-6470182364f780033db8fa401ad5b3da31251d06.tar.bz2
ttsd-worker-task-6470182364f780033db8fa401ad5b3da31251d06.zip
ipc: integrated with ttsd
Change-Id: I08ee3b7a1e6eaeba8c37835129d78221bb62e6f5 Signed-off-by: Michal Kolodziejski <m.kolodziejs@samsung.com>
-rw-r--r--packaging/task-worker.spec1
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/ipc.c74
3 files changed, 67 insertions, 9 deletions
diff --git a/packaging/task-worker.spec b/packaging/task-worker.spec
index 0e3e938..610e7d3 100644
--- a/packaging/task-worker.spec
+++ b/packaging/task-worker.spec
@@ -14,6 +14,7 @@ BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(json-glib-1.0)
BuildRequires: pkgconfig(capi-appfw-service-application)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(things-service-worker)
%description
Process and Memory Tizen Things Daemon Worker
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index abe145b..81b5b5e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,6 +4,7 @@ pkg_check_modules(APP_PKGS REQUIRED
dlog
json-glib-1.0
aul
+ things-service-worker
)
FOREACH (flag ${APP_PKGS_CFLAGS})
diff --git a/src/ipc.c b/src/ipc.c
index 607b756..a5b8300 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -17,12 +17,14 @@
#include <glib.h>
#include <string.h>
#include <stdio.h>
+#include <ttd-worker-lib.h>
#include "ipc.h"
#include "err-check.h"
#include "task-worker.h"
#include "log.h"
-static void send_report(const char *report, int status);
+static void send_report(const char *report_data, int status);
+static void submit_result_cb(ttd_worker_submit_result_e result, ttd_worker_report *report, void *user_data);
static struct ipc
{
@@ -38,9 +40,7 @@ void ipc_init(const char *command_id, int counter)
ON_NULL_RETURN(command_id);
ON_TRUE_RETURN(counter < 0);
- int len = strlen(command_id) + 1;
- ipc_data.command_id = (char *)g_malloc(len * sizeof(char));
- snprintf(ipc_data.command_id, len, "%s", command_id);
+ ipc_data.command_id = strdup(command_id);
g_atomic_int_set(&ipc_data.counter, counter);
}
@@ -56,17 +56,73 @@ void ipc_send_report(const char *report)
if (!g_atomic_int_dec_and_test(&ipc_data.counter))
{
- send_report(report, 1 /*WORKING STATE*/);
+ send_report(report, TTD_WORKER_WORKING);
}
else
{
- send_report(report, 2 /*COMPLETED STATE*/);
+ send_report(report, TTD_WORKER_COMPLETED);
cleanup_and_exit();
}
}
-//TODO change int status to enum, when project will be integrated with TTSD
-static void send_report(const char *report, int status)
+struct report_data
{
- //TODO send report here
+ char *data;
+ ttd_worker_working_state_e status;
+};
+
+static gboolean invoke_on_main_thread_cb(gpointer user_data)
+{
+ ON_NULL_RETURN_VAL(user_data, FALSE);
+
+ struct report_data *r_data = (struct report_data *)user_data;
+
+ ON_NULL_RETURN_VAL(r_data->data, FALSE);
+
+ ttd_worker_report *report = ttd_worker_report_new_by_cmd_id(ipc_data.command_id);
+ ttd_worker_report_set_working_state(report, r_data->status);
+
+ ttd_worker_report_set_report_data(report, r_data->data);
+
+ if (r_data->status == TTD_WORKER_WORKING)
+ {
+ ttd_worker_submit_report(report, submit_result_cb, NULL);
+ }
+ else if (r_data->status == TTD_WORKER_COMPLETED)
+ {
+ ttd_worker_submit_result_e result;
+ ttd_worker_submit_report_sync(report, &result);
+
+ if (result == TTD_WORKER_SUBMIT_SUCCESS)
+ DBG("Sending final result succeeded");
+ else
+ DBG("Sending final result failed");
+
+ ttd_worker_report_free(report);
+
+ cleanup_and_exit();
+ }
+
+ g_free(r_data->data);
+ g_free(r_data);
+ return FALSE;
+}
+
+static void send_report(const char *report_data, ttd_worker_working_state_e status)
+{
+ struct report_data *r_data = (struct report_data *)g_malloc(sizeof(struct report_data));
+
+ r_data->data = strdup(report_data);
+ r_data->status = status;
+ g_main_context_invoke(NULL, invoke_on_main_thread_cb, r_data);
+}
+
+static void submit_result_cb(ttd_worker_submit_result_e result, ttd_worker_report *report, void *user_data)
+{
+ if (result == TTD_WORKER_SUBMIT_SUCCESS)
+ DBG("Sending result succeeded");
+ else
+ DBG("Sending result failed");
+
+ ttd_worker_report_free(report);
} \ No newline at end of file