| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ | |
| 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/observer_list.h" | |
| 13 #include "chromeos/chromeos_export.h" | |
| 14 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | |
| 15 #include "dbus/object_path.h" | |
| 16 | |
| 17 namespace chromeos { | |
| 18 | |
| 19 // FakeBluetoothGattDescriptorClient simulates the behavior of the Bluetooth | |
| 20 // Daemon GATT characteristic descriptor objects and is used in test cases in | |
| 21 // place of a mock and on the Linux desktop. | |
| 22 class CHROMEOS_EXPORT FakeBluetoothGattDescriptorClient | |
| 23 : public BluetoothGattDescriptorClient { | |
| 24 public: | |
| 25 struct Properties : public BluetoothGattDescriptorClient::Properties { | |
| 26 explicit Properties(const PropertyChangedCallback& callback); | |
| 27 ~Properties() override; | |
| 28 | |
| 29 // dbus::PropertySet override | |
| 30 void Get(dbus::PropertyBase* property, | |
| 31 dbus::PropertySet::GetCallback callback) override; | |
| 32 void GetAll() override; | |
| 33 void Set(dbus::PropertyBase* property, | |
| 34 dbus::PropertySet::SetCallback callback) override; | |
| 35 }; | |
| 36 | |
| 37 FakeBluetoothGattDescriptorClient(); | |
| 38 ~FakeBluetoothGattDescriptorClient() override; | |
| 39 | |
| 40 // DBusClient override. | |
| 41 void Init(dbus::Bus* bus) override; | |
| 42 | |
| 43 // BluetoothGattDescriptorClient overrides. | |
| 44 void AddObserver(Observer* observer) override; | |
| 45 void RemoveObserver(Observer* observer) override; | |
| 46 std::vector<dbus::ObjectPath> GetDescriptors() override; | |
| 47 Properties* GetProperties(const dbus::ObjectPath& object_path) override; | |
| 48 void ReadValue(const dbus::ObjectPath& object_path, | |
| 49 const ValueCallback& callback, | |
| 50 const ErrorCallback& error_callback) override; | |
| 51 void WriteValue(const dbus::ObjectPath& object_path, | |
| 52 const std::vector<uint8>& value, | |
| 53 const base::Closure& callback, | |
| 54 const ErrorCallback& error_callback) override; | |
| 55 | |
| 56 // Makes the descriptor with the UUID |uuid| visible under the characteristic | |
| 57 // with object path |characteristic_path|. Descriptor object paths are | |
| 58 // hierarchical to their characteristics. |uuid| must belong to a descriptor | |
| 59 // for which there is a constant defined below, otherwise this method has no | |
| 60 // effect. Returns the object path of the created descriptor. In the no-op | |
| 61 // case, returns an invalid path. | |
| 62 dbus::ObjectPath ExposeDescriptor(const dbus::ObjectPath& characteristic_path, | |
| 63 const std::string& uuid); | |
| 64 void HideDescriptor(const dbus::ObjectPath& descriptor_path); | |
| 65 | |
| 66 // Object path components and UUIDs of GATT characteristic descriptors. | |
| 67 static const char kClientCharacteristicConfigurationPathComponent[]; | |
| 68 static const char kClientCharacteristicConfigurationUUID[]; | |
| 69 | |
| 70 private: | |
| 71 // Property callback passed when we create Properties structures. | |
| 72 void OnPropertyChanged(const dbus::ObjectPath& object_path, | |
| 73 const std::string& property_name); | |
| 74 | |
| 75 // Notifies observers. | |
| 76 void NotifyDescriptorAdded(const dbus::ObjectPath& object_path); | |
| 77 void NotifyDescriptorRemoved(const dbus::ObjectPath& object_path); | |
| 78 | |
| 79 // Mapping from object paths to Properties structures. | |
| 80 struct DescriptorData { | |
| 81 DescriptorData(); | |
| 82 ~DescriptorData(); | |
| 83 | |
| 84 scoped_ptr<Properties> properties; | |
| 85 }; | |
| 86 typedef std::map<dbus::ObjectPath, DescriptorData*> PropertiesMap; | |
| 87 PropertiesMap properties_; | |
| 88 | |
| 89 // List of observers interested in event notifications from us. | |
| 90 base::ObserverList<Observer> observers_; | |
| 91 | |
| 92 // Weak pointer factory for generating 'this' pointers that might live longer | |
| 93 // than we do. | |
| 94 // Note: This should remain the last member so it'll be destroyed and | |
| 95 // invalidate its weak pointers before any other members are destroyed. | |
| 96 base::WeakPtrFactory<FakeBluetoothGattDescriptorClient> | |
| 97 weak_ptr_factory_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattDescriptorClient); | |
| 100 }; | |
| 101 | |
| 102 } // namespace chromeos | |
| 103 | |
| 104 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_ | |
| OLD | NEW |