Chromium Code Reviews| 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 DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_ | |
| 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_ | |
| 7 | |
| 8 #include <SensorsApi.h> | |
| 9 #include "base/callback_forward.h" | |
| 10 #include "base/threading/non_thread_safe.h" | |
| 11 #include "base/win/scoped_comptr.h" | |
| 12 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" | |
| 13 | |
| 14 namespace device { | |
| 15 | |
| 16 class PlatformSensorConfiguration; | |
| 17 struct ReaderInitParams; | |
| 18 struct SensorReading; | |
| 19 | |
| 20 // Generic class that uses ISensor interface to fetch sensor data. Used | |
| 21 // by PlatformSensorWin and deliveres notifications via Client interface. | |
| 22 // Instances of this class are created by PlatformSensorProviderWin and | |
| 23 // live on sensor thread. | |
| 24 class PlatformSensorReaderWin final : public base::NonThreadSafe { | |
|
Mikhail
2016/10/26 06:40:15
it probably should not be base::NonThreadSafe, whe
shalamov
2016/10/26 12:09:43
Done.
| |
| 25 public: | |
| 26 // Client interface that can be used to receive notifications about sensor | |
| 27 // error or data change events. | |
| 28 class Client { | |
| 29 public: | |
| 30 virtual void OnReadingUpdated(const SensorReading& reading) = 0; | |
| 31 virtual void OnSensorError() = 0; | |
| 32 | |
| 33 protected: | |
| 34 virtual ~Client() {} | |
| 35 }; | |
| 36 | |
| 37 using ReaderFunctor = base::Callback<HRESULT(ISensorDataReport& report, | |
| 38 SensorReading& reading)>; | |
|
Mikhail
2016/10/26 06:40:16
does this semantics come from platform?
shalamov
2016/10/26 12:09:43
No, it is a signature of a function that should be
| |
| 39 | |
| 40 static std::unique_ptr<PlatformSensorReaderWin> Create( | |
| 41 mojom::SensorType type, | |
| 42 base::win::ScopedComPtr<ISensorManager> sensor_manager); | |
| 43 | |
| 44 void SetClient(Client* client); | |
| 45 | |
| 46 unsigned long GetMinimalReportingIntervalMs() const; | |
|
Mikhail
2016/10/26 06:40:15
pls document which methods are thread-safe and whi
shalamov
2016/10/26 12:09:43
Done.
| |
| 47 mojom::ReportingMode GetReportingMode() const; | |
| 48 bool StartSensor(const PlatformSensorConfiguration& configuration); | |
| 49 void StopSensor(); | |
| 50 ~PlatformSensorReaderWin(); | |
| 51 | |
| 52 private: | |
| 53 PlatformSensorReaderWin(base::win::ScopedComPtr<ISensor> sensor, | |
| 54 const ReaderInitParams& params); | |
| 55 | |
| 56 static base::win::ScopedComPtr<ISensor> GetSensorForType( | |
| 57 REFSENSOR_TYPE_ID sensor_type, | |
| 58 base::win::ScopedComPtr<ISensorManager> sensor_manager); | |
| 59 | |
| 60 bool SetReportingInterval(const PlatformSensorConfiguration& configuration); | |
| 61 HRESULT SensorReadingChanged(ISensorDataReport& report, | |
| 62 SensorReading& reading) const; | |
| 63 void SensorError(); | |
| 64 | |
| 65 private: | |
| 66 friend class EventListener; | |
| 67 base::Lock lock_; | |
| 68 bool sensor_active_; | |
| 69 Client* client_; | |
| 70 ReaderFunctor read_func_; | |
| 71 const mojom::ReportingMode reporting_mode_; | |
| 72 const unsigned long min_reporting_interval_ms_; | |
| 73 base::win::ScopedComPtr<ISensor> sensor_; | |
| 74 scoped_refptr<EventListener> event_listener_; | |
| 75 DISALLOW_COPY_AND_ASSIGN(PlatformSensorReaderWin); | |
| 76 }; | |
| 77 | |
| 78 } // namespace device | |
| 79 | |
| 80 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_ | |
| OLD | NEW |