summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_channel_mac.h
blob: 588a45c555817c79aaa628c048bec8e3a6ed7b59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef DEVICE_BLUETOOTH_BLUETOOTH_CHANNEL_MAC_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_CHANNEL_MAC_H_

#import <IOKit/IOReturn.h>

#include <string>

#include "base/macros.h"

@class IOBluetoothDevice;

namespace device {

class BluetoothSocketMac;

// Wraps a native RFCOMM or L2CAP channel.
class BluetoothChannelMac {
 public:
  BluetoothChannelMac();
  virtual ~BluetoothChannelMac();

  // Sets the channel's owning socket to |socket|. Should only be called if the
  // socket was previously unset. Note: This can synchronously call back into
  // socket->OnChannelOpenComplete().
  virtual void SetSocket(BluetoothSocketMac* socket);

  // Returns the Bluetooth address for the device associated with |this|
  // channel.
  std::string GetDeviceAddress();

  // Returns the Bluetooth device associated with |this| channel.
  virtual IOBluetoothDevice* GetDevice() = 0;

  // Returns the outgoing MTU (maximum transmission unit) for the channel.
  virtual uint16_t GetOutgoingMTU() = 0;

  // Writes |data| of length |length| bytes into the channel. The |refcon| is a
  // user-supplied value that gets passed to the write callback.
  // Returns kIOReturnSuccess if the data was buffered successfully.
  // If the return value is an error condition none of the data was sent.
  // The number of bytes to be sent must not exceed the channel MTU.
  //
  // Once the data has been successfully passed to the hardware to be
  // transmitted, the socket's method OnChannelWriteComplete() will be called
  // with the |refcon| that was passed to this method.
  virtual IOReturn WriteAsync(void* data, uint16_t length, void* refcon) = 0;

 protected:
  BluetoothSocketMac* socket() { return socket_; }

 private:
  // The socket that owns |this|.
  BluetoothSocketMac* socket_;

  DISALLOW_COPY_AND_ASSIGN(BluetoothChannelMac);
};

}  // namespace device

#endif  // DEVICE_BLUETOOTH_BLUETOOTH_CHANNEL_MAC_H_