main: implementation 13/183213/5
authorMichal Kolodziejski <m.kolodziejs@samsung.com>
Mon, 2 Jul 2018 11:40:53 +0000 (13:40 +0200)
committerMichal Kolodziejski <m.kolodziejs@samsung.com>
Tue, 10 Jul 2018 12:14:07 +0000 (14:14 +0200)
Change-Id: Ifc140f9d3ed40ba1fd347a1ec52526ab84004d7b
Signed-off-by: Michal Kolodziejski <m.kolodziejs@samsung.com>
src/task-factory.c
src/task-worker.c
src/worker.c

index 938a85a..4aa889a 100644 (file)
@@ -192,6 +192,7 @@ static void execute_scan_apps_cpu(task_t *task)
 static void send_report(char *report)
 {
     //TODO send report here
+    DBG("%s", report);
 }
 
 static void release_system_task(task_t *task)
index 9112f9d..5a50377 100644 (file)
  * limitations under the License.
  */
 
+#include <glib.h>
+#include <signal.h>
+#include <string.h>
+#include <stdio.h>
+#include <glib-unix.h>
+#include "appinfo-provider.h"
+#include "config-deserializer.h"
+#include "log.h"
+#include "scheduler.h"
+#include "task-worker.h"
+#include "stats.h"
+
+static gboolean sigint_handler(gpointer user_data);
+
+static struct app_data
+{
+       GMainLoop *main_loop;
+       scheduler_t *scheduler;
+       config_t *current_config;
+} data = {
+       .main_loop = NULL,
+       .scheduler = NULL
+};
+
 int main(int argc, char *argv[])
 {
+       if (argc != 3)
+       {
+               DBG("Wrong number of input arguments!");
+               return -1;
+       }
+
+       int cfg_size = 0;
+       int total_duration = 0;
+       data.current_config = deserialize_configs(argv[2], &cfg_size, &total_duration);
+       app_provider_init();
+       if (!stats_init())
+       {
+               ERR("Stats module initialization failed");
+               g_free(data.current_config);
+               app_provider_shutdown();
+               return -2;
+       }
+
+       data.scheduler = scheduler_create();
+       data.main_loop = g_main_loop_new(NULL, true);
+       g_unix_signal_add(SIGINT, sigint_handler, data.main_loop);
+
+       scheduler_change_config(data.scheduler, data.current_config, cfg_size, total_duration);
+
+       g_main_loop_run(data.main_loop);
+
+       g_main_loop_unref(data.main_loop);
+       app_provider_shutdown();
+       scheduler_destroy(data.scheduler);
+       g_free(data.current_config);
+
+       DBG("Task-Worker finished!");
        return 0;
 }
 
 void cleanup_and_exit()
 {
-       //TODO implement
+       g_main_loop_quit(data.main_loop);
 }
+
+static gboolean sigint_handler(gpointer user_data)
+{
+       g_main_loop_quit(data.main_loop);
+
+       return TRUE;
+}
\ No newline at end of file
index dbd4d69..c48beb1 100644 (file)
@@ -85,7 +85,15 @@ int worker_enqueue_task(worker_t *worker, task_t *task)
 {
     ON_NULL_RETURN_VAL(worker, -1);
 
-    return g_thread_pool_push(worker->thread_pool, task, NULL);
+    GError *err = NULL;
+
+    gboolean res = g_thread_pool_push(worker->thread_pool, task, &err);
+    if (err != NULL)
+    {
+        ERR("Failed to enqueue task, err: %s", err->message);
+        g_error_free (err);
+    }
+    return res;
 }
 
 static void worker_function(gpointer data, gpointer user_data)