mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-03 14:23:02 +02:00
src/confd: minor refactor, add convenience macro REGISTER_OPER()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -47,6 +47,10 @@ static inline void print_val(sr_val_t *val)
|
||||
if ((rc = register_change(s, m, x, f, c, a, u))) \
|
||||
goto err
|
||||
|
||||
#define REGISTER_OPER(s,m,x,c,a,f,u) \
|
||||
if ((rc = register_oper(s, m, x, c, a, f, u))) \
|
||||
goto err
|
||||
|
||||
#define REGISTER_RPC(s,x,c,a,u) \
|
||||
if ((rc = register_rpc(s, x, c, a, u))) \
|
||||
goto err
|
||||
@@ -68,6 +72,15 @@ static inline int register_change(sr_session_ctx_t *session, const char *module,
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int register_oper(sr_session_ctx_t *session, const char *module, const char *xpath,
|
||||
sr_oper_get_items_cb cb, void *arg, int flags, sr_subscription_ctx_t **sub)
|
||||
{
|
||||
int rc = sr_oper_get_subscribe(session, module, xpath, cb, arg, flags | SR_SUBSCR_DEFAULT, sub);
|
||||
if (rc)
|
||||
ERROR("failed subscribing to %s oper: %s", xpath, sr_strerror(rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int register_rpc(sr_session_ctx_t *session, const char *xpath,
|
||||
sr_rpc_cb cb, void *arg, sr_subscription_ctx_t **sub)
|
||||
{
|
||||
|
||||
@@ -639,22 +639,15 @@ int ietf_system_init(struct confd *confd)
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
rc = sr_oper_get_subscribe(confd->session, "ietf-system", CLOCK_PATH_,
|
||||
clock_cb, NULL, SR_SUBSCR_DEFAULT, &confd->sub);
|
||||
if (rc != SR_ERR_OK)
|
||||
goto err;
|
||||
|
||||
rc = sr_oper_get_subscribe(confd->session, "ietf-system", PLATFORM_PATH_,
|
||||
platform_cb, NULL, SR_SUBSCR_DEFAULT, &confd->sub);
|
||||
if (rc != SR_ERR_OK)
|
||||
goto err;
|
||||
|
||||
REGISTER_CHANGE(confd->session, "ietf-system", "/ietf-system:system/hostname", 0, change_hostname, confd, &confd->sub);
|
||||
REGISTER_CHANGE(confd->session, "ietf-system", "/ietf-system:system/infix-system:motd", 0, change_motd, confd, &confd->sub);
|
||||
REGISTER_CHANGE(confd->session, "ietf-system", "/ietf-system:system/clock", 0, change_clock, confd, &confd->sub);
|
||||
REGISTER_CHANGE(confd->session, "ietf-system", "/ietf-system:system/ntp", 0, change_ntp, confd, &confd->sub);
|
||||
REGISTER_CHANGE(confd->session, "ietf-system", "/ietf-system:system/dns-resolver", 0, change_dns, confd, &confd->sub);
|
||||
|
||||
REGISTER_OPER(confd->session, "ietf-system", CLOCK_PATH_, clock_cb, NULL, 0, &confd->sub);
|
||||
REGISTER_OPER(confd->session, "ietf-system", PLATFORM_PATH_, platform_cb, NULL, 0, &confd->sub);
|
||||
|
||||
REGISTER_RPC(confd->session, "/ietf-system:system-restart", rpc_exec, "reboot", &confd->sub);
|
||||
REGISTER_RPC(confd->session, "/ietf-system:system-shutdown", rpc_exec, "poweroff", &confd->sub);
|
||||
REGISTER_RPC(confd->session, "/ietf-system:set-current-datetime", rpc_set_datetime, NULL, &confd->sub);
|
||||
|
||||
Reference in New Issue
Block a user