Change the policy of switchng car run/stop in 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_restriction_state_car_stop = 0;
114 int g_prv_apps_state_car_stop = 0;
115
116 void stmInitialize() {
117     // Initialize previous state
118     memset(&g_prv_state, 0, sizeof(g_prv_state));
119
120     g_prv_state.layer.on_screen.state   = gStmLayoutNoNone;
121     g_prv_state.layer.restriction.state = gStmLayoutNoNone;
122     g_prv_state.layer.apps.state        = gStmLayoutNoNone;
123     g_prv_state.layer.homescreen.state  = gStmLayoutNoNone;
124     g_prv_state.parking_brake.state = gStmParkingBrakeStateNoOn;
125     g_prv_state.accel_pedal.state   = gStmAccelPedalStateNoOff;
126     g_prv_state.car.state           = gStmCarStateNoStop;
127     g_prv_state.lamp.state          = gStmLampStateNoOff;
128
129     // Initialize current state
130     g_crr_state = g_prv_state;
131 }
132
133 int stmTransitionState(int event, stm_state_t* state) {
134     int event_no, category_no, area_no;
135     int restriction_state, apps_state;
136     int parking_brake_state, accel_pedal_state, car_state, lamp_state;
137
138     event_no    = event & STM_MSK_EVT_NO;
139     category_no = event & STM_MSK_CTG_NO;
140     area_no     = event & STM_MSK_ARA_NO;
141
142     // Backup previous state
143     g_prv_state = g_crr_state;
144
145     // Get previous state
146     restriction_state = g_prv_state.layer.restriction.state;
147     apps_state = g_prv_state.layer.apps.state;
148     parking_brake_state  = g_prv_state.parking_brake.state;
149     accel_pedal_state = g_prv_state.accel_pedal.state;
150     car_state  = g_prv_state.car.state;
151     lamp_state = g_prv_state.lamp.state;
152
153     // Clear flags
154     g_crr_state.layer.on_screen.is_changed = STM_FALSE;
155     g_crr_state.layer.restriction.is_changed = STM_FALSE;
156     g_crr_state.layer.apps.is_changed = STM_FALSE;
157     g_crr_state.layer.homescreen.is_changed = STM_FALSE;
158     g_crr_state.parking_brake.is_changed = STM_FALSE;
159     g_crr_state.accel_pedal.is_changed = STM_FALSE;
160     g_crr_state.car.is_changed = STM_FALSE;
161     g_crr_state.lamp.is_changed = STM_FALSE;
162
163     switch (event_no) {
164     case STM_EVT_NO_ACTIVATE:
165         switch (category_no) {
166         case STM_CTG_NO_HOMESCREEN:
167             // Apps layer
168             g_crr_state.layer.apps.state = gStmLayoutNoNone;
169             g_crr_state.layer.apps.is_changed = STM_TRUE;
170
171             // Homescreen layer
172             g_crr_state.layer.homescreen.state = gStmLayoutNoHs;
173             g_crr_state.layer.homescreen.is_changed = STM_TRUE;
174             break;
175         case STM_CTG_NO_MAP:
176             switch (area_no) {
177             case STM_ARA_NO_FULL:
178                 // Apps layer
179                 switch (apps_state) {
180                 case gStmLayoutNoMf:
181                     // nop
182                     break;
183                 default:
184                     g_crr_state.layer.apps.state = gStmLayoutNoMf;
185                     g_crr_state.layer.apps.is_changed = STM_TRUE;
186                     break;
187                 }
188                 break;
189             case STM_ARA_NO_NORMAL:
190                 // Apps layer
191                 switch (apps_state) {
192                 case gStmLayoutNoM1:
193                     // nop
194                     break;
195                 case gStmLayoutNoS1:
196                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
197                     g_crr_state.layer.apps.is_changed = STM_TRUE;
198                     break;
199                 default:
200                     g_crr_state.layer.apps.state = gStmLayoutNoM1;
201                     g_crr_state.layer.apps.is_changed = STM_TRUE;
202                 }
203                 break;
204             case STM_ARA_NO_SPLIT_MAIN:
205                 // Apps layer
206                 switch (apps_state) {
207                 case gStmLayoutNoS1:
208                 case gStmLayoutNoS2:
209                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
210                     g_crr_state.layer.apps.is_changed = STM_TRUE;
211                     break;
212                 default:
213                     // nop
214                     break;
215                 }
216                 break;
217             }
218             break;
219         case STM_CTG_NO_GENERAL:
220             switch (area_no) {
221             case STM_ARA_NO_NORMAL:
222                 // Apps layer
223                 switch (apps_state) {
224                 case gStmLayoutNoMf:
225                     // nop
226                     break;
227                 default:
228                     g_crr_state.layer.apps.state = gStmLayoutNoG;
229                     g_crr_state.layer.apps.is_changed = STM_TRUE;
230                     break;
231                 }
232                 break;
233             default:
234                 // nop
235                 break;
236             }
237             break;
238         case STM_CTG_NO_SPLITABLE:
239             switch (area_no) {
240             case STM_ARA_NO_NORMAL:
241                 // Apps layer
242                 switch (apps_state) {
243                 case gStmLayoutNoM1:
244                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
245                     g_crr_state.layer.apps.is_changed = STM_TRUE;
246                     break;
247                 case gStmLayoutNoMf:
248                 case gStmLayoutNoS1:
249                     // nop
250                     break;
251                 default:
252                     g_crr_state.layer.apps.state = gStmLayoutNoS1;
253                     g_crr_state.layer.apps.is_changed = STM_TRUE;
254                     break;
255                 }
256                 break;
257             case STM_ARA_NO_SPLIT_MAIN:
258                 // Apps layer
259                 switch (apps_state) {
260                 case gStmLayoutNoS1:
261                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
262                     g_crr_state.layer.apps.is_changed = STM_TRUE;
263                     break;
264                 case gStmLayoutNoS2:
265                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
266                     g_crr_state.layer.apps.is_changed = STM_TRUE;
267                     break;
268                 default:
269                     // nop
270                     break;
271                 }
272                 break;
273             case STM_ARA_NO_SPLIT_SUB:
274                 // Apps layer
275                 switch (apps_state) {
276                 case gStmLayoutNoM1:
277                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
278                     g_crr_state.layer.apps.is_changed = STM_TRUE;
279                     break;
280                 case gStmLayoutNoM2:
281                     g_crr_state.layer.apps.state = gStmLayoutNoM2;
282                     g_crr_state.layer.apps.is_changed = STM_TRUE;
283                     break;
284                 case gStmLayoutNoS1:
285                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
286                     g_crr_state.layer.apps.is_changed = STM_TRUE;
287                     break;
288                 case gStmLayoutNoS2:
289                     g_crr_state.layer.apps.state = gStmLayoutNoS2;
290                     g_crr_state.layer.apps.is_changed = STM_TRUE;
291                     break;
292                 default:
293                     // nop
294                     break;
295                 }
296                 break;
297             default:
298                 // nop
299                 break;
300             }
301             break;
302         case STM_CTG_NO_RESTRICTION:
303             switch (area_no) {
304             case STM_ARA_NO_RESTRICTION_NORMAL:
305                 // restriction Layer
306                 switch (restriction_state) {
307                 case gStmLayoutNoNone:
308                     g_crr_state.layer.restriction.state = gStmLayoutNoRestriction;
309                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
310                     break;
311                 default:
312                     // nop
313                     break;
314                 }
315                 break;
316             case STM_ARA_NO_RESTRICTION_SPLIT_MAIN:
317                 // restriction Layer
318                 switch (restriction_state) {
319                 case gStmLayoutNoNone:
320                     g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitMain;
321                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
322                     break;
323                 default:
324                     // nop
325                     break;
326                 }
327                 break;
328             case STM_ARA_NO_RESTRICTION_SPLIT_SUB:
329                 // restriction Layer
330                 switch (restriction_state) {
331                 case gStmLayoutNoNone:
332                     g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitSub;
333                     g_crr_state.layer.restriction.is_changed = STM_TRUE;
334                     break;
335                 default:
336                     // nop
337                     break;
338                 }
339                 break;
340             default:
341                 // nop
342                 break;
343             }
344             break;
345         default:
346             // nop
347             break;
348         }
349     case STM_EVT_NO_DEACTIVATE:
350         switch (category_no) {
351         case STM_CTG_NO_RESTRICTION:
352             // restriction Layer
353             switch (restriction_state) {
354             case gStmLayoutNoRestriction:
355             case gStmLayoutNoRestrictionSplitMain:
356             case gStmLayoutNoRestrictionSplitSub:
357                 g_crr_state.layer.restriction.state = gStmLayoutNoNone;
358                 g_crr_state.layer.restriction.is_changed = STM_TRUE;
359                 break;
360             default:
361                 // nop
362                 break;
363             }
364         default:
365             // nop
366             break;
367         }
368         break;
369     case STM_EVT_NO_PARKING_BRAKE_OFF:
370         if (gStmParkingBrakeStateNoOff != parking_brake_state) {
371             g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOff;
372             g_crr_state.parking_brake.is_changed = STM_TRUE;
373         }
374         break;
375     case STM_EVT_NO_PARKING_BRAKE_ON:
376         if (gStmParkingBrakeStateNoOn != parking_brake_state) {
377             g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOn;
378             g_crr_state.parking_brake.is_changed = STM_TRUE;
379         }
380         break;
381     case STM_EVT_NO_ACCEL_PEDAL_OFF:
382         if (gStmAccelPedalStateNoOff != accel_pedal_state) {
383             g_crr_state.accel_pedal.state = gStmAccelPedalStateNoOff;
384             g_crr_state.accel_pedal.is_changed = STM_TRUE;
385         }
386         break;
387     case STM_EVT_NO_ACCEL_PEDAL_ON:
388         if (gStmAccelPedalStateNoOn != accel_pedal_state) {
389             g_crr_state.accel_pedal.state = gStmAccelPedalStateNoOn;
390             g_crr_state.accel_pedal.is_changed = STM_TRUE;
391         }
392         break;
393     case STM_EVT_NO_CAR_STOP:
394         if (gStmCarStateNoStop != car_state) {
395             g_crr_state.layer.apps.state = g_prv_apps_state_car_stop;
396             g_crr_state.layer.apps.is_changed = STM_TRUE;
397
398             g_crr_state.car.state = gStmCarStateNoStop;
399             g_crr_state.car.is_changed = STM_TRUE;
400         }
401         break;
402     case STM_EVT_NO_CAR_RUN:
403         if (gStmCarStateNoRun != car_state) {
404             g_prv_apps_state_car_stop = apps_state;
405             g_crr_state.layer.apps.state = gStmLayoutNoM1;
406             g_crr_state.layer.apps.is_changed = STM_TRUE;
407
408             g_crr_state.car.state = gStmCarStateNoRun;
409             g_crr_state.car.is_changed = STM_TRUE;
410         }
411         break;
412     case STM_EVT_NO_LAMP_OFF:
413         if (gStmLampStateNoOff != lamp_state) {
414             g_crr_state.lamp.state = gStmLampStateNoOff;
415             g_crr_state.lamp.is_changed = STM_TRUE;
416         }
417         break;
418     case STM_EVT_NO_LAMP_ON:
419         if (gStmLampStateNoOn != lamp_state) {
420             g_crr_state.lamp.state = gStmLampStateNoOn;
421             g_crr_state.lamp.is_changed = STM_TRUE;
422         }
423         break;
424     default:
425         // nop
426         break;
427     }
428
429     // Set car state
430     if (g_crr_state.parking_brake.is_changed
431         || g_crr_state.accel_pedal.is_changed) {
432         if ((gStmParkingBrakeStateNoOff == g_crr_state.parking_brake.state)
433             && (gStmAccelPedalStateNoOn == g_crr_state.accel_pedal.state)){
434             if (gStmCarStateNoRun != car_state) {
435                 // Car state is changed stop -> run
436                 g_crr_state.car.state = gStmCarStateNoRun;
437                 g_crr_state.car.is_changed = STM_TRUE;
438
439                 // Update restriction layer
440                 g_prv_restriction_state_car_stop = restriction_state;
441                 g_crr_state.layer.restriction.state = gStmLayoutNoNone;
442                 g_crr_state.layer.restriction.is_changed = STM_TRUE;
443
444                 // Update apps layer
445                 g_prv_apps_state_car_stop = apps_state;
446                 g_crr_state.layer.apps.state = gStmLayoutNoM1;
447                 g_crr_state.layer.apps.is_changed = STM_TRUE;
448             }
449         }
450         else {
451             if (gStmCarStateNoStop != car_state) {
452                 // Car state is changed run -> stop
453                 g_crr_state.car.state = gStmCarStateNoStop;
454                 g_crr_state.car.is_changed = STM_TRUE;
455
456                 // Update restriction layer
457                 g_crr_state.layer.restriction.state = g_prv_restriction_state_car_stop;
458                 g_crr_state.layer.restriction.is_changed = STM_TRUE;
459
460                 // Update apps layer
461                 g_crr_state.layer.apps.state = g_prv_apps_state_car_stop;
462                 g_crr_state.layer.apps.is_changed = STM_TRUE;
463             }
464         }
465     }
466
467     // Copy current state for return
468     memcpy(state, &g_crr_state, sizeof(g_crr_state));
469
470     return 0;
471 }