[go: nahoru, domu]

blob: 35451c7bff3f84c64fb9b1ee2c465f4f62c9c525 [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
thakis08c9d69b02016-04-11 04:37:2513#include <memory>
14
isherman@chromium.org8696f572014-06-12 12:59:2015#include "base/mac/scoped_nsobject.h"
16#include "base/macros.h"
isherman@chromium.org8696f572014-06-12 12:59:2017#include "device/bluetooth/bluetooth_channel_mac.h"
18
19@class BluetoothRfcommChannelDelegate;
20
21namespace device {
22
23class BluetoothRfcommChannelMac : public BluetoothChannelMac {
24 public:
25 // Creates a new RFCOMM channel wrapper with the given |socket| and native
26 // |channel|.
27 // NOTE: The |channel| is expected to already be retained.
28 BluetoothRfcommChannelMac(BluetoothSocketMac* socket,
29 IOBluetoothRFCOMMChannel* channel);
Peter Boströmec0e7662021-09-23 21:20:5730
31 BluetoothRfcommChannelMac(const BluetoothRfcommChannelMac&) = delete;
32 BluetoothRfcommChannelMac& operator=(const BluetoothRfcommChannelMac&) =
33 delete;
34
dchengb5aaf402014-10-22 23:07:5235 ~BluetoothRfcommChannelMac() override;
isherman@chromium.org8696f572014-06-12 12:59:2036
37 // Opens a new RFCOMM channel with Channel ID |channel_id| to the target
38 // |device|. Returns the opened channel and sets |status| to kIOReturnSuccess
39 // if the open process was successfully started (or if an existing RFCOMM
40 // channel was found). Otherwise, sets |status| to an error status.
thakis08c9d69b02016-04-11 04:37:2541 static std::unique_ptr<BluetoothRfcommChannelMac> OpenAsync(
isherman@chromium.org8696f572014-06-12 12:59:2042 BluetoothSocketMac* socket,
43 IOBluetoothDevice* device,
isherman@chromium.orgedc0de32014-06-14 19:31:4844 BluetoothRFCOMMChannelID channel_id,
isherman@chromium.org8696f572014-06-12 12:59:2045 IOReturn* status);
46
47 // BluetoothChannelMac:
dchengb5aaf402014-10-22 23:07:5248 void SetSocket(BluetoothSocketMac* socket) override;
49 IOBluetoothDevice* GetDevice() override;
50 uint16_t GetOutgoingMTU() override;
51 IOReturn WriteAsync(void* data, uint16_t length, void* refcon) override;
isherman@chromium.org8696f572014-06-12 12:59:2052
53 void OnChannelOpenComplete(IOBluetoothRFCOMMChannel* channel,
54 IOReturn status);
55 void OnChannelClosed(IOBluetoothRFCOMMChannel* channel);
56 void OnChannelDataReceived(IOBluetoothRFCOMMChannel* channel,
57 void* data,
58 size_t length);
59 void OnChannelWriteComplete(IOBluetoothRFCOMMChannel* channel,
60 void* refcon,
61 IOReturn status);
62
63 private:
64 // The wrapped native RFCOMM channel.
65 base::scoped_nsobject<IOBluetoothRFCOMMChannel> channel_;
isherman@chromium.orgedc0de32014-06-14 19:31:4866
67 // The delegate for the native channel.
isherman@chromium.org8696f572014-06-12 12:59:2068 base::scoped_nsobject<BluetoothRfcommChannelDelegate> delegate_;
isherman@chromium.org8696f572014-06-12 12:59:2069};
70
71} // namespace device
72
73#endif // DEVICE_BLUETOOTH_BLUETOOTH_RFCOMM_CHANNEL_MAC_H_