• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include "client_business_impl.h"
20 #include "common.h"
21 #include "ipc_skeleton.h"
22 #include "iproxy_client.h"
23 #include "rpc_errno.h"
24 #include "rpc_log.h"
25 #include "samgr_lite.h"
26 #include "serializer.h"
27 
28 #define INVALID_CB_ID 0xFF
29 #define WAIT_SERVER_READY_INTERVAL_COUNT 50
30 #define EXIT_TIMEOUT 60 // 60s
31 
32 static IClientProxy *g_serverProxy = NULL;
33 
ServerDeadCallback(void * arg)34 static void ServerDeadCallback(void *arg)
35 {
36     RPC_LOG_INFO("====== server dead ServerDeadCallback called ======");
37 }
38 
AddDeathCallback()39 static void AddDeathCallback()
40 {
41     uint32_t cbId = INVALID_CB_ID;
42 
43     SvcIdentity svcIdentity = SAMGR_GetRemoteIdentity(IPC_TEST_SMALL, NULL);
44     int32_t ret = AddDeathRecipient(svcIdentity, ServerDeadCallback, NULL, &cbId);
45     if (ret != ERR_NONE) {
46         RPC_LOG_ERROR("[ipc_test_client] AddDeathRecipient failed, ret:[%d]", ret);
47         return;
48     }
49     RPC_LOG_INFO("[ipc_test_client] add death callback success, cbId = [%u]", cbId);
50 }
51 
HOS_SystemInit(void)52 static void HOS_SystemInit(void)
53 {
54     SAMGR_Bootstrap();
55     return;
56 }
57 
ClientSendData()58 void ClientSendData()
59 {
60     const int32_t executionInterval = 2; // 2s
61     SendBool();
62     SendInt8();
63     SendInt16();
64     SendInt32();
65     SendInt64();
66     sleep(executionInterval);
67     SendUint8();
68     SendUint16();
69     SendUint32();
70     SendUint64();
71     SendFloat();
72     SendDouble();
73     sleep(executionInterval);
74     SendInt8Vector();
75     SendInt8Vector();
76     SendInt16Vector();
77     SendInt32Vector();
78     SendInt64Vector();
79     sleep(executionInterval);
80     SendUint8Vector();
81     SendUint16Vector();
82     SendUint32Vector();
83     SendUint64Vector();
84     SendFloatVector();
85     SendDoubleVector();
86     sleep(executionInterval);
87     SendFileDescriptor();
88     SendString();
89     SendRawData();
90     SendBuffer();
91     //remoteObject sent in RegisterToService
92     RPC_LOG_INFO("[ipc_test_client] SendData end");
93     return;
94 }
95 
main(int argc,char * argv[])96 int main(int argc, char *argv[])
97 {
98     RPC_LOG_INFO("[ipc_test_client] Enter System Ability Client");
99     HOS_SystemInit();
100     RPC_LOG_INFO("[ipc_test_client] SystemInit end");
101     InitLocalIdentity();
102     RegisterToService();
103     AddDeathCallback();
104     ClientSendData();
105 
106     // auto exit when timeout
107     sleep(EXIT_TIMEOUT);
108     RPC_LOG_INFO("[ipc_test_client] exit");
109     return 0;
110 }