1 /* 2 * Copyright (C) 2021-2022 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 OBEX_TRANSPORT_H 17 #define OBEX_TRANSPORT_H 18 19 #include <memory> 20 #include "btstack.h" 21 #include "obex_packet.h" 22 #include "obex_types.h" 23 #include "packet.h" 24 #include "raw_address.h" 25 #include "transport/transport_def.h" 26 27 namespace OHOS { 28 namespace bluetooth { 29 class ObexTransport; 30 class ObexIncomingConnect; 31 class ObexTransportObserver { 32 public: ~ObexTransportObserver()33 virtual ~ObexTransportObserver(){}; 34 virtual void OnTransportConnectIncoming(ObexIncomingConnect &incomingConnect); 35 virtual void OnTransportIncomingDisconnected(const std::string &btAddr); 36 virtual void OnTransportConnected(ObexTransport &transport) = 0; 37 virtual void OnTransportDisconnected(ObexTransport &transport) = 0; 38 virtual void OnTransportDataBusy(ObexTransport &transport, uint8_t isBusy) = 0; 39 virtual void OnTransportDataAvailable(ObexTransport &transport, ObexPacket &obexPacket) = 0; 40 virtual void OnTransportError(ObexTransport &transport, int errCd) = 0; 41 }; 42 class ObexTransport { 43 public: ~ObexTransport()44 virtual ~ObexTransport(){}; 45 virtual bool Write(Packet &pkt) = 0; 46 // the maximum allowed OBEX packet that can be send over the transport 47 virtual int GetMaxSendPacketSize() = 0; 48 // the maximum allowed OBEX packet that can be received over the transport 49 virtual int GetMaxReceivePacketSize() = 0; 50 // This function is used to get the Bluetooth address of the peer of the connected channel 51 virtual const RawAddress &GetRemoteAddress() = 0; 52 // is transport Connected 53 virtual bool IsConnected() = 0; 54 // get transport key 55 virtual const std::string &GetTransportKey() = 0; 56 }; 57 58 // ObexClientTransport 59 class ObexClientTransport : public ObexTransport { 60 public: ObexClientTransport(ObexTransportObserver & observer)61 ObexClientTransport(ObexTransportObserver &observer) : observer_(observer) 62 {} ~ObexClientTransport()63 ~ObexClientTransport() override{}; 64 virtual int Connect() = 0; 65 virtual int Disconnect() = 0; 66 67 protected: 68 ObexTransportObserver &observer_; 69 BT_DISALLOW_COPY_AND_ASSIGN(ObexClientTransport); 70 }; 71 // ObexIncomingConnect 72 class ObexIncomingConnect { 73 public: ~ObexIncomingConnect()74 virtual ~ObexIncomingConnect(){}; 75 // accept the connection request 76 virtual int AcceptConnection() = 0; 77 // reject the connection request 78 virtual int RejectConnection() = 0; 79 // This function is used to get the Bluetooth address of the peer of the connected channel 80 virtual const RawAddress &GetRemoteAddress() = 0; 81 // Port 82 virtual int GetPort() = 0; 83 }; 84 // ObexServerTransport 85 class ObexServerTransport { 86 public: 87 ObexServerTransport(ObexTransportObserver &observer); 88 virtual ~ObexServerTransport() = default; 89 virtual int Listen() = 0; 90 virtual int Disconnect() = 0; 91 virtual int Disconnect(ObexTransport &subTransport) = 0; 92 // Server accept the connection request 93 virtual int AcceptConnection(ObexIncomingConnect &incomingConnect) = 0; 94 // Server reject the connection request 95 virtual int RejectConnection(ObexIncomingConnect &incomingConnect) = 0; 96 // get transport key 97 virtual const std::string &GetTransportKey() = 0; 98 99 protected: 100 ObexTransportObserver &observer_; 101 BT_DISALLOW_COPY_AND_ASSIGN(ObexServerTransport); 102 }; 103 } // namespace bluetooth 104 } // namespace OHOS 105 #endif // OBEX_TRANSPORT_H 106