platform_sensor_linux.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifndef SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_
  5. #define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_
  6. #include "services/device/generic_sensor/platform_sensor.h"
  7. namespace device {
  8. class SensorReader;
  9. struct SensorInfoLinux;
  10. class PlatformSensorLinux : public PlatformSensor {
  11. public:
  12. PlatformSensorLinux(mojom::SensorType type,
  13. SensorReadingSharedBuffer* reading_buffer,
  14. PlatformSensorProvider* provider,
  15. const SensorInfoLinux* sensor_device);
  16. PlatformSensorLinux(const PlatformSensorLinux&) = delete;
  17. PlatformSensorLinux& operator=(const PlatformSensorLinux&) = delete;
  18. mojom::ReportingMode GetReportingMode() override;
  19. // Called by a sensor reader. Takes new readings.
  20. void UpdatePlatformSensorReading(SensorReading reading);
  21. // Called by a sensor reader if an error occurs.
  22. void NotifyPlatformSensorError();
  23. protected:
  24. ~PlatformSensorLinux() override;
  25. bool StartSensor(const PlatformSensorConfiguration& configuration) override;
  26. void StopSensor() override;
  27. bool CheckSensorConfiguration(
  28. const PlatformSensorConfiguration& configuration) override;
  29. PlatformSensorConfiguration GetDefaultConfiguration() override;
  30. private:
  31. const PlatformSensorConfiguration default_configuration_;
  32. const mojom::ReportingMode reporting_mode_;
  33. // A sensor reader that reads values from sensor files
  34. // and stores them to a SensorReading structure.
  35. std::unique_ptr<SensorReader> sensor_reader_;
  36. base::WeakPtrFactory<PlatformSensorLinux> weak_factory_{this};
  37. };
  38. } // namespace device
  39. #endif // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_