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