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

Side by Side Diff: services/device/generic_sensor/platform_sensor_reader_linux.h

Issue 2898433002: Revert of Move //device/generic_sensor to be part of the internal implementation of the Device Service. (Closed)
Patch Set: Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
(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 SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_
6 #define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/thread_checker.h"
12
13 namespace base {
14 class SingleThreadTaskRunner;
15 }
16
17 namespace device {
18
19 class PlatformSensorConfiguration;
20 class PlatformSensorLinux;
21 struct SensorInfoLinux;
22
23 // A generic reader class that can be implemented with two different strategies:
24 // polling and on trigger. All methods are not thread-safe and must be called
25 // on a polling thread that allows I/O.
26 class SensorReader {
27 public:
28 // Creates a new instance of SensorReader. At the moment, only polling
29 // reader is supported.
30 static std::unique_ptr<SensorReader> Create(
31 const SensorInfoLinux* sensor_device,
32 base::WeakPtr<PlatformSensorLinux> sensor,
33 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
34
35 virtual ~SensorReader();
36
37 // Starts fetching data based on strategy this reader has chosen.
38 // Only polling strategy is supported at the moment.
39 virtual void StartFetchingData(
40 const PlatformSensorConfiguration& configuration) = 0;
41
42 // Stops fetching data.
43 virtual void StopFetchingData() = 0;
44
45 protected:
46 SensorReader(base::WeakPtr<PlatformSensorLinux> sensor,
47 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
48
49 // Notifies |sensor_| about an error.
50 void NotifyReadError();
51
52 // In builds with DCHECK enabled checks that methods of this
53 // and derived classes are called on a right thread.
54 THREAD_CHECKER(thread_checker_);
55
56 // A sensor that this reader is owned by and notifies about errors and
57 // readings to.
58 base::WeakPtr<PlatformSensorLinux> sensor_;
59
60 // A task runner that is used to report about new readings and errors
61 // to a |sensor_|.
62 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
63
64 // Indicates if reading is active.
65 bool is_reading_active_;
66
67 DISALLOW_COPY_AND_ASSIGN(SensorReader);
68 };
69
70 } // namespace device
71
72 #endif // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698