X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=examples%2Fpong_xapp.py;h=23db376181daec61ed5d7c63dbfe97eca851b9c3;hb=bbc9028aa34ae48e7806596cd05fbe7a5bfd7fb8;hp=496c72e02280f0cc3059bdfae9f7291d0a0ccf7c;hpb=21f659c694968e95ad4e1a568538a586c5291b62;p=ric-plt%2Fxapp-frame-py.git diff --git a/examples/pong_xapp.py b/examples/pong_xapp.py index 496c72e..23db376 100644 --- a/examples/pong_xapp.py +++ b/examples/pong_xapp.py @@ -18,26 +18,31 @@ Test xapp 2 that works with 1 # limitations under the License. # ================================================================================== import json -from ricxappframe.xapp_frame import RMRXapp +from ricxappframe.xapp_frame import RMRXapp, rmr -# Note, this is an OOP pattern for this that I find slightly more natural -# The problem is we want the client xapp to be able to call methods defined in the RMRXapp -# Another exactly equivelent way would have been to use Closures like -# def consume(summary, sbuf): -# xapp.rts() -# xapp = RMRXapp(consume) -# However, the subclass looks slightly more natural. Open to the alternative. +def post_init(_self): + """post init""" + print("pong xapp could do some useful stuff here!") -class MyXapp(RMRXapp): - def consume(self, summary, sbuf): - """callbnack called for each new message""" - print(summary) - jpay = json.loads(summary["payload"]) - self.rmr_rts(sbuf, new_payload=json.dumps({"ACK": jpay["test_send"]}).encode(), new_mtype=60001, retries=100) - self.rmr_free(sbuf) +def sixtyh(self, summary, sbuf): + """callback for 60000""" + self.logger.info("pong registered 60000 handler called!") + # see comment in ping about this; bytes does not work with the ric mdc logger currently + print("pong 60000 handler received: {0}".format(summary)) + jpay = json.loads(summary[rmr.RMR_MS_MSG_PAYLOAD]) + self.rmr_rts(sbuf, new_payload=json.dumps({"ACK": jpay["test_send"]}).encode(), new_mtype=60001, retries=100) + self.rmr_free(sbuf) -xapp = MyXapp(use_fake_sdl=True) -xapp.run() +def defh(self, summary, sbuf): + """default callback""" + self.logger.info("pong default handler called!") + print("pong default handler received: {0}".format(summary)) + self.rmr_free(sbuf) + + +xapp = RMRXapp(default_handler=defh, post_init=post_init, use_fake_sdl=True) +xapp.register_callback(sixtyh, 60000) +xapp.run() # will not thread by default