observer.pr 8.21 KB
Newer Older
1
system my_observer;
Maxime Perrotin's avatar
Maxime Perrotin committed
2
    /* CIF TEXT (144, 214), (507, 312) */
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
    
Maxime Perrotin's avatar
Maxime Perrotin committed
12
13
14
15
    signal foo (T_Uint32)
       renames output do_something
       from     orchestrator
       to           another_function;
Maxime Perrotin's avatar
Maxime Perrotin committed
16
17
    /* CIF ENDTEXT */
    channel c
Maxime Perrotin's avatar
Maxime Perrotin committed
18
19
20
        from env to my_observer with observe,
pre_in_orchestrator_pulse,
foo;
Maxime Perrotin's avatar
Maxime Perrotin committed
21
        from my_observer to env with foo;
Maxime Perrotin's avatar
Maxime Perrotin committed
22
23
24
    endchannel;
    block my_observer;
        signalroute r
Maxime Perrotin's avatar
Maxime Perrotin committed
25
26
27
            from env to my_observer with observe,
pre_in_orchestrator_pulse,
foo;
Maxime Perrotin's avatar
Maxime Perrotin committed
28
            from my_observer to env with foo;
Maxime Perrotin's avatar
Maxime Perrotin committed
29
        connect c and r;
Maxime Perrotin's avatar
Maxime Perrotin committed
30
        /* CIF PROCESS (259, 87), (150, 75) */
Maxime Perrotin's avatar
Maxime Perrotin committed
31
        process my_observer;
32
            /* CIF TEXT (0, 57), (256, 248) */
Maxime Perrotin's avatar
Maxime Perrotin committed
33
            monitor st System_State;
Maxime Perrotin's avatar
Maxime Perrotin committed
34
            
Maxime Perrotin's avatar
Maxime Perrotin committed
35
            monitor event Observable_Event;
36
            
37
38
39
40
41
            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
42
43
            
            dcl p1 T_Int;
44
45
46
            
            successstates  good;
            errorstates corrupted;
Maxime Perrotin's avatar
Maxime Perrotin committed
47
            /* CIF ENDTEXT */
48
            /* CIF procedure (149, 457), (106, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
49
50
51
52
53
54
55
56
            procedure Discard_Event;
                /* CIF START (182, 39), (70, 35) */
                START;
                    /* CIF task (142, 94), (148, 35) */
                    task Event := No_Event : {};
                    /* CIF return (199, 149), (35, 35) */
                    return ;
            endprocedure;
57
            /* CIF procedure (274, 120), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
58
            procedure observe;
59
                /* CIF TEXT (288, 48), (337, 136) */
Maxime Perrotin's avatar
Maxime Perrotin committed
60
                --  this procedure could be generated automatically,
Maxime Perrotin's avatar
Maxime Perrotin committed
61
                -- and be read-only.
Maxime Perrotin's avatar
Maxime Perrotin committed
62
63
64
                
                   fpar in/out model           System_State,
                             in/out last_event  Observable_Event;
65
66
67
                   returns Observer_State_Kind;
                
                dcl curr_status Observer_State_Kind := regular_state;
Maxime Perrotin's avatar
Maxime Perrotin committed
68
                /* CIF ENDTEXT */
69
                /* CIF START (782, 118), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
70
                START;
71
                    /* CIF task (748, 173), (137, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
72
                    task st := model,
73
Event := Last_Event;
74
                    /* CIF PROCEDURECALL (663, 233), (308, 35) */
75
                    call writeln('[observer] Event: ', present(event));
76
                    /* CIF decision (760, 288), (113, 50) */
77
                    decision present(event);
78
                        /* CIF ANSWER (259, 358), (93, 24) */
79
                        (input_event):
80
                            /* CIF PROCEDURECALL (162, 402), (289, 35) */
81
                            call writeln('FROM: ', event.input_event.source);
82
                            /* CIF PROCEDURECALL (162, 457), (289, 35) */
83
                            call writeln('TO: ', event.input_event.dest);
84
                        /* CIF ANSWER (555, 358), (103, 24) */
85
                        (output_event):
86
                            /* CIF PROCEDURECALL (462, 402), (290, 35) */
87
                            call writeln('FROM: ', event.output_event.source);
88
                            /* CIF PROCEDURECALL (463, 457), (289, 35) */
89
                            call writeln('TO: ', event.output_event.dest);
90
                        /* CIF ANSWER (791, 358), (114, 24) */
91
                        (system_startup):
92
                            /* CIF PROCEDURECALL (764, 402), (169, 35) */
93
                            call writeln('system startup');
94
                        /* CIF ANSWER (989, 358), (78, 24) */
95
                        (no_event):
96
                            /* CIF PROCEDURECALL (944, 402), (169, 35) */
97
                            call writeln('no_event');
98
                        /* CIF ANSWER (1146, 358), (123, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
99
                        (unhandled_input):
100
                            /* CIF PROCEDURECALL (1137, 402), (142, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
101
                            call writeln('Lost input');
102
                    enddecision;
103
104
                    /* CIF return (799, 508), (35, 35) */
                    return call observer_status;
