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.
5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_
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"
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
{
25 struct Properties
: public BluetoothGattDescriptorClient::Properties
{
26 explicit Properties(const PropertyChangedCallback
& callback
);
27 virtual ~Properties();
29 // dbus::PropertySet override
30 virtual void Get(dbus::PropertyBase
* property
,
31 dbus::PropertySet::GetCallback callback
) OVERRIDE
;
32 virtual void GetAll() OVERRIDE
;
33 virtual void Set(dbus::PropertyBase
* property
,
34 dbus::PropertySet::SetCallback callback
) OVERRIDE
;
37 FakeBluetoothGattDescriptorClient();
38 virtual ~FakeBluetoothGattDescriptorClient();
40 // DBusClient override.
41 virtual void Init(dbus::Bus
* bus
) OVERRIDE
;
43 // BluetoothGattDescriptorClient overrides.
44 virtual void AddObserver(Observer
* observer
) OVERRIDE
;
45 virtual void RemoveObserver(Observer
* observer
) OVERRIDE
;
46 virtual std::vector
<dbus::ObjectPath
> GetDescriptors() OVERRIDE
;
47 virtual Properties
* GetProperties(const dbus::ObjectPath
& object_path
)
50 // Makes the descriptor with the UUID |uuid| visible under the characteristic
51 // with object path |characteristic_path|. Descriptor object paths are
52 // hierarchical to their characteristics. |uuid| must belong to a descriptor
53 // for which there is a constant defined below, otherwise this method has no
54 // effect. Returns the object path of the created descriptor. In the no-op
55 // case, returns an invalid path.
56 dbus::ObjectPath
ExposeDescriptor(const dbus::ObjectPath
& characteristic_path
,
57 const std::string
& uuid
);
58 void HideDescriptor(const dbus::ObjectPath
& descriptor_path
);
60 // Object path components and UUIDs of GATT characteristic descriptors.
61 static const char kClientCharacteristicConfigurationPathComponent
[];
62 static const char kClientCharacteristicConfigurationUUID
[];
65 // Property callback passed when we create Properties structures.
66 void OnPropertyChanged(const dbus::ObjectPath
& object_path
,
67 const std::string
& property_name
);
69 // Notifies observers.
70 void NotifyDescriptorAdded(const dbus::ObjectPath
& object_path
);
71 void NotifyDescriptorRemoved(const dbus::ObjectPath
& object_path
);
73 // Mapping from object paths to Properties structures.
74 typedef std::map
<dbus::ObjectPath
, Properties
*> PropertiesMap
;
75 PropertiesMap properties_
;
77 // List of observers interested in event notifications from us.
78 ObserverList
<Observer
> observers_
;
80 // Weak pointer factory for generating 'this' pointers that might live longer
82 // Note: This should remain the last member so it'll be destroyed and
83 // invalidate its weak pointers before any other members are destroyed.
84 base::WeakPtrFactory
<FakeBluetoothGattDescriptorClient
>
87 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattDescriptorClient
);
90 } // namespace chromeos
92 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_DESCRIPTOR_CLIENT_H_