Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h

Issue 2105423003: bluetooth: Update the map of GATT services when services resolve (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address luiz's comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ 5 #ifndef DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_
6 #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ 6 #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 void RemoveObserver(Observer* observer) override; 48 void RemoveObserver(Observer* observer) override;
49 std::vector<dbus::ObjectPath> GetServices() override; 49 std::vector<dbus::ObjectPath> GetServices() override;
50 Properties* GetProperties(const dbus::ObjectPath& object_path) override; 50 Properties* GetProperties(const dbus::ObjectPath& object_path) override;
51 51
52 // Makes a service visible for device with object path |device_path|. Note 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, 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. 54 // this method will fail, if the service is already visible.
55 void ExposeHeartRateService(const dbus::ObjectPath& device_path); 55 void ExposeHeartRateService(const dbus::ObjectPath& device_path);
56 void HideHeartRateService(); 56 void HideHeartRateService();
57 57
58 // Makes a service visible for device with object path |device_path| without 58 // Makes a service visible for device with object path |device_path|. Note
59 // delay. Note that only one instance of a specific service is simulated at a 59 // that only one instance of a specific service is simulated at a time. Hence,
60 // time, if the service is already visible. 60 // this method will fail, if the service is already visible.
61 void ExposeHeartRateServiceWithoutDelay(const dbus::ObjectPath& device_path); 61 void ExposeBatteryService(const dbus::ObjectPath& device_path);
62 62
63 // Returns whether or not the Heart Rate Service is visible. 63 // Returns whether or not the Heart Rate Service is visible.
64 bool IsHeartRateVisible() const; 64 bool IsHeartRateVisible() const;
65 // Returns whether or not the Battery Service is visible.
66 bool IsBatteryServiceVisible() const;
65 67
66 // Returns the current object path of the visible Heart Rate service. If the 68 // Returns the current object path of the visible Heart Rate service. If the
67 // service is not visible, returns an invalid empty path. 69 // service is not visible, returns an invalid empty path.
68 dbus::ObjectPath GetHeartRateServicePath() const; 70 dbus::ObjectPath GetHeartRateServicePath() const;
69 71
72 // Returns the current object path of the visible Battery service. If the
73 // service is not visible, returns an invalid empty path.
74 dbus::ObjectPath GetBatteryServicePath() const;
75
70 // Final object path components and the corresponding UUIDs of the GATT 76 // Final object path components and the corresponding UUIDs of the GATT
71 // services that we emulate. Service paths are hierarchical to Bluetooth 77 // services that we emulate. Service paths are hierarchical to Bluetooth
72 // device paths, so if the path component is "service0000", and the device 78 // device paths, so if the path component is "service0000", and the device
73 // path is "/org/foo/device0", the service path is 79 // path is "/org/foo/device0", the service path is
74 // "/org/foo/device0/service0000". 80 // "/org/foo/device0/service0000".
75 static const char kHeartRateServicePathComponent[]; 81 static const char kHeartRateServicePathComponent[];
76 static const char kHeartRateServiceUUID[]; 82 static const char kHeartRateServiceUUID[];
77 83
84 // Final object path components and the corresponding UUIDs of the GATT
85 // services that we emulate. Service paths are hierarchical to Bluetooth
86 // device paths, so if the path component is "service0001", and the device
87 // path is "/org/foo/device0", the service path is
88 // "/org/foo/device0/service0001".
89 static const char kBatteryServicePathComponent[];
90 static const char kBatteryServiceUUID[];
91
78 private: 92 private:
79 // Property callback passed when we create Properties structures. 93 // Property callback passed when we create Properties structures.
80 void OnPropertyChanged(const dbus::ObjectPath& object_path, 94 void OnPropertyChanged(const dbus::ObjectPath& object_path,
81 const std::string& property_name); 95 const std::string& property_name);
82 96
83 // Notifies observers. 97 // Notifies observers.
84 void NotifyServiceAdded(const dbus::ObjectPath& object_path); 98 void NotifyServiceAdded(const dbus::ObjectPath& object_path);
85 void NotifyServiceRemoved(const dbus::ObjectPath& object_path); 99 void NotifyServiceRemoved(const dbus::ObjectPath& object_path);
86 100
87 // Tells FakeBluetoothGattCharacteristicClient to expose GATT characteristics. 101 // Tells FakeBluetoothGattCharacteristicClient to expose GATT characteristics.
88 // This is scheduled from ExposeHeartRateService to simulate asynchronous 102 // This is scheduled from ExposeHeartRateService to simulate asynchronous
89 // retrieval of characteristics. If the Heart Rate Service is hidden at the 103 // retrieval of characteristics. If the Heart Rate Service is hidden at the
90 // time this method is called, then it does nothing. 104 // time this method is called, then it does nothing.
91 void ExposeHeartRateCharacteristics(); 105 void ExposeHeartRateCharacteristics();
92 106
93 // Toggles the ServicesResolved property for the device with |object_path|.
94 // This should be done after a service is fully discovered.
95 void ToggleServicesResolvedProperty(const dbus::ObjectPath& object_path,
96 bool resolved);
97
98 // Static properties we return. As long as a service is exposed, this will be 107 // Static properties we return. As long as a service is exposed, this will be
99 // non-null. Otherwise it will be null. 108 // non-null. Otherwise it will be null.
100 std::unique_ptr<Properties> heart_rate_service_properties_; 109 std::unique_ptr<Properties> heart_rate_service_properties_;
110 std::unique_ptr<Properties> battery_service_properties_;
101 std::string heart_rate_service_path_; 111 std::string heart_rate_service_path_;
112 std::string battery_service_path_;
102 113
103 // List of observers interested in event notifications from us. 114 // List of observers interested in event notifications from us.
104 base::ObserverList<Observer> observers_; 115 base::ObserverList<Observer> observers_;
105 116
106 // Weak pointer factory for generating 'this' pointers that might live longer 117 // Weak pointer factory for generating 'this' pointers that might live longer
107 // than we do. 118 // than we do.
108 // Note: This should remain the last member so it'll be destroyed and 119 // Note: This should remain the last member so it'll be destroyed and
109 // invalidate its weak pointers before any other members are destroyed. 120 // invalidate its weak pointers before any other members are destroyed.
110 base::WeakPtrFactory<FakeBluetoothGattServiceClient> weak_ptr_factory_; 121 base::WeakPtrFactory<FakeBluetoothGattServiceClient> weak_ptr_factory_;
111 122
112 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattServiceClient); 123 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattServiceClient);
113 }; 124 };
114 125
115 } // namespace bluez 126 } // namespace bluez
116 127
117 #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_ 128 #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_SERVICE_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698