1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_SENSORS_FAKE_SENSOR_SERVICE_H_
#define CHROMEOS_COMPONENTS_SENSORS_FAKE_SENSOR_SERVICE_H_
#include <map>
#include <set>
#include <vector>
#include "base/sequence_checker.h"
#include "chromeos/components/sensors/fake_sensor_device.h"
#include "chromeos/components/sensors/mojom/sensor.mojom.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
namespace chromeos {
namespace sensors {
class FakeSensorService final : public mojom::SensorService {
public:
FakeSensorService();
FakeSensorService(const FakeSensorService&) = delete;
FakeSensorService& operator=(const FakeSensorService&) = delete;
~FakeSensorService() override;
void AddReceiver(
mojo::PendingReceiver<mojom::SensorService> pending_receiver);
void ClearReceivers();
bool HasReceivers() const;
void SetDevice(int32_t iio_device_id,
std::set<mojom::DeviceType> types,
std::unique_ptr<FakeSensorDevice> sensor_device);
// Implementation of mojom::SensorService.
void GetDeviceIds(mojom::DeviceType type,
GetDeviceIdsCallback callback) override;
void GetAllDeviceIds(GetAllDeviceIdsCallback callback) override;
void GetDevice(
int32_t iio_device_id,
mojo::PendingReceiver<mojom::SensorDevice> device_request) override;
void RegisterNewDevicesObserver(
mojo::PendingRemote<mojom::SensorServiceNewDevicesObserver> observer)
override;
private:
struct DeviceData {
DeviceData();
DeviceData(DeviceData&&);
DeviceData& operator=(DeviceData&&);
~DeviceData();
std::set<mojom::DeviceType> types;
std::unique_ptr<FakeSensorDevice> sensor_device;
};
// First is the iio_device_id, second is the device's data.
std::map<int32_t, DeviceData> devices_;
mojo::ReceiverSet<mojom::SensorService> receiver_set_;
mojo::RemoteSet<mojom::SensorServiceNewDevicesObserver> observers_;
SEQUENCE_CHECKER(sequence_checker_);
};
} // namespace sensors
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_SENSORS_FAKE_SENSOR_SERVICE_H_
|