From 41d3448a2211e86dca0d51bfb51c8de269e2eee7 Mon Sep 17 00:00:00 2001 From: Mateo Cindric Date: Sat, 14 Jan 2023 13:14:48 +0000 Subject: [PATCH] interfaces-plugin: change main.c to use extern plugin functions --- src/interfaces/src/main.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/interfaces/src/main.c b/src/interfaces/src/main.c index fe03630f..7030a679 100644 --- a/src/interfaces/src/main.c +++ b/src/interfaces/src/main.c @@ -10,17 +10,17 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -#include #include +#include #include -#include "plugin.h" -#include "plugin/common.h" - -#include - volatile int exit_application = 0; +// extern needed data to build the plugin executable +extern const char* PLUGIN_NAME; +extern int sr_plugin_init_cb(sr_session_ctx_t* session, void** private_data); +extern void sr_plugin_cleanup_cb(sr_session_ctx_t* session, void* private_data); + static void sigint_handler(__attribute__((unused)) int signum); int main(void) @@ -33,11 +33,23 @@ int main(void) sr_log_stderr(SR_LL_INF); /* connect to sysrepo */ - SRPC_SAFE_CALL_ERR(error, sr_connect(SR_CONN_DEFAULT, &connection), out); - SRPC_SAFE_CALL_ERR(error, sr_session_start(connection, SR_DS_RUNNING, &session), out); + error = sr_connect(SR_CONN_DEFAULT, &connection); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_connect error (%d): %s", error, sr_strerror(error)); + goto out; + } - /* init plugin */ - SRPC_SAFE_CALL_ERR(error, sr_plugin_init_cb(session, &private_data), out); + error = sr_session_start(connection, SR_DS_RUNNING, &session); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_session_start error (%d): %s", error, sr_strerror(error)); + goto out; + } + + error = sr_plugin_init_cb(session, &private_data); + if (error) { + SRPLG_LOG_ERR(PLUGIN_NAME, "sr_plugin_init_cb error"); + goto out; + } /* loop until ctrl-c is pressed / SIGINT is received */ signal(SIGINT, sigint_handler); @@ -47,7 +59,6 @@ int main(void) } out: - /* cleanup plugin */ sr_plugin_cleanup_cb(session, private_data); sr_disconnect(connection); @@ -58,4 +69,4 @@ static void sigint_handler(__attribute__((unused)) int signum) { SRPLG_LOG_INF(PLUGIN_NAME, "Sigint called, exiting..."); exit_application = 1; -} \ No newline at end of file +}