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 "bus_center_client_stub.h" 17 18 #include <stdint.h> 19 20 #include "client_bus_center_manager.h" 21 #include "ipc_skeleton.h" 22 #include "lnn_log.h" 23 #include "softbus_def.h" 24 #include "softbus_errcode.h" 25 ClientOnJoinLNNResult(IpcIo * data,IpcIo * reply)26 int32_t ClientOnJoinLNNResult(IpcIo *data, IpcIo *reply) 27 { 28 if (data == NULL) { 29 LNN_LOGE(LNN_EVENT, "invalid param"); 30 return SOFTBUS_ERR; 31 } 32 33 uint32_t addrSize; 34 ReadUint32(data, &addrSize); 35 if (addrSize != sizeof(ConnectionAddr)) { 36 LNN_LOGE(LNN_EVENT, "read addr failed. addrSize=%{public}d", addrSize); 37 return SOFTBUS_ERR; 38 } 39 void *addr = (void *)ReadBuffer(data, addrSize); 40 if (addr == NULL) { 41 LNN_LOGE(LNN_EVENT, "read addr failed"); 42 return SOFTBUS_ERR; 43 } 44 int32_t retCode = 0; 45 ReadInt32(data, &retCode); 46 size_t networkIdLen; 47 const char *networkId = NULL; 48 if (retCode == 0) { 49 networkId = (const char *)ReadString(data, &networkIdLen); 50 if (networkId == NULL) { 51 LNN_LOGE(LNN_EVENT, "read networkId failed"); 52 return SOFTBUS_ERR; 53 } 54 } 55 int32_t retReply = LnnOnJoinResult(addr, networkId, retCode); 56 if (retReply != SOFTBUS_OK) { 57 LNN_LOGE(LNN_EVENT, "LnnOnJoinResult failed"); 58 return SOFTBUS_ERR; 59 } 60 return SOFTBUS_OK; 61 } 62 ClientOnJoinMetaNodeResult(IpcIo * data,IpcIo * reply)63 int32_t ClientOnJoinMetaNodeResult(IpcIo *data, IpcIo *reply) 64 { 65 (void)data; 66 (void)reply; 67 return SOFTBUS_OK; 68 } 69 ClientOnLeaveLNNResult(IpcIo * data,IpcIo * reply)70 int32_t ClientOnLeaveLNNResult(IpcIo *data, IpcIo *reply) 71 { 72 if (data == NULL) { 73 LNN_LOGE(LNN_EVENT, "invalid param"); 74 return SOFTBUS_ERR; 75 } 76 size_t networkIdLen; 77 const char *networkId = (const char *)ReadString(data, &networkIdLen); 78 if (networkId == NULL) { 79 LNN_LOGE(LNN_EVENT, "read networkId failed"); 80 return SOFTBUS_ERR; 81 } 82 int32_t retCode = 0; 83 ReadInt32(data, &retCode); 84 int32_t retReply = LnnOnLeaveResult(networkId, retCode); 85 if (retReply != SOFTBUS_OK) { 86 LNN_LOGE(LNN_EVENT, "LnnOnLeaveResult failed"); 87 return SOFTBUS_ERR; 88 } 89 return SOFTBUS_OK; 90 } 91 ClientOnLeaveMetaNodeResult(IpcIo * data,IpcIo * reply)92 int32_t ClientOnLeaveMetaNodeResult(IpcIo *data, IpcIo *reply) 93 { 94 (void)data; 95 (void)reply; 96 return SOFTBUS_OK; 97 } 98 ClientOnNodeOnlineStateChanged(IpcIo * data,IpcIo * reply)99 int32_t ClientOnNodeOnlineStateChanged(IpcIo *data, IpcIo *reply) 100 { 101 if (data== NULL) { 102 LNN_LOGE(LNN_EVENT, "invalid param"); 103 return SOFTBUS_ERR; 104 } 105 bool isOnline; 106 ReadBool(data, &isOnline); 107 uint32_t infoSize = 0; 108 ReadUint32(data, &infoSize); 109 if (infoSize != sizeof(NodeBasicInfo)) { 110 LNN_LOGE(LNN_EVENT, 111 "read basic info failed. infoSize=%{public}d", infoSize); 112 return SOFTBUS_ERR; 113 } 114 void *info = (void *)ReadBuffer(data, infoSize); 115 if (info == NULL) { 116 LNN_LOGE(LNN_EVENT, "read basic info failed"); 117 return SOFTBUS_ERR; 118 } 119 int32_t retReply = LnnOnNodeOnlineStateChanged("", isOnline, info); 120 if (retReply != SOFTBUS_OK) { 121 LNN_LOGE(LNN_EVENT, "LnnOnNodeOnlineStateChanged failed"); 122 return SOFTBUS_ERR; 123 } 124 return SOFTBUS_OK; 125 } 126 ClientOnNodeBasicInfoChanged(IpcIo * data,IpcIo * reply)127 int32_t ClientOnNodeBasicInfoChanged(IpcIo *data, IpcIo *reply) 128 { 129 if (data == NULL) { 130 LNN_LOGE(LNN_EVENT, "invalid param"); 131 return SOFTBUS_ERR; 132 } 133 134 int32_t type = 0; 135 ReadInt32(data, &type); 136 uint32_t infoSize = 0; 137 ReadUint32(data, &infoSize); 138 if (infoSize != sizeof(NodeBasicInfo)) { 139 LNN_LOGE(LNN_EVENT, 140 "read basic info failed. infoSize=%{public}d", infoSize); 141 return SOFTBUS_ERR; 142 } 143 void *info = (void *)ReadBuffer(data, infoSize); 144 if (info == NULL) { 145 LNN_LOGE(LNN_EVENT, "read basic info failed"); 146 return SOFTBUS_ERR; 147 } 148 int32_t retReply = LnnOnNodeBasicInfoChanged("", info, type); 149 if (retReply != SOFTBUS_OK) { 150 LNN_LOGE(LNN_EVENT, 151 "LnnOnNodeBasicInfoChanged failed"); 152 return SOFTBUS_ERR; 153 } 154 return SOFTBUS_OK; 155 } 156 ClientOnTimeSyncResult(IpcIo * data,IpcIo * reply)157 int32_t ClientOnTimeSyncResult(IpcIo *data, IpcIo *reply) 158 { 159 if (data == NULL) { 160 LNN_LOGE(LNN_EVENT, "invalid param"); 161 return SOFTBUS_ERR; 162 } 163 164 uint32_t infoSize = 0; 165 ReadUint32(data, &infoSize); 166 if (infoSize != sizeof(TimeSyncResultInfo)) { 167 LNN_LOGE(LNN_EVENT, "read info failed. infoSize=%{public}d", infoSize); 168 return SOFTBUS_ERR; 169 } 170 void *info = (void *)ReadBuffer(data, infoSize); 171 if (info == NULL) { 172 LNN_LOGE(LNN_EVENT, "read info failed"); 173 return SOFTBUS_ERR; 174 } 175 int32_t retCode = 0; 176 ReadInt32(data, &retCode); 177 178 int32_t retReply = LnnOnTimeSyncResult(info, retCode); 179 if (retReply != SOFTBUS_OK) { 180 LNN_LOGE(LNN_EVENT, "LnnOnTimeSyncResult failed"); 181 return SOFTBUS_ERR; 182 } 183 return SOFTBUS_OK; 184 } 185 ClientOnPublishLNNResult(IpcIo * data,IpcIo * reply)186 void ClientOnPublishLNNResult(IpcIo *data, IpcIo *reply) 187 { 188 if (reply == NULL) { 189 LNN_LOGE(LNN_EVENT, "invalid param"); 190 return; 191 } 192 int32_t publishId; 193 ReadInt32(data, &publishId); 194 int32_t reason; 195 ReadInt32(data, &reason); 196 LnnOnPublishLNNResult(publishId, reason); 197 } 198 ClientOnRefreshLNNResult(IpcIo * data,IpcIo * reply)199 void ClientOnRefreshLNNResult(IpcIo *data, IpcIo *reply) 200 { 201 if (data == NULL) { 202 LNN_LOGE(LNN_EVENT, "invalid param"); 203 return; 204 } 205 int32_t refreshId; 206 ReadInt32(data, &refreshId); 207 int32_t reason; 208 ReadInt32(data, &reason); 209 LnnOnRefreshLNNResult(refreshId, reason); 210 } 211 ClientOnRefreshDeviceFound(IpcIo * data,IpcIo * reply)212 void ClientOnRefreshDeviceFound(IpcIo *data, IpcIo *reply) 213 { 214 if (data == NULL) { 215 LNN_LOGE(LNN_EVENT, "invalid param"); 216 return; 217 } 218 uint32_t infoSize; 219 ReadUint32(data, &infoSize); 220 if (infoSize != sizeof(DeviceInfo)) { 221 LNN_LOGE(LNN_EVENT, 222 "read info failed. infoSize=%{public}d", infoSize); 223 return; 224 } 225 void *info = (void *)ReadBuffer(data, infoSize); 226 if (info == NULL) { 227 LNN_LOGE(LNN_EVENT, "read info failed"); 228 return; 229 } 230 LnnOnRefreshDeviceFound(info); 231 } 232