• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
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 <stdlib.h>
17 #include <string.h>
18 #include <stdint.h>
19 #include <pthread.h>
20 
21 #include "cmsis_os2.h"
22 #include "softbus_bus_center.h"
23 #include "rpc_mini_samgr.h"
24 #include "ipc_skeleton.h"
25 #include "serializer.h"
26 #include "samgr_lite.h"
27 #include "iproxy_client.h"
28 
29 #define DEFAULT_THREAD_STACK_SIZE 10240
30 
31 #define IPC_LENGTH 64
32 
33 
RpcClientMain(void * args)34 void RpcClientMain(void *args)
35 {
36     pthread_setname_np(pthread_self(), "rpc_client");
37     if (args == NULL) {
38         return;
39     }
40     printf("%s %d\n", __FUNCTION__, __LINE__);
41     static IClientProxy *miniInterface = NULL;
42 
43     NodeBasicInfo *nodeInfo[4];
44     int32_t infoNum = 4;
45     int32_t ret = GetAllNodeDeviceInfo("com.ohos.devicemanagerui", &nodeInfo, &infoNum);
46     if (ret != 0) {
47         printf("GetAllNodeDeviceInfo failed, error=%d\n", ret);
48     } else {
49         printf("GetAllNodeDeviceInfo infonum=%d\n", infoNum);
50         for (int i = 0; i < infoNum; i++) {
51             if (nodeInfo[i] == NULL) {
52                 printf("node %d info is null\n", i);
53                 break;
54             }
55             printf("trusted deviceid %s\n", nodeInfo[i]->networkId);
56         }
57     }
58 
59     if (nodeInfo[0]->networkId == NULL) {
60         printf("all nodes are null, get all trust node device info failed\n");
61         return;
62     }
63 
64     IUnknown *miniDefApi = SAMGR_GetInstance()->GetRemoteDefaultFeatureApi(nodeInfo[0]->networkId, "mini_sa_rpc");
65     if (miniDefApi == NULL) {
66         printf("[%s:%d]\n", __func__, __LINE__);
67         return;
68     }
69     printf("[%s:%d]\n", __func__, __LINE__);
70     miniDefApi->QueryInterface(miniDefApi, 0, (void **) &miniInterface);
71     IpcIo reply;
72     uint8_t tmpData[IPC_LENGTH];
73     IpcIoInit(&reply, tmpData, IPC_LENGTH, 0);
74     WriteInt32(&reply, *(int32_t *)args);
75     miniInterface->Invoke(miniInterface, 1, &reply, NULL, NULL);
76 }
77 
RpcClientTest(int32_t * progress)78 void RpcClientTest(int32_t* progress)
79 {
80     pthread_t threadId;
81     pthread_attr_t threadAttr;
82     int ret = pthread_attr_init(&threadAttr);
83     if (ret != 0) {
84         printf("pthread_attr_init failed %d\n", ret);
85         return;
86     }
87 
88     if (pthread_attr_setstacksize(&threadAttr, DEFAULT_THREAD_STACK_SIZE) != 0) {
89         printf("pthread_attr_setstacksize failed\n");
90         return;
91     }
92     int32_t *prog = malloc(sizeof(int32_t));
93     if (prog == NULL) {
94         return;
95     } else {
96         *prog = *progress;
97     }
98     ret = pthread_create(&threadId, &threadAttr, RpcClientMain, (void*)prog);
99     if (ret != 0) {
100         printf("pthread_create failed %d\n", ret);
101         return;
102     }
103     pthread_detach(threadId);
104 }
105