Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chromeos / dbus / fake_bluetooth_gatt_service_client.h
blob59bcdb56f56da7642ddf8ea71987485705ad679c
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_SERVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/bluetooth_gatt_service_client.h"
16 #include "dbus/object_path.h"
17 #include "dbus/property.h"
19 namespace chromeos {
21 // FakeBluetoothGattServiceClient simulates the behavior of the Bluetooth Daemon
22 // GATT service objects and is used in test cases in place of a mock and on the
23 // Linux desktop.
24 class CHROMEOS_EXPORT FakeBluetoothGattServiceClient
25 : public BluetoothGattServiceClient {
26 public:
27 struct Properties : public BluetoothGattServiceClient::Properties {
28 explicit Properties(const PropertyChangedCallback& callback);
29 virtual ~Properties();
31 // dbus::PropertySet override
32 virtual void Get(dbus::PropertyBase* property,
33 dbus::PropertySet::GetCallback callback) OVERRIDE;
34 virtual void GetAll() OVERRIDE;
35 virtual void Set(dbus::PropertyBase* property,
36 dbus::PropertySet::SetCallback callback) OVERRIDE;
39 FakeBluetoothGattServiceClient();
40 virtual ~FakeBluetoothGattServiceClient();
42 // DBusClient override.
43 virtual void Init(dbus::Bus* bus) OVERRIDE;
45 // BluetoothGattServiceClient overrides.
46 virtual void AddObserver(Observer* observer) OVERRIDE;
47 virtual void RemoveObserver(Observer* observer) OVERRIDE;
48 virtual std::vector<dbus::ObjectPath> GetServices() OVERRIDE;
49 virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
50 OVERRIDE;
52 // Makes a service visible for device with object path |device_path|. Note
53 // that only one instance of a specific service is simulated at a time. Hence,
54 // this method will fail, if the service is already visible.
55 void ExposeHeartRateService(const dbus::ObjectPath& device_path);
56 void HideHeartRateService();
58 // Returns whether or not the Heart Rate Service is visible.
59 bool IsHeartRateVisible() const;
61 // Returns the current object path of the visible Heart Rate service. If the
62 // service is not visible, returns an invalid empty path.
63 dbus::ObjectPath GetHeartRateServicePath() const;
65 // Final object path components and the corresponding UUIDs of the GATT
66 // services that we emulate. Service paths are hierarchical to Bluetooth
67 // device paths, so if the path component is "service0000", and the device
68 // path is "/org/foo/device0", the service path is
69 // "/org/foo/device0/service0000".
70 static const char kHeartRateServicePathComponent[];
71 static const char kHeartRateServiceUUID[];
73 private:
74 // Property callback passed when we create Properties structures.
75 void OnPropertyChanged(const dbus::ObjectPath& object_path,
76 const std::string& property_name);
78 // Notifies observers.
79 void NotifyServiceAdded(const dbus::ObjectPath& object_path);
80 void NotifyServiceRemoved(const dbus::ObjectPath& object_path);
82 // Tells FakeBluetoothGattCharacteristicClient to expose GATT characteristics.
83 // This is scheduled from ExposeHeartRateService to simulate asynchronous
84 // retrieval of characteristics. If the Heart Rate Service is hidden at the
85 // time this method is called, then it does nothing.
86 void ExposeHeartRateCharacteristics();
88 // Static properties we return. As long as a service is exposed, this will be
89 // non-null. Otherwise it will be null.
90 scoped_ptr<Properties> heart_rate_service_properties_;
91 std::string heart_rate_service_path_;
93 // List of observers interested in event notifications from us.
94 ObserverList<Observer> observers_;
96 // Weak pointer factory for generating 'this' pointers that might live longer
97 // than we do.
98 // Note: This should remain the last member so it'll be destroyed and
99 // invalidate its weak pointers before any other members are destroyed.
100 base::WeakPtrFactory<FakeBluetoothGattServiceClient> weak_ptr_factory_;
102 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattServiceClient);
105 } // namespace chromeos
107 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_