1 /*
2  * Copyright (C) 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 "ipc_service_init.h"
17 
18 #include "device_auth_defines.h"
19 #include "hc_log.h"
20 #include "ipc_dev_auth_stub.h"
21 #include "ipc_skeleton.h"
22 #include "ohos_init.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
GetName(Service * service)28 static const char *GetName(Service *service)
29 {
30     (void)service;
31     return DEV_AUTH_SERVICE_NAME;
32 }
33 
Initialize(Service * service,Identity identity)34 static BOOL Initialize(Service *service, Identity identity)
35 {
36     if (service == NULL) {
37         LOGW("invalid param");
38         return FALSE;
39     }
40 
41     DevAuthService *mgrService = (DevAuthService *)service;
42     mgrService->identity = identity;
43     return TRUE;
44 }
45 
MessageHandle(Service * service,Request * request)46 static BOOL MessageHandle(Service *service, Request *request)
47 {
48     if ((service == NULL) || (request == NULL)) {
49         LOGE("invalid param");
50         return FALSE;
51     }
52     return TRUE;
53 }
54 
GetTaskConfig(Service * service)55 static TaskConfig GetTaskConfig(Service *service)
56 {
57     const uint16_t stackSz = 0x1000; /* task stack size 4096 for task configuration */
58     const uint16_t queSize = 32; /* task queue size 32 for task configuration */
59     (void)service;
60     TaskConfig config = { LEVEL_HIGH, PRI_BELOW_NORMAL, stackSz, queSize, SHARED_TASK };
61     return config;
62 }
63 
ServiceInit(void)64 void ServiceInit(void)
65 {
66     static DevAuthService service = {
67         .GetName = GetName,
68         .Initialize = Initialize,
69         .MessageHandle = MessageHandle,
70         .GetTaskConfig = GetTaskConfig,
71         SERVER_IPROXY_IMPL_BEGIN,
72         .Invoke = OnRemoteInvoke,
73         IPROXY_END,
74     };
75 
76 #ifdef __LINUX__
77     sleep(1); /* delay 1 second on boot */
78 #endif
79     if (!SAMGR_GetInstance()->RegisterService((Service *)&service)) {
80         LOGE("%s, RegisterService failed", DEV_AUTH_SERVICE_NAME);
81         return;
82     }
83     if (!SAMGR_GetInstance()->RegisterDefaultFeatureApi(DEV_AUTH_SERVICE_NAME, GET_IUNKNOWN(service))) {
84         LOGE("%s, RegisterDefaultFeatureApi failed", DEV_AUTH_SERVICE_NAME);
85         return;
86     }
87     LOGI("%s, init success", DEV_AUTH_SERVICE_NAME);
88     return;
89 }
90 SYS_SERVICE_INIT(ServiceInit);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96