From 5131db3c2a88babb0b572fa107a1e150af9778dc Mon Sep 17 00:00:00 2001 From: Jeonghoon Park Date: Tue, 19 Jun 2018 13:55:21 +0900 Subject: [PATCH] pushing report from worker to cmd mgr module Change-Id: I88ee2dedbbced214d6156f819d1fca24f4268105 --- daemon/src/ttd-cmd-mgr.c | 26 +++++++++++++++++++++++--- daemon/src/ttd-worker-interface.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/daemon/src/ttd-cmd-mgr.c b/daemon/src/ttd-cmd-mgr.c index e9ec48d..0d231ed 100644 --- a/daemon/src/ttd-cmd-mgr.c +++ b/daemon/src/ttd-cmd-mgr.c @@ -28,7 +28,7 @@ #define CMD_MGR_GET_INTERVAL_SEC (3600 * 3) #define RESULT_WAIT_IN_SEC (10) #define RESULT_WAIT_TIME (RESULT_WAIT_IN_SEC * 1000000) -#define RESULT_WAIT_TRY_MAX (6) +#define RESULT_WAIT_TRY_MAX (10) // #define CMD_FETCH_TEST @@ -42,6 +42,7 @@ struct __cmd_mgr_h { GAsyncQueue *cmd_id_queue; GHashTable *cmd_hash; GAsyncQueue *result_queue; + const char *current_cmd_id; GMutex mutex; GThread *get_thread; int get_thread_running; @@ -92,10 +93,22 @@ int ttd_cmd_mgr_push_result(const char *id, ttd_cmd_result_e result, const char *data) { ttd_result_data_s *result_item = NULL; + const char *curr_id = NULL; retvm_if(!g_handle, -1, "cmd mgr is not initialized yet"); retvm_if(!id, -1, "cmd id is NULL"); + g_mutex_lock(&g_handle->mutex); + curr_id = g_handle->current_cmd_id; + g_mutex_unlock(&g_handle->mutex); + + retvm_if(!curr_id, -1, "current cmd id is NULL"); + + if (0 != g_strcmp0(id, curr_id)) { + _E("invaild cmd id[%s] - current cmd id[%s]", id, curr_id); + return -1; + } + result_item = g_try_new0(ttd_result_data_s, 1); result_item->cmd_id = g_strdup(id); @@ -290,6 +303,9 @@ static gpointer _launch_thread(gpointer data) goto DONE_N_WAIT; } + g_mutex_lock(&handle->mutex); + g_handle->current_cmd_id = cmd_id; + g_mutex_unlock(&handle->mutex); ret = launch_func(cmd_data); if (ret) { _E("cmd[%s] launch failed", cmd_id); @@ -306,14 +322,17 @@ static gpointer _launch_thread(gpointer data) static unsigned int count = 0; result_item = g_async_queue_timeout_pop( - g_handle->result_queue, RESULT_WAIT_TIME); + g_handle->result_queue, RESULT_WAIT_TIME); /* 10 sec */ if (!result_item) { count++; - if (count <= RESULT_WAIT_TRY_MAX) + if (count <= RESULT_WAIT_TRY_MAX) /* 10 times */ continue; + /* Wait 100 sec to receive a result, + * IS IT(100 sec) "ENOUGH" to install pkgs or task monitoring ??? + */ /* timeout to wait result, report fail */ report = ttd_build_json_create_report(cmd_id, cmd_type, TTD_CMD_STATE_FAILED, 0, "timeout to wait result ", NULL); @@ -364,6 +383,7 @@ static gpointer _launch_thread(gpointer data) DONE_N_WAIT: if (cmd_id) { g_mutex_lock(&handle->mutex); + g_handle->current_cmd_id = NULL; g_hash_table_remove(handle->cmd_hash, cmd_id); g_mutex_unlock(&handle->mutex); g_free(cmd_id); diff --git a/daemon/src/ttd-worker-interface.c b/daemon/src/ttd-worker-interface.c index 0505f4a..4468914 100644 --- a/daemon/src/ttd-worker-interface.c +++ b/daemon/src/ttd-worker-interface.c @@ -19,6 +19,7 @@ #include "ttd-worker-interface.h" #include "common-worker-inf-def.h" #include "common-worker-inf-dbus.h" +#include "ttd-cmd-mgr.h" struct _worker_interface_h { guint owner_id; @@ -26,19 +27,38 @@ struct _worker_interface_h { TtdWorkerDbus *dbus_obj; }; -static void +static gboolean __received_from_worker(TtdWorkerDbus *obj, - GDBusMethodInvocation *context, - GVariant *parameters, - void *user_data) + GDBusMethodInvocation *invocation, + const gchar *cmd_id, + const gchar *report, + gint working_state, + gpointer user_data) { int ret = 0; - ret_if(!obj); - ret_if(!context); - ret_if(!parameters); + if (!cmd_id) { + _E("cmd_id is NULL"); + ret = -1; + goto EXIT; + } + + if ((working_state < TTD_CMD_RESULT_RUNNING) || + (working_state > TTD_CMD_RESULT_FAIL)) { + _E("invail working state [%d]", working_state); + ret = -1; + goto EXIT; + } + + if (!report) + _W("report is NULL"); + + ret = ttd_cmd_mgr_push_result(cmd_id, working_state, report); + +EXIT: + ttd_worker_dbus_complete_ttd_worker_submit_report(obj, invocation, ret); - ttd_worker_dbus_complete_ttd_worker_submit_report(obj, context, ret); + return FALSE; } static void __on_name_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data) -- 2.7.4