diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2013-10-10 20:21:33 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2013-10-10 20:21:33 +0200 |
commit | 2c9168cf34d370b4ea2b21177402d01a7cfffea8 (patch) | |
tree | 16f3935dc484a58ca2a2477a7acc129c5437ca22 | |
parent | 4cb8b94db8180e84a55c3ef88044507111077783 (diff) |
vty: Make vty_event dispatch signals and use it in the testcase
The testcase didn't work on Ubuntu 12.04 because vty_create will
directly call vty_event (e.g. not through the plt). This means
that the approach to override vty_event in the testcase failed.
Use the signal interface of libosmocore and make the testcase
use it. The signals can be generally useful as well.
-rw-r--r-- | include/osmocom/core/signal.h | 1 | ||||
-rw-r--r-- | include/osmocom/vty/vty.h | 14 | ||||
-rw-r--r-- | src/vty/telnet_interface.c | 14 | ||||
-rw-r--r-- | tests/vty/vty_test.c | 21 |
4 files changed, 45 insertions, 5 deletions
diff --git a/include/osmocom/core/signal.h b/include/osmocom/core/signal.h index b3a5aaee..19a2688f 100644 --- a/include/osmocom/core/signal.h +++ b/include/osmocom/core/signal.h @@ -19,6 +19,7 @@ enum { SS_L_GLOBAL = OSMO_SIGNAL_SS_RESERVED, SS_L_INPUT, SS_L_NS, + SS_L_VTY, }; /* application-defined signal types. */ diff --git a/include/osmocom/vty/vty.h b/include/osmocom/vty/vty.h index e656abf6..ea987bf3 100644 --- a/include/osmocom/vty/vty.h +++ b/include/osmocom/vty/vty.h @@ -190,6 +190,20 @@ extern void *tall_vty_ctx; extern struct cmd_element cfg_description_cmd; extern struct cmd_element cfg_no_description_cmd; + +/** + * signal handling + */ +enum signal_vty { + S_VTY_EVENT, +}; + +struct vty_signal_data { + enum event event; + int sock; + struct vty *vty; +}; + /*! @} */ #endif diff --git a/src/vty/telnet_interface.c b/src/vty/telnet_interface.c index 1abf141d..32ab6bee 100644 --- a/src/vty/telnet_interface.c +++ b/src/vty/telnet_interface.c @@ -30,6 +30,7 @@ #include <osmocom/core/socket.h> #include <osmocom/core/talloc.h> #include <osmocom/core/logging.h> +#include <osmocom/core/signal.h> #include <osmocom/vty/telnet_interface.h> #include <osmocom/vty/buffer.h> @@ -166,12 +167,23 @@ static int telnet_new_connection(struct osmo_fd *fd, unsigned int what) /*! \brief callback from core VTY code about VTY related events */ void vty_event(enum event event, int sock, struct vty *vty) { + struct vty_signal_data sig_data = { 0, }; struct telnet_connection *connection = vty->priv; - struct osmo_fd *bfd = &connection->fd; + struct osmo_fd *bfd; if (vty->type != VTY_TERM) return; + sig_data.event = event; + sig_data.sock = sock; + sig_data.vty = vty; + osmo_signal_dispatch(SS_L_VTY, S_VTY_EVENT, &sig_data); + + if (!connection) + return; + + bfd = &connection->fd; + switch (event) { case VTY_READ: bfd->when |= BSC_FD_READ; diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c index 5f93b3db..2a7347f8 100644 --- a/tests/vty/vty_test.c +++ b/tests/vty/vty_test.c @@ -28,6 +28,7 @@ #include <osmocom/core/talloc.h> #include <osmocom/core/logging.h> #include <osmocom/core/utils.h> +#include <osmocom/core/signal.h> #include <osmocom/vty/misc.h> #include <osmocom/vty/vty.h> #include <osmocom/vty/command.h> @@ -67,12 +68,22 @@ static int do_vty_command(struct vty *vty, const char *cmd) return ret; } -/* Override the implementation from telnet_interface.c */ -void vty_event(enum event event, int sock, struct vty *vty) +/* Handle the events from telnet_interface.c */ +static int vty_event_cb(unsigned int subsys, unsigned int signal, + void *handler_data, void *_signal_data) { - last_vty_connection_event = event; + struct vty_signal_data *signal_data; - fprintf(stderr, "Got VTY event: %d\n", event); + if (subsys != SS_L_VTY) + return 0; + if (signal != S_VTY_EVENT) + return 0; + + signal_data = _signal_data; + last_vty_connection_event = signal_data->event; + + fprintf(stderr, "Got VTY event: %d\n", signal_data->event); + return 0; } static void test_node_tree_structure(void) @@ -169,6 +180,8 @@ static void test_node_tree_structure(void) int main(int argc, char **argv) { + osmo_signal_register_handler(SS_L_VTY, vty_event_cb, NULL); + test_cmd_string_from_valstr(); test_node_tree_structure(); printf("All tests passed\n"); |