Skip to content

Commit 58c9bb9

Browse files
committed
cffi: port to libyang4/sysrepo4
Add support for the new major versions of libyang.so and libsysrepo.so. Modify cffi/cdefs.h file according to sysrepo modifications: - Remove sr_conn_flag_t enum values, sr_connect does not use the flags anymore. Add the context flag instead. - Add sr_cache_running and sr_context_options. Adapt SysrepoConnection init to use the new syrepo functions: sr_cache_running and sr_context_options. Allow only libsysrepo.so.8 only. Signed-off-by: Jeremie Leska <[email protected]>
1 parent 642b3f3 commit 58c9bb9

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

cffi/cdefs.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ sr_log_level_t sr_log_get_syslog(void);
4444
typedef struct sr_conn_ctx_s sr_conn_ctx_t;
4545
typedef struct sr_session_ctx_s sr_session_ctx_t;
4646
typedef enum sr_conn_flag_e {
47-
SR_CONN_CACHE_RUNNING,
48-
SR_CONN_CTX_SET_PRIV_PARSED,
47+
SR_CONN_DEFAULT,
4948
...
5049
} sr_conn_flag_t;
51-
typedef uint32_t sr_conn_options_t;
50+
51+
typedef enum {
52+
SR_CTX_DEFAULT,
53+
SR_CTX_NO_PRINTED,
54+
SR_CTX_SET_PRIV_PARSED,
55+
...
56+
} sr_context_flag_t;
57+
5258
typedef enum sr_datastore_e {
5359
SR_DS_STARTUP,
5460
SR_DS_RUNNING,
@@ -76,8 +82,10 @@ struct timespec {
7682
long tv_nsec;
7783
};
7884

79-
int sr_connect(const sr_conn_options_t, sr_conn_ctx_t **);
85+
int sr_connect(const uint32_t opts, sr_conn_ctx_t **);
8086
int sr_disconnect(sr_conn_ctx_t *);
87+
void sr_cache_running(int);
88+
uint32_t sr_context_options(uint32_t, int, uint32_t *);
8189
const struct ly_ctx *sr_acquire_context(sr_conn_ctx_t *);
8290
void sr_release_context(sr_conn_ctx_t *);
8391
int sr_install_module(sr_conn_ctx_t *, const char *, const char *, const char **);

cffi/source.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#include <sysrepo/version.h>
88
#include <sysrepo/netconf_acm.h>
99

10-
#if (SR_VERSION_MAJOR != 7)
11-
#error "This version of sysrepo bindings only works with libsysrepo.so.7"
12-
#endif
13-
#if (SR_VERSION_MINOR < 10)
14-
#error "Need at least libsysrepo.so.7.10"
10+
#if (SR_VERSION_MAJOR != 8)
11+
#error "This version of sysrepo bindings only works with libsysrepo.so.8"
1512
#endif

sysrepo/connection.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,21 @@ def __init__(self, cache_running: bool = False):
4242
Always cache running datastore data which makes mainly repeated retrieval of
4343
data much faster. Affects all sessions created on this connection.
4444
"""
45-
flags = 0
46-
if cache_running:
47-
flags |= lib.SR_CONN_CACHE_RUNNING
45+
ctx_flags = 0
4846

4947
# mandatory flag to work with libyang-python
50-
flags |= lib.SR_CONN_CTX_SET_PRIV_PARSED
48+
ctx_flags |= lib.SR_CTX_SET_PRIV_PARSED
5149

5250
conn_p = ffi.new("sr_conn_ctx_t **")
5351
# valid_signals() is only available since python 3.8
5452
valid_signals = getattr(signal, "valid_signals", lambda: range(1, signal.NSIG))
5553
sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, valid_signals())
5654
try:
57-
check_call(lib.sr_connect, flags, conn_p)
55+
lib.sr_cache_running(cache_running)
56+
lib.sr_context_options(ctx_flags, 0, ffi.NULL)
57+
check_call(lib.sr_connect, 0, conn_p)
5858
self.cdata = ffi.gc(conn_p[0], lib.sr_disconnect)
59+
5960
finally:
6061
signal.pthread_sigmask(signal.SIG_SETMASK, sigmask)
6162

0 commit comments

Comments
 (0)