observer.pr 8.33 KB
Newer Older
1
system my_observer;
Maxime Perrotin's avatar
Maxime Perrotin committed
2
    /* CIF TEXT (145, 177), (507, 168) */
Maxime Perrotin's avatar
Maxime Perrotin committed
3
4
5
    use datamodel comment 'observer.asn';
    
    exported procedure observe;
Maxime Perrotin's avatar
Maxime Perrotin committed
6
7
       fpar in/out model           System_State,
                 in/out last_event  Observable_Event;
Maxime Perrotin's avatar
Maxime Perrotin committed
8
9
    referenced;
    
Maxime Perrotin's avatar
Maxime Perrotin committed
10
    signal pre_in_orchestrator_pulse (t_int) renames input pulse to orchestrator;
Maxime Perrotin's avatar
Maxime Perrotin committed
11
12
    
    signal foo renames input pulse to orchestrator;
Maxime Perrotin's avatar
Maxime Perrotin committed
13
14
    /* CIF ENDTEXT */
    channel c
Maxime Perrotin's avatar
Maxime Perrotin committed
15
16
17
        from env to my_observer with observe,
pre_in_orchestrator_pulse,
foo;
Maxime Perrotin's avatar
Maxime Perrotin committed
18
19
20
    endchannel;
    block my_observer;
        signalroute r
Maxime Perrotin's avatar
Maxime Perrotin committed
21
22
23
            from env to my_observer with observe,
pre_in_orchestrator_pulse,
foo;
Maxime Perrotin's avatar
Maxime Perrotin committed
24
        connect c and r;
Maxime Perrotin's avatar
Maxime Perrotin committed
25
        /* CIF PROCESS (250, 87), (150, 75) */
Maxime Perrotin's avatar
Maxime Perrotin committed
26
        process my_observer;
Maxime Perrotin's avatar
Maxime Perrotin committed
27
            /* CIF TEXT (0, 57), (256, 184) */
Maxime Perrotin's avatar
Maxime Perrotin committed
28
            monitor st System_State;
Maxime Perrotin's avatar
Maxime Perrotin committed
29
            
Maxime Perrotin's avatar
Maxime Perrotin committed
30
            monitor event Observable_Event;
31
            
32
33
34
35
36
            dcl count T_Int
               renames st.orchestrator.counter;
            
            dcl actual_val T_UInt32
               renames st.another_function.param1;
Maxime Perrotin's avatar
Maxime Perrotin committed
37
38
            
            dcl p1 T_Int;
Maxime Perrotin's avatar
Maxime Perrotin committed
39
            /* CIF ENDTEXT */
Maxime Perrotin's avatar
Maxime Perrotin committed
40
            /* CIF procedure (2060, 152), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
41
            procedure observe;
Maxime Perrotin's avatar
Maxime Perrotin committed
42
                /* CIF TEXT (140, 48), (313, 120) */
Maxime Perrotin's avatar
Maxime Perrotin committed
43
                --  this procedure could be generated automatically,
Maxime Perrotin's avatar
Maxime Perrotin committed
44
                -- and be read-only.
Maxime Perrotin's avatar
Maxime Perrotin committed
45
46
47
                
                   fpar in/out model           System_State,
                             in/out last_event  Observable_Event;
Maxime Perrotin's avatar
Maxime Perrotin committed
48
                /* CIF ENDTEXT */
Maxime Perrotin's avatar
Maxime Perrotin committed
49
                /* CIF START (464, 153), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
50
                START;
Maxime Perrotin's avatar
Maxime Perrotin committed
51
                    /* CIF task (430, 208), (137, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
52
                    task st := model,
53
Event := Last_Event;
Maxime Perrotin's avatar
Maxime Perrotin committed
54
                    /* CIF PROCEDURECALL (345, 268), (308, 35) */
55
                    call writeln('[observer] Event: ', present(event));
