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

Side by Side Diff: device/generic_sensor/platform_sensor_provider_linux.h

Issue 2533793002: [sensors](CrOS/Linux) Implement Sensor device manager for sensors (Closed)
Patch Set: Merge SensorDeviceManager with Platform....Provider. Rename SensorDeviceService to SensorDeviceMana… 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ 5 #ifndef DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_
6 #define DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ 6 #define DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_
7 7
8 #include "device/generic_sensor/platform_sensor_provider.h" 8 #include "device/generic_sensor/platform_sensor_provider.h"
9 9
10 #include "device/generic_sensor/platform_sensor_manager_linux.h"
11
10 namespace base { 12 namespace base {
13 template <typename T>
14 struct DefaultSingletonTraits;
11 class Thread; 15 class Thread;
12 } 16 }
13 17
14 namespace device { 18 namespace device {
15 19
16 struct SensorDataLinux; 20 struct SensorInfoLinux;
17 class SensorReader;
18 21
19 class PlatformSensorProviderLinux : public PlatformSensorProvider { 22 class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProviderLinux
23 : public PlatformSensorProvider,
24 public SensorDeviceManager::Delegate {
20 public: 25 public:
21 PlatformSensorProviderLinux(); 26 static PlatformSensorProviderLinux* GetInstance();
27
28 // Sets another service provided by tests.
29 void SetSensorDeviceManagerForTesting(
30 std::unique_ptr<SensorDeviceManager> sensor_device_manager);
31
32 // Sets task runner for tests.
33 void SetFileTaskRunnerForTesting(
34 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
35
36 protected:
22 ~PlatformSensorProviderLinux() override; 37 ~PlatformSensorProviderLinux() override;
23 38
24 static PlatformSensorProviderLinux* GetInstance();
25
26 protected:
27 void CreateSensorInternal(mojom::SensorType type, 39 void CreateSensorInternal(mojom::SensorType type,
28 mojo::ScopedSharedBufferMapping mapping, 40 mojo::ScopedSharedBufferMapping mapping,
29 const CreateSensorCallback& callback) override; 41 const CreateSensorCallback& callback) override;
30 42
31 void AllSensorsRemoved() override; 43 void AllSensorsRemoved() override;
32 44
33 void SetFileTaskRunner( 45 void SetFileTaskRunner(
34 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override; 46 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override;
35 47
36 private: 48 private:
37 void SensorReaderFound( 49 friend struct base::DefaultSingletonTraits<PlatformSensorProviderLinux>;
50
51 using SensorDeviceMap =
52 std::unordered_map<mojom::SensorType, std::unique_ptr<SensorInfoLinux>>;
53
54 PlatformSensorProviderLinux();
55
56 void SensorDeviceFound(
38 mojom::SensorType type, 57 mojom::SensorType type,
39 mojo::ScopedSharedBufferMapping mapping, 58 mojo::ScopedSharedBufferMapping mapping,
40 const PlatformSensorProviderBase::CreateSensorCallback& callback, 59 const PlatformSensorProviderBase::CreateSensorCallback& callback,
41 const SensorDataLinux& data, 60 SensorInfoLinux* sensor_device);
42 std::unique_ptr<SensorReader> sensor_reader); 61
62 bool StartPollingThread();
43 63
44 // Stops a polling thread if there are no sensors left. Must be called on 64 // Stops a polling thread if there are no sensors left. Must be called on
45 // a different that polling thread that allows io. 65 // a different than the polling thread which allows I/O.
46 void StopPollingThread(); 66 void StopPollingThread();
47 67
48 // TODO(maksims): make a separate class Manager that will 68 // Initializes a sensor device manager.
49 // create provide sensors with a polling task runner, check sensors existence 69 bool InitializeSenorDeviceManager();
50 // and notify provider if a new sensor has appeared and it can be created if a 70
51 // request comes again for the same sensor. 71 // Shutdowns a service that tracks events from iio subsystem.
Reilly Grant (use Gerrit) 2016/12/08 02:31:15 s/Shutdowns/Shuts down/
maksims (do not use this acc) 2016/12/08 18:39:17 Done.
52 // A use case example: a request for a sensor X comes, manager checks if the 72 void Shutdown();
53 // sensor exists on a platform and notifies a provider it is not found. 73
54 // The provider stores this information into its cache and doesn't try to 74 // Returns SensorInfoLinux structure of a requested type.
55 // create this specific sensor if a request comes. But when, for example, 75 // If a request cannot be processed immediately, returns nullptr and
56 // the sensor X is plugged into a usb port, the manager notices that and 76 // all the requests stored in |requests_map_| are processed after
57 // notifies the provider, which updates its cache and starts handling requests 77 // enumeration is ready.
58 // for the sensor X. 78 SensorInfoLinux* GetSensorDevice(mojom::SensorType type);
59 // 79
60 // Right now, this thread is used to find sensors files and poll data. 80 // Returns all found iio devices. Currently not implemented.
81 void GetAllSensorDevices();
82
83 // Processed stored requests in |request_map_|.
84 void ProcessStoredRequests();
85
86 // Called when sensors are created asynchronously after enumeration is done.
87 void CreateSensorAndNotify(mojom::SensorType type,
88 SensorInfoLinux* sensor_device);
89
90 bool enumeration_ready() { return enumeration_ready_; }
91
92 bool sensor_device_manager_started() {
93 return sensor_device_manager_started_;
94 }
95
96 // SensorDeviceManager::Delegate implements:
97 void OnEnumerationReady() override;
98 void OnDeviceAdded(mojom::SensorType type,
99 std::unique_ptr<SensorInfoLinux> sensor_device) override;
100 void OnDeviceRemoved(mojom::SensorType type,
101 const std::string& device_node) override;
102
103 // Set to true when enumeration is ready.
104 bool enumeration_ready_;
105
106 // Set to true when |sensor_device_manager_| has been started.
107 bool sensor_device_manager_started_;
108
109 // Stores all available sensor devices by type.
110 SensorDeviceMap sensor_devices_by_type_;
111
112 // A thread that is used by sensor readers in case of polling strategy.
61 std::unique_ptr<base::Thread> polling_thread_; 113 std::unique_ptr<base::Thread> polling_thread_;
62 114
63 // A task runner that is passed to polling sensors to poll data. 115 // This manager is being used to get |SensorInfoLinux|, which represents
64 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_; 116 // all the information of a concrete sensor provided by OS.
117 std::unique_ptr<SensorDeviceManager> sensor_device_manager_;
65 118
66 // Browser's file thread task runner passed from renderer. Used to 119 // Browser's file thread task runner passed from renderer. Used by this
67 // stop a polling thread. 120 // provider to stop a polling thread and passed to a manager that
121 // runs a linux device monitor service on this task runner.
68 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 122 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
69 123
70 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderLinux); 124 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderLinux);
71 }; 125 };
72 126
73 } // namespace device 127 } // namespace device
74 128
75 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ 129 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698