bluetooth_rfcomm_channel_mac.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_
  6. #import <IOBluetooth/IOBluetooth.h>
  7. #import <IOKit/IOReturn.h>
  8. #include <stddef.h>
  9. #include <stdint.h>
  10. #include <memory>
  11. #include "base/mac/scoped_nsobject.h"
  12. #include "device/bluetooth/bluetooth_channel_mac.h"
  13. @class BluetoothRfcommChannelDelegate;
  14. namespace device {
  15. class BluetoothRfcommChannelMac : public BluetoothChannelMac {
  16. public:
  17. // Creates a new RFCOMM channel wrapper with the given |socket| and native
  18. // |channel|.
  19. // NOTE: The |channel| is expected to already be retained.
  20. BluetoothRfcommChannelMac(BluetoothSocketMac* socket,
  21. IOBluetoothRFCOMMChannel* channel);
  22. BluetoothRfcommChannelMac(const BluetoothRfcommChannelMac&) = delete;
  23. BluetoothRfcommChannelMac& operator=(const BluetoothRfcommChannelMac&) =
  24. delete;
  25. ~BluetoothRfcommChannelMac() override;
  26. // Opens a new RFCOMM channel with Channel ID |channel_id| to the target
  27. // |device|. Returns the opened channel and sets |status| to kIOReturnSuccess
  28. // if the open process was successfully started (or if an existing RFCOMM
  29. // channel was found). Otherwise, sets |status| to an error status.
  30. static std::unique_ptr<BluetoothRfcommChannelMac> OpenAsync(
  31. BluetoothSocketMac* socket,
  32. IOBluetoothDevice* device,
  33. BluetoothRFCOMMChannelID channel_id,
  34. IOReturn* status);
  35. // BluetoothChannelMac:
  36. void SetSocket(BluetoothSocketMac* socket) override;
  37. IOBluetoothDevice* GetDevice() override;
  38. uint16_t GetOutgoingMTU() override;
  39. IOReturn WriteAsync(void* data, uint16_t length, void* refcon) override;
  40. void OnChannelOpenComplete(IOBluetoothRFCOMMChannel* channel,
  41. IOReturn status);
  42. void OnChannelClosed(IOBluetoothRFCOMMChannel* channel);
  43. void OnChannelDataReceived(IOBluetoothRFCOMMChannel* channel,
  44. void* data,
  45. size_t length);
  46. void OnChannelWriteComplete(IOBluetoothRFCOMMChannel* channel,
  47. void* refcon,
  48. IOReturn status);
  49. private:
  50. // The wrapped native RFCOMM channel.
  51. base::scoped_nsobject<IOBluetoothRFCOMMChannel> channel_;
  52. // The delegate for the native channel.
  53. base::scoped_nsobject<BluetoothRfcommChannelDelegate> delegate_;
  54. };
  55. } // namespace device
  56. #endif // DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_