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