summaryrefslogtreecommitdiff
path: root/chromium/services/device/generic_sensor/platform_sensor_linux.h
blob: 465f7fc15693839342b29b5579e82f4d4cd9ca25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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 SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_
#define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_

#include "services/device/generic_sensor/platform_sensor.h"

namespace device {

class SensorReader;
struct SensorInfoLinux;

class PlatformSensorLinux : public PlatformSensor {
 public:
  PlatformSensorLinux(mojom::SensorType type,
                      SensorReadingSharedBuffer* reading_buffer,
                      PlatformSensorProvider* provider,
                      const SensorInfoLinux* sensor_device);

  PlatformSensorLinux(const PlatformSensorLinux&) = delete;
  PlatformSensorLinux& operator=(const PlatformSensorLinux&) = delete;

  mojom::ReportingMode GetReportingMode() override;

  // Called by a sensor reader. Takes new readings.
  void UpdatePlatformSensorReading(SensorReading reading);

  // Called by a sensor reader if an error occurs.
  void NotifyPlatformSensorError();

 protected:
  ~PlatformSensorLinux() override;
  bool StartSensor(const PlatformSensorConfiguration& configuration) override;
  void StopSensor() override;
  bool CheckSensorConfiguration(
      const PlatformSensorConfiguration& configuration) override;
  PlatformSensorConfiguration GetDefaultConfiguration() override;

 private:
  const PlatformSensorConfiguration default_configuration_;
  const mojom::ReportingMode reporting_mode_;

  // A sensor reader that reads values from sensor files
  // and stores them to a SensorReading structure.
  std::unique_ptr<SensorReader> sensor_reader_;

  base::WeakPtrFactory<PlatformSensorLinux> weak_factory_{this};
};

}  // namespace device

#endif  // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_