1 /*
2 * Copyright (c) 2020-2021 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
16 #include "bootstrap_service.h"
17 #include "samgr_lite.h"
18 #include <ohos_init.h>
19 #include <securec.h>
20 #include "service.h"
21 #include "common.h"
22 #include "hctest_internal.h"
23
24 typedef struct TestService {
25 INHERIT_SERVICE;
26 Identity identity;
27 uint8 flag;
28 } TestService;
29
30 static const char *GetName(Service *service);
31 static BOOL Initialize(Service *service, Identity identity);
32 static BOOL MessageHandle(Service *service, Request *request);
33 static TaskConfig GetTaskConfig(Service *service);
Init(void)34 static void Init(void)
35 {
36 static TestService testService;
37 testService.GetName = GetName;
38 testService.Initialize = Initialize;
39 testService.MessageHandle = MessageHandle;
40 testService.GetTaskConfig = GetTaskConfig;
41 testService.flag = FALSE;
42 SAMGR_GetInstance()->RegisterService((Service *)&testService);
43 }
44 SYSEX_SERVICE_INIT_PRI(Init,4);
GetName(Service * service)45 static const char *GetName(Service *service)
46 {
47 (void)service;
48 return HCTEST_SERVICE;
49 };
50
Initialize(Service * service,Identity identity)51 static BOOL Initialize(Service *service, Identity identity)
52 {
53 TestService *testService = (TestService *)service;
54 testService->identity = identity;
55 Request request = {.msgId = MSG_START_TEST};
56 int times = 0;
57 while (times < MAXIMUM_TRY_TIMES) {
58 int ret = SAMGR_SendRequest(&testService->identity, &request, (Handler)MessageHandle);
59 if (ret == 0) {
60 return TRUE;
61 }
62 times++;
63 ret = SAMGR_SendRequest(&testService->identity, &request, (Handler)MessageHandle);
64 }
65 return FALSE;
66 };
67
MessageHandle(Service * service,Request * request)68 static BOOL MessageHandle(Service *service, Request *request)
69 {
70 TestService *testService = (TestService *)service;
71 if (request == NULL) {
72 return FALSE;
73 }
74 switch (request->msgId) {
75 case MSG_START_TEST:
76 if ((testService->flag & TEST_FLAG) != TEST_FLAG) {
77 INIT_TEST_CALL();
78 testService->flag |= TEST_FLAG;
79 }
80 (void)SAMGR_SendResponseByIdentity(&testService->identity, request, NULL);
81 break;
82 default:
83 break;
84 }
85 return TRUE;
86 };
87
GetTaskConfig(Service * service)88 static TaskConfig GetTaskConfig(Service *service)
89 {
90 TaskConfig config = {LEVEL_MIDDLE, PRI_NORMAL, 0x1800, TASK_QUEUE_SIZE, SINGLE_TASK};
91 (void)service;
92 return config;
93 };
94