Release 060
[ric-plt/xapp-frame-py.git] / ricxappframe / xapp_frame.py
index 6b70bb6..e977e27 100644 (file)
@@ -25,9 +25,6 @@ from rmr import rmr
 from mdclogpy import Logger
 
 
 from mdclogpy import Logger
 
 
-mdc_logger = Logger(name=__name__)
-
-
 # Private base class; not for direct client use
 
 
 # Private base class; not for direct client use
 
 
@@ -57,6 +54,8 @@ class _BaseXapp:
             runs this user provided function after the base xapp is initialized
             it's signature should be post_init(self)
         """
             runs this user provided function after the base xapp is initialized
             it's signature should be post_init(self)
         """
+        # PUBLIC, can be used by xapps using self.(name):
+        self.logger = Logger(name=__name__)
 
         # Start rmr rcv thread
         self._rmr_loop = xapp_rmr.RmrLoop(port=rmr_port, wait_for_ready=rmr_wait_for_ready)
 
         # Start rmr rcv thread
         self._rmr_loop = xapp_rmr.RmrLoop(port=rmr_port, wait_for_ready=rmr_wait_for_ready)
@@ -303,11 +302,16 @@ class RMRXapp(_BaseXapp):
         """
         self._dispatch[message_type] = handler
 
         """
         self._dispatch[message_type] = handler
 
-    def run(self):
+    def run(self, thread=False):
         """
         This function should be called when the client xapp is ready to wait for their handlers to be called on received messages
 
         """
         This function should be called when the client xapp is ready to wait for their handlers to be called on received messages
 
-        execution is returned to caller
+        Parameters
+        ----------
+        thread: bool (optional)
+            if thread is True, execution is returned to caller and the queue read loop is executed in a thread.
+            The thread can be stopped using .stop()
+            if False, execution is not returned and the framework loops
         """
 
         def loop():
         """
 
         def loop():
@@ -320,14 +324,17 @@ class RMRXapp(_BaseXapp):
                         func = self._default_handler
                     func(self, summary, sbuf)
 
                         func = self._default_handler
                     func(self, summary, sbuf)
 
-        Thread(target=loop).start()
+        if thread:
+            Thread(target=loop).start()
+        else:
+            loop()
 
     def stop(self):
         """
         stops the rmr xapp completely.
         """
         super().stop()
 
     def stop(self):
         """
         stops the rmr xapp completely.
         """
         super().stop()
-        mdc_logger.debug("Stopping queue reading thread..")
+        self.logger.debug("Stopping queue reading thread..")
         self._keep_going = False
 
 
         self._keep_going = False