OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_BLUEZ_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_BLUEZ_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
14 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
15 #include "device/bluetooth/bluetooth_export.h" | 15 #include "device/bluetooth/bluetooth_export.h" |
16 #include "device/bluetooth/bluetooth_socket.h" | 16 #include "device/bluetooth/bluetooth_socket.h" |
17 #include "device/bluetooth/bluetooth_socket_net.h" | 17 #include "device/bluetooth/bluetooth_socket_net.h" |
18 #include "device/bluetooth/bluetooth_uuid.h" | 18 #include "device/bluetooth/bluetooth_uuid.h" |
19 #include "device/bluetooth/dbus/bluetooth_profile_manager_client.h" | 19 #include "device/bluetooth/dbus/bluetooth_profile_manager_client.h" |
20 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" | 20 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" |
21 | 21 |
22 namespace dbus { | 22 namespace dbus { |
23 class FileDescriptor; | 23 class FileDescriptor; |
24 } // namespace dbus | 24 } // namespace dbus |
25 | 25 |
26 namespace chromeos { | 26 namespace bluez { |
27 | 27 |
28 class BluetoothDeviceChromeOS; | 28 class BluetoothDeviceBlueZ; |
29 class BluetoothAdapterChromeOS; | 29 class BluetoothAdapterBlueZ; |
30 class BluetoothAdapterProfileChromeOS; | 30 class BluetoothAdapterProfileBlueZ; |
31 | 31 |
32 // The BluetoothSocketChromeOS class implements BluetoothSocket for the | 32 // The BluetoothSocketBlueZ class implements BluetoothSocket for the |
33 // Chrome OS platform. | 33 // Chrome OS platform. |
34 // | 34 // |
35 // This class is not thread-safe, but is only called from the UI thread. | 35 // This class is not thread-safe, but is only called from the UI thread. |
36 class DEVICE_BLUETOOTH_EXPORT BluetoothSocketChromeOS | 36 class DEVICE_BLUETOOTH_EXPORT BluetoothSocketBlueZ |
37 : public device::BluetoothSocketNet, | 37 : public device::BluetoothSocketNet, |
38 public device::BluetoothAdapter::Observer, | 38 public device::BluetoothAdapter::Observer, |
39 public bluez::BluetoothProfileServiceProvider::Delegate { | 39 public bluez::BluetoothProfileServiceProvider::Delegate { |
40 public: | 40 public: |
41 enum SecurityLevel { | 41 enum SecurityLevel { SECURITY_LEVEL_LOW, SECURITY_LEVEL_MEDIUM }; |
42 SECURITY_LEVEL_LOW, | |
43 SECURITY_LEVEL_MEDIUM | |
44 }; | |
45 | 42 |
46 static scoped_refptr<BluetoothSocketChromeOS> CreateBluetoothSocket( | 43 static scoped_refptr<BluetoothSocketBlueZ> CreateBluetoothSocket( |
47 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 44 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
48 scoped_refptr<device::BluetoothSocketThread> socket_thread); | 45 scoped_refptr<device::BluetoothSocketThread> socket_thread); |
49 | 46 |
50 // Connects this socket to the service on |device| published as UUID |uuid|, | 47 // Connects this socket to the service on |device| published as UUID |uuid|, |
51 // the underlying protocol and PSM or Channel is obtained through service | 48 // the underlying protocol and PSM or Channel is obtained through service |
52 // discovery. On a successful connection the socket properties will be updated | 49 // discovery. On a successful connection the socket properties will be updated |
53 // and |success_callback| called. On failure |error_callback| will be called | 50 // and |success_callback| called. On failure |error_callback| will be called |
54 // with a message explaining the cause of the failure. | 51 // with a message explaining the cause of the failure. |
55 virtual void Connect(const BluetoothDeviceChromeOS* device, | 52 virtual void Connect(const BluetoothDeviceBlueZ* device, |
56 const device::BluetoothUUID& uuid, | 53 const device::BluetoothUUID& uuid, |
57 SecurityLevel security_level, | 54 SecurityLevel security_level, |
58 const base::Closure& success_callback, | 55 const base::Closure& success_callback, |
59 const ErrorCompletionCallback& error_callback); | 56 const ErrorCompletionCallback& error_callback); |
60 | 57 |
61 // Listens using this socket using a service published on |adapter|. The | 58 // Listens using this socket using a service published on |adapter|. The |
62 // service is either RFCOMM or L2CAP depending on |socket_type| and published | 59 // service is either RFCOMM or L2CAP depending on |socket_type| and published |
63 // as UUID |uuid|. The |service_options| argument is interpreted according to | 60 // as UUID |uuid|. The |service_options| argument is interpreted according to |
64 // |socket_type|. |success_callback| will be called if the service is | 61 // |socket_type|. |success_callback| will be called if the service is |
65 // successfully registered, |error_callback| on failure with a message | 62 // successfully registered, |error_callback| on failure with a message |
66 // explaining the cause. | 63 // explaining the cause. |
67 enum SocketType { kRfcomm, kL2cap }; | 64 enum SocketType { kRfcomm, kL2cap }; |
68 virtual void Listen( | 65 virtual void Listen( |
69 scoped_refptr<device::BluetoothAdapter> adapter, | 66 scoped_refptr<device::BluetoothAdapter> adapter, |
70 SocketType socket_type, | 67 SocketType socket_type, |
71 const device::BluetoothUUID& uuid, | 68 const device::BluetoothUUID& uuid, |
72 const device::BluetoothAdapter::ServiceOptions& service_options, | 69 const device::BluetoothAdapter::ServiceOptions& service_options, |
73 const base::Closure& success_callback, | 70 const base::Closure& success_callback, |
74 const ErrorCompletionCallback& error_callback); | 71 const ErrorCompletionCallback& error_callback); |
75 | 72 |
76 // BluetoothSocket: | 73 // BluetoothSocket: |
77 void Close() override; | 74 void Close() override; |
78 void Disconnect(const base::Closure& callback) override; | 75 void Disconnect(const base::Closure& callback) override; |
79 void Accept(const AcceptCompletionCallback& success_callback, | 76 void Accept(const AcceptCompletionCallback& success_callback, |
80 const ErrorCompletionCallback& error_callback) override; | 77 const ErrorCompletionCallback& error_callback) override; |
81 | 78 |
82 protected: | 79 protected: |
83 ~BluetoothSocketChromeOS() override; | 80 ~BluetoothSocketBlueZ() override; |
84 | 81 |
85 private: | 82 private: |
86 BluetoothSocketChromeOS( | 83 BluetoothSocketBlueZ( |
87 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 84 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
88 scoped_refptr<device::BluetoothSocketThread> socket_thread); | 85 scoped_refptr<device::BluetoothSocketThread> socket_thread); |
89 | 86 |
90 // Register the underlying profile client object with the Bluetooth Daemon. | 87 // Register the underlying profile client object with the Bluetooth Daemon. |
91 void RegisterProfile(BluetoothAdapterChromeOS* adapter, | 88 void RegisterProfile(BluetoothAdapterBlueZ* adapter, |
92 const base::Closure& success_callback, | 89 const base::Closure& success_callback, |
93 const ErrorCompletionCallback& error_callback); | 90 const ErrorCompletionCallback& error_callback); |
94 void OnRegisterProfile(const base::Closure& success_callback, | 91 void OnRegisterProfile(const base::Closure& success_callback, |
95 const ErrorCompletionCallback& error_callback, | 92 const ErrorCompletionCallback& error_callback, |
96 BluetoothAdapterProfileChromeOS* profile); | 93 BluetoothAdapterProfileBlueZ* profile); |
97 void OnRegisterProfileError(const ErrorCompletionCallback& error_callback, | 94 void OnRegisterProfileError(const ErrorCompletionCallback& error_callback, |
98 const std::string& error_message); | 95 const std::string& error_message); |
99 | 96 |
100 // Called by dbus:: on completion of the ConnectProfile() method. | 97 // Called by dbus:: on completion of the ConnectProfile() method. |
101 void OnConnectProfile(const base::Closure& success_callback); | 98 void OnConnectProfile(const base::Closure& success_callback); |
102 void OnConnectProfileError(const ErrorCompletionCallback& error_callback, | 99 void OnConnectProfileError(const ErrorCompletionCallback& error_callback, |
103 const std::string& error_name, | 100 const std::string& error_name, |
104 const std::string& error_message); | 101 const std::string& error_message); |
105 | 102 |
106 // BluetoothAdapter::Observer: | 103 // BluetoothAdapter::Observer: |
107 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 104 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
108 bool present) override; | 105 bool present) override; |
109 | 106 |
110 // Called by dbus:: on completion of the RegisterProfile() method call | 107 // Called by dbus:: on completion of the RegisterProfile() method call |
111 // triggered as a result of the adapter becoming present again. | 108 // triggered as a result of the adapter becoming present again. |
112 void OnInternalRegisterProfile(BluetoothAdapterProfileChromeOS* profile); | 109 void OnInternalRegisterProfile(BluetoothAdapterProfileBlueZ* profile); |
113 void OnInternalRegisterProfileError(const std::string& error_message); | 110 void OnInternalRegisterProfileError(const std::string& error_message); |
114 | 111 |
115 // bluez::BluetoothProfileServiceProvider::Delegate: | 112 // bluez::BluetoothProfileServiceProvider::Delegate: |
116 void Released() override; | 113 void Released() override; |
117 void NewConnection( | 114 void NewConnection( |
118 const dbus::ObjectPath& device_path, | 115 const dbus::ObjectPath& device_path, |
119 scoped_ptr<dbus::FileDescriptor> fd, | 116 scoped_ptr<dbus::FileDescriptor> fd, |
120 const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, | 117 const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, |
121 const ConfirmationCallback& callback) override; | 118 const ConfirmationCallback& callback) override; |
122 void RequestDisconnection(const dbus::ObjectPath& device_path, | 119 void RequestDisconnection(const dbus::ObjectPath& device_path, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 std::string device_address_; | 159 std::string device_address_; |
163 dbus::ObjectPath device_path_; | 160 dbus::ObjectPath device_path_; |
164 | 161 |
165 // UUID of the profile being connected to, or listening on. | 162 // UUID of the profile being connected to, or listening on. |
166 device::BluetoothUUID uuid_; | 163 device::BluetoothUUID uuid_; |
167 | 164 |
168 // Copy of the profile options used for registering the profile. | 165 // Copy of the profile options used for registering the profile. |
169 scoped_ptr<bluez::BluetoothProfileManagerClient::Options> options_; | 166 scoped_ptr<bluez::BluetoothProfileManagerClient::Options> options_; |
170 | 167 |
171 // The profile registered with the adapter for this socket. | 168 // The profile registered with the adapter for this socket. |
172 BluetoothAdapterProfileChromeOS* profile_; | 169 BluetoothAdapterProfileBlueZ* profile_; |
173 | 170 |
174 // Pending request to an Accept() call. | 171 // Pending request to an Accept() call. |
175 struct AcceptRequest { | 172 struct AcceptRequest { |
176 AcceptRequest(); | 173 AcceptRequest(); |
177 ~AcceptRequest(); | 174 ~AcceptRequest(); |
178 | 175 |
179 AcceptCompletionCallback success_callback; | 176 AcceptCompletionCallback success_callback; |
180 ErrorCompletionCallback error_callback; | 177 ErrorCompletionCallback error_callback; |
181 }; | 178 }; |
182 scoped_ptr<AcceptRequest> accept_request_; | 179 scoped_ptr<AcceptRequest> accept_request_; |
183 | 180 |
184 // Queue of incoming connection requests. | 181 // Queue of incoming connection requests. |
185 struct ConnectionRequest { | 182 struct ConnectionRequest { |
186 ConnectionRequest(); | 183 ConnectionRequest(); |
187 ~ConnectionRequest(); | 184 ~ConnectionRequest(); |
188 | 185 |
189 dbus::ObjectPath device_path; | 186 dbus::ObjectPath device_path; |
190 scoped_ptr<dbus::FileDescriptor> fd; | 187 scoped_ptr<dbus::FileDescriptor> fd; |
191 bluez::BluetoothProfileServiceProvider::Delegate::Options options; | 188 bluez::BluetoothProfileServiceProvider::Delegate::Options options; |
192 ConfirmationCallback callback; | 189 ConfirmationCallback callback; |
193 bool accepting; | 190 bool accepting; |
194 bool cancelled; | 191 bool cancelled; |
195 }; | 192 }; |
196 std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_; | 193 std::queue<linked_ptr<ConnectionRequest>> connection_request_queue_; |
197 | 194 |
198 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); | 195 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketBlueZ); |
199 }; | 196 }; |
200 | 197 |
201 } // namespace chromeos | 198 } // namespace bluez |
202 | 199 |
203 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ | 200 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_BLUEZ_H_ |
OLD | NEW |