laforge has submitted this change. (
https://gerrit.osmocom.org/c/osmo-e1d/+/35558?usp=email )
(
4 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
)Change subject: Add functions for events from server to client
......................................................................
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
---
M include/osmocom/e1d/proto_clnt.h
M include/osmocom/e1d/proto_srv.h
M src/e1d.h
M src/osmo-e1d.c
M src/osmo-e1gen.c
M src/proto_clnt.c
M src/proto_srv.c
7 files changed, 76 insertions(+), 2 deletions(-)
Approvals:
tnt: Looks good to me, approved
Jenkins Builder: Verified
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_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 *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 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 @@
/* 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 @@
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 @@
{
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_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);
+}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-e1d/+/35558?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-e1d
Gerrit-Branch: master
Gerrit-Change-Id: I5ee3268f8349b611c3cf3fa0572dc5eab280ab2e
Gerrit-Change-Number: 35558
Gerrit-PatchSet: 5
Gerrit-Owner: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: tnt <tnt(a)246tNt.com>
Gerrit-MessageType: merged