source: ogServer-Git/sources/main.c @ 48de515

Last change on this file since 48de515 was 48de515, checked in by OpenGnSys Support Team <soporte-og@…>, 4 years ago

#971 split socket core logic and main files

Extract socket core and main from ogAdmServer file.

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[48de515]1/*
2 * Copyright (C) 2020 Soleta Networks <info@soleta.eu>
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Affero General Public License as published by the
6 * Free Software Foundation, version 3.
7 */
8
9#include "ogAdmServer.h"
10#include "dbi.h"
11#include "utils.h"
12#include "list.h"
13#include "rest.h"
14#include "client.h"
15#include "json.h"
16#include "schedule.h"
17#include "core.h"
18#include <syslog.h>
19
20int main(int argc, char *argv[])
21{
22        struct ev_io ev_io_server_rest, ev_io_agent_rest;
23        int i;
24
25        og_loop = ev_default_loop(0);
26
27        if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
28                exit(EXIT_FAILURE);
29
30        openlog("ogAdmServer", LOG_PID, LOG_DAEMON);
31
32        if (!validacionParametros(argc, argv, 1)) // Valida parámetros de ejecución
33                exit(EXIT_FAILURE);
34
35        if (!tomaConfiguracion(szPathFileCfg)) { // Toma parametros de configuracion
36                exit(EXIT_FAILURE);
37        }
38
39        for (i = 0; i < MAXIMOS_CLIENTES; i++) {
40                tbsockets[i].ip[0] = '\0';
41                tbsockets[i].cli = NULL;
42        }
43
44        socket_rest = og_socket_server_init("8888");
45        if (socket_rest < 0)
46                exit(EXIT_FAILURE);
47
48        ev_io_init(&ev_io_server_rest, og_server_accept_cb, socket_rest, EV_READ);
49        ev_io_start(og_loop, &ev_io_server_rest);
50
51        socket_agent_rest = og_socket_server_init("8889");
52        if (socket_agent_rest < 0)
53                exit(EXIT_FAILURE);
54
55        ev_io_init(&ev_io_agent_rest, og_server_accept_cb, socket_agent_rest, EV_READ);
56        ev_io_start(og_loop, &ev_io_agent_rest);
57
58        if (og_dbi_schedule_get() < 0)
59                exit(EXIT_FAILURE);
60
61        og_schedule_next(og_loop);
62
63        syslog(LOG_INFO, "Waiting for connections\n");
64
65        while (1)
66                ev_loop(og_loop, 0);
67
68        exit(EXIT_SUCCESS);
69}
Note: See TracBrowser for help on using the repository browser.