summaryrefslogtreecommitdiffstats
path: root/sources/main.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2020-06-24 14:37:19 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-06-24 14:43:10 +0200
commit48de51537ec18606f8adc52e9c43d222a330cf58 (patch)
tree36d833f0c004d52ba4145a2f6947d6a83deca6a9 /sources/main.c
parentc46fa3c9e560ccf4adc35319559d778482b8aac6 (diff)
#971 split socket core logic and main files
Extract socket core and main from ogAdmServer file.
Diffstat (limited to 'sources/main.c')
-rw-r--r--sources/main.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/sources/main.c b/sources/main.c
new file mode 100644
index 0000000..31263d6
--- /dev/null
+++ b/sources/main.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2020 Soleta Networks <info@soleta.eu>
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU Affero General Public License as published by the
+ * Free Software Foundation, version 3.
+ */
+
+#include "ogAdmServer.h"
+#include "dbi.h"
+#include "utils.h"
+#include "list.h"
+#include "rest.h"
+#include "client.h"
+#include "json.h"
+#include "schedule.h"
+#include "core.h"
+#include <syslog.h>
+
+int main(int argc, char *argv[])
+{
+ struct ev_io ev_io_server_rest, ev_io_agent_rest;
+ int i;
+
+ og_loop = ev_default_loop(0);
+
+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
+ exit(EXIT_FAILURE);
+
+ openlog("ogAdmServer", LOG_PID, LOG_DAEMON);
+
+ if (!validacionParametros(argc, argv, 1)) // Valida parámetros de ejecución
+ exit(EXIT_FAILURE);
+
+ if (!tomaConfiguracion(szPathFileCfg)) { // Toma parametros de configuracion
+ exit(EXIT_FAILURE);
+ }
+
+ for (i = 0; i < MAXIMOS_CLIENTES; i++) {
+ tbsockets[i].ip[0] = '\0';
+ tbsockets[i].cli = NULL;
+ }
+
+ socket_rest = og_socket_server_init("8888");
+ if (socket_rest < 0)
+ exit(EXIT_FAILURE);
+
+ ev_io_init(&ev_io_server_rest, og_server_accept_cb, socket_rest, EV_READ);
+ ev_io_start(og_loop, &ev_io_server_rest);
+
+ socket_agent_rest = og_socket_server_init("8889");
+ if (socket_agent_rest < 0)
+ exit(EXIT_FAILURE);
+
+ ev_io_init(&ev_io_agent_rest, og_server_accept_cb, socket_agent_rest, EV_READ);
+ ev_io_start(og_loop, &ev_io_agent_rest);
+
+ if (og_dbi_schedule_get() < 0)
+ exit(EXIT_FAILURE);
+
+ og_schedule_next(og_loop);
+
+ syslog(LOG_INFO, "Waiting for connections\n");
+
+ while (1)
+ ev_loop(og_loop, 0);
+
+ exit(EXIT_SUCCESS);
+}