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