X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fbindings%2Frmr-python%2Frmr%2Frmr.py;h=d1326c0f7f3aff781d31ee81fefa962a3fa8223f;hb=eaf0993ee018afdc58cfccb6f90852db7a431e4e;hp=bc6523708aadcfeda364958969b895dbcf36e699;hpb=46ae0f44cd0ea713601f16adc5ea709e607eb2e8;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 bc65237..d1326c0 100644 --- a/src/bindings/rmr-python/rmr/rmr.py +++ b/src/bindings/rmr-python/rmr/rmr.py @@ -18,7 +18,7 @@ import uuid 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, pythonapi +from ctypes import create_string_buffer # 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 @@ -83,17 +83,20 @@ def _get_mapping_dict(cache={}): def _state_to_status(stateno): """ - convery a msg state to status - """ - sdict = _get_mapping_dict() - return sdict.get(stateno, "UNKNOWN STATE") + Convert a msg state to status + Parameters + ---------- + stateno: int + the state of the rmr message buffer -def _errno(): - """Suss out the C error number value which might be useful in understanding - an underlying reason when RMr returns a failure. + Returns + ------- + string + the cooresponding message state """ - return c_int.in_dll(pythonapi, "errno").value + sdict = _get_mapping_dict() + return sdict.get(stateno, "UNKNOWN STATE") ############## @@ -116,6 +119,7 @@ class rmr_mbuf_t(Structure): unsigned char* payload; // transported data unsigned char* xaction; // pointer to fixed length transaction id bytes int sub_id; // subscription id + int tp_state; // transport state (a.k.a errno) // these things are off limits to the user application void* tp_buf; // underlying transport allocated pointer (e.g. nng message) void* header; // internal message header (whole buffer: header+payload) @@ -142,6 +146,7 @@ class rmr_mbuf_t(Structure): ), # according to th following the python bytes are already unsinged https://bytes.com/topic/python/answers/695078-ctypes-unsigned-char ("xaction", POINTER(c_char)), ("sub_id", c_int), + ("tp_state", c_int), ] @@ -292,7 +297,7 @@ def message_summary(ptr_to_rmr_buf_t): "payload max size": rmr_payload_size(ptr_to_rmr_buf_t), "meid": meid, "message source": get_src(ptr_to_rmr_buf_t), - "errno": _errno(), + "errno": ptr_to_rmr_buf_t.contents.tp_state, }