herald  2.0.0
activities.h
1 // Copyright 2021 Herald Project Contributors
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #ifndef HERALD_ACTIVITIES_H
6 #define HERALD_ACTIVITIES_H
7 
8 #include "../context.h"
9 #include "../datatype/data.h"
10 #include "../datatype/target_identifier.h"
11 
12 #include <memory>
13 #include <functional>
14 #include <optional>
15 #include <tuple>
16 
17 namespace herald {
18 namespace engine {
19 
20 using namespace herald::datatype;
21 
22 // Types used in coordination of Herald sensor activities
23 
26 
28 namespace Features {
30  static FeatureTag HeraldBluetoothProtocolConnection = herald::datatype::Data(std::byte(0x01),1);
31 }
32 
34 using Priority = std::uint8_t;
35 
40 namespace Priorities {
41  constexpr Priority Critical(200);
42  constexpr Priority High(150);
43  constexpr Priority Default(100);
44  constexpr Priority Low(50);
45 }
46 
47 struct Activity; // fwd decl
48 
52 using Prerequisite = std::tuple<FeatureTag,std::optional<TargetIdentifier>>;
54 using PrioritisedPrerequisite = std::tuple<FeatureTag,Priority,std::optional<TargetIdentifier>>;
55 
56 
57 // THE FOLLOWING IS FOR PLATFORMS WITH CALLBACK / STD::ASYNC+STD::FUTURE SUPPORT
59 //using ConnectionCallback = std::function<void(const std::vector<PrioritisedPrerequisite> connectedTo)>;
60 
62 //using CompletionCallback = std::function<void(const Activity,std::optional<Activity>)>; // function by value
63 
65 //using ActivityFunction = std::function<void(const Activity,CompletionCallback)>; // function by value
66 
67 // THE FOLLOWING IS FOR PLATFORMS WITHOUT STD::ASYNC SUPPORT (i.e. that are SYNC ONLY)
68 
70 using ActivityFunction = std::function<std::optional<Activity>(const Activity)>;
71 
72 // END RESULTS ONLY PLATFORMS
73 
75 struct Activity {
80  std::string name;
82  std::vector<Prerequisite> prerequisites; // no target id means all that are connected
85 };
86 
94 public:
95  CoordinationProvider() = default;
96  virtual ~CoordinationProvider() = default;
97 
98  // Coordination methods - Since v1.2-beta3
100  virtual std::vector<FeatureTag> connectionsProvided() = 0;
101 
105  virtual std::vector<PrioritisedPrerequisite> provision(const std::vector<PrioritisedPrerequisite>& requested) = 0;
106 
107  // Runtime coordination callbacks
109  virtual std::vector<PrioritisedPrerequisite> requiredConnections() = 0;
111  virtual std::vector<Activity> requiredActivities() = 0;
112 };
113 
114 }
115 }
116 
117 #endif
The main data workhorse class of the Herald API.
Definition: data.h:33
Coordination management class that arranges Sensor's periodic requirements and activity interdependen...
Definition: activities.h:93
virtual std::vector< PrioritisedPrerequisite > requiredConnections()=0
Get a list of what connections are required to which devices now (may start, maintain,...
virtual std::vector< FeatureTag > connectionsProvided()=0
What connections does this Sensor type provide for Coordination.
virtual std::vector< Activity > requiredActivities()=0
Get a list of activities that are currently outstanding in this iteration.
virtual std::vector< PrioritisedPrerequisite > provision(const std::vector< PrioritisedPrerequisite > &requested)=0
Runtime connection provisioning (if it isn't requested, it can be closed)
Contains all low-level Herald datatype implementations.
Definition: base64_string.h:14
DataRef<> Data
Defaults references to Data to equal the DataRef with the default Memory Arena dimensions,...
Definition: data.h:506
std::tuple< FeatureTag, Priority, std::optional< TargetIdentifier > > PrioritisedPrerequisite
a Presrequisite with a relative priority assigned to assist Herald to prioritise effectively.
Definition: activities.h:54
std::tuple< FeatureTag, std::optional< TargetIdentifier > > Prerequisite
An absolute prerequisite required before an activity can take place.
Definition: activities.h:52
std::function< std::optional< Activity >(const Activity)> ActivityFunction
A convenience Function alias that invokes an activity and optionally returns a follow-on activity.
Definition: activities.h:70
std::uint8_t Priority
A relative priority between different activities.
Definition: activities.h:34
Acts as a non-global memory arena for arbitrary classes.
Definition: aggregates.h:15
An activity that needs to be performed due to some state being achieved in a Sensor.
Definition: activities.h:75
std::string name
A human readable name for this activity used for logging.
Definition: activities.h:80
ActivityFunction executor
The Activity function to call when all prerequisites have been met. May not be called.
Definition: activities.h:84
std::vector< Prerequisite > prerequisites
A list of non-prioritised pre-requisities (priority is taken from the priority field in Activity).
Definition: activities.h:82
Priority priority
The relative priority for this Activity compared to the scale.
Definition: activities.h:78