X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fbindings%2Frmr-python%2Frmr%2Frmr.py;h=413d8dcbdaeb042695fd5bed863316e0df9a1e79;hb=5894fe2cbcae9f2929b9bb5b765e9e333ddaed6a;hp=336dca32e62e4c716adb8603ae136c23ae80ab44;hpb=04c3a6eab6289751feb358c4d3ebe451992d80cf;p=ric-plt%2Flib%2Frmr.git diff --git a/src/bindings/rmr-python/rmr/rmr.py b/src/bindings/rmr-python/rmr/rmr.py index 336dca3..413d8dc 100644 --- a/src/bindings/rmr-python/rmr/rmr.py +++ b/src/bindings/rmr-python/rmr/rmr.py @@ -1,7 +1,7 @@ # vim: expandtab ts=4 sw=4: # ================================================================================== -# Copyright (c) 2019 Nokia -# Copyright (c) 2018-2019 AT&T Intellectual Property. +# Copyright (c) 2019-2020 Nokia +# Copyright (c) 2018-2020 AT&T Intellectual Property. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,15 +20,14 @@ import json from ctypes import RTLD_GLOBAL, Structure, c_int, POINTER, c_char, c_char_p, c_void_p, memmove, cast from ctypes import CDLL from ctypes import create_string_buffer -from rmr.exceptions import BadBufferAllocation +from rmr.exceptions import BadBufferAllocation, MeidSizeOutOfRange, InitFailed # https://docs.python.org/3.7/library/ctypes.html # https://stackoverflow.com/questions/2327344/ctypes-loading-a-c-shared-library-that-has-dependencies/30845750#30845750 # make sure you do a set -x LD_LIBRARY_PATH /usr/local/lib/; # even though we don't use these directly, they contain symbols we need -_ = CDLL("libnng.so", mode=RTLD_GLOBAL) -rmr_c_lib = CDLL("librmr_nng.so", mode=RTLD_GLOBAL) +rmr_c_lib = CDLL("librmr_si.so", mode=RTLD_GLOBAL) # Internal Helpers (not a part of public api) @@ -169,8 +168,14 @@ def rmr_init(uproto_port, max_msg_size, flags): """ Refer to rmr C documentation for rmr_init extern void* rmr_init(char* uproto_port, int max_msg_size, int flags) + + This python function checks that the context is not None and raises + an excption if it is. """ - return _rmr_init(uproto_port, max_msg_size, flags) + mrc = _rmr_init(uproto_port, max_msg_size, flags) + if mrc is None: + raise InitFailed() + return mrc _rmr_ready = rmr_c_lib.rmr_ready @@ -391,7 +396,16 @@ def rmr_set_meid(ptr_mbuf, byte_str): """ Refer to the rmr C documentation for rmr_bytes2meid extern int rmr_bytes2meid(rmr_mbuf_t* mbuf, unsigned char const* src, int len); + + Caution: the meid length supported in an RMR message is 32 bytes, but C applications + expect this to be a nil terminated string and thus only 31 bytes are actually available. + + Raises: exceptions.MeidSizeOutOfRang """ + max = _get_constants().get("RMR_MAX_MEID", 32) + if len(byte_str) >= max: + raise MeidSizeOutOfRange + return _rmr_bytes2meid(ptr_mbuf, byte_str, len(byte_str)) @@ -421,7 +435,7 @@ def rmr_get_meid(ptr_mbuf): string: meid """ - sz = _get_constants().get("RMR_MAX_MEID", 64) # size for buffer to fill + sz = _get_constants().get("RMR_MAX_MEID", 32) # size for buffer to fill buf = create_string_buffer(sz) _rmr_get_meid(ptr_mbuf, buf) return buf.value