summaryrefslogtreecommitdiff
path: root/cesar/maximus/python/py/test_cb.py
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/python/py/test_cb.py')
-rw-r--r--cesar/maximus/python/py/test_cb.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/cesar/maximus/python/py/test_cb.py b/cesar/maximus/python/py/test_cb.py
new file mode 100644
index 0000000000..5bb8f46b97
--- /dev/null
+++ b/cesar/maximus/python/py/test_cb.py
@@ -0,0 +1,84 @@
+#! usr/bin/env python
+
+print "\n*** " + __file__ + " ***\n"
+
+import sys
+sys.path.append('./test')
+sys.path.append('../test')
+import startup
+
+
+# TICKET #47
+# To be run with "test_cb.elf" station executable
+# (to be compiled under "/trunk/maximus/stationtest").
+
+from interface import *
+
+# Instantiate a Maximus object and initialize it.
+maximus = Maximus()
+maximus.init(sys.argv)
+
+# Create three stations.
+sta = maximus.create_sta()
+
+def get_seg_cb1 (msg):
+ print "=> get_seg_cb1"
+m1 = maximus.create_fcall ('get_seg')
+m1.set_cb (get_seg_cb1)
+m1.send_async (sta)
+maximus.wait()
+
+def get_seg_cb2 (msg):
+ print "=> get_seg_cb2"
+def a():
+ m2 = maximus.create_fcall ('get_seg')
+ m2.set_cb (get_seg_cb2)
+ m2.send_async (sta)
+a()
+maximus.wait()
+
+def b():
+ s = "=> get_seg_cb3"
+ def get_seg_cb3 (msg):
+ print s
+ m3 = maximus.create_fcall ('get_seg')
+ m3.set_cb (get_seg_cb3)
+ m3.send_async (sta)
+b()
+maximus.wait()
+
+
+# TICKET #48
+
+def a2 (m, msg):
+ s = 'I am "a2", '
+ def cb_a2(msg):
+ print s + m
+ msg.set_cb (cb_a2)
+
+def cb_b2_inner (msg):
+ print 'I am "b2", ' + m
+
+def b2 (m, msg):
+ msg.set_cb (lambda x: cb_b2_inner (x))
+
+def c (m, msg):
+ class CCb:
+ def __call__ (self, msg):
+ print self.s + m
+ c_cb = CCb ()
+ c_cb.s = 'I am "c", '
+ msg.set_cb (c_cb)
+
+m = 'I am being called'
+msg = maximus.create_fcall ('get_seg')
+a2 (m, msg)
+msg.send (sta)
+b2 (m, msg)
+msg.send (sta)
+c (m, msg)
+msg.send (sta)
+
+sta.remove()
+
+print "\n*** END ***\n"