Fix the path to the host specific system configurations
[staging/basesystem.git] / service / system / task_manager / server / src / tskm_wakeup.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "tskm_wakeup.h"
18 #include "tskm_debug.h"
19 #include "tskm_util.h"
20 #include "tskm_state.h"
21 #include "tskm_port_subsys.h"
22 #include "tskm_port_pf.h"
23
24 #include "tskm_gstep.h"
25
26
27 /*********************************************************
28  *        Get gradual startup context
29  *********************************************************/
30 TSKM_STATIC TSKM_GSTEP_CTX_t*
31 gstepGetWakeupCtx(TSKM_MAIN_CTX_t* p_main) {
32   return &p_main->wakeup;
33 }
34
35 /***********************************************************************
36  *        Startup completion process
37  ***********************************************************************/
38 TSKM_STATIC void wakeupFinish(TSKM_MAIN_CTX_t* p_main) {
39   return;
40 }
41
42 /*********************************************************
43  *        Challenge for a transition to the next state
44  *********************************************************/
45 TSKM_STATIC void tryTransNextState(TSKM_MAIN_CTX_t* p_main) {
46   TSKM_GSTEP_CTX_t* p_wakeup;
47   TSKM_GSTEP_t* p_current;
48
49   p_wakeup = gstepGetWakeupCtx(p_main);
50   p_current = gstepGetCurrent(p_wakeup);
51
52   if (!p_current) {
53     return;
54   }
55
56   // LCOV_EXCL_BR_START 8: Because the second condition in the if statement is never false
57   if (tskm_svcsIsWaiting(&p_main->svcs) == TSKM_FALSE &&  // No waiting services
58       ((p_wakeup->compState & p_current->nextTransCond)
59           == p_current->nextTransCond)) {  // Event completion condition
60     // LCOV_EXCL_BR_STOP
61     if (gstepIsLast(p_wakeup)) {
62       tskm_stateTransit(p_main, TSKM_ST_WAKEUP, TSKM_ST_RUNNING);
63     } else {
64       tskm_stateTransit(p_main, TSKM_ST_WAKEUP, TSKM_ST_WAKEUP);
65     }
66   }
67 }
68
69 /*********************************************************
70  *        Gradual startup request issuance process
71  *********************************************************/
72 TSKM_ERR_t tskm_entryWakeup_Req(TSKM_MAIN_CTX_t* p_main,
73                                 TSKM_GSTEP_t* p_current) {
74   uint32_t ii;
75
76   // Refer to the stepId and perform preprocessing if needed.
77   if (p_current->gstepId == TSKM_GSTEP_BUPCHK) {
78     TSKM_PRINTF(TSKM_LOG_STATE, "BUPCHK EXE");
79     // When TaskManager is used as a system Launcher, system data is initialized here.
80   }
81
82   // Start process
83   for (ii = 0; ii < p_current->execSvcNum; ii++) {
84     TSKM_ERR_t tskmRet;
85     TSKM_SVCID_t svcId = p_current->execSvcIdList[ii];
86     TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, svcId);
87
88     tskmRet = tskm_svcExec(p_svc);
89     TSKM_ERR_CHK_DFT;
90   }
91
92   // Issue gradual startup request
93   for (ii = 0; ii < p_current->reqNum; ii++) {
94     TSKM_ERR_t tskmRet;
95     TSKM_GSTEP_REQ_INFO_t* p_req = &p_current->reqList[ii];
96     TSKM_SVC_CTX_t* p_svc = tskm_svcsGetSvcBySvcId(&p_main->svcs, p_req->svcId);
97
98     // Queuing in the SVC layer even for services that are not started.
99     tskmRet = tskm_svcWakeupRequest(p_svc, p_req);
100     TSKM_ERR_CHK_DFT;  // LCOV_EXCL_BR_LINE 6: Because TSKM_ERR_CHK_DFT does not specify a condition for goto to ERROR
101   }
102
103   if (p_current->nextTransCond) {
104     TSKM_PRINTF(TSKM_LOG_STATE, "WAIT COMP:%s(%llx)",
105                 tskm_convInitCompId2Str(p_current->nextTransCond),
106                 p_current->nextTransCond);
107   }
108
109   return TSKM_E_OK;
110
111   // LCOV_EXCL_START 6: Checked in Death testing, but it is not reflected in the coverage and excluded
112   ERROR:
113   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
114   return TSKM_E_NG;
115   // LCOV_EXCL_STOP
116 }
117
118 /*********************************************************
119  *        Gradual startup entry process
120  *********************************************************/
121 TSKM_ERR_t tskm_entryWakeup(TSKM_MAIN_CTX_t* p_main) {
122   TSKM_FUNC_IN();
123
124   TSKM_GSTEP_CTX_t* p_wakeup;
125   TSKM_GSTEP_t* p_current;
126
127   p_main->state = TSKM_ST_WAKEUP;
128   p_wakeup = gstepGetWakeupCtx(p_main);
129   p_current = gstepGetCurrent(p_wakeup);
130
131   if (p_current == NULL) {  // LCOV_EXCL_BR_LINE 8: Because condition false setting is not possible
132     // LCOV_EXCL_START 8: Because condition false setting is not possible
133     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
134     TSKM_ASSERT(0);
135     tskm_pf_exit(EXIT_FAILURE);
136     // LCOV_EXCL_STOP
137   }
138
139   TSKM_PRINTF(TSKM_LOG_SVCSTATE, "WAKEUP GSTEP:%d", p_wakeup->gstepIdx);
140
141   if (tskm_entryWakeup_Req(p_main, p_current) == TSKM_E_NG) {  // LCOV_EXCL_BR_LINE 200:the function of tskm_entryWakeup_Req can not be TSKM_E_NG at this case // NOLINT(whitespace/line_length)
142     // LCOV_EXCL_START 200:the function of tskm_entryWakeup_Req can not be TSKM_E_NG at this case // NOLINT(whitespace/line_length)
143     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
144     tskm_pf_exit(EXIT_FAILURE);
145     // LCOV_EXCL_STOP
146   }
147
148   TSKM_FUNC_OUT();
149   return TSKM_E_OK;
150 }
151
152 /*********************************************************
153  *        Gradual startup exit process
154  *********************************************************/
155 TSKM_ERR_t tskm_exitWakeup(TSKM_MAIN_CTX_t* p_main) {
156   TSKM_GSTEP_CTX_t* p_wakeup;
157
158   TSKM_FUNC_IN();
159   p_wakeup = gstepGetWakeupCtx(p_main);
160
161   // Exit process at the end of the gradual startup
162   if (gstepIsLast(p_wakeup)) {
163     TSKM_PRINTF(TSKM_LOG_STATE, "WAKEUP FIN");
164     wakeupFinish(p_main);
165   }
166
167   changeNextStep(p_wakeup);  // Transition to next step
168
169   TSKM_FUNC_OUT();
170   return TSKM_E_OK;
171 }
172
173 /*********************************************************
174  *        Gradual startup handler
175  *********************************************************/
176 TSKM_ERR_t tskm_handleWakeup(TSKM_MAIN_CTX_t* p_main, TSKM_EVENT_INFO_t* p_ev) {
177   TSKM_FUNC_IN();
178   TSKM_ERR_t tskmRet = TSKM_E_OK;
179
180   switch (p_ev->event) {
181     case TSKM_EV_PRI_REP_WAKEUP_COMP:  // Event completion notification at startup
182     {
183       TSKM_PRINTF(TSKM_LOG_SVCSTATE, "INIT COMP :%s(%#llx) from:%d",
184                   tskm_convInitCompId2Str(p_ev->prm.repWakeupComp.compId),
185                   p_ev->prm.repWakeupComp.compId, p_ev->fromPid);
186       TSKM_GSTEP_CTX_t* p_wakeup = gstepGetWakeupCtx(p_main);
187       p_wakeup->compState |= p_ev->prm.repWakeupComp.compId;
188       tryTransNextState(p_main);
189     }
190       break;
191     case TSKM_EV_LCL_CHG_SVC_STATE:  // Service state change
192       tryTransNextState(p_main);
193       break;
194     default:
195       tskmRet = tskm_handleAccon(p_main, p_ev);
196       break;
197   }
198   TSKM_FUNC_OUT();
199   return tskmRet;
200 }  // LCOV_EXCL_BR_LINE 10: Final line
201