Maxime Perrotin's avatar
Maxime Perrotin committed
56
                    /* CIF decision (442, 323), (113, 50) */
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
                    decision present(event);
                        /* CIF ANSWER (97, 393), (93, 24) */
                        (input_event):
                            /* CIF PROCEDURECALL (0, 437), (289, 35) */
                            call writeln('FROM: ', event.input_event.source);
                            /* CIF PROCEDURECALL (0, 492), (289, 35) */
                            call writeln('TO: ', event.input_event.dest);
                        /* CIF ANSWER (392, 393), (103, 24) */
                        (output_event):
                            /* CIF PROCEDURECALL (299, 437), (290, 35) */
                            call writeln('FROM: ', event.output_event.source);
                            /* CIF PROCEDURECALL (300, 492), (289, 35) */
                            call writeln('TO: ', event.output_event.dest);
                        /* CIF ANSWER (627, 393), (114, 24) */
                        (system_startup):
                            /* CIF PROCEDURECALL (600, 437), (169, 35) */
                            call writeln('system startup');
                        /* CIF ANSWER (825, 393), (78, 24) */
                        (no_event):
                            /* CIF PROCEDURECALL (780, 437), (169, 35) */
                            call writeln('no_event');
                    enddecision;
Maxime Perrotin's avatar
Maxime Perrotin committed
79
                    /* CIF return (481, 543), (35, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
80
81
                    return ;
            endprocedure;
Maxime Perrotin's avatar
Maxime Perrotin committed
82
            /* CIF START (683, 86), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
83
            START;
Maxime Perrotin's avatar
Maxime Perrotin committed
84
                /* CIF PROCEDURECALL (638, 141), (159, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
85
                call writeln ('observer init');
Maxime Perrotin's avatar
Maxime Perrotin committed
86
                /* CIF NEXTSTATE (676, 191), (83, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
87
                NEXTSTATE first_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
88
            /* CIF state (662, 434), (101, 34) */
89
            state second_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
90
                /* CIF provided (594, 489), (239, 45) */
91
                provided st.orchestrator.magic_number = 42;
Maxime Perrotin's avatar
Maxime Perrotin committed
92
                    /* CIF NEXTSTATE (663, 554), (101, 35) */
93
94
                    NEXTSTATE third_state;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
95
            /* CIF state (663, 324), (101, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
96
            state Wait_count;
Maxime Perrotin's avatar
Maxime Perrotin committed
97
                /* CIF provided (671, 379), (85, 35) */
98
                provided count = 3
Maxime Perrotin's avatar
Maxime Perrotin committed
99
                /* CIF comment (780, 376), (104, 40) */
100
101
                comment 'Called AFTER
the input';
Maxime Perrotin's avatar
Maxime Perrotin committed
102
                    /* CIF NEXTSTATE (662, 434), (101, 34) */
103
104
                    NEXTSTATE second_state;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
105
            /* CIF state (676, 191), (83, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
106
            state first_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
107
                /* CIF provided (644, 248), (139, 56) */
Maxime Perrotin's avatar
Maxime Perrotin committed
108
109
                provided input pulse
to orchestrator
Maxime Perrotin's avatar
Maxime Perrotin committed
110
                /* CIF comment (810, 256), (111, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
111
112
                comment 'Called BEFORE
the input';
Maxime Perrotin's avatar
Maxime Perrotin committed
113
                    /* CIF NEXTSTATE (663, 324), (101, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
114
115
                    NEXTSTATE Wait_count;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
116
            /* CIF state (992, 237), (97, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
117
            state fourth_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
118
                /* CIF provided (943, 297), (193, 79) */
Maxime Perrotin's avatar
Maxime Perrotin committed
119
120
121
                provided output do_something(p)
from     orchestrator
to           another_function
Maxime Perrotin's avatar
Maxime Perrotin committed
122
                /* CIF comment (1159, 308), (146, 56) */
Maxime Perrotin's avatar
Maxime Perrotin committed
123
124
125
                comment 'intercept the output
and modify the value
of the parameter';
Maxime Perrotin's avatar
Maxime Perrotin committed
126
                    /* CIF decision (1005, 396), (70, 50) */
