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_PROXYCHANNEL_PIPELINE_H
17 #define SOFTBUS_PROXYCHANNEL_PIPELINE_H
18 
19 #include "stdbool.h"
20 #include "stdint.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 typedef struct {
27     void (*onDataReceived)(int32_t channelId, const char *data, uint32_t len);
28     void (*onDisconnected)(int32_t channelId);
29 } ITransProxyPipelineListener;
30 
31 typedef struct {
32     void (*onChannelOpened)(int32_t requestId, int32_t channelId);
33     void (*onChannelOpenFailed)(int32_t requestId, int32_t reason);
34 } ITransProxyPipelineCallback;
35 
36 typedef enum {
37     MSG_TYPE_INVALID = 0,
38 
39     MSG_TYPE_P2P_NEGO = 0xABADBEEF,
40     MSG_TYPE_IP_PORT_EXCHANGE,
41 
42     MSG_TYPE_CNT = 2,
43 } TransProxyPipelineMsgType;
44 
45 typedef struct {
46     bool bleDirect;
47 } TransProxyPipelineChannelOption;
48 int32_t TransProxyPipelineGenRequestId(void);
49 int32_t TransProxyPipelineRegisterListener(TransProxyPipelineMsgType type, const ITransProxyPipelineListener *listener);
50 int32_t TransProxyPipelineOpenChannel(int32_t requestId, const char *networkId,
51     const TransProxyPipelineChannelOption *option, const ITransProxyPipelineCallback *callback);
52 int32_t TransProxyPipelineSendMessage(
53     int32_t channelId, const uint8_t *data, uint32_t dataLen, TransProxyPipelineMsgType type);
54 int32_t TransProxyPipelineGetChannelIdByNetworkId(const char *networkId);
55 int32_t TransProxyPipelineGetUuidByChannelId(int32_t channelId, char *uuid, uint32_t uuidLen);
56 int32_t TransProxyPipelineCloseChannel(int32_t channelId);
57 int32_t TransProxyPipelineCloseChannelDelay(int32_t channelId);
58 int32_t TransProxyPipelineInit(void);
59 int32_t TransProxyReuseByChannelId(int32_t channelId);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif
66