| OLD | NEW |
| (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_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ | |
| 6 #define SERVICES_DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ | |
| 7 | |
| 8 #include "services/device/generic_sensor/platform_sensor_provider.h" | |
| 9 | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "services/device/generic_sensor/linux/sensor_device_manager.h" | |
| 12 | |
| 13 namespace base { | |
| 14 template <typename T> | |
| 15 struct DefaultSingletonTraits; | |
| 16 class Thread; | |
| 17 } | |
| 18 | |
| 19 namespace device { | |
| 20 | |
| 21 struct SensorInfoLinux; | |
| 22 | |
| 23 class PlatformSensorProviderLinux : public PlatformSensorProvider, | |
| 24 public SensorDeviceManager::Delegate { | |
| 25 public: | |
| 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: | |
| 37 ~PlatformSensorProviderLinux() override; | |
| 38 | |
| 39 void CreateSensorInternal(mojom::SensorType type, | |
| 40 mojo::ScopedSharedBufferMapping mapping, | |
| 41 const CreateSensorCallback& callback) override; | |
| 42 | |
| 43 void AllSensorsRemoved() override; | |
| 44 | |
| 45 void SetFileTaskRunner( | |
| 46 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override; | |
| 47 | |
| 48 private: | |
| 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( | |
| 57 mojom::SensorType type, | |
| 58 mojo::ScopedSharedBufferMapping mapping, | |
| 59 const PlatformSensorProviderBase::CreateSensorCallback& callback, | |
| 60 const SensorInfoLinux* sensor_device); | |
| 61 | |
| 62 bool StartPollingThread(); | |
| 63 | |
| 64 // Stops a polling thread if there are no sensors left. Must be called on | |
| 65 // a different than the polling thread which allows I/O. | |
| 66 void StopPollingThread(); | |
| 67 | |
| 68 // Shuts down a service that tracks events from iio subsystem. | |
| 69 void Shutdown(); | |
| 70 | |
| 71 // Returns SensorInfoLinux structure of a requested type. | |
| 72 // If a request cannot be processed immediately, returns nullptr and | |
| 73 // all the requests stored in |requests_map_| are processed after | |
| 74 // enumeration is ready. | |
| 75 SensorInfoLinux* GetSensorDevice(mojom::SensorType type); | |
| 76 | |
| 77 // Returns all found iio devices. Currently not implemented. | |
| 78 void GetAllSensorDevices(); | |
| 79 | |
| 80 // Processed stored requests in |request_map_|. | |
| 81 void ProcessStoredRequests(); | |
| 82 | |
| 83 // Called when sensors are created asynchronously after enumeration is done. | |
| 84 void CreateSensorAndNotify(mojom::SensorType type, | |
| 85 SensorInfoLinux* sensor_device); | |
| 86 | |
| 87 // SensorDeviceManager::Delegate implements: | |
| 88 void OnSensorNodesEnumerated() override; | |
| 89 void OnDeviceAdded(mojom::SensorType type, | |
| 90 std::unique_ptr<SensorInfoLinux> sensor_device) override; | |
| 91 void OnDeviceRemoved(mojom::SensorType type, | |
| 92 const std::string& device_node) override; | |
| 93 | |
| 94 // Set to true when enumeration is ready. | |
| 95 bool sensor_nodes_enumerated_; | |
| 96 | |
| 97 // Set to true when |sensor_device_manager_| has already started enumeration. | |
| 98 bool sensor_nodes_enumeration_started_; | |
| 99 | |
| 100 // Stores all available sensor devices by type. | |
| 101 SensorDeviceMap sensor_devices_by_type_; | |
| 102 | |
| 103 // A thread that is used by sensor readers in case of polling strategy. | |
| 104 std::unique_ptr<base::Thread> polling_thread_; | |
| 105 | |
| 106 // This manager is being used to get |SensorInfoLinux|, which represents | |
| 107 // all the information of a concrete sensor provided by OS. | |
| 108 std::unique_ptr<SensorDeviceManager> sensor_device_manager_; | |
| 109 | |
| 110 // Browser's file thread task runner passed from renderer. Used by this | |
| 111 // provider to stop a polling thread and passed to a manager that | |
| 112 // runs a linux device monitor service on this task runner. | |
| 113 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | |
| 114 | |
| 115 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderLinux); | |
| 116 }; | |
| 117 | |
| 118 } // namespace device | |
| 119 | |
| 120 #endif // SERVICES_DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_
H_ | |
| OLD | NEW |