• 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_CONN_MANAGER_H
17 #define SOFTBUS_CONN_MANAGER_H
18 
19 #include "softbus_conn_interface.h"
20 
21 #define CONNECT_TYPE_SHIFT 16
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 typedef struct {
30     /**
31      * @brief To connect the device, you can use the br/ble/tcp type to initiate a connection to the remote end.
32      * The existing connection can be reused. If there is no physical connection, the logical connection will be made.
33      * @see {@link TcpConnectDevice} or {@link ConnectDevice} or {@link BleConnectDevice}.
34      * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}.
35      * @param[in] requestId Request ID.
36      * @param[in] result Indicates a pointer to the connection request. For details, see {@link ConnectResult}.
37      * @return <b>SOFTBUS_OK</b> if the connection to the device is successfully.
38      */
39     int32_t (*ConnectDevice)(const ConnectOption *option, uint32_t requestId, const ConnectResult *result);
40 
41     /**
42      * @brief Send data to the peer. Enable br/ble/tcp to send data.
43      * @see {@link TcpPostBytes} or {@link PostBytes} or {@link BlePostBytes}.
44      * @param[in] connectionId Connection ID.
45      * @param[in] data Connection message content.
46      * @param[in] len Data length.
47      * @param[in] pid Identification ID.
48      * @param[in] flag Message send flag.
49      * @return <b>SOFTBUS_OK</b> if sending by byte is successfully.
50      */
51     int32_t (*PostBytes)(uint32_t connectionId, const char *data, int32_t len, int32_t pid, int32_t flag);
52 
53     /**
54      * @brief To disconnect the device, use the br/ble/tcp type of disconnect device logically to disconnect
55      * the physical connection when the logical connection reference is zero.
56      * @see {@link TcpDisconnectDevice} or {@link DisconnectDevice} or {@link BleDisconnectDevice}.
57      * @param[in] connectionId Connection ID.
58      * @return <b>SOFTBUS_OK</b> if the device disconnected is successfully.
59      */
60     int32_t (*DisconnectDevice)(uint32_t connectionId);
61 
62     /**
63      * @brief Disconnects all connected devices, and disconnects logical and physical connections on
64      * specified devices of type br/ble/tcp.
65      * @see {@link TcpDisconnectDeviceNow} or {@link DisconnectDeviceNow} or {@link BleDisconnectDeviceNow}.
66      * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}.
67      * @return <b>SOFTBUS_OK</b> If the device is successfully disconnected through the address.
68      */
69     int32_t (*DisconnectDeviceNow)(const ConnectOption *option);
70 
71     /**
72      * @brief Get an internal object of type br/ble/tcp based on the connection id.
73      * @see {@link TcpGetConnectionInfo} or {@link GetConnectionInfo} or {@link BleGetConnectionInfo}.
74      * @param[in] connectionId Connection ID.
75      * @param[out] info Indicates a pointer to the connection information. For details, see {@link ConnectionInfo}.
76      * @return <b>SOFTBUS_OK</b> if get the connection information is successfully.
77      */
78     int32_t (*GetConnectionInfo)(uint32_t connectionId, ConnectionInfo *info);
79 
80     /**
81      * @brief Start the local monitoring service and listen for br/ble/tcp peer connection events.
82      * @see {@link TcpStartLocalListening} or {@link StartLocalListening} or {@link BleStartLocalListening}.
83      * @param[in] info Indicates a pointer to local listener information.
84      * For details, see {@link LocalListenerInfo}.
85      * @return <b>SOFTBUS_OK</b> if local listeners start successfully.
86      */
87     int32_t (*StartLocalListening)(const LocalListenerInfo *info);
88 
89     /**
90      * @brief Stop the local monitoring service and stop monitoring br/ble/tcp peer connection events.
91      * @see {@link TcpStopLocalListening} or {@link StopLocalListening} or {@link BleStopLocalListening}.
92      * @param[in] info Indicates a pointer to local listener information. For details, see {@link LocalListenerInfo}.
93      * @return <b>SOFTBUS_OK</b> if local listeners start successfully.
94      */
95     int32_t (*StopLocalListening)(const LocalListenerInfo *info);
96     bool (*CheckActiveConnection)(const ConnectOption *info);
97     int32_t (*UpdateConnection)(uint32_t connectionId, UpdateOption *option);
98 } ConnectFuncInterface;
99 
100 #define MAGIC_NUMBER  0xBABEFACE
101 typedef struct {
102     int32_t magic;
103     int32_t module;
104     int64_t seq;
105     int32_t flag;
106     uint32_t len;
107 } __attribute__((packed))ConnPktHead;
108 
109 #ifdef __cplusplus
110 #if __cplusplus
111 }
112 #endif /* __cplusplus */
113 #endif /* __cplusplus */
114 
115 #endif
116