From f7f64c8db298455c19897d4ece458a77fac56b4b Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:15:08 +0000 Subject: [PATCH] Add ercp_connect() call to ERCP interface This is used by sesman to connect to sockets in the restart directory. --- libipm/ercp.c | 26 ++++++++++++++++++++++++++ libipm/ercp.h | 10 ++++++++++ 2 files changed, 36 insertions(+) diff --git a/libipm/ercp.c b/libipm/ercp.c index a5ba61c9..e048f5fb 100644 --- a/libipm/ercp.c +++ b/libipm/ercp.c @@ -81,6 +81,32 @@ ercp_trans_from_eicp_trans(struct trans *trans, /*****************************************************************************/ +struct trans * +ercp_connect(const char *port, int (*term_func)(void)) +{ + struct trans *t; + + if ((t = trans_create(TRANS_MODE_UNIX, 128, 128)) != NULL) + { + t->is_term = term_func; + + if (trans_connect(t, NULL, port, 3000) != 0) + { + trans_delete(t); + t = NULL; + } + else if (ercp_init_trans(t) != 0) + { + trans_delete(t); + t = NULL; + } + } + + return t; +} + +/*****************************************************************************/ + int ercp_msg_in_check_available(struct trans *trans, int *available) { diff --git a/libipm/ercp.h b/libipm/ercp.h index aac0a8d6..c77bf984 100644 --- a/libipm/ercp.h +++ b/libipm/ercp.h @@ -88,6 +88,16 @@ ercp_trans_from_eicp_trans(struct trans *trans, ttrans_data_in callback_func, void *callback_data); +/** + * Connects to an ERCP endpoint. + * + * @param port Path to UDS object in filesystem + * @param term_func Function to poll during connection for program + * termination, or NULL for none. + */ +struct trans * +ercp_connect(const char *port, + int (*term_func)(void)); /** * Checks an ERCP transport to see if a complete message is