1 /*
2 * Copyright (C) 2022 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 <stdio.h>
17 #include <unistd.h>
18 #include <ohos_init.h>
19 #include <iunknown.h>
20 #include <samgr_lite.h>
21
22 #include "devattest_log.h"
23 #include "attest_framework_define.h"
24
25 typedef struct {
26 INHERIT_SERVICE;
27 Identity identity;
28 } AttestFrameworkService;
29
30 // 实现服务的生命周期函数
GetName(Service * service)31 static const char *GetName(Service *service)
32 {
33 (void)service;
34 return ATTEST_SERVICE;
35 }
36
Initialize(Service * service,Identity identity)37 static BOOL Initialize(Service *service, Identity identity)
38 {
39 AttestFrameworkService *attestService = (AttestFrameworkService *)service;
40 attestService->identity = identity;
41 return TRUE;
42 }
43
MessageHandle(Service * service,Request * msg)44 static BOOL MessageHandle(Service *service, Request *msg)
45 {
46 (void)service;
47 HILOGI("[SERVER MessageHandle] msg->msgId:%d", msg->msgId);
48 return FALSE;
49 }
50
GetTaskConfig(Service * service)51 static TaskConfig GetTaskConfig(Service *service)
52 {
53 (void)service;
54 TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, ATTEST_STACK_SIZE, ATTEST_QUEUE_SIZE, SINGLE_TASK};
55 return config;
56 }
57
58 // 创建服务对象
59 static AttestFrameworkService g_attestService = {
60 .GetName = GetName,
61 .Initialize = Initialize,
62 .MessageHandle = MessageHandle,
63 .GetTaskConfig = GetTaskConfig,
64 {-1, -1, NULL}
65 };
66
67 // 向SAMGR注册服务及接口
Init(void)68 static void Init(void)
69 {
70 SAMGR_GetInstance()->RegisterService((Service *)&g_attestService);
71 }
72
73 // 定义服务的初始化入口
74 SYS_SERVICE_INIT(Init);