summaryrefslogtreecommitdiff
path: root/cesar/maximus/python/utest/script_1/test_cb.py
blob: 99f39daf300ff8846883316aa0b981066e001d23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! 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"