5 #ifndef HERALD_SENSOR_DELEGATE_H
6 #define HERALD_SENSOR_DELEGATE_H
8 #include "datatype/sensor_type.h"
9 #include "datatype/proximity.h"
10 #include "datatype/payload_data.h"
11 #include "datatype/target_identifier.h"
12 #include "datatype/immediate_send_data.h"
13 #include "datatype/location.h"
14 #include "datatype/sensor_state.h"
21 using namespace datatype;
57 template<
typename F,
typename... Args,
typename = decltype(std::declval<F>()(std::declval<Args&&>()...))>
58 std::true_type isValidImpl(
void*);
60 template<
typename F,
typename... Args>
61 std::false_type isValidImpl(...);
63 inline constexpr
auto isValid = [] (
auto f) {
64 return [](
auto&&... args) {
65 return decltype(isValidImpl<decltype(f),decltype(args)&&...>(
nullptr)){};
81 constexpr
auto hasSensorFunction = isValid(
82 [](
auto&& s,
auto&& sensor,
auto&& didRead,
auto&& fromTarget) ->
83 decltype(((decltype(s))s).get().sensor(sensor,didRead,fromTarget)) {}
87 template<
typename T,
typename... Args>
88 using HasSensorFunctionT = decltype(hasSensorFunction(std::declval<T>(),std::declval<Args>()...));
89 template<
typename T,
typename... Args>
90 constexpr
auto HasSensorFunctionV = HasSensorFunctionT<T,Args...>::value;
93 template <
typename... SensorDelegateTs>
96 static constexpr std::size_t Size =
sizeof...(SensorDelegateTs);
101 delegates(std::array<
102 std::variant<std::reference_wrapper<SensorDelegateTs>...>
104 >({std::variant<std::reference_wrapper<SensorDelegateTs>...>(dels)...})) {
124 for (
auto& delegateV : delegates) {
125 std::visit([sensor,didDetect](
auto&& arg) {
127 if constexpr (HasSensorFunctionV<decltype(arg),decltype(sensor),decltype(didDetect)>) {
128 ((decltype(arg))arg).get().sensor(sensor,didDetect);
136 for (
auto& delegateV : delegates) {
137 std::visit([sensor,didRead,fromTarget](
auto&& arg) {
139 if constexpr (HasSensorFunctionV<decltype(arg),decltype(sensor),decltype(didRead),decltype(fromTarget)>) {
140 ((decltype(arg))arg).get().sensor(sensor,didRead,fromTarget);
148 for (
auto& delegateV : delegates) {
149 std::visit([sensor,didReceive,fromTarget](
auto&& arg) {
151 if constexpr (HasSensorFunctionV<decltype(arg),decltype(sensor),decltype(didReceive),decltype(fromTarget)>) {
152 ((decltype(arg))arg).get().sensor(sensor,didReceive,fromTarget);
160 for (
auto& delegateV : delegates) {
161 std::visit([sensor,didShare,fromTarget](
auto&& arg) {
163 if constexpr (HasSensorFunctionV<decltype(arg),decltype(sensor),decltype(didShare),decltype(fromTarget)>) {
164 ((decltype(arg))arg).get().sensor(sensor,didShare,fromTarget);
172 for (
auto& delegateV : delegates) {
173 std::visit([sensor,didMeasure,fromTarget](
auto&& arg) {
175 if constexpr (HasSensorFunctionV<decltype(arg),decltype(sensor),decltype(didMeasure),decltype(fromTarget)>) {
176 ((decltype(arg))arg).get().sensor(sensor,didMeasure,fromTarget);
183 template <
typename LocationT>
185 for (
auto& delegateV : delegates) {
186 std::visit([sensor,didVisit](
auto&& arg) {
188 if constexpr (HasSensorFunctionV<decltype(arg),decltype(sensor),decltype(didVisit)>) {
189 ((decltype(arg))arg).get().sensor(sensor,didVisit);
197 for (
auto& delegateV : delegates) {
198 std::visit([sensor,didMeasure,fromTarget,withPayload](
auto&& arg) {
200 if constexpr (HasSensorFunctionV<decltype(arg),decltype(sensor),decltype(didMeasure),decltype(fromTarget),decltype(withPayload)>) {
201 ((decltype(arg))arg).get().sensor(sensor,didMeasure,fromTarget,withPayload);
209 for (
auto& delegateV : delegates) {
210 std::visit([sensor,didUpdateState](
auto&& arg) {
212 if constexpr (HasSensorFunctionV<decltype(arg),decltype(sensor),decltype(didUpdateState)>) {
213 ((decltype(arg))arg).get().sensor(sensor,didUpdateState);
221 std::variant<std::reference_wrapper<SensorDelegateTs>...>
A set of variant typed Sensor Delegate instances. Delegate callbacks can be invoked on the whole set,...
Definition: sensor_delegate.h:94
void sensor(SensorType sensor, const SensorState &didUpdateState)
Sensor state update.
Definition: sensor_delegate.h:208
void sensor(SensorType sensor, const Location< LocationT > &didVisit)
Detection of time spent at location, e.g. at specific restaurant between 02/06/2020 19:00 and 02/06/2...
Definition: sensor_delegate.h:184
void sensor(SensorType sensor, const TargetIdentifier &didDetect)
Detection of a target with an ephemeral identifier, e.g. BLE central detecting a BLE peripheral.
Definition: sensor_delegate.h:123
void sensor(SensorType sensor, const PayloadData &didRead, const TargetIdentifier &fromTarget)
Read payload data from target, e.g. encrypted device identifier from BLE peripheral after successful ...
Definition: sensor_delegate.h:135
void sensor(SensorType sensor, const Proximity &didMeasure, const TargetIdentifier &fromTarget)
Measure proximity to target, e.g. a sample of RSSI values from BLE peripheral.
Definition: sensor_delegate.h:171
void sensor(SensorType sensor, const Proximity &didMeasure, const TargetIdentifier &fromTarget, const PayloadData &withPayload)
Measure proximity to target with payload data. Combines didMeasure and didRead into a single convenie...
Definition: sensor_delegate.h:196
void sensor(SensorType sensor, const ImmediateSendData &didReceive, const TargetIdentifier &fromTarget)
Receive written immediate send data from target, e.g. important timing signal.
Definition: sensor_delegate.h:147
void sensor(SensorType sensor, const DataSections< 8 > &didShare, const TargetIdentifier &fromTarget)
Read payload data of other targets recently acquired by a target, e.g. Android peripheral sharing pay...
Definition: sensor_delegate.h:159
Represents a fixed array of Data references using the default memory arena that tracks its own in-use...
Definition: data.h:513
Definition: location.h:18
Definition: payload_data.h:13
Definition: target_identifier.h:17
SensorType
Sensor type as qualifier for target identifier.
Definition: sensor_type.h:14
SensorState
Definition: sensor_state.h:11
Acts as a non-global memory arena for arbitrary classes.
Definition: aggregates.h:15
Definition: sensor_delegate.h:70
Definition: proximity.h:17