Index: device/bluetooth/bluetooth_profile_experimental_chromeos.cc |
diff --git a/device/bluetooth/bluetooth_profile_experimental_chromeos.cc b/device/bluetooth/bluetooth_profile_experimental_chromeos.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..63741223cdef8dd6c7f2dc88c50b17a6b27a8d43 |
--- /dev/null |
+++ b/device/bluetooth/bluetooth_profile_experimental_chromeos.cc |
@@ -0,0 +1,179 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "device/bluetooth/bluetooth_profile_experimental_chromeos.h" |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/logging.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/string_util.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "chromeos/dbus/experimental_bluetooth_profile_manager_client.h" |
+#include "chromeos/dbus/experimental_bluetooth_profile_service_provider.h" |
+#include "dbus/bus.h" |
+#include "dbus/file_descriptor.h" |
+#include "dbus/object_path.h" |
+#include "device/bluetooth/bluetooth_profile.h" |
+#include "device/bluetooth/bluetooth_socket.h" |
+#include "device/bluetooth/bluetooth_socket_experimental_chromeos.h" |
+ |
+using device::BluetoothProfile; |
+using device::BluetoothSocket; |
+ |
+namespace chromeos { |
+ |
+BluetoothProfileExperimentalChromeOS::BluetoothProfileExperimentalChromeOS() |
+ : weak_ptr_factory_(this) { |
+ |
+} |
+ |
+BluetoothProfileExperimentalChromeOS::~BluetoothProfileExperimentalChromeOS() { |
+ DCHECK(object_path_.value().empty()); |
+ DCHECK(profile_.get() == NULL); |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::Init( |
+ const std::string& uuid, |
+ const device::BluetoothProfile::Options& options, |
+ const ProfileCallback& callback) { |
+ DCHECK(object_path_.value().empty()); |
+ DCHECK(profile_.get() == NULL); |
+ |
+ ExperimentalBluetoothProfileManagerClient::Options bluetooth_options; |
+ bluetooth_options.name = options.name; |
+ bluetooth_options.service = uuid; |
+ bluetooth_options.channel = options.channel; |
+ bluetooth_options.psm = options.psm; |
+ bluetooth_options.require_authentication = options.require_authentication; |
+ bluetooth_options.require_authorization = options.require_authorization; |
+ bluetooth_options.auto_connect = options.auto_connect; |
+ bluetooth_options.version = options.version; |
+ bluetooth_options.features = options.features; |
+ |
+ // The object path is relatively meaningless, but has to be unique, so we |
+ // use the UUID of the profile. |
+ std::string uuid_path; |
+ ReplaceChars(uuid, ":", "_", &uuid_path); |
+ |
+ object_path_ = dbus::ObjectPath("/org/chromium/bluetooth_profile/" + |
+ uuid_path); |
+ |
+ dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
+ profile_.reset(ExperimentalBluetoothProfileServiceProvider::Create( |
+ system_bus, object_path_, this)); |
+ DCHECK(profile_.get()); |
+ |
+ VLOG(1) << object_path_.value() << ": Register profile"; |
+ DBusThreadManager::Get()->GetExperimentalBluetoothProfileManagerClient()-> |
+ RegisterProfile( |
+ object_path_, |
+ uuid, |
+ bluetooth_options, |
+ base::Bind( |
+ &BluetoothProfileExperimentalChromeOS::OnRegisterProfile, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ callback), |
+ base::Bind( |
+ &BluetoothProfileExperimentalChromeOS::OnRegisterProfileError, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ callback)); |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::Unregister() { |
+ DCHECK(!object_path_.value().empty()); |
+ DCHECK(profile_.get()); |
+ |
+ profile_.reset(); |
+ |
+ VLOG(1) << object_path_.value() << ": Unregister profile"; |
+ DBusThreadManager::Get()->GetExperimentalBluetoothProfileManagerClient()-> |
+ UnregisterProfile( |
+ object_path_, |
+ base::Bind( |
+ &BluetoothProfileExperimentalChromeOS::OnUnregisterProfile, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::Bind( |
+ &BluetoothProfileExperimentalChromeOS::OnUnregisterProfileError, |
+ weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::SetConnectionCallback( |
+ const SocketCallback& callback) { |
+ socket_callback_ = callback; |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::Release() { |
youngki
2013/04/25 14:34:34
Add TODO to implement this method.
keybuk
2013/04/25 17:16:41
This IS the implementation ;) while we have to pro
|
+ VLOG(1) << object_path_.value() << ": Release"; |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::NewConnection( |
+ const dbus::ObjectPath& device_path, |
+ dbus::FileDescriptor* fd, |
+ const ExperimentalBluetoothProfileServiceProvider::Delegate::Options& |
+ ptions, |
+ const ConfirmationCallback& callback) { |
+ VLOG(1) << object_path_.value() << ": New connection from device: " |
+ << device_path.value();; |
+ if (socket_callback_.is_null()) { |
+ callback.Run(REJECTED); |
+ return; |
+ } |
+ |
+ callback.Run(SUCCESS); |
+ |
+ // TODO(keybuk): look up the device |
+ |
+ scoped_refptr<BluetoothSocket> socket(( |
+ BluetoothSocketExperimentalChromeOS::Create(fd))); |
+ socket_callback_.Run(socket); |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::RequestDisconnection( |
youngki
2013/04/25 14:34:34
Add TODO to implement this method.
keybuk
2013/04/25 17:16:41
As above, this IS the implementation - we don't ha
|
+ const dbus::ObjectPath& device_path, |
+ const ConfirmationCallback& callback) { |
+ VLOG(1) << object_path_.value() << ": Request disconnection"; |
+ callback.Run(SUCCESS); |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::Cancel() { |
youngki
2013/04/25 14:34:34
Add TODO to implement this method.
keybuk
2013/04/25 17:16:41
Also this IS the implementation, the method is req
|
+ VLOG(1) << object_path_.value() << ": Cancel"; |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::OnRegisterProfile( |
+ const ProfileCallback& callback) { |
+ VLOG(1) << object_path_.value() << ": Profile registered"; |
+ callback.Run(this); |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::OnRegisterProfileError( |
+ const ProfileCallback& callback, |
+ const std::string& error_name, |
+ const std::string& error_message) { |
+ LOG(WARNING) << object_path_.value() << ": Failed to register profile: " |
+ << error_name << ": " << error_message; |
+ callback.Run(NULL); |
+ |
+ Unregister(); |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::OnUnregisterProfile() { |
+ VLOG(1) << object_path_.value() << ": Profile unregistered"; |
+ object_path_ = dbus::ObjectPath(""); |
+ delete this; |
+} |
+ |
+void BluetoothProfileExperimentalChromeOS::OnUnregisterProfileError( |
+ const std::string& error_name, |
+ const std::string& error_message) { |
+ LOG(WARNING) << object_path_.value() << ": Failed to unregister profile: " |
+ << error_name << ": " << error_message; |
+ object_path_ = dbus::ObjectPath(""); |
+ delete this; |
+} |
+ |
+} // namespace chromeos |