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 #ifndef SOFTBUS_TRANSMISSION_H 17 #define SOFTBUS_TRANSMISSION_H 18 19 #include <stdint.h> 20 #include "softbus_def.h" 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif 27 28 typedef struct { 29 /** 30 * @brief callback after the specified channel is opened. 31 * @see {@link TransRegisterNetworkingChannelListener} 32 * @param[in] channelId indicates that channel is open. 33 * @param[in] uuid indicates the pointer to the uuid. 34 * @param[in] isServer indicates server side or client side. 35 * @return <b>SOFTBUS_ERR</b> the processing failed after the callback. 36 * @return <b>SOFTBUS_OK</b> the processing success after the callback. 37 */ 38 int (*onChannelOpened)(int32_t channelId, const char *uuid, unsigned char isServer); // compatible nearby 39 /** 40 * @brief callback after open channel failed. 41 * @see {@link TransRegisterNetworkingChannelListener} 42 * @param[in] channelId indicates the opening channelId. 43 * @param[in] uuid indicates the pointer to the uuid. 44 */ 45 void (*onChannelOpenFailed)(int32_t channelId, const char *uuid); 46 /** 47 * @brief callback after closed channel. 48 * @see {@link TransRegisterNetworkingChannelListener} 49 * @param[in] channelId indicates the opening channelId. 50 */ 51 void (*onChannelClosed)(int32_t channelId); 52 /** 53 * @brief callback after receive message. 54 * @see {@link TransRegisterNetworkingChannelListener} 55 * @param[in] channelId indicates the opened channelId. 56 * @param[in] data indicates the pointer to the message data. 57 * @param[in] len indicates the message data of len. 58 */ 59 void (*onMessageReceived)(int32_t channelId, const char *data, uint32_t len); 60 } INetworkingListener; 61 62 /** 63 * @brief To open a proxy channel to the specified device. 64 * @see {@link TransCloseNetWorkingChannel} 65 * @param[in] sessionName indicates the pointer to the package name. 66 * @param[in] peerNetworkId indicates the pointer to the peer network id. 67 * @return <b>INVALID_CHANNEL_ID</b> Failed to open channel, return invalid channel id. 68 * @return <b>NewChannelId</b> Success to open channel, and return valid channel id. 69 */ 70 int TransOpenNetWorkingChannel(const char *sessionName, const char *peerNetworkId); 71 72 /** 73 * @brief To close the sepcified proxy channel. 74 * this interface is only called once when the channelId already opened. 75 * @see {@link TransOpenNetWorkingChannel} 76 * @param[in] channelId indicates the opened ChannelId. 77 * @return <b>SOFTBUS_MALLOC_ERR</b> Failed to allocate space for global variable of information. 78 * @return <b>SOFTBUS_TRANS_PROXY_DEL_CHANNELID_INVALID</b> Failed to delete channel info. 79 * @return <b>SOFTBUS_OK</b> Success to close this proxy channel, returns other internal error codes otherwise. 80 */ 81 int TransCloseNetWorkingChannel(int32_t channelId); 82 83 /** 84 * @brief send message through the sepcified channel. 85 * this interface is current only called once when the sync device info. 86 * @see {@link TransOpenNetWorkingChannel} 87 * @param[in] channelId indicates the opened ChannelId. 88 * @param[in] data indicates the pointer to message data. 89 * @param[in] dataLen indicates the message data of len. 90 * @param[in] priority indicates the message send priority. 91 * @return <b>SOFTBUS_MALLOC_ERR</b> Failed to allocate space for global variable of information. 92 * @return <b>SOFTBUS_TRANS_PROXY_SEND_CHANNELID_INVALID</b> Failed to get channel info. 93 * @return <b>SOFTBUS_TRANS_PROXY_CHANNLE_STATUS_INVALID</b> the channel status is abnormal. 94 * @return <b>SOFTBUS_TRANS_PROXY_PACKMSG_ERR</b> Failed to packaged the message data. 95 * @return <b>SOFTBUS_OK</b> Success to send message to the channel, returns other internal error codes otherwise. 96 */ 97 int TransSendNetworkingMessage(int32_t channelId, const char *data, uint32_t dataLen, int32_t priority); 98 99 /** 100 * @brief regiester listener to channel listener manager. 101 * this interface is current only called once when the sync info manager. 102 * @see {@link INetworkingListener} 103 * @param[in] listener indicates regiestered function callback. 104 * @return <b>SOFTBUS_ERR</b> Failed to add listener to channel listener manager. 105 * @return <b>SOFTBUS_OK</b> Success to register channel listener, return other internal errorcodes otherwise. 106 */ 107 int TransRegisterNetworkingChannelListener(const INetworkingListener *listener); 108 109 #ifdef __cplusplus 110 #if __cplusplus 111 } 112 #endif 113 #endif 114 #endif 115