• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "bootstrap_service.h"
16 #include <ohos_init.h>
17 #include "samgr_lite.h"
18 
19 #define LOAD_FLAG 0x01
20 typedef struct Bootstrap {
21     INHERIT_SERVICE;
22     Identity identity;
23     uint8 flag;
24 } Bootstrap;
25 static const char *GetName(Service *service);
26 static BOOL Initialize(Service *service, Identity identity);
27 static TaskConfig GetTaskConfig(Service *service);
28 static BOOL MessageHandle(Service *service, Request *request);
29 
Init(void)30 static void Init(void)
31 {
32     static Bootstrap bootstrap;
33     bootstrap.GetName = GetName;
34     bootstrap.Initialize = Initialize;
35     bootstrap.MessageHandle = MessageHandle;
36     bootstrap.GetTaskConfig = GetTaskConfig;
37     bootstrap.flag = FALSE;
38     SAMGR_GetInstance()->RegisterService((Service *)&bootstrap);
39 }
40 SYS_SERVICE_INIT(Init);
41 
GetName(Service * service)42 static const char *GetName(Service *service)
43 {
44     (void)service;
45     return BOOTSTRAP_SERVICE;
46 }
47 
Initialize(Service * service,Identity identity)48 static BOOL Initialize(Service *service, Identity identity)
49 {
50     Bootstrap *bootstrap = (Bootstrap *)service;
51     bootstrap->identity = identity;
52     return TRUE;
53 }
54 
MessageHandle(Service * service,Request * request)55 static BOOL MessageHandle(Service *service, Request *request)
56 {
57     Bootstrap *bootstrap = (Bootstrap *)service;
58     switch (request->msgId) {
59         case BOOT_SYS_COMPLETED:
60             if ((bootstrap->flag & LOAD_FLAG) != LOAD_FLAG) {
61                 INIT_APP_CALL(service);
62                 INIT_APP_CALL(feature);
63                 bootstrap->flag |= LOAD_FLAG;
64             }
65             (void)SAMGR_SendResponseByIdentity(&bootstrap->identity, request, NULL);
66             break;
67 
68         case BOOT_APP_COMPLETED:
69             (void)SAMGR_SendResponseByIdentity(&bootstrap->identity, request, NULL);
70             break;
71 
72         case BOOT_REG_SERVICE:
73             (void)SAMGR_SendResponseByIdentity(&bootstrap->identity, request, NULL);
74             break;
75 
76         default:
77             break;
78     }
79     return TRUE;
80 }
81 
GetTaskConfig(Service * service)82 static TaskConfig GetTaskConfig(Service *service)
83 {
84     (void)service;
85     // The bootstrap service uses a stack of 2 KB (0x800) in size and a queue of 20 elements.
86     // You can adjust it according to the actual situation.
87     TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 0x800, 20, SHARED_TASK};
88     return config;
89 }
90