* 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
{
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)