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