1 /*
2 * Copyright (c) 2025 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 <ohos_init.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19
20 #include "common.h"
21 #include "rpc_errno.h"
22 #include "rpc_log.h"
23 #include "ipc_skeleton.h"
24 #include "samgr_lite.h"
25 #include "serializer.h"
26 #include "server_business_impl.h"
27
28 #define WAIT_SERVER_READY_INTERVAL_COUNT 50
29 #define STACK_SIZE 0x800
30 #define QUEUE_SIZE 50
31 #define WAIT_FOR_SERVER 2
32 #define EXIT_TIMEOUT 60 // 60s
33
34 typedef struct IPCSaInterface {
35 INHERIT_SERVER_IPROXY;
36 } IPCSaInterface;
37
38 typedef struct IPCSaService {
39 INHERIT_SERVICE;
40 INHERIT_IUNKNOWNENTRY(IPCSaInterface);
41 Identity identity;
42 } IPCSaService;
43
GetName(Service * service)44 static const char *GetName(Service *service)
45 {
46 (void)service;
47 return IPC_TEST_SMALL;
48 }
49
Initialize(Service * service,Identity identity)50 static BOOL Initialize(Service *service, Identity identity)
51 {
52 if (service == NULL) {
53 RPC_LOG_ERROR("invalid param");
54 return FALSE;
55 }
56 IPCSaService *ipcSaService = (IPCSaService *)service;
57 ipcSaService->identity = identity;
58 return TRUE;
59 }
60
MessageHandle(Service * service,Request * msg)61 static BOOL MessageHandle(Service *service, Request *msg)
62 {
63 RPC_LOG_INFO("[ipc_test_server] MessageHandle called");
64 return FALSE;
65 }
66
GetTaskConfig(Service * service)67 static TaskConfig GetTaskConfig(Service *service)
68 {
69 (void)service;
70 TaskConfig config = { LEVEL_HIGH, PRI_BELOW_NORMAL, STACK_SIZE, QUEUE_SIZE, SHARED_TASK };
71 return config;
72 }
73
74 static IPCSaService g_ipcSaService = {
75 .GetName = GetName,
76 .Initialize = Initialize,
77 .MessageHandle = MessageHandle,
78 .GetTaskConfig = GetTaskConfig,
79 SERVER_IPROXY_IMPL_BEGIN,
80 .Invoke = DispatchInvoke,
81 IPROXY_END,
82 };
83
HOS_SystemInit(void)84 void __attribute__((weak)) HOS_SystemInit(void)
85 {
86 SAMGR_Bootstrap();
87 return;
88 }
89
main(int argc,char * argv[])90 int main(int argc, char *argv[])
91 {
92 RPC_LOG_INFO("[ipc_test_server] server enter");
93 HOS_SystemInit();
94
95 // auto exit when timeout
96 sleep(EXIT_TIMEOUT);
97 RPC_LOG_INFO("[ipc_test_server] exit");
98 return 0;
99 }
100
Init(void)101 static void Init(void)
102 {
103 // server register to samgr_lite
104 RPC_LOG_INFO("[ipc_test_server] Init start");
105 sleep(WAIT_FOR_SERVER);
106 SAMGR_GetInstance()->RegisterService((Service *)&g_ipcSaService);
107 SAMGR_GetInstance()->RegisterDefaultFeatureApi(IPC_TEST_SMALL, GET_IUNKNOWN(g_ipcSaService));
108 }
109
110 SYSEX_SERVICE_INIT(Init);
111