Home | History | Annotate | Download | only in bluetooth
      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_CHANNEL_MAC_H_
      6 #define DEVICE_BLUETOOTH_BLUETOOTH_CHANNEL_MAC_H_
      7 
      8 #import <IOKit/IOReturn.h>
      9 
     10 #include <string>
     11 
     12 #include "base/macros.h"
     13 
     14 @class IOBluetoothDevice;
     15 
     16 namespace device {
     17 
     18 class BluetoothSocketMac;
     19 
     20 // Wraps a native RFCOMM or L2CAP channel.
     21 class BluetoothChannelMac {
     22  public:
     23   BluetoothChannelMac();
     24   virtual ~BluetoothChannelMac();
     25 
     26   // Sets the channel's owning socket to |socket|. Should only be called if the
     27   // socket was previously unset. Note: This can synchronously call back into
     28   // socket->OnChannelOpenComplete().
     29   virtual void SetSocket(BluetoothSocketMac* socket);
     30 
     31   // Returns the Bluetooth address for the device associated with |this|
     32   // channel.
     33   std::string GetDeviceAddress();
     34 
     35   // Returns the Bluetooth device associated with |this| channel.
     36   virtual IOBluetoothDevice* GetDevice() = 0;
     37 
     38   // Returns the outgoing MTU (maximum transmission unit) for the channel.
     39   virtual uint16_t GetOutgoingMTU() = 0;
     40 
     41   // Writes |data| of length |length| bytes into the channel. The |refcon| is a
     42   // user-supplied value that gets passed to the write callback.
     43   // Returns kIOReturnSuccess if the data was buffered successfully.
     44   // If the return value is an error condition none of the data was sent.
     45   // The number of bytes to be sent must not exceed the channel MTU.
     46   //
     47   // Once the data has been successfully passed to the hardware to be
     48   // transmitted, the socket's method OnChannelWriteComplete() will be called
     49   // with the |refcon| that was passed to this method.
     50   virtual IOReturn WriteAsync(void* data, uint16_t length, void* refcon) = 0;
     51 
     52  protected:
     53   BluetoothSocketMac* socket() { return socket_; }
     54 
     55  private:
     56   // The socket that owns |this|.
     57   BluetoothSocketMac* socket_;
     58 
     59   DISALLOW_COPY_AND_ASSIGN(BluetoothChannelMac);
     60 };
     61 
     62 }  // namespace device
     63 
     64 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_CHANNEL_MAC_H_
     65