Modify for restriction role
[apps/agl-service-windowmanager.git] / src / policy_manager / zipc / dummy_stm.c
1 #include <string.h>
2 #include "dummy_stm.h"
3
4 const char* gStmEventName[] = {
5     "activate",
6     "deactivate",
7     "parking_brake_off",
8     "parking_brake_on",
9     "car_stop",
10     "car_run",
11     "timer_expired",
12     "lamp_off",
13     "lamp_on"
14 };
15
16 const int gStmEventNo[] = {
17     STM_EVT_NO_ACTIVATE,
18     STM_EVT_NO_DEACTIVATE,
19     STM_EVT_NO_PARKING_BRAKE_OFF,
20     STM_EVT_NO_PARKING_BRAKE_ON,
21     STM_EVT_NO_CAR_STOP,
22     STM_EVT_NO_CAR_RUN,
23     STM_EVT_NO_TIMER_EXPIRED,
24     STM_EVT_NO_LAMP_OFF,
25     STM_EVT_NO_LAMP_ON
26 };
27
28 const char* gStmCategoryName[] = {
29     "homescreen",
30     "map",
31     "general",
32     "splitable",
33     "popup",
34     "system_alert",
35     "restriction",
36 };
37
38 const int gStmCategoryNo[] = {
39     STM_CTG_NO_HOMESCREEN,
40     STM_CTG_NO_MAP,
41     STM_CTG_NO_GENERAL,
42     STM_CTG_NO_SPLITABLE,
43     STM_CTG_NO_POPUP,
44     STM_CTG_NO_SYSTEM_ALERT,
45     STM_CTG_NO_RESTRICTION,
46 };
47
48 const char* gStmAreaName[] = {
49     "full",
50     "normal",
51     "split.main",
52     "split.sub",
53     "onscreen",
54     "restriction.normal",
55     "restriction.split.main",
56     "restriction.split.sub",
57 };
58
59 const int gStmAreaNo[] = {
60     STM_ARA_NO_FULL,
61     STM_ARA_NO_NORMAL,
62     STM_ARA_NO_SPLIT_MAIN,
63     STM_ARA_NO_SPLIT_SUB,
64     STM_ARA_NO_ON_SCREEN,
65     STM_ARA_NO_RESTRICTION_NORMAL,
66     STM_ARA_NO_RESTRICTION_SPLIT_MAIN,
67     STM_ARA_NO_RESTRICTION_SPLIT_SUB,
68 };
69
70 // String for state
71 const char* gStmParkingBrakeStateNo2Name[] = {
72     "parking_brake_off",
73     "parking_brake_on"
74 };
75
76 const char* gStmCarStateNo2Name[] = {
77     "car_stop",
78     "car_run"
79 };
80
81 const char* gStmLampStateNo2Name[] = {
82     "lamp_off",
83     "lamp_on"
84 };
85
86 const char* gStmLayoutNo2Name[] = {
87     "none",
88     "pu",
89     "sa",
90     "m1",
91     "m2",
92     "mf",
93     "s1",
94     "s2",
95     "g",
96     "hs",
97     "restriction",
98     "restriction.split.main",
99     "restriction.split.sub",
100 };
101
102 stm_state_t g_crr_state;
103 stm_state_t g_prv_state;
104 int g_prv_apps_state_car_stop = 0;
105
106 void stmInitialize() {
107     // Initialize previous state
108     memset(&g_prv_state, 0, sizeof(g_prv_state));
109
110     g_prv_state.layer.on_screen.state   = gStmLayoutNoNone;
111     g_prv_state.layer.restriction.state = gStmLayoutNoNone;
112     g_prv_state.layer.apps.state        = gStmLayoutNoNone;
113     g_prv_state.layer.homescreen.state  = gStmLayoutNoNone;
114     g_prv_state.parking_brake.state = gStmParkingBrakeStateNoOn;
115     g_prv_state.car.state           = gStmCarStateNoStop;
116     g_prv_state.lamp.state          = gStmLampStateNoOff;
117
118     // Initialize current state
119     g_crr_state = g_prv_state;
120 }
121
122 int stmTransitionState(int event, stm_state_t* state) {
123     int event_no, category_no, area_no;
124     int restriction_state, apps_state, parking_brake_state, car_state, lamp_state;
125
126     event_no    = event & STM_MSK_EVT_NO;
127     category_no = event & STM_MSK_CTG_NO;
128     area_no     = event & STM_MSK_ARA_NO;
129
130     // Backup previous state
131     g_prv_state = g_crr_state;
132
133     // Get previous state
134     restriction_state = g_prv_state.layer.restriction.state;
135     apps_state = g_prv_state.layer.apps.state;
136     parking_brake_state  = g_prv_state.parking_brake.state;
137     car_state  = g_prv_state.car.state;
138     lamp_state = g_prv_state.lamp.state;
139
140     // Clear flags
141     g_crr_state.layer.on_screen.is_changed = STM_FALSE;
142     g_crr_state.layer.restriction.is_changed = STM_FALSE;
143     g_crr_state.layer.apps.is_changed = STM_FALSE;
144     g_crr_state.layer.homescreen.is_changed = STM_FALSE;
145     g_crr_state.parking_brake.is_changed = STM_FALSE;
146     g_crr_state.car.is_changed = STM_FALSE;
147     g_crr_state.lamp.is_changed = STM_FALSE;
148
149     switch (event_no) {
150     case STM_EVT_NO_ACTIVATE:
151         switch (category_no) {
152         case STM_CTG_NO_HOMESCREEN:
153             // Apps layer
154             g_crr_state.layer.apps.state = gStmLayoutNoNone;
155             g_crr_state.layer.apps.is_changed = STM_TRUE;
156
157             // Homescreen layer
158             g_crr_state.layer.homescreen.state = gStmLayoutNoHs;
159             g_crr_state.layer.homescreen.is_changed = STM_TRUE;
160             break;
161         case STM_CTG_NO_MAP:
162             switch (area_no) {
163             case STM_ARA_NO_FULL:
164                 // Apps layer
165                 switch (apps_state) {
166                 case gStmLayoutNoMf:
167                     // nop
168                     break;
169                 default:
170                     g_crr_state.layer.apps.state = gStmLayoutNoMf;
171                     g_crr_state.layer.apps.is_changed = STM_TRUE;
172                     break;
173                 }
174                 break;
175             case STM_ARA_NO_NORMAL:
176                 // Apps layer
177                 switch (apps_state) {
178                 case gStmLayoutNoM1:
179                     // nop
180                     break;
181                 case gStmLayoutNoS1:
182                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
183                     g_crr_state.layer.apps.is_changed = STM_TRUE;
184                     break;
185                 default:
186                     g_crr_state.layer.apps.state = gStmLayoutNoM1;
187                     g_crr_state.layer.apps.is_changed = STM_TRUE;
188                 }
189                 break;
190             case STM_ARA_NO_SPLIT_MAIN:
191                 // Apps layer
192                 switch (apps_state) {
193                 case gStmLayoutNoS1:
194                 case gStmLayoutNoS2:
195                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
196                     g_crr_state.layer.apps.is_changed = STM_TRUE;
197                     break;
198                 default:
199                     // nop
200                     break;
201                 }
202                 break;
203             }
204             break;
205         case STM_CTG_NO_GENERAL:
206             switch (area_no) {
207             case STM_ARA_NO_NORMAL:
208                 // Apps layer
209                 switch (apps_state) {
210                 case gStmLayoutNoMf:
211                     // nop
212                     break;
213                 default:
214                     g_crr_state.layer.apps.state = gStmLayoutNoG;
215                     g_crr_state.layer.apps.is_changed = STM_TRUE;
216                     break;
217                 }
218                 break;
219             default:
220                 // nop
221                 break;
222             }
223             break;
224         case STM_CTG_NO_SPLITABLE:
225             switch (area_no) {
226             case STM_ARA_NO_NORMAL:
227                 // Apps layer
228                 switch (apps_state) {
229                 case gStmLayoutNoMf:
230                     // nop
231                     break;
232                 case gStmLayoutNoS1:
233                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
234                     g_crr_state.layer.apps.is_changed = STM_TRUE;
235                     break;
236                 default:
237                     g_crr_state.layer.apps.state = gStmLayoutNoS1;
238                     g_crr_state.layer.apps.is_changed = STM_TRUE;
239                     break;
240                 }
241                 break;
242             case STM_ARA_NO_SPLIT_MAIN:
243                 // Apps layer
244                 switch (apps_state) {
245                 case gStmLayoutNoS1:
246                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
247                     g_crr_state.layer.apps.is_changed = STM_TRUE;
248                     break;
249                 case gStmLayoutNoS2:
250                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
251                     g_crr_state.layer.apps.is_changed = STM_TRUE;
252                     break;
253                 default:
254                     // nop
255                     break;
256                 }
257                 break;
258             case STM_ARA_NO_SPLIT_SUB:
259                 // Apps layer
260                 switch (apps_state) {
261                 case gStmLayoutNoM1:
262                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
263                     g_crr_state.layer.apps.is_changed = STM_TRUE;
264                     break;
265                 case gStmLayoutNoM2:
266                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
267                     g_crr_state.layer.apps.is_changed = STM_TRUE;
268                     break;
269                 case gStmLayoutNoS1:
270                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
271                     g_crr_state.layer.apps.is_changed = STM_TRUE;
272                     break;
273                 case gStmLayoutNoS2:
274                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
275                     g_crr_state.layer.apps.is_changed = STM_TRUE;
276                     break;
277                 default:
278                     // nop
279                     break;
280                 }
281                 break;
282             default:
283                 // nop
284                 break;
285             }
286             break;
287         case STM_CTG_NO_RESTRICTION:
288             switch (area_no) {
289             case STM_ARA_NO_RESTRICTION_NORMAL:
290                 // restriction Layer
291                 switch (restriction_state) {
292                 case gStmLayoutNoNone:
293                     g_crr_state.layer.restriction.state = gStmLayoutNoRestriction;
294                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
295                     break;
296                 default:
297                     // nop
298                     break;
299                 }
300                 break;
301             case STM_ARA_NO_RESTRICTION_SPLIT_MAIN:
302                 // restriction Layer
303                 switch (restriction_state) {
304                 case gStmLayoutNoNone:
305                     g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitMain;
306                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
307                     break;
308                 default:
309                     // nop
310                     break;
311                 }
312                 break;
313             case STM_ARA_NO_RESTRICTION_SPLIT_SUB:
314                 // restriction Layer
315                 switch (restriction_state) {
316                 case gStmLayoutNoNone:
317                     g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitSub;
318                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
319                     break;
320                 default:
321                     // nop
322                     break;
323                 }
324                 break;
325             default:
326                 // nop
327                 break;
328             }
329             break;
330         default:
331             // nop
332             break;
333         }
334     case STM_EVT_NO_DEACTIVATE:
335         switch (category_no) {
336         case STM_CTG_NO_RESTRICTION:
337             // restriction Layer
338             switch (restriction_state) {
339             case gStmLayoutNoRestriction:
340             case gStmLayoutNoRestrictionSplitMain:
341             case gStmLayoutNoRestrictionSplitSub:
342                 g_crr_state.layer.restriction.state = gStmLayoutNoNone;
343                 g_crr_state.layer.restriction.is_changed = STM_TRUE;
344                 break;
345             default:
346                 // nop
347                 break;
348             }
349         default:
350             // nop
351             break;
352         }
353         break;
354     case STM_EVT_NO_PARKING_BRAKE_OFF:
355         if (gStmParkingBrakeStateNoOff != parking_brake_state) {
356             g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOff;
357             g_crr_state.parking_brake.is_changed = STM_TRUE;
358         }
359         break;
360     case STM_EVT_NO_PARKING_BRAKE_ON:
361         if (gStmParkingBrakeStateNoOn != parking_brake_state) {
362             g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOn;
363             g_crr_state.parking_brake.is_changed = STM_TRUE;
364         }
365         break;
366     case STM_EVT_NO_CAR_STOP:
367         if (gStmCarStateNoStop != car_state) {
368             g_crr_state.layer.apps.state = g_prv_apps_state_car_stop;
369             g_crr_state.layer.apps.is_changed = STM_TRUE;
370
371             g_crr_state.car.state = gStmCarStateNoStop;
372             g_crr_state.car.is_changed = STM_TRUE;
373         }
374         break;
375     case STM_EVT_NO_CAR_RUN:
376         if (gStmCarStateNoRun != car_state) {
377             g_prv_apps_state_car_stop = apps_state;
378             g_crr_state.layer.apps.state = gStmLayoutNoM1;
379             g_crr_state.layer.apps.is_changed = STM_TRUE;
380
381             g_crr_state.car.state = gStmCarStateNoRun;
382             g_crr_state.car.is_changed = STM_TRUE;
383         }
384         break;
385     case STM_EVT_NO_LAMP_OFF:
386         if (gStmLampStateNoOff != lamp_state) {
387             g_crr_state.lamp.state = gStmLampStateNoOff;
388             g_crr_state.lamp.is_changed = STM_TRUE;
389         }
390         break;
391     case STM_EVT_NO_LAMP_ON:
392         if (gStmLampStateNoOn != lamp_state) {
393             g_crr_state.lamp.state = gStmLampStateNoOn;
394             g_crr_state.lamp.is_changed = STM_TRUE;
395         }
396         break;
397     default:
398         // nop
399         break;
400     }
401
402     // Copy current state for return
403     memcpy(state, &g_crr_state, sizeof(g_crr_state));
404
405     return 0;
406 }