#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
GAsyncQueue *cmd_id_queue;
GHashTable *cmd_hash;
GAsyncQueue *result_queue;
+ const char *current_cmd_id;
GMutex mutex;
GThread *get_thread;
int get_thread_running;
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);
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);
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);
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);
#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;
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)