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 #include "modules/sensor/SensorPollingStrategy.h" |
| 6 |
| 7 #include "platform/Timer.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 SensorPollingStrategy::SensorPollingStrategy(double frequencySec, std::unique_pt
r<Function<void()>> func) |
| 12 : m_frequency(frequencySec) |
| 13 , m_pollFunc(std::move(func)) { } |
| 14 |
| 15 class ContiniousSensorPollingStrategy : public SensorPollingStrategy { |
| 16 public: |
| 17 DEFINE_INLINE_VIRTUAL_TRACE() |
| 18 { |
| 19 SensorPollingStrategy::trace(visitor); |
| 20 } |
| 21 |
| 22 ContiniousSensorPollingStrategy(double frequencySec, std::unique_ptr<Functio
n<void()>> func) |
| 23 : SensorPollingStrategy(frequencySec, std::move(func)) |
| 24 , m_timer(this, &ContiniousSensorPollingStrategy::pollForData) {} |
| 25 private: |
| 26 // SensorPollingStrategy overrides. |
| 27 void startPolling() override; |
| 28 void stopPolling() override; |
| 29 |
| 30 void pollForData(Timer<ContiniousSensorPollingStrategy>*); |
| 31 |
| 32 Timer<ContiniousSensorPollingStrategy> m_timer; |
| 33 }; |
| 34 |
| 35 void ContiniousSensorPollingStrategy::startPolling() |
| 36 { |
| 37 m_timer.startRepeating(1/m_frequency, BLINK_FROM_HERE); |
| 38 } |
| 39 |
| 40 void ContiniousSensorPollingStrategy::stopPolling() |
| 41 { |
| 42 m_timer.stop(); |
| 43 } |
| 44 |
| 45 void ContiniousSensorPollingStrategy::pollForData(Timer<ContiniousSensorPollingS
trategy>*) |
| 46 { |
| 47 (*m_pollFunc)(); |
| 48 } |
| 49 |
| 50 // static |
| 51 SensorPollingStrategy* SensorPollingStrategy::create(double frequencySec, std::u
nique_ptr<Function<void()>> func, device::sensors::blink::ReportingMode mode) |
| 52 { |
| 53 if (mode == device::sensors::blink::ReportingMode::CONTINUOUS) |
| 54 return new ContiniousSensorPollingStrategy(frequencySec, std::move(func)
); |
| 55 else // FIXME : implement strategy for onchange event |
| 56 return new ContiniousSensorPollingStrategy(frequencySec, std::move(func)
); |
| 57 } |
| 58 |
| 59 } // namespace blink |
OLD | NEW |