Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_reader_win.h |
| diff --git a/device/generic_sensor/platform_sensor_reader_win.h b/device/generic_sensor/platform_sensor_reader_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b83de88e7eb753e84fc9e847a6b1c2268a5a8637 |
| --- /dev/null |
| +++ b/device/generic_sensor/platform_sensor_reader_win.h |
| @@ -0,0 +1,80 @@ |
| +// 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 DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_ |
| +#define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_ |
| + |
| +#include <SensorsApi.h> |
| +#include "base/callback_forward.h" |
| +#include "base/threading/non_thread_safe.h" |
| +#include "base/win/scoped_comptr.h" |
| +#include "device/generic_sensor/public/interfaces/sensor.mojom.h" |
| + |
| +namespace device { |
| + |
| +class PlatformSensorConfiguration; |
| +struct ReaderInitParams; |
| +struct SensorReading; |
| + |
| +// Generic class that uses ISensor interface to fetch sensor data. Used |
| +// by PlatformSensorWin and deliveres notifications via Client interface. |
| +// Instances of this class are created by PlatformSensorProviderWin and |
| +// live on sensor thread. |
| +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.
|
| + public: |
| + // Client interface that can be used to receive notifications about sensor |
| + // error or data change events. |
| + class Client { |
| + public: |
| + virtual void OnReadingUpdated(const SensorReading& reading) = 0; |
| + virtual void OnSensorError() = 0; |
| + |
| + protected: |
| + virtual ~Client() {} |
| + }; |
| + |
| + using ReaderFunctor = base::Callback<HRESULT(ISensorDataReport& report, |
| + 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
|
| + |
| + static std::unique_ptr<PlatformSensorReaderWin> Create( |
| + mojom::SensorType type, |
| + base::win::ScopedComPtr<ISensorManager> sensor_manager); |
| + |
| + void SetClient(Client* client); |
| + |
| + 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.
|
| + mojom::ReportingMode GetReportingMode() const; |
| + bool StartSensor(const PlatformSensorConfiguration& configuration); |
| + void StopSensor(); |
| + ~PlatformSensorReaderWin(); |
| + |
| + private: |
| + PlatformSensorReaderWin(base::win::ScopedComPtr<ISensor> sensor, |
| + const ReaderInitParams& params); |
| + |
| + static base::win::ScopedComPtr<ISensor> GetSensorForType( |
| + REFSENSOR_TYPE_ID sensor_type, |
| + base::win::ScopedComPtr<ISensorManager> sensor_manager); |
| + |
| + bool SetReportingInterval(const PlatformSensorConfiguration& configuration); |
| + HRESULT SensorReadingChanged(ISensorDataReport& report, |
| + SensorReading& reading) const; |
| + void SensorError(); |
| + |
| + private: |
| + friend class EventListener; |
| + base::Lock lock_; |
| + bool sensor_active_; |
| + Client* client_; |
| + ReaderFunctor read_func_; |
| + const mojom::ReportingMode reporting_mode_; |
| + const unsigned long min_reporting_interval_ms_; |
| + base::win::ScopedComPtr<ISensor> sensor_; |
| + scoped_refptr<EventListener> event_listener_; |
| + DISALLOW_COPY_AND_ASSIGN(PlatformSensorReaderWin); |
| +}; |
| + |
| +} // namespace device |
| + |
| +#endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_ |