[go: nahoru, domu]

blob: 5f98f27a0d2f8b8d6995f2cdf1acbb7308d267ff [file] [log] [blame]
isherman@chromium.org8696f572014-06-12 12:59:201// 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>
10
11#include "base/mac/scoped_nsobject.h"
12#include "base/macros.h"
13#include "base/memory/scoped_ptr.h"
14#include "device/bluetooth/bluetooth_channel_mac.h"
15
16@class BluetoothRfcommChannelDelegate;
17
18namespace device {
19
20class BluetoothRfcommChannelMac : public BluetoothChannelMac {
21 public:
22 // Creates a new RFCOMM channel wrapper with the given |socket| and native
23 // |channel|.
24 // NOTE: The |channel| is expected to already be retained.
25 BluetoothRfcommChannelMac(BluetoothSocketMac* socket,
26 IOBluetoothRFCOMMChannel* channel);
dchengb5aaf402014-10-22 23:07:5227 ~BluetoothRfcommChannelMac() override;
isherman@chromium.org8696f572014-06-12 12:59:2028
29 // Opens a new RFCOMM channel with Channel ID |channel_id| to the target
30 // |device|. Returns the opened channel and sets |status| to kIOReturnSuccess
31 // if the open process was successfully started (or if an existing RFCOMM
32 // channel was found). Otherwise, sets |status| to an error status.
33 static scoped_ptr<BluetoothRfcommChannelMac> OpenAsync(
34 BluetoothSocketMac* socket,
35 IOBluetoothDevice* device,
isherman@chromium.orgedc0de32014-06-14 19:31:4836 BluetoothRFCOMMChannelID channel_id,
isherman@chromium.org8696f572014-06-12 12:59:2037 IOReturn* status);
38
39 // BluetoothChannelMac:
dchengb5aaf402014-10-22 23:07:5240 void SetSocket(BluetoothSocketMac* socket) override;
41 IOBluetoothDevice* GetDevice() override;
42 uint16_t GetOutgoingMTU() override;
43 IOReturn WriteAsync(void* data, uint16_t length, void* refcon) override;
isherman@chromium.org8696f572014-06-12 12:59:2044
45 void OnChannelOpenComplete(IOBluetoothRFCOMMChannel* channel,
46 IOReturn status);
47 void OnChannelClosed(IOBluetoothRFCOMMChannel* channel);
48 void OnChannelDataReceived(IOBluetoothRFCOMMChannel* channel,
49 void* data,
50 size_t length);
51 void OnChannelWriteComplete(IOBluetoothRFCOMMChannel* channel,
52 void* refcon,
53 IOReturn status);
54
55 private:
56 // The wrapped native RFCOMM channel.
57 base::scoped_nsobject<IOBluetoothRFCOMMChannel> channel_;
isherman@chromium.orgedc0de32014-06-14 19:31:4858
59 // The delegate for the native channel.
isherman@chromium.org8696f572014-06-12 12:59:2060 base::scoped_nsobject<BluetoothRfcommChannelDelegate> delegate_;
61
62 DISALLOW_COPY_AND_ASSIGN(BluetoothRfcommChannelMac);
63};
64
65} // namespace device
66
67#endif // DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_