isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 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 "base/mac/scoped_nsobject.h" |
| 16 | #include "base/macros.h" |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 17 | #include "device/bluetooth/bluetooth_channel_mac.h" |
| 18 | |
| 19 | @class BluetoothRfcommChannelDelegate; |
| 20 | |
| 21 | namespace device { |
| 22 | |
| 23 | class BluetoothRfcommChannelMac : public BluetoothChannelMac { |
| 24 | public: |
| 25 | // Creates a new RFCOMM channel wrapper with the given |socket| and native |
| 26 | // |channel|. |
| 27 | // NOTE: The |channel| is expected to already be retained. |
| 28 | BluetoothRfcommChannelMac(BluetoothSocketMac* socket, |
| 29 | IOBluetoothRFCOMMChannel* channel); |
Peter Boström | ec0e766 | 2021-09-23 21:20:57 | [diff] [blame^] | 30 | |
| 31 | BluetoothRfcommChannelMac(const BluetoothRfcommChannelMac&) = delete; |
| 32 | BluetoothRfcommChannelMac& operator=(const BluetoothRfcommChannelMac&) = |
| 33 | delete; |
| 34 | |
dcheng | b5aaf40 | 2014-10-22 23:07:52 | [diff] [blame] | 35 | ~BluetoothRfcommChannelMac() override; |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 36 | |
| 37 | // Opens a new RFCOMM channel with Channel ID |channel_id| to the target |
| 38 | // |device|. Returns the opened channel and sets |status| to kIOReturnSuccess |
| 39 | // if the open process was successfully started (or if an existing RFCOMM |
| 40 | // channel was found). Otherwise, sets |status| to an error status. |
thakis | 08c9d69b0 | 2016-04-11 04:37:25 | [diff] [blame] | 41 | static std::unique_ptr<BluetoothRfcommChannelMac> OpenAsync( |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 42 | BluetoothSocketMac* socket, |
| 43 | IOBluetoothDevice* device, |
isherman@chromium.org | edc0de3 | 2014-06-14 19:31:48 | [diff] [blame] | 44 | BluetoothRFCOMMChannelID channel_id, |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 45 | IOReturn* status); |
| 46 | |
| 47 | // BluetoothChannelMac: |
dcheng | b5aaf40 | 2014-10-22 23:07:52 | [diff] [blame] | 48 | void SetSocket(BluetoothSocketMac* socket) override; |
| 49 | IOBluetoothDevice* GetDevice() override; |
| 50 | uint16_t GetOutgoingMTU() override; |
| 51 | IOReturn WriteAsync(void* data, uint16_t length, void* refcon) override; |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 52 | |
| 53 | void OnChannelOpenComplete(IOBluetoothRFCOMMChannel* channel, |
| 54 | IOReturn status); |
| 55 | void OnChannelClosed(IOBluetoothRFCOMMChannel* channel); |
| 56 | void OnChannelDataReceived(IOBluetoothRFCOMMChannel* channel, |
| 57 | void* data, |
| 58 | size_t length); |
| 59 | void OnChannelWriteComplete(IOBluetoothRFCOMMChannel* channel, |
| 60 | void* refcon, |
| 61 | IOReturn status); |
| 62 | |
| 63 | private: |
| 64 | // The wrapped native RFCOMM channel. |
| 65 | base::scoped_nsobject<IOBluetoothRFCOMMChannel> channel_; |
isherman@chromium.org | edc0de3 | 2014-06-14 19:31:48 | [diff] [blame] | 66 | |
| 67 | // The delegate for the native channel. |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 68 | base::scoped_nsobject<BluetoothRfcommChannelDelegate> delegate_; |
isherman@chromium.org | 8696f57 | 2014-06-12 12:59:20 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace device |
| 72 | |
| 73 | #endif // DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_ |