Maxime Perrotin's avatar
Maxime Perrotin committed
127
                    decision p = 42;
Maxime Perrotin's avatar
Maxime Perrotin committed
128
                        /* CIF ANSWER (939, 466), (70, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
129
                        (true):
Maxime Perrotin's avatar
Maxime Perrotin committed
130
                            /* CIF task (939, 510), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
131
                            task p := 99;
Maxime Perrotin's avatar
Maxime Perrotin committed
132
                            /* CIF NEXTSTATE (932, 565), (85, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
133
                            NEXTSTATE fifth_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
134
                        /* CIF ANSWER (1039, 466), (70, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
135
                        (false):
Maxime Perrotin's avatar
Maxime Perrotin committed
136
                            /* CIF NEXTSTATE (1028, 510), (92, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
137
138
139
                            NEXTSTATE unexpected;
                    enddecision;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
140
            /* CIF state (1286, 90), (88, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
141
            state third_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
142
                /* CIF provided (954, 145), (173, 72) */
Maxime Perrotin's avatar
Maxime Perrotin committed
143
144
                provided output paramesstogui
from orchestrator;
Maxime Perrotin's avatar
Maxime Perrotin committed
145
                    /* CIF NEXTSTATE (992, 237), (97, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
146
                    NEXTSTATE fourth_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
                /* CIF input (1317, 145), (218, 49) */
                input pre_in_orchestrator_pulse(toto)
                /* CIF comment (1555, 152), (127, 56) */
                comment 'alias for
input pulse to
orchestrator';
                    /* CIF decision (1391, 214), (70, 50) */
                    decision toto;
                        /* CIF ANSWER (1335, 284), (70, 24) */
                        (1):
                        /* CIF ANSWER (1425, 284), (70, 24) */
                        else:
                    enddecision;
                    /* CIF NEXTSTATE (1391, 324), (70, 35) */
                    NEXTSTATE -;
Maxime Perrotin's avatar
Maxime Perrotin committed
162
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
163
            /* CIF state (154, 262), (95, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
164
165
            state end_success;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
166
            /* CIF state (157, 314), (92, 35) */
167
168
            state unexpected;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
169
            /* CIF state (1710, 437), (87, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
170
            state sixth_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
171
                /* CIF provided (1694, 492), (121, 50) */
Maxime Perrotin's avatar
Maxime Perrotin committed
172
                provided actual_val = 100;
Maxime Perrotin's avatar
Maxime Perrotin committed
173
                    /* CIF NEXTSTATE (1706, 562), (95, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
174
175
                    NEXTSTATE end_success;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
176
            /* CIF state (1728, 88), (145, 57) */
177
            state fifth_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
178
                /* CIF provided (1708, 165), (184, 68) */
179
180
                provided input do_something(val)
to another_function
Maxime Perrotin's avatar
Maxime Perrotin committed
181
                /* CIF comment (1915, 163), (134, 72) */
182
183
184
185
                comment 'intercept the input
before execution
(=post-output)
alter it again';
Maxime Perrotin's avatar
Maxime Perrotin committed
186
                    /* CIF decision (1750, 253), (99, 68) */
187
                    decision val = 99;
Maxime Perrotin's avatar
Maxime Perrotin committed
188
                        /* CIF ANSWER (1723, 343), (62, 24) */
189
                        (true):
Maxime Perrotin's avatar
Maxime Perrotin committed
190
                            /* CIF task (1707, 387), (93, 35) */
191
                            task val := val + 1;
Maxime Perrotin's avatar
Maxime Perrotin committed
192
                            /* CIF NEXTSTATE (1710, 437), (87, 35) */
193
                            NEXTSTATE sixth_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
194
                        /* CIF ANSWER (1839, 343), (70, 24) */
195
                        (false):
Maxime Perrotin's avatar
Maxime Perrotin committed
196
                            /* CIF NEXTSTATE (1827, 387), (92, 35) */
197
198
199
                            NEXTSTATE unexpected;
                    enddecision;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
200
201
        endprocess my_observer;
    endblock;
202
endsystem;