Skip to content

Commit

Permalink
interfaces-plugin: change main.c to use extern plugin functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zinccyy committed Jan 14, 2023
1 parent 10432c3 commit 41d3448
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/interfaces/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <signal.h>
#include <sysrepo.h>
#include <signal.h>
#include <unistd.h>

#include "plugin.h"
#include "plugin/common.h"

#include <srpc.h>

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)
Expand All @@ -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);
Expand All @@ -47,7 +59,6 @@ int main(void)
}

out:
/* cleanup plugin */
sr_plugin_cleanup_cb(session, private_data);
sr_disconnect(connection);

Expand All @@ -58,4 +69,4 @@ static void sigint_handler(__attribute__((unused)) int signum)
{
SRPLG_LOG_INF(PLUGIN_NAME, "Sigint called, exiting...");
exit_application = 1;
}
}

0 comments on commit 41d3448

Please sign in to comment.