blob: 70cbedc5b30e56ed2785bced6f72e94a47ccd5f1 [file] [log] [blame]
Harald Weltef5a0fa32019-03-03 15:44:18 +01001#include <unistd.h>
Harald Weltece638d82019-03-17 09:36:04 +01002#include <signal.h>
Harald Weltef5a0fa32019-03-03 15:44:18 +01003
4#include <sys/eventfd.h>
5
6#include <osmocom/core/utils.h>
7#include <osmocom/core/talloc.h>
8#include <osmocom/core/application.h>
9#include <osmocom/core/select.h>
10
11#include "debug.h"
12#include "slotmap.h"
13#include "rest_api.h"
14#include "rspro_server.h"
15
16struct rspro_server *g_rps;
17void *g_tall_ctx;
Harald Welteb54a51e2019-03-31 15:57:59 +020018__thread void *talloc_asn1_ctx;
19
Harald Weltef5a0fa32019-03-03 15:44:18 +010020struct osmo_fd g_event_ofd;
21
Harald Weltece638d82019-03-17 09:36:04 +010022static void handle_sig_usr1(int signal)
23{
24 OSMO_ASSERT(signal == SIGUSR1);
Harald Welteb54a51e2019-03-31 15:57:59 +020025 talloc_report_full(g_tall_ctx, stderr);
Harald Weltece638d82019-03-17 09:36:04 +010026}
27
Harald Weltef5a0fa32019-03-03 15:44:18 +010028int main(int argc, char **argv)
29{
Harald Welte0c50c342019-07-21 20:16:29 +020030 void *talloc_rest_ctx;
Harald Weltef5a0fa32019-03-03 15:44:18 +010031 int rc;
32
33 g_tall_ctx = talloc_named_const(NULL, 0, "global");
Harald Welteb54a51e2019-03-31 15:57:59 +020034 talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
Harald Welte0c50c342019-07-21 20:16:29 +020035 talloc_rest_ctx = talloc_named_const(g_tall_ctx, 0, "rest");
Harald Welte92fd7342019-07-18 18:46:48 +020036 msgb_talloc_ctx_init(g_tall_ctx, 0);
Harald Weltef5a0fa32019-03-03 15:44:18 +010037
38 osmo_init_logging2(g_tall_ctx, &log_info);
39
40 g_rps = rspro_server_create(g_tall_ctx, "0.0.0.0", 9998);
41 if (!g_rps)
42 exit(1);
43 g_rps->slotmaps = slotmap_init(g_rps);
44 if (!g_rps->slotmaps)
45 goto out_rspro;
46
47 g_rps->comp_id.type = ComponentType_remsimServer;
48 OSMO_STRLCPY_ARRAY(g_rps->comp_id.name, "fixme-name");
49 OSMO_STRLCPY_ARRAY(g_rps->comp_id.software, "remsim-server");
50 OSMO_STRLCPY_ARRAY(g_rps->comp_id.sw_version, PACKAGE_VERSION);
51 /* FIXME: other members of app_comp_id */
52
53 rc = eventfd(0, 0);
54 if (rc < 0)
55 goto out_rps;
56 osmo_fd_setup(&g_event_ofd, rc, BSC_FD_READ, event_fd_cb, g_rps, 0);
57 osmo_fd_register(&g_event_ofd);
58
Harald Weltece638d82019-03-17 09:36:04 +010059 signal(SIGUSR1, handle_sig_usr1);
60
Harald Welte0c50c342019-07-21 20:16:29 +020061 rc = rest_api_init(talloc_rest_ctx, 9997);
Harald Weltef5a0fa32019-03-03 15:44:18 +010062 if (rc < 0)
63 goto out_eventfd;
64
65 while (1) {
66 osmo_select_main(0);
67 }
68
69 rest_api_fini();
70
71 exit(0);
72
73out_eventfd:
74 close(g_event_ofd.fd);
75out_rps:
76 talloc_free(g_rps->slotmaps);
77 talloc_free(g_rps);
78out_rspro:
79 rspro_server_destroy(g_rps);
80
81 exit(1);
82}