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