Avi Drissman | 0db8484 | 2022-09-13 19:47:04 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_ |
| 6 | #define DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_ |
| 7 | |
| 8 | #import <IOBluetooth/IOBluetooth.h> |
| 9 | #import <IOKit/IOReturn.h> |
avi | 176e269 | 2015-12-22 19:26:52 | [diff] [blame] | 10 | #include <stddef.h> |
| 11 | #include <stdint.h> |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 12 | |
thakis | 08c9d69b0 | 2016-04-11 04:37:25 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 15 | #include "device/bluetooth/bluetooth_channel_mac.h" |
| 16 | |
| 17 | @class BluetoothRfcommChannelDelegate; |
| 18 | |
| 19 | namespace device { |
| 20 | |
| 21 | class BluetoothRfcommChannelMac : public BluetoothChannelMac { |
| 22 | public: |
| 23 | // Creates a new RFCOMM channel wrapper with the given |socket| and native |
| 24 | // |channel|. |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 25 | BluetoothRfcommChannelMac(BluetoothSocketMac* socket, |
| 26 | IOBluetoothRFCOMMChannel* channel); |
Peter Boström | ec0e766 | 2021-09-23 21:20:57 | [diff] [blame] | 27 | |
| 28 | BluetoothRfcommChannelMac(const BluetoothRfcommChannelMac&) = delete; |
| 29 | BluetoothRfcommChannelMac& operator=(const BluetoothRfcommChannelMac&) = |
| 30 | delete; |
| 31 | |
dcheng | b5aaf40 | 2014-10-22 23:07:52 | [diff] [blame] | 32 | ~BluetoothRfcommChannelMac() override; |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 33 | |
| 34 | // Opens a new RFCOMM channel with Channel ID |channel_id| to the target |
| 35 | // |device|. Returns the opened channel and sets |status| to kIOReturnSuccess |
| 36 | // if the open process was successfully started (or if an existing RFCOMM |
| 37 | // channel was found). Otherwise, sets |status| to an error status. |
thakis | 08c9d69b0 | 2016-04-11 04:37:25 | [diff] [blame] | 38 | static std::unique_ptr<BluetoothRfcommChannelMac> OpenAsync( |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 39 | BluetoothSocketMac* socket, |
| 40 | IOBluetoothDevice* device, |
isherman@chromium.org | edc0de3 | 2014-06-14 19:31:48 | [diff] [blame] | 41 | BluetoothRFCOMMChannelID channel_id, |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 42 | IOReturn* status); |
| 43 | |
| 44 | // BluetoothChannelMac: |
dcheng | b5aaf40 | 2014-10-22 23:07:52 | [diff] [blame] | 45 | void SetSocket(BluetoothSocketMac* socket) override; |
| 46 | IOBluetoothDevice* GetDevice() override; |
| 47 | uint16_t GetOutgoingMTU() override; |
| 48 | IOReturn WriteAsync(void* data, uint16_t length, void* refcon) override; |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 49 | |
| 50 | void OnChannelOpenComplete(IOBluetoothRFCOMMChannel* channel, |
| 51 | IOReturn status); |
| 52 | void OnChannelClosed(IOBluetoothRFCOMMChannel* channel); |
| 53 | void OnChannelDataReceived(IOBluetoothRFCOMMChannel* channel, |
| 54 | void* data, |
| 55 | size_t length); |
| 56 | void OnChannelWriteComplete(IOBluetoothRFCOMMChannel* channel, |
| 57 | void* refcon, |
| 58 | IOReturn status); |
| 59 | |
| 60 | private: |
| 61 | // The wrapped native RFCOMM channel. |
Avi Drissman | 36cfbd8d | 2023-06-13 19:37:25 | [diff] [blame] | 62 | IOBluetoothRFCOMMChannel* __strong channel_; |
isherman@chromium.org | edc0de3 | 2014-06-14 19:31:48 | [diff] [blame] | 63 | |
| 64 | // The delegate for the native channel. |
Avi Drissman | 36cfbd8d | 2023-06-13 19:37:25 | [diff] [blame] | 65 | BluetoothRfcommChannelDelegate* __strong delegate_; |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace device |
| 69 | |
| 70 | #endif // DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_ |