The role "video" can be shown in split area for ALS
[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 gStmLayoutNoM1:
230                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
231                     g_crr_state.layer.apps.is_changed = STM_TRUE;
232                     break;
233                 case gStmLayoutNoMf:
234                 case gStmLayoutNoS1:
235                     // nop
236                     break;
237                 default:
238                     g_crr_state.layer.apps.state = gStmLayoutNoS1;
239                     g_crr_state.layer.apps.is_changed = STM_TRUE;
240                     break;
241                 }
242                 break;
243             case STM_ARA_NO_SPLIT_MAIN:
244                 // Apps layer
245                 switch (apps_state) {
246                 case gStmLayoutNoS1:
247                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
248                     g_crr_state.layer.apps.is_changed = STM_TRUE;
249                     break;
250                 case gStmLayoutNoS2:
251                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
252                     g_crr_state.layer.apps.is_changed = STM_TRUE;
253                     break;
254                 default:
255                     // nop
256                     break;
257                 }
258                 break;
259             case STM_ARA_NO_SPLIT_SUB:
260                 // Apps layer
261                 switch (apps_state) {
262                 case gStmLayoutNoM1:
263                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
264                     g_crr_state.layer.apps.is_changed = STM_TRUE;
265                     break;
266                 case gStmLayoutNoM2:
267                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
268                     g_crr_state.layer.apps.is_changed = STM_TRUE;
269                     break;
270                 case gStmLayoutNoS1:
271                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
272                     g_crr_state.layer.apps.is_changed = STM_TRUE;
273                     break;
274                 case gStmLayoutNoS2:
275                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
276                     g_crr_state.layer.apps.is_changed = STM_TRUE;
277                     break;
278                 default:
279                     // nop
280                     break;
281                 }
282                 break;
283             default:
284                 // nop
285                 break;
286             }
287             break;
288         case STM_CTG_NO_RESTRICTION:
289             switch (area_no) {
290             case STM_ARA_NO_RESTRICTION_NORMAL:
291                 // restriction Layer
292                 switch (restriction_state) {
293                 case gStmLayoutNoNone:
294                     g_crr_state.layer.restriction.state = gStmLayoutNoRestriction;
295                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
296                     break;
297                 default:
298                     // nop
299                     break;
300                 }
301                 break;
302             case STM_ARA_NO_RESTRICTION_SPLIT_MAIN:
303                 // restriction Layer
304                 switch (restriction_state) {
305                 case gStmLayoutNoNone:
306                     g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitMain;
307                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
308                     break;
309                 default:
310                     // nop
311                     break;
312                 }
313                 break;
314             case STM_ARA_NO_RESTRICTION_SPLIT_SUB:
315                 // restriction Layer
316                 switch (restriction_state) {
317                 case gStmLayoutNoNone:
318                     g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitSub;
319                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
320                     break;
321                 default:
322                     // nop
323                     break;
324                 }
325                 break;
326             default:
327                 // nop
328                 break;
329             }
330             break;
331         default:
332             // nop
333             break;
334         }
335     case STM_EVT_NO_DEACTIVATE:
336         switch (category_no) {
337         case STM_CTG_NO_RESTRICTION:
338             // restriction Layer
339             switch (restriction_state) {
340             case gStmLayoutNoRestriction:
341             case gStmLayoutNoRestrictionSplitMain:
342             case gStmLayoutNoRestrictionSplitSub:
343                 g_crr_state.layer.restriction.state = gStmLayoutNoNone;
344                 g_crr_state.layer.restriction.is_changed = STM_TRUE;
345                 break;
346             default:
347                 // nop
348                 break;
349             }
350         default:
351             // nop
352             break;
353         }
354         break;
355     case STM_EVT_NO_PARKING_BRAKE_OFF:
356         if (gStmParkingBrakeStateNoOff != parking_brake_state) {
357             g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOff;
358             g_crr_state.parking_brake.is_changed = STM_TRUE;
359         }
360         break;
361     case STM_EVT_NO_PARKING_BRAKE_ON:
362         if (gStmParkingBrakeStateNoOn != parking_brake_state) {
363             g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOn;
364             g_crr_state.parking_brake.is_changed = STM_TRUE;
365         }
366         break;
367     case STM_EVT_NO_CAR_STOP:
368         if (gStmCarStateNoStop != car_state) {
369             g_crr_state.layer.apps.state = g_prv_apps_state_car_stop;
370             g_crr_state.layer.apps.is_changed = STM_TRUE;
371
372             g_crr_state.car.state = gStmCarStateNoStop;
373             g_crr_state.car.is_changed = STM_TRUE;
374         }
375         break;
376     case STM_EVT_NO_CAR_RUN:
377         if (gStmCarStateNoRun != car_state) {
378             g_prv_apps_state_car_stop = apps_state;
379             g_crr_state.layer.apps.state = gStmLayoutNoM1;
380             g_crr_state.layer.apps.is_changed = STM_TRUE;
381
382             g_crr_state.car.state = gStmCarStateNoRun;
383             g_crr_state.car.is_changed = STM_TRUE;
384         }
385         break;
386     case STM_EVT_NO_LAMP_OFF:
387         if (gStmLampStateNoOff != lamp_state) {
388             g_crr_state.lamp.state = gStmLampStateNoOff;
389             g_crr_state.lamp.is_changed = STM_TRUE;
390         }
391         break;
392     case STM_EVT_NO_LAMP_ON:
393         if (gStmLampStateNoOn != lamp_state) {
394             g_crr_state.lamp.state = gStmLampStateNoOn;
395             g_crr_state.lamp.is_changed = STM_TRUE;
396         }
397         break;
398     default:
399         // nop
400         break;
401     }
402
403     // Copy current state for return
404     memcpy(state, &g_crr_state, sizeof(g_crr_state));
405
406     return 0;
407 }