1 // Copyright 2013 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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_MAC_H_
8 #import <IOBluetooth/IOBluetooth.h>
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/sequenced_task_runner.h"
17 #include "device/bluetooth/bluetooth_profile.h"
18 #include "device/bluetooth/bluetooth_socket.h"
19 #include "device/bluetooth/bluetooth_uuid.h"
21 @
class RFCOMMConnectionListener
;
22 @
class IOBluetoothDevice
;
23 @
class IOBluetoothRFCOMMChannel
;
27 class BluetoothProfileMac
: public BluetoothProfile
{
29 // BluetoothProfile override.
30 virtual void Unregister() OVERRIDE
;
31 virtual void SetConnectionCallback(
32 const ConnectionCallback
& callback
) OVERRIDE
;
34 // Makes an outgoing connection to |device|, calling |success_callback| on
35 // success or |error_callback| on error. If successful, this method also calls
36 // |connection_callback_| before calling |success_callback|.
37 void Connect(IOBluetoothDevice
* device
,
38 const base::Closure
& success_callback
,
39 const BluetoothSocket::ErrorCompletionCallback
& error_callback
);
41 // Callback that is invoked when the OS completes an SDP query.
42 // |status| is the returned status from the SDP query. The remaining
43 // parameters are those from |Connect()|.
44 void OnSDPQueryComplete(
46 IOBluetoothDevice
* device
,
47 const ConnectionCallback
& connection_callback
,
48 const base::Closure
& success_callback
,
49 const BluetoothSocket::ErrorCompletionCallback
& error_callback
);
51 // Callback that is invoked when the OS detects a new incoming RFCOMM channel
52 // connection. |rfcomm_channel| is the newly opened channel.
53 void OnRFCOMMChannelOpened(IOBluetoothRFCOMMChannel
* rfcomm_channel
);
56 friend BluetoothProfile
* CreateBluetoothProfileMac(const BluetoothUUID
& uuid
,
57 const Options
& options
);
59 BluetoothProfileMac(const BluetoothUUID
& uuid
, const Options
& options
);
60 virtual ~BluetoothProfileMac();
62 const BluetoothUUID uuid_
;
63 const uint16 rfcomm_channel_id_
;
64 ConnectionCallback connection_callback_
;
66 // A simple helper that registers for OS notifications and forwards them to
68 base::scoped_nsobject
<RFCOMMConnectionListener
> rfcomm_connection_listener_
;
70 // A handle to the service record registered in the system SDP server.
71 // Used to eventually unregister the service.
72 const BluetoothSDPServiceRecordHandle service_record_handle_
;
74 // Note: This should remain the last member so it'll be destroyed and
75 // invalidate its weak pointers before any other members are destroyed.
76 base::WeakPtrFactory
<BluetoothProfileMac
> weak_ptr_factory_
;
78 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileMac
);
83 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_MAC_H_