Maxime Perrotin's avatar
Maxime Perrotin committed
105
            endprocedure;
106
            /* CIF START (556, 96), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
107
            START;
108
                /* CIF NEXTSTATE (549, 151), (83, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
109
                NEXTSTATE first_state;
110
            /* CIF state (864, 245), (97, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
111
            state fourth_state;
112
                /* CIF provided (816, 305), (193, 79) */
Maxime Perrotin's avatar
Maxime Perrotin committed
113
114
115
                provided output do_something(p)
from     orchestrator
to           another_function
116
                /* CIF comment (1032, 316), (146, 56) */
Maxime Perrotin's avatar
Maxime Perrotin committed
117
118
119
                comment 'intercept the output
and modify the value
of the parameter';
120
                    /* CIF decision (877, 404), (70, 50) */
Maxime Perrotin's avatar
Maxime Perrotin committed
121
                    decision p = 42;
122
                        /* CIF ANSWER (812, 474), (70, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
123
                        (true):
124
                            /* CIF task (812, 518), (70, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
125
                            task p := 99;
126
                            /* CIF NEXTSTATE (804, 573), (85, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
127
                            NEXTSTATE fifth_state;
128
                        /* CIF ANSWER (912, 474), (70, 24) */
Maxime Perrotin's avatar
Maxime Perrotin committed
129
                        (false):
130
131
                            /* CIF NEXTSTATE (900, 518), (92, 35) */
                            NEXTSTATE corrupted;
Maxime Perrotin's avatar
Maxime Perrotin committed
132
133
                    enddecision;
            endstate;
134
            /* CIF state (868, 98), (88, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
135
            state third_state;
136
                /* CIF provided (827, 153), (173, 72) */
Maxime Perrotin's avatar
Maxime Perrotin committed
137
138
                provided output paramesstogui
from orchestrator;
139
                    /* CIF NEXTSTATE (864, 245), (97, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
140
                    NEXTSTATE fourth_state;
141
            endstate;
142
            /* CIF state (1208, 430), (87, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
143
            state sixth_state;
144
145
146
147
                /* CIF provided (1192, 485), (121, 50) */
                provided actual_val = 99;
                    /* CIF NEXTSTATE (1204, 555), (95, 35) */
                    NEXTSTATE corrupted;
Maxime Perrotin's avatar
Maxime Perrotin committed
148
            endstate;
149
            /* CIF state (1226, 131), (145, 57) */
150
            state fifth_state;
151
                /* CIF provided (1206, 208), (184, 68) */
152
                provided input do_something(val)
153
154
155
156
157
158
to another_function;
                    /* CIF decision (1248, 296), (99, 68) */
                    decision val;
                        /* CIF ANSWER (1221, 386), (62, 24) */
                        (/= 42):
                            /* CIF NEXTSTATE (1208, 430), (87, 35) */
159
                            NEXTSTATE sixth_state;
160
161
162
163
                        /* CIF ANSWER (1337, 386), (70, 24) */
                        else:
                            /* CIF NEXTSTATE (1325, 430), (92, 35) */
                            NEXTSTATE Good;
164
165
                    enddecision;
            endstate;
166
167
            /* CIF state (230, 314), (92, 35) */
            state corrupted;
Maxime Perrotin's avatar
Maxime Perrotin committed
168
169
            endstate;
            /* CIF state (266, 262), (95, 35) */
170
            state good;
Maxime Perrotin's avatar
Maxime Perrotin committed
171
            endstate;
172
            /* CIF state (540, 392), (101, 34) */
Maxime Perrotin's avatar
Maxime Perrotin committed
173
            state second_state;
174
                /* CIF provided (472, 447), (239, 45) */
Maxime Perrotin's avatar
Maxime Perrotin committed
175
                provided st.orchestrator.magic_number = 42;
176
                    /* CIF NEXTSTATE (541, 512), (101, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
177
178
                    NEXTSTATE third_state;
            endstate;
179
            /* CIF state (541, 282), (101, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
180
            state Wait_count;
181
182
183
                /* CIF provided (549, 337), (85, 35) */
                provided count = 3;
                    /* CIF NEXTSTATE (540, 392), (101, 34) */
Maxime Perrotin's avatar
Maxime Perrotin committed
184
185
                    NEXTSTATE second_state;
            endstate;
186
            /* CIF state (549, 151), (83, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
187
            state first_state;
188
                /* CIF provided (522, 206), (139, 56) */
Maxime Perrotin's avatar
Maxime Perrotin committed
189
190
                provided input pulse
to orchestrator
191
                /* CIF comment (688, 214), (111, 40) */
Maxime Perrotin's avatar
Maxime Perrotin committed
192
193
                comment 'Called AFTER
the input';
194
                    /* CIF NEXTSTATE (541, 282), (101, 35) */
Maxime Perrotin's avatar
Maxime Perrotin committed
195
196
                    NEXTSTATE Wait_count;
            endstate;
Maxime Perrotin's avatar
Maxime Perrotin committed
197
198
        endprocess my_observer;
    endblock;
199
endsystem;