Initial pass of the py xapp frame
This is not yet completed:
- Docs will come soon
- More unit test coverage will come soon
- More functionality will come soon
However, to avoid a gargantuan commit at the beginning that solves world
hunger, we cut off here on a basically usable framework.
NOTE: a significant portion of this code is *already reviewed* as it
came out of A1. For example, the entire SDLWrapper class, and most of
the RMRLoop. This code will
be deleted from A1 when this is in pypi.
Issue-ID: RIC-228
Change-Id: I9f87b0178cf5fb1cb6b988c29ce11218ed575607
Signed-off-by: Tommy Carpenter <tc677g@att.com>
diff --git a/examples/pong_xapp.py b/examples/pong_xapp.py
new file mode 100644
index 0000000..496c72e
--- /dev/null
+++ b/examples/pong_xapp.py
@@ -0,0 +1,43 @@
+"""
+Test xapp 2 that works with 1
+"""
+# ==================================================================================
+# Copyright (c) 2020 Nokia
+# Copyright (c) 2020 AT&T Intellectual Property.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==================================================================================
+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.
+
+
+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)
+
+
+xapp = MyXapp(use_fake_sdl=True)
+xapp.run()