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_H_ |
| 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <map> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" |
| 15 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" |
| 16 #include "mojo/public/cpp/system/buffer.h" |
| 17 |
| 18 namespace device { |
| 19 |
| 20 class PlatformSensorProvider; |
| 21 class PlatformSensorConfiguration; |
| 22 |
| 23 // Base class for the sensors provided by the platform. Concrete instances of |
| 24 // this class are created by platform specific PlatformSensorProvider. |
| 25 class PlatformSensor : public base::RefCountedThreadSafe<PlatformSensor> { |
| 26 public: |
| 27 // The interface that must be implemented by PlatformSensor clients. |
| 28 class Client { |
| 29 public: |
| 30 virtual void OnSensorReadingChanged() = 0; |
| 31 virtual void OnSensorError() = 0; |
| 32 virtual bool IsNotificationSuspended() = 0; |
| 33 |
| 34 protected: |
| 35 virtual ~Client() {} |
| 36 }; |
| 37 |
| 38 virtual mojom::ReportingMode GetReportingMode() = 0; |
| 39 |
| 40 mojom::SensorType GetType() const; |
| 41 |
| 42 bool StartListening(Client* client, |
| 43 const PlatformSensorConfiguration& config); |
| 44 bool StopListening(Client* client, const PlatformSensorConfiguration& config); |
| 45 |
| 46 void UpdateSensor(); |
| 47 |
| 48 void AddClient(Client*); |
| 49 void RemoveClient(Client*); |
| 50 |
| 51 protected: |
| 52 virtual ~PlatformSensor(); |
| 53 PlatformSensor(mojom::SensorType type, |
| 54 mojo::ScopedSharedBufferMapping mapping, |
| 55 PlatformSensorProvider* provider); |
| 56 |
| 57 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>; |
| 58 |
| 59 virtual bool UpdateSensorInternal(const ConfigMap& configurations) = 0; |
| 60 virtual bool CheckSensorConfiguration( |
| 61 const PlatformSensorConfiguration& configuration) = 0; |
| 62 |
| 63 void NotifySensorReadingChanged(); |
| 64 void NotifySensorError(); |
| 65 |
| 66 mojo::ScopedSharedBufferMapping shared_buffer_mapping_; |
| 67 |
| 68 private: |
| 69 friend class base::RefCountedThreadSafe<PlatformSensor>; |
| 70 |
| 71 mojom::SensorType type_; |
| 72 base::ObserverList<Client, true> clients_; |
| 73 ConfigMap config_map_; |
| 74 PlatformSensorProvider* provider_; |
| 75 base::WeakPtrFactory<PlatformSensor> weak_factory_; |
| 76 DISALLOW_COPY_AND_ASSIGN(PlatformSensor); |
| 77 }; |
| 78 |
| 79 } // namespace device |
| 80 |
| 81 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ |
OLD | NEW |