#! usr/bin/env python import sys sys.path.append('script_2') 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) del sta print "\n*** END ***\n"