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

Unified Diff: device/generic_sensor/linux/platform_sensor_manager.h

Issue 2533793002: [sensors](CrOS/Linux) Implement Sensor device manager for sensors (Closed)
Patch Set: construct manager Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: device/generic_sensor/linux/platform_sensor_manager.h
diff --git a/device/generic_sensor/linux/platform_sensor_manager.h b/device/generic_sensor/linux/platform_sensor_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..5d45e38e823150e509a3e50ee7e17fb887e6b4e5
--- /dev/null
+++ b/device/generic_sensor/linux/platform_sensor_manager.h
@@ -0,0 +1,83 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_GENERIC_SENSOR_LINUX_PLATFORM_SENSOR_MANAGER_H_
+#define DEVICE_GENERIC_SENSOR_LINUX_PLATFORM_SENSOR_MANAGER_H_
Reilly Grant (use Gerrit) 2016/12/09 18:54:19 Please rename this file to sensor_device_manager.h
+
+#include "base/scoped_observer.h"
+
+#include "device/base/device_monitor_linux.h"
+#include "device/generic_sensor/public/interfaces/sensor.mojom.h"
+
+namespace device {
+
+struct SensorInfoLinux;
+
+// This SensorDeviceManager uses LinuxDeviceMonitor to enumerate devices
+// and listen to "add/removed" events to notify |provider_| about
+// added or removed iio devices. It has own cache to speed up an identification
+// process of removed devices.
+class DEVICE_GENERIC_SENSOR_EXPORT SensorDeviceManager
+ : public DeviceMonitorLinux::Observer {
+ public:
+ class Delegate {
+ public:
+ // Called when SensorDeviceManager has enumerated through all possible
+ // iio udev devices.
+ virtual void OnSensorNodesEnumerated() = 0;
+
+ // Called after SensorDeviceManager has identified a udev device, which
+ // belongs to "iio" subsystem.
+ virtual void OnDeviceAdded(mojom::SensorType type,
+ std::unique_ptr<SensorInfoLinux> sensor) = 0;
+
+ // Called after "removed" event is received from LinuxDeviceMonitor and
+ // sensor is identified as known.
+ virtual void OnDeviceRemoved(mojom::SensorType type,
+ const std::string& device_node) = 0;
+
+ protected:
+ virtual ~Delegate() {}
+ };
+
+ SensorDeviceManager();
+ ~SensorDeviceManager() override;
+
+ // Starts this service.
+ virtual void Start(Delegate* delegate);
+
+ protected:
+ using SensorDeviceMap = std::unordered_map<std::string, mojom::SensorType>;
+
+ // Wrappers around udev system methods that can be implemented differently
+ // by tests.
+ virtual std::string GetUdevDeviceGetSubsystem(udev_device* dev);
+ virtual std::string GetUdevDeviceGetSyspath(udev_device* dev);
+ virtual std::string GetUdevDeviceGetSysattrValue(
+ udev_device* dev,
+ const std::string& attribute);
+ virtual std::string GetUdevDeviceGetDevnode(udev_device* dev);
+
+ // DeviceMonitorLinux::Observer:
+ void OnDeviceAdded(udev_device* udev_device) override;
+ void OnDeviceRemoved(udev_device* device) override;
+
+ // Represents a map of sensors that are already known to this manager after
+ // initial enumeration.
+ SensorDeviceMap sensors_by_node_;
+
+ base::ThreadChecker thread_checker_;
+ ScopedObserver<DeviceMonitorLinux, DeviceMonitorLinux::Observer> observer_;
+
+ Delegate* delegate_;
+
+ // A task runner, which |delegate_| lives on.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(SensorDeviceManager);
+};
+
+} // namespace device
+
+#endif // DEVICE_GENERIC_SENSOR_LINUX_PLATFORM_SENSOR_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698