X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=examples%2Fpong_xapp.py;h=5c90685e546e712792d07a21833aef26d8468e88;hb=refs%2Fchanges%2F25%2F3125%2F1;hp=7542c90b9d1dc7f404744c41b06eed6f4683597e;hpb=99a0b48593f885940b66e80edbdc2840242b5fd8;p=ric-plt%2Fxapp-frame-py.git diff --git a/examples/pong_xapp.py b/examples/pong_xapp.py index 7542c90..5c90685 100644 --- a/examples/pong_xapp.py +++ b/examples/pong_xapp.py @@ -21,26 +21,28 @@ import json from ricxappframe.xapp_frame import RMRXapp -# 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 post_init(self): - print("ping xapp could do some useful stuff here!") +def sixtyh(self, summary, sbuf): + """callback for 60000""" + self.logger.info("registered 60000 handler called!") + # see comment in ping about this; bytes does not work with the ric mdc logger currently + 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 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 defh(self, summary, sbuf): + """default callback""" + self.logger.info("default handler called!") + print(summary) + self.rmr_free(sbuf) -xapp = MyXapp(use_fake_sdl=True) -xapp.run() + +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