/* * 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 #include #include #include #include #include "appinfo-provider.h" #include "config-deserializer.h" #include "log.h" #include "scheduler.h" #include "task-worker.h" #include "process.h" #include "ipc.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) { ERR("Wrong number of input arguments!"); return -1; } int cfg_size = 0; int task_counter = 0; data.current_config = deserialize_configs(argv[2], &cfg_size, &task_counter); if (task_counter == 0) { ERR("Task counter equals 0"); g_free(data.current_config); return -2; } app_provider_init(); ipc_init(argv[1], task_counter); if (process_init() != 0) { ERR("Process module initialization failed"); g_free(data.current_config); ipc_shutdown(); app_provider_shutdown(); return -3; } 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); g_main_loop_run(data.main_loop); g_main_loop_unref(data.main_loop); scheduler_destroy(data.scheduler); app_provider_shutdown(); ipc_shutdown(); free_configs(data.current_config, cfg_size); return 0; } void cleanup_and_exit() { g_main_loop_quit(data.main_loop); } static gboolean sigint_handler(gpointer user_data) { g_main_loop_quit(data.main_loop); return TRUE; }