| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 DEVICE_GENERIC_SENSOR_LINUX_SENSOR_DEVICE_MANAGER_H_ | |
| 6 #define DEVICE_GENERIC_SENSOR_LINUX_SENSOR_DEVICE_MANAGER_H_ | |
| 7 | |
| 8 #include "base/scoped_observer.h" | |
| 9 | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "device/base/device_monitor_linux.h" | |
| 12 #include "device/generic_sensor/generic_sensor_export.h" | |
| 13 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" | |
| 14 | |
| 15 namespace device { | |
| 16 | |
| 17 struct SensorInfoLinux; | |
| 18 | |
| 19 // This SensorDeviceManager uses LinuxDeviceMonitor to enumerate devices | |
| 20 // and listen to "add/removed" events to notify |provider_| about | |
| 21 // added or removed iio devices. It has own cache to speed up an identification | |
| 22 // process of removed devices. | |
| 23 class DEVICE_GENERIC_SENSOR_EXPORT SensorDeviceManager | |
| 24 : public DeviceMonitorLinux::Observer { | |
| 25 public: | |
| 26 class Delegate { | |
| 27 public: | |
| 28 // Called when SensorDeviceManager has enumerated through all possible | |
| 29 // iio udev devices. | |
| 30 virtual void OnSensorNodesEnumerated() = 0; | |
| 31 | |
| 32 // Called after SensorDeviceManager has identified a udev device, which | |
| 33 // belongs to "iio" subsystem. | |
| 34 virtual void OnDeviceAdded(mojom::SensorType type, | |
| 35 std::unique_ptr<SensorInfoLinux> sensor) = 0; | |
| 36 | |
| 37 // Called after "removed" event is received from LinuxDeviceMonitor and | |
| 38 // sensor is identified as known. | |
| 39 virtual void OnDeviceRemoved(mojom::SensorType type, | |
| 40 const std::string& device_node) = 0; | |
| 41 | |
| 42 protected: | |
| 43 virtual ~Delegate() {} | |
| 44 }; | |
| 45 | |
| 46 SensorDeviceManager(); | |
| 47 ~SensorDeviceManager() override; | |
| 48 | |
| 49 // Starts this service. | |
| 50 virtual void Start(Delegate* delegate); | |
| 51 | |
| 52 protected: | |
| 53 using SensorDeviceMap = std::unordered_map<std::string, mojom::SensorType>; | |
| 54 | |
| 55 // Wrappers around udev system methods that can be implemented differently | |
| 56 // by tests. | |
| 57 virtual std::string GetUdevDeviceGetSubsystem(udev_device* dev); | |
| 58 virtual std::string GetUdevDeviceGetSyspath(udev_device* dev); | |
| 59 virtual std::string GetUdevDeviceGetSysattrValue( | |
| 60 udev_device* dev, | |
| 61 const std::string& attribute); | |
| 62 virtual std::string GetUdevDeviceGetDevnode(udev_device* dev); | |
| 63 | |
| 64 // DeviceMonitorLinux::Observer: | |
| 65 void OnDeviceAdded(udev_device* udev_device) override; | |
| 66 void OnDeviceRemoved(udev_device* device) override; | |
| 67 | |
| 68 // Represents a map of sensors that are already known to this manager after | |
| 69 // initial enumeration. | |
| 70 SensorDeviceMap sensors_by_node_; | |
| 71 | |
| 72 THREAD_CHECKER(thread_checker_); | |
| 73 | |
| 74 ScopedObserver<DeviceMonitorLinux, DeviceMonitorLinux::Observer> observer_; | |
| 75 | |
| 76 Delegate* delegate_; | |
| 77 | |
| 78 // A task runner, which |delegate_| lives on. | |
| 79 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(SensorDeviceManager); | |
| 82 }; | |
| 83 | |
| 84 } // namespace device | |
| 85 | |
| 86 #endif // DEVICE_GENERIC_SENSOR_LINUX_SENSOR_DEVICE_MANAGER_H_ | |
| OLD | NEW |