--- /dev/null
+/*
+ * 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_TASK_H__
+#define __TT_DAEMON_TASK_H__
+
+typedef struct __ttd_task ttd_task;
+typedef int (*ttd_task_func)(void *task_data);
+typedef void (*ttd_task_complete_func)(int result, void *user_data);
+
+ttd_task *ttd_task_new(int priority, ttd_task_func task_fn, void *task_data);
+int ttd_task_set_complete_func(ttd_task *task, ttd_task_complete_func complete_fn, void *user_data);
+int ttd_task_run(ttd_task *task);
+int ttd_task_sort_func(const void *a, const void *b, void *user_data);
+
+#endif /* __TT_DAEMON_TASK_H__ */
--- /dev/null
+/*
+ * 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.
+ */
+
+#include <glib.h>
+#include "ttd-log.h"
+#include "ttd-task.h"
+
+struct __ttd_task {
+ int priority;
+ ttd_task_func task_func;
+ void *task_data;
+ ttd_task_complete_func complete_func;
+ void *user_data;
+};
+
+ttd_task *ttd_task_new(int priority, ttd_task_func task_func, void *task_data)
+{
+ ttd_task *task = NULL;
+
+ task = g_malloc0(sizeof(struct __ttd_task));
+ if (task) {
+ task->priority = priority;
+ task->task_func = task_func;
+ task->task_data = task_data;
+ }
+ return task;
+}
+
+int ttd_task_set_complete_func(ttd_task *task, ttd_task_complete_func complete_func, void *user_data)
+{
+ if (!task)
+ return -1;
+
+ task->complete_func = complete_func;
+ task->user_data = user_data;
+
+ return 0;
+}
+
+int ttd_task_sort_func(const void *a, const void *b, void *user_data)
+{
+ const ttd_task *task_a = a;
+ const ttd_task *task_b = b;
+
+ if (!task_a || !task_b)
+ return 0;
+
+ return (task_a->priority - task_b->priority);
+}
+
+int ttd_task_run(ttd_task *task)
+{
+ int ret = 0;
+
+ retvm_if(!task, -1, "task is NULL");
+ retvm_if(!task->task_func, -1, "task_func is NULL");
+
+ ret = task->task_func(task->task_data);
+
+ if (task->complete_func) {
+ /* TODO : call it in mainloop or in thread????? */
+ task->complete_func(ret, task->user_data);
+ }
+ return 0;
+}