[go: nahoru, domu]

blob: 8d613b05cd61022265759e7d5ce29822b685a7b6 [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>
avi176e2692015-12-22 19:26:5210#include <stddef.h>
11#include <stdint.h>
isherman@chromium.org8696f572014-06-12 12:59:2012
13#include "base/mac/scoped_nsobject.h"
14#include "base/macros.h"
15#include "base/memory/scoped_ptr.h"
16#include "device/bluetooth/bluetooth_channel_mac.h"
17
18@class BluetoothRfcommChannelDelegate;
19
20namespace device {
21
22class BluetoothRfcommChannelMac : public BluetoothChannelMac {
23 public:
24 // Creates a new RFCOMM channel wrapper with the given |socket| and native
25 // |channel|.
26 // NOTE: The |channel| is expected to already be retained.
27 BluetoothRfcommChannelMac(BluetoothSocketMac* socket,
28 IOBluetoothRFCOMMChannel* channel);
dchengb5aaf402014-10-22 23:07:5229 ~BluetoothRfcommChannelMac() override;
isherman@chromium.org8696f572014-06-12 12:59:2030
31 // Opens a new RFCOMM channel with Channel ID |channel_id| to the target
32 // |device|. Returns the opened channel and sets |status| to kIOReturnSuccess
33 // if the open process was successfully started (or if an existing RFCOMM
34 // channel was found). Otherwise, sets |status| to an error status.
35 static scoped_ptr<BluetoothRfcommChannelMac> OpenAsync(
36 BluetoothSocketMac* socket,
37 IOBluetoothDevice* device,
isherman@chromium.orgedc0de32014-06-14 19:31:4838 BluetoothRFCOMMChannelID channel_id,
isherman@chromium.org8696f572014-06-12 12:59:2039 IOReturn* status);
40
41 // BluetoothChannelMac:
dchengb5aaf402014-10-22 23:07:5242 void SetSocket(BluetoothSocketMac* socket) override;
43 IOBluetoothDevice* GetDevice() override;
44 uint16_t GetOutgoingMTU() override;
45 IOReturn WriteAsync(void* data, uint16_t length, void* refcon) override;
isherman@chromium.org8696f572014-06-12 12:59:2046
47 void OnChannelOpenComplete(IOBluetoothRFCOMMChannel* channel,
48 IOReturn status);
49 void OnChannelClosed(IOBluetoothRFCOMMChannel* channel);
50 void OnChannelDataReceived(IOBluetoothRFCOMMChannel* channel,
51 void* data,
52 size_t length);
53 void OnChannelWriteComplete(IOBluetoothRFCOMMChannel* channel,
54 void* refcon,
55 IOReturn status);
56
57 private:
58 // The wrapped native RFCOMM channel.
59 base::scoped_nsobject<IOBluetoothRFCOMMChannel> channel_;
isherman@chromium.orgedc0de32014-06-14 19:31:4860
61 // The delegate for the native channel.
isherman@chromium.org8696f572014-06-12 12:59:2062 base::scoped_nsobject<BluetoothRfcommChannelDelegate> delegate_;
63
64 DISALLOW_COPY_AND_ASSIGN(BluetoothRfcommChannelMac);
65};
66
67} // namespace device
68
69#endif // DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_