17#include "sensorring/platform/SensorringExport.hpp"
62 template <
typename Response,
typename Predicate>
static bool waitForAll(std::vector<std::future<Response> >& futures, std::chrono::steady_clock::duration timeout, Predicate&& success_predicate)
noexcept;
93 std::vector<device::IDevice*> _devices;
98 std::vector<T*> devices;
99 for (
auto& device : _devices) {
100 if (
auto* cast =
dynamic_cast<T*
>(device)) {
101 devices.push_back(cast);
108 for (
auto& device : _devices) {
109 if (
auto* cast =
dynamic_cast<T*
>(device)) {
116 std::vector<device::IDevice*> filtered;
117 for (
auto& device : devices) {
118 if (
dynamic_cast<T*
>(device)) {
119 filtered.push_back(device);
125template <
typename Response,
typename Predicate>
bool DeviceGroup::waitForAll(std::vector<std::future<Response> >& futures, std::chrono::steady_clock::duration timeout, Predicate&& success_predicate)
noexcept {
128 const auto deadline = std::chrono::steady_clock::now() + timeout;
131 for (
auto& fut : futures) {
132 if (fut.wait_until(deadline) != std::future_status::ready) {
139 for (
auto& fut : futures) {
140 if (!success_predicate(fut.get())) {
void invokeForEachDevice(std::function< void(device::IDevice *)> callback) const
Invokes callback once per device in the group.
static bool waitForAll(std::vector< std::future< Response > > &futures, std::chrono::steady_clock::duration timeout, Predicate &&success_predicate) noexcept
Waits until all futures are ready within the given timeout, then checks each result with a predicate.
Definition DeviceGroup.hpp:125
static DeviceGroup createFromDevicesOfType(std::vector< device::IDevice * > devices)
Builds a DeviceGroup containing only devices of type T from the given list.
Definition DeviceGroup.hpp:115
~DeviceGroup()=default
Destructor.
std::vector< T * > getDevicesOfType() const
Returns devices that are of type T (dynamic_cast).
Definition DeviceGroup.hpp:97
unsigned int getDeviceCount() const
Returns the number of devices in the group.
std::vector< device::IDevice * > getDevices() const
Returns all devices in the group.
void invokeForEachDeviceOfType(std::function< void(T *)> callback) const
Invokes callback for each device that is of type T.
Definition DeviceGroup.hpp:107
DeviceGroup(std::vector< device::IDevice * > devices)
Constructs a group from the given device pointers.
Thin base interface for all concrete devices in the SensorRing.
Definition IDevice.hpp:18