Harald Welte | f5a0fa3 | 2019-03-03 15:44:18 +0100 | [diff] [blame] | 1 | #include <unistd.h> |
Harald Welte | ce638d8 | 2019-03-17 09:36:04 +0100 | [diff] [blame] | 2 | #include <signal.h> |
Harald Welte | f5a0fa3 | 2019-03-03 15:44:18 +0100 | [diff] [blame] | 3 | |
| 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 | |
| 16 | struct rspro_server *g_rps; |
| 17 | void *g_tall_ctx; |
Harald Welte | b54a51e | 2019-03-31 15:57:59 +0200 | [diff] [blame] | 18 | __thread void *talloc_asn1_ctx; |
| 19 | |
Harald Welte | f5a0fa3 | 2019-03-03 15:44:18 +0100 | [diff] [blame] | 20 | struct osmo_fd g_event_ofd; |
| 21 | |
Harald Welte | ce638d8 | 2019-03-17 09:36:04 +0100 | [diff] [blame] | 22 | static void handle_sig_usr1(int signal) |
| 23 | { |
| 24 | OSMO_ASSERT(signal == SIGUSR1); |
Harald Welte | b54a51e | 2019-03-31 15:57:59 +0200 | [diff] [blame] | 25 | talloc_report_full(g_tall_ctx, stderr); |
Harald Welte | ce638d8 | 2019-03-17 09:36:04 +0100 | [diff] [blame] | 26 | } |
| 27 | |
Harald Welte | f5a0fa3 | 2019-03-03 15:44:18 +0100 | [diff] [blame] | 28 | int main(int argc, char **argv) |
| 29 | { |
Harald Welte | 0c50c34 | 2019-07-21 20:16:29 +0200 | [diff] [blame] | 30 | void *talloc_rest_ctx; |
Harald Welte | f5a0fa3 | 2019-03-03 15:44:18 +0100 | [diff] [blame] | 31 | int rc; |
| 32 | |
| 33 | g_tall_ctx = talloc_named_const(NULL, 0, "global"); |
Harald Welte | b54a51e | 2019-03-31 15:57:59 +0200 | [diff] [blame] | 34 | talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1"); |
Harald Welte | 0c50c34 | 2019-07-21 20:16:29 +0200 | [diff] [blame] | 35 | talloc_rest_ctx = talloc_named_const(g_tall_ctx, 0, "rest"); |
Harald Welte | 92fd734 | 2019-07-18 18:46:48 +0200 | [diff] [blame] | 36 | msgb_talloc_ctx_init(g_tall_ctx, 0); |
Harald Welte | f5a0fa3 | 2019-03-03 15:44:18 +0100 | [diff] [blame] | 37 | |
| 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 Welte | ce638d8 | 2019-03-17 09:36:04 +0100 | [diff] [blame] | 59 | signal(SIGUSR1, handle_sig_usr1); |
| 60 | |
Harald Welte | 0c50c34 | 2019-07-21 20:16:29 +0200 | [diff] [blame] | 61 | rc = rest_api_init(talloc_rest_ctx, 9997); |
Harald Welte | f5a0fa3 | 2019-03-03 15:44:18 +0100 | [diff] [blame] | 62 | 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 | |
| 73 | out_eventfd: |
| 74 | close(g_event_ofd.fd); |
| 75 | out_rps: |
| 76 | talloc_free(g_rps->slotmaps); |
| 77 | talloc_free(g_rps); |
| 78 | out_rspro: |
| 79 | rspro_server_destroy(g_rps); |
| 80 | |
| 81 | exit(1); |
| 82 | } |