aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2024-01-14 14:29:00 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2024-01-19 18:23:01 +0100
commitcd7d8a96a2c3c1ec06d92a003ba481a611676464 (patch)
tree6446ffd1328b3e9c1972da1ce7e7fc0d1a69d930
parent69459b0a03a6937a6b1e76d22a4291042f1e076c (diff)
Add functions for events from server to client
The client may register a callback function to receive events. Because there is no relation between the connected client and the interface, all events are broadcasted to all clients that are connected to the server. Change-Id: I5ee3268f8349b611c3cf3fa0572dc5eab280ab2e
-rw-r--r--include/osmocom/e1d/proto_clnt.h2
-rw-r--r--include/osmocom/e1d/proto_srv.h2
-rw-r--r--src/e1d.h3
-rw-r--r--src/osmo-e1d.c3
-rw-r--r--src/osmo-e1gen.c2
-rw-r--r--src/proto_clnt.c19
-rw-r--r--src/proto_srv.c32
7 files changed, 61 insertions, 2 deletions
diff --git a/include/osmocom/e1d/proto_clnt.h b/include/osmocom/e1d/proto_clnt.h
index 53ccf89..26bd44e 100644
--- a/include/osmocom/e1d/proto_clnt.h
+++ b/include/osmocom/e1d/proto_clnt.h
@@ -49,3 +49,5 @@ int osmo_e1dp_client_ts_open(struct osmo_e1dp_client *clnt,
int osmo_e1dp_client_ts_open_force(struct osmo_e1dp_client *clnt,
uint8_t intf, uint8_t line, uint8_t ts,
enum osmo_e1dp_ts_mode mode, uint16_t read_bufsize);
+void osmo_e1dp_client_event_register(struct osmo_e1dp_client *clnt,
+ void (*cb)(enum osmo_e1dp_msg_type event, uint8_t intf, uint8_t line, uint8_t ts, uint8_t *data, int len));
diff --git a/include/osmocom/e1d/proto_srv.h b/include/osmocom/e1d/proto_srv.h
index e794725..f95ae13 100644
--- a/include/osmocom/e1d/proto_srv.h
+++ b/include/osmocom/e1d/proto_srv.h
@@ -46,3 +46,5 @@ struct osmo_e1dp_server_handler {
struct osmo_e1dp_server *osmo_e1dp_server_create(void *ctx, const char *path,
struct osmo_e1dp_server_handler *handlers, void *handler_data);
void osmo_e1dp_server_destroy(struct osmo_e1dp_server *srv);
+void osmo_e1dp_server_event(struct osmo_e1dp_server *srv, enum osmo_e1dp_msg_type event,
+ uint8_t intf, uint8_t line, uint8_t ts, uint8_t *data, int len);
diff --git a/src/e1d.h b/src/e1d.h
index 45ecb82..3188cfc 100644
--- a/src/e1d.h
+++ b/src/e1d.h
@@ -193,9 +193,12 @@ struct e1_intf {
struct llist_head lines;
};
+struct osmo_e1dp_server;
+
struct e1_daemon {
void *ctx;
struct llist_head interfaces;
+ struct osmo_e1dp_server *srv;
};
extern const struct octoi_ops e1d_octoi_ops;
diff --git a/src/osmo-e1d.c b/src/osmo-e1d.c
index dc264d9..329f584 100644
--- a/src/osmo-e1d.c
+++ b/src/osmo-e1d.c
@@ -44,8 +44,8 @@
#include <osmocom/vty/misc.h>
#include <osmocom/vty/cpu_sched_vty.h>
-#include <osmocom/e1d/proto_srv.h>
#include <osmocom/e1d/proto.h>
+#include <osmocom/e1d/proto_srv.h>
#include "e1d.h"
#include <osmocom/octoi/octoi.h>
@@ -221,6 +221,7 @@ int main(int argc, char *argv[])
/* server init */
srv = osmo_e1dp_server_create(g_e1d_ctx, E1DP_DEFAULT_SOCKET, e1d_ctl_handlers, e1d);
OSMO_ASSERT(srv);
+ e1d->srv = srv;
/* main loop */
while (!g_shutdown) {
diff --git a/src/osmo-e1gen.c b/src/osmo-e1gen.c
index 008f083..81ef21a 100644
--- a/src/osmo-e1gen.c
+++ b/src/osmo-e1gen.c
@@ -436,3 +436,5 @@ int main(int argc, char **argv)
return 0;
}
+
+void osmo_e1dp_server_event(void) {}
diff --git a/src/proto_clnt.c b/src/proto_clnt.c
index 93853e9..99d1cc2 100644
--- a/src/proto_clnt.c
+++ b/src/proto_clnt.c
@@ -64,18 +64,26 @@
#include "log.h"
+typedef void (*osmo_e1dp_event_cb_t)(enum osmo_e1dp_msg_type, uint8_t, uint8_t, uint8_t, uint8_t *, int);
/*! Internal representation of client program connected to the CTL socket */
struct osmo_e1dp_client {
void *ctx; /*!< talloc context */
struct osmo_fd ctl_fd; /*!< osmo-fd wrapped unix domain (CTL) socket to @osmo-e1d@ */
+ osmo_e1dp_event_cb_t event_cb;
+ /*!< callback function for incoming events */
};
static int
_e1dp_client_event(struct osmo_e1dp_client *clnt, struct msgb *msgb)
{
- /* FIXME */
+ struct osmo_e1dp_msg_hdr *hdr = msgb_l1(msgb);
+
+ if (!clnt->event_cb)
+ return -EINVAL;
+
+ clnt->event_cb(hdr->type, hdr->intf, hdr->line, hdr->ts, msgb_l2(msgb), msgb_l2len(msgb));
return 0;
}
@@ -455,3 +463,12 @@ osmo_e1dp_client_ts_open_force(struct osmo_e1dp_client *clnt,
{
return _client_ts_open(clnt, intf, line, ts, mode, read_bufsize, E1DP_TS_OPEN_F_FORCE);
}
+
+/*! Register event handler for incoming event messages.
+ * \param[in] clnt Client previously returned from osmo_e1dp_client_create(). */
+void
+osmo_e1dp_client_event_register(struct osmo_e1dp_client *clnt,
+ void (*cb)(enum osmo_e1dp_msg_type event, uint8_t intf, uint8_t line, uint8_t ts, uint8_t *data, int len))
+{
+ clnt->event_cb = cb;
+}
diff --git a/src/proto_srv.c b/src/proto_srv.c
index 2b85ac6..ab2fd30 100644
--- a/src/proto_srv.c
+++ b/src/proto_srv.c
@@ -260,3 +260,35 @@ osmo_e1dp_server_destroy(struct osmo_e1dp_server *srv)
osmo_fd_close(&srv->ctl_fd);
talloc_free(srv);
}
+
+void
+osmo_e1dp_server_event(struct osmo_e1dp_server *srv, enum osmo_e1dp_msg_type event,
+ uint8_t intf, uint8_t line, uint8_t ts, uint8_t *data, int len)
+{
+ struct osmo_e1dp_msg_hdr *hdr;
+ struct msgb *msgb;
+ struct osmo_e1dp_server_conn *conn;
+
+ /* Call handler */
+ msgb = msgb_alloc(E1DP_MAX_LEN, "e1d proto tx (event) message");
+
+ msgb->l1h = msgb_put(msgb, sizeof(struct osmo_e1dp_msg_hdr));
+ hdr = msgb_l1(msgb);
+ if (data && len) {
+ msgb->l2h = msgb_put(msgb, len);
+ memcpy(msgb->l2h, data, len);
+ }
+ hdr->magic = E1DP_MAGIC;
+ hdr->type = event;
+ hdr->len = msgb_length(msgb);
+ hdr->intf = intf;
+ hdr->line = line;
+ hdr->ts = ts;
+
+ /* Send event */
+ llist_for_each_entry(conn, &srv->conns, list)
+ osmo_e1dp_send(&conn->fd, msgb, -1);
+
+ /* Done */
+ msgb_free(msgb);
+}