X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ricxappframe%2Frmr%2Fhelpers.py;h=3cf1c548397809974477bb20501cde81965b226b;hb=refs%2Fchanges%2F22%2F4322%2F3;hp=339526af3de9980eceba4c5ba9e5485f2b4e7e70;hpb=666e8319bd0e618576be79a14208d7eaf0de99f2;p=ric-plt%2Fxapp-frame-py.git diff --git a/ricxappframe/rmr/helpers.py b/ricxappframe/rmr/helpers.py index 339526a..3cf1c54 100644 --- a/ricxappframe/rmr/helpers.py +++ b/ricxappframe/rmr/helpers.py @@ -1,4 +1,3 @@ -# vim: ts=4 sw=4 expandtab: # ================================================================================== # Copyright (c) 2019 Nokia # Copyright (c) 2018-2019 AT&T Intellectual Property. @@ -19,23 +18,21 @@ # Mnemonic: helpers.py # Abstract: This is a collection of extensions to the RMR base package # which are likely to be convenient for Python programs. -# Date: 26 September 2019 -# --------------------------------------------------------------------------- from ricxappframe.rmr import rmr -def rmr_rcvall_msgs(mrc, pass_filter=[], timeout=0): +def rmr_rcvall_msgs(mrc, pass_filter=None, timeout=0): """ Assembles an array of all messages which can be received without blocking (but see the timeout parameter). Effectively drains the message queue if RMR is started in mt-call mode, or draining any waiting TCP buffers. If the pass_filter parameter is supplied, it is treated as one or more message types to accept (pass through). Using the default, an empty list, - results in capturing all messages. if the timeout parameter is supplied, - this call may block up to that number of milliseconds waiting for a - message to arrive. Using the default, zero, results in non-blocking - no-wait behavior. + results in capturing all messages. If the timeout parameter is supplied + and is not zero, this call may block up to that number of milliseconds + waiting for a message to arrive. Using the default, zero, results in + non-blocking no-wait behavior. Parameters ---------- @@ -60,17 +57,17 @@ def rmr_rcvall_msgs(mrc, pass_filter=[], timeout=0): mbuf = rmr.rmr_torcv_msg(mrc, mbuf, timeout) # first call may have non-zero timeout timeout = 0 # reset so subsequent calls do not wait summary = rmr.message_summary(mbuf) - if summary["message status"] != "RMR_OK": # ok indicates msg received, stop on all other states; e.g., RMR_ERR_TIMEOUT + if summary[rmr.RMR_MS_MSG_STATUS] != "RMR_OK": # ok indicates msg received, stop on all other states break - if len(pass_filter) == 0 or summary["message type"] in pass_filter: # no filter, or passes; capture it + if pass_filter is None or len(pass_filter) == 0 or summary[rmr.RMR_MS_MSG_TYPE] in pass_filter: # no filter, or passes; capture it new_messages.append(summary) rmr.rmr_free_msg(mbuf) # free the single buffer to avoid leak return new_messages -def rmr_rcvall_msgs_raw(mrc, pass_filter=[], timeout=0): +def rmr_rcvall_msgs_raw(mrc, pass_filter=None, timeout=0): """ Same as rmr_rcvall_msgs, but answers tuples with the raw sbuf. Useful if return-to-sender (rts) functions are required. @@ -100,11 +97,11 @@ def rmr_rcvall_msgs_raw(mrc, pass_filter=[], timeout=0): mbuf = rmr.rmr_torcv_msg(mrc, mbuf, timeout) # first call may have non-zero timeout timeout = 0 # reset so subsequent calls do not wait summary = rmr.message_summary(mbuf) - if summary["message status"] != "RMR_OK": # e.g., RMR_ERR_TIMEOUT + if summary[rmr.RMR_MS_MSG_STATUS] != "RMR_OK": rmr.rmr_free_msg(mbuf) # free the failed-to-receive buffer break - if len(pass_filter) == 0 or mbuf.contents.mtype in pass_filter: # no filter, or passes; capture it + if pass_filter is None or len(pass_filter) == 0 or mbuf.contents.mtype in pass_filter: # no filter, or passes; capture it new_messages.append((summary, mbuf)) # caller is responsible for freeing the buffer else: rmr.rmr_free_msg(mbuf) # free the filtered-out message buffer