OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_EXPERIMENTAL_CHROMEOS_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_EXPERIMENTAL_CHROMEOS_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/dbus/experimental_bluetooth_profile_service_provider.h" |
| 16 #include "dbus/object_path.h" |
| 17 #include "device/bluetooth/bluetooth_profile.h" |
| 18 |
| 19 namespace dbus { |
| 20 |
| 21 class FileDescriptor; |
| 22 |
| 23 } // namespace dbus |
| 24 |
| 25 namespace device { |
| 26 |
| 27 class BluetoothAdapter; |
| 28 |
| 29 } // namespace device |
| 30 |
| 31 namespace chromeos { |
| 32 |
| 33 // The BluetoothProfileExperimentalChromeOS class implements BluetoothProfile |
| 34 // for the Chrome OS platform using the Bluetooth Smart capable backend (there |
| 35 // is no implementation for the older backend). It will be renamed to |
| 36 // BluetoothProfileChromeOS, once the backend is the sole implementation. |
| 37 class CHROMEOS_EXPORT BluetoothProfileExperimentalChromeOS |
| 38 : public device::BluetoothProfile, |
| 39 private ExperimentalBluetoothProfileServiceProvider::Delegate { |
| 40 public: |
| 41 // BluetoothProfile override. |
| 42 virtual void Unregister() OVERRIDE; |
| 43 virtual void SetConnectionCallback( |
| 44 const ConnectionCallback& callback) OVERRIDE; |
| 45 |
| 46 // Return the UUID of the profile. |
| 47 const std::string& uuid() const { return uuid_; } |
| 48 |
| 49 private: |
| 50 friend class BluetoothProfile; |
| 51 |
| 52 BluetoothProfileExperimentalChromeOS(); |
| 53 virtual ~BluetoothProfileExperimentalChromeOS(); |
| 54 |
| 55 // Called by BluetoothProfile::Register to initialize the profile object |
| 56 // asynchronously. |uuid|, |options| and |callback| are the arguments to |
| 57 // BluetoothProfile::Register. |
| 58 void Init(const std::string& uuid, |
| 59 const device::BluetoothProfile::Options& options, |
| 60 const ProfileCallback& callback); |
| 61 |
| 62 // ExperimentalBluetoothProfileServiceProvider::Delegate override. |
| 63 virtual void Release() OVERRIDE; |
| 64 virtual void NewConnection( |
| 65 const dbus::ObjectPath& device_path, |
| 66 scoped_ptr<dbus::FileDescriptor> fd, |
| 67 const ExperimentalBluetoothProfileServiceProvider::Delegate::Options& |
| 68 options, |
| 69 const ConfirmationCallback& callback) OVERRIDE; |
| 70 virtual void RequestDisconnection( |
| 71 const dbus::ObjectPath& device_path, |
| 72 const ConfirmationCallback& callback) OVERRIDE; |
| 73 virtual void Cancel() OVERRIDE; |
| 74 |
| 75 // Called by dbus:: on completion of the D-Bus method call to register the |
| 76 // profile object. |
| 77 void OnRegisterProfile(const ProfileCallback& callback); |
| 78 void OnRegisterProfileError(const ProfileCallback& callback, |
| 79 const std::string& error_name, |
| 80 const std::string& error_message); |
| 81 |
| 82 // Called by dbus:: on completion of the D-Bus method call to unregister |
| 83 // the profile object. |
| 84 void OnUnregisterProfile(); |
| 85 void OnUnregisterProfileError(const std::string& error_name, |
| 86 const std::string& error_message); |
| 87 |
| 88 // Method run once the file descriptor has been validated in order to get |
| 89 // the default adapter, and method run once the default adapter has been |
| 90 // obtained in order to get the device object to be passed to the connection |
| 91 // callback. |
| 92 // |
| 93 // The |fd| argument is moved compared to the NewConnection() call since it |
| 94 // becomes the result of a PostTaskAndReplyWithResult() call. |
| 95 void GetAdapter( |
| 96 const dbus::ObjectPath& device_path, |
| 97 const ExperimentalBluetoothProfileServiceProvider::Delegate::Options& |
| 98 options, |
| 99 const ConfirmationCallback& callback, |
| 100 scoped_ptr<dbus::FileDescriptor> fd); |
| 101 void OnGetAdapter( |
| 102 const dbus::ObjectPath& device_path, |
| 103 const ExperimentalBluetoothProfileServiceProvider::Delegate::Options& |
| 104 options, |
| 105 const ConfirmationCallback& callback, |
| 106 scoped_ptr<dbus::FileDescriptor> fd, |
| 107 scoped_refptr<device::BluetoothAdapter>); |
| 108 |
| 109 // UUID of the profile passed during initialization. |
| 110 std::string uuid_; |
| 111 |
| 112 // Object path of the local profile D-Bus object. |
| 113 dbus::ObjectPath object_path_; |
| 114 |
| 115 // Local profile D-Bus object used for receiving profile delegate methods |
| 116 // from BlueZ. |
| 117 scoped_ptr<ExperimentalBluetoothProfileServiceProvider> profile_; |
| 118 |
| 119 // Callback used on both outgoing and incoming connections to pass the |
| 120 // connected socket to profile object owner. |
| 121 ConnectionCallback connection_callback_; |
| 122 |
| 123 // Note: This should remain the last member so it'll be destroyed and |
| 124 // invalidate its weak pointers before any other members are destroyed. |
| 125 base::WeakPtrFactory<BluetoothProfileExperimentalChromeOS> weak_ptr_factory_; |
| 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileExperimentalChromeOS); |
| 128 }; |
| 129 |
| 130 } // namespace chromeos |
| 131 |
| 132 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_EXPERIMENTAL_CHROMEOS_H_ |
OLD | NEW |