| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_DBUS_BLUETOOTH_PROPERTY_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DBUS_BLUETOOTH_PROPERTY_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "dbus/message.h" | |
| 11 #include "dbus/object_proxy.h" | |
| 12 #include "dbus/property.h" | |
| 13 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 | |
| 17 // BlueZ predates the common D-Bus Properties API (though it inspired it), | |
| 18 // override dbus::PropertySet to generate the correct method call to get | |
| 19 // all properties, conenect to the correct signal and parse it correctly. | |
| 20 // | |
| 21 // BluetoothPropertySet should be used with BluetoothProperty<>. | |
| 22 class BluetoothPropertySet : public dbus::PropertySet { | |
| 23 public: | |
| 24 BluetoothPropertySet(dbus::ObjectProxy* object_proxy, | |
| 25 const std::string& interface, | |
| 26 PropertyChangedCallback callback) | |
| 27 : dbus::PropertySet(object_proxy, interface, callback) {} | |
| 28 | |
| 29 // dbus::PropertySet override. | |
| 30 // | |
| 31 // Call after construction to connect property change notification | |
| 32 // signals. Sub-classes may override to use different D-Bus signals. | |
| 33 virtual void ConnectSignals() OVERRIDE; | |
| 34 | |
| 35 // dbus::PropertySet override. | |
| 36 // | |
| 37 // Queries the remote object for values of all properties and updates | |
| 38 // initial values. | |
| 39 virtual void GetAll() OVERRIDE; | |
| 40 | |
| 41 // dbus::PropertySet override. | |
| 42 // | |
| 43 // Method connected by ConnectSignals() and called by dbus:: when | |
| 44 // a property is changed. | |
| 45 virtual void ChangedReceived(dbus::Signal* signal) OVERRIDE; | |
| 46 }; | |
| 47 | |
| 48 // BlueZ predates the common D-Bus Properties API (though it inspired it), | |
| 49 // override dbus::Property<> to generate the correct method call to set a | |
| 50 // new property value. | |
| 51 template <class T> | |
| 52 class BluetoothProperty : public dbus::Property<T> { | |
| 53 public: | |
| 54 // Import the callbacks into our namespace (this is a template derived from | |
| 55 // a template, the C++ standard gets a bit wibbly and doesn't do it for us). | |
| 56 // | |
| 57 // |success| indicates whether or not the value could be retrived, or new | |
| 58 // value set. For Get, if true the new value can be obtained by calling | |
| 59 // value() on the property; for Set() a Get() call may be necessary. | |
| 60 typedef typename dbus::Property<T>::GetCallback GetCallback; | |
| 61 typedef typename dbus::Property<T>::SetCallback SetCallback; | |
| 62 | |
| 63 // dbus::Property<> override. | |
| 64 // | |
| 65 // Requests an updated value from the remote object incurring a | |
| 66 // round-trip. |callback| will be called when the new value is available. | |
| 67 virtual void Get(GetCallback callback) OVERRIDE { | |
| 68 NOTREACHED() << "BlueZ does not implement Get for properties"; | |
| 69 } | |
| 70 | |
| 71 // dbus::Property<> override. | |
| 72 // | |
| 73 // Requests that the remote object change the property value to |value|, | |
| 74 // |callback| will be called to indicate the success or failure of the | |
| 75 // request, however the new value may not be available depending on the | |
| 76 // remote object. | |
| 77 virtual void Set(const T& value, SetCallback callback) OVERRIDE { | |
| 78 dbus::MethodCall method_call(this->property_set()->interface(), | |
| 79 bluetooth_common::kSetProperty); | |
| 80 dbus::MessageWriter writer(&method_call); | |
| 81 writer.AppendString(this->name()); | |
| 82 this->AppendToWriter(&writer, value); | |
| 83 | |
| 84 dbus::ObjectProxy *object_proxy = this->property_set()->object_proxy(); | |
| 85 DCHECK(object_proxy); | |
| 86 object_proxy->CallMethod(&method_call, | |
| 87 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 88 base::Bind(&dbus::Property<T>::OnSet, | |
| 89 this->GetWeakPtr(), | |
| 90 callback)); | |
| 91 } | |
| 92 }; | |
| 93 | |
| 94 } // namespace chromeos | |
| 95 | |
| 96 #endif // CHROME_BROWSER_CHROMEOS_DBUS_BLUETOOTH_PROPERTY_H_ | |
| OLD | NEW |