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 "trans_inner_session.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_OK</b> the processing success after the callback; returns an error code otherwise.. 39 */ 40 int (*onChannelOpened)(int32_t channelId, const char *uuid, unsigned char isServer); 41 /** 42 * @brief callback after open channel failed. 43 * @see {@link TransRegisterNetworkingChannelListener} 44 * @param[in] channelId indicates the opening channelId. 45 * @param[in] uuid indicates the pointer to the uuid. 46 */ 47 void (*onChannelOpenFailed)(int32_t channelId, const char *uuid); 48 /** 49 * @brief callback after closed channel. 50 * @see {@link TransRegisterNetworkingChannelListener} 51 * @param[in] channelId indicates the opening channelId. 52 */ 53 void (*onChannelClosed)(int32_t channelId); 54 /** 55 * @brief callback after receive message. 56 * @see {@link TransRegisterNetworkingChannelListener} 57 * @param[in] channelId indicates the opened channelId. 58 * @param[in] data indicates the pointer to the message data. 59 * @param[in] len indicates the message data of len. 60 */ 61 void (*onMessageReceived)(int32_t channelId, const char *data, uint32_t len); 62 } INetworkingListener; 63 64 /** 65 * @brief To open a proxy channel to the specified device. 66 * @see {@link TransCloseNetWorkingChannel} 67 * @param[in] sessionName indicates the pointer to the package name. 68 * @param[in] peerNetworkId indicates the pointer to the peer network id. 69 * @param[in] preferred indicates the pointer to preferred link list, allow null 70 * @return <b>INVALID_CHANNEL_ID</b> Failed to open channel, return invalid channel id. 71 * @return <b>NewChannelId</b> Success to open channel, and return valid channel id. 72 */ 73 int TransOpenNetWorkingChannel( 74 const char *sessionName, const char *peerNetworkId, const LanePreferredLinkList *preferred); 75 76 /** 77 * @brief To close the sepcified proxy channel. 78 * this interface is only called once when the channelId already opened. 79 * @see {@link TransOpenNetWorkingChannel} 80 * @param[in] channelId indicates the opened ChannelId. 81 * @return <b>SOFTBUS_MALLOC_ERR</b> Failed to allocate space for global variable of information. 82 * @return <b>SOFTBUS_OK</b> Success to close this proxy channel, returns other internal error codes otherwise. 83 */ 84 int TransCloseNetWorkingChannel(int32_t channelId); 85 86 /** 87 * @brief send message through the sepcified channel. 88 * this interface is current only called once when the sync device info. 89 * @see {@link TransOpenNetWorkingChannel} 90 * @param[in] channelId indicates the opened ChannelId. 91 * @param[in] data indicates the pointer to message data. 92 * @param[in] dataLen indicates the message data of len. 93 * @param[in] priority indicates the message send priority. 94 * @return <b>SOFTBUS_MALLOC_ERR</b> Failed to allocate space for global variable of information. 95 * @return <b>SOFTBUS_TRANS_PROXY_CHANNLE_STATUS_INVALID</b> the channel status is abnormal. 96 * @return <b>SOFTBUS_TRANS_PROXY_PACKMSG_ERR</b> Failed to packaged the message data. 97 * @return <b>SOFTBUS_OK</b> Success to send message to the channel, returns other internal error codes otherwise. 98 */ 99 int TransSendNetworkingMessage(int32_t channelId, const char *data, uint32_t dataLen, int32_t priority); 100 101 /** 102 * @brief regiester listener to channel listener manager. 103 * this interface is current only called once when the sync info manager. 104 * @see {@link INetworkingListener} 105 * @param[in] listener indicates regiestered function callback. 106 * @return <b>SOFTBUS_OK</b> Success to register channel listener, return other internal errorcodes otherwise. 107 */ 108 int TransRegisterNetworkingChannelListener(const char *sessionName, const INetworkingListener *listener); 109 110 /** 111 * @brief Creates a session server. 112 * @param pkgName Indicates the pointer to the service bundle name. 113 * It is the unique identifier of the upper-layer service. The value cannot be empty or exceed 64 characters. 114 * @param sessionName Indicates the pointer to the session name, which is the unique ID of the session server. 115 * The value cannot be empty or exceed 255 characters. 116 * @param listener Indicates the pointer to the session callback. 117 * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise. 118 */ 119 int32_t TransCreateSessionServerInner( 120 const char *pkgName, const char *sessionName, const ISessionListenerInner *listener); 121 122 /** 123 * @brief To open a bytes channel to the specified device. 124 * @see {@link TransCloseSessionInner} 125 * @param[in] sessionName indicates the pointer to the sessionName name. 126 * @param[in] peerNetworkId indicates the pointer to the peer network id. 127 * @param[in] channelId will return valid channelId. 128 * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise. 129 */ 130 int32_t TransOpenSessionInner(const char *sessionName, const char *peerNetworkId, uint32_t reqId); 131 132 /** 133 * @brief send message through the sepcified channel. 134 * this interface is current only called once when the sync device info. 135 * @see {@link TransOpenSessionInner} 136 * @param[in] channelId indicates the opened ChannelId. 137 * @param[in] data indicates the pointer to message data. 138 * @param[in] dataLen indicates the message data of len. 139 * @return <b>SOFTBUS_OK</b> Success to send message to the channel, returns other internal error codes otherwise. 140 */ 141 int32_t TransSendDataInner(int32_t channelId, const char *data, uint32_t len); 142 143 /** 144 * @brief To close the sepcified bytes channel. 145 * this interface is only called once when the channelId already opened. 146 * @see {@link TransOpenSessionInner} 147 * @param[in] channelId indicates the opened ChannelId. 148 */ 149 void TransCloseSessionInner(int32_t channelId); 150 151 #ifdef __cplusplus 152 #if __cplusplus 153 } 154 #endif 155 #endif 156 #endif 157