8 #include <swarmio/data/Variant.pb.h> 11 #include <shared_mutex> 29 std::map<std::string, data::Variant>
_values;
83 std::map<const Node*, data::telemetry::Status>
_reports;
97 virtual void Update() override final;
111 std::list<std::string> emptyList;
112 return Subscribe(endpoint, node, interval, emptyList);
124 static UpdateAwaiter Subscribe(
Endpoint* endpoint,
const Node* node, uint32_t interval,
const std::list<std::string>& keys);
132 Service(
Endpoint* endpoint, std::chrono::milliseconds period = std::chrono::milliseconds(10))
135 FinishConstruction();
144 void SetValue(
const std::string& key,
const data::Variant& value)
146 std::unique_lock<std::shared_timed_mutex> guard(_valuesMutex);
147 _values[key] = value;
157 std::unique_lock<std::shared_timed_mutex> guard(_valuesMutex);
169 std::unique_lock<std::shared_timed_mutex> guard(_schemaMutex);
170 (*_schema.mutable_fields())[key] = field;
173 _statusKeys.insert(key);
177 _statusKeys.erase(key);
188 std::unique_lock<std::shared_timed_mutex> guard(_schemaMutex);
189 _schema.mutable_fields()->erase(key);
190 _statusKeys.erase(key);
200 std::unique_lock<std::shared_timed_mutex> guard(_observersMutex);
201 _observers.insert(observer);
211 std::unique_lock<std::shared_timed_mutex> guard(_observersMutex);
212 _observers.erase(observer);
217 std::shared_lock<std::shared_timed_mutex> guard(_reportsMutex);
218 return _reports[node];
229 virtual bool ReceiveMessage(
const Node* sender,
const data::Message*
message)
override;
238 virtual void DescribeService(data::discovery::Response& descriptor)
override;
std::shared_timed_mutex _valuesMutex
Mutex to protect the map of values.
void RemoveValue(const std::string &key)
Remove a value from the local telemetry cache.
Telemetry Service can subscribe to receive updates from remote nodes on named values.
std::map< const Node *, data::telemetry::Status > _reports
Cached values for remote status reports.
void SetValue(const std::string &key, const data::Variant &value)
Add or update a value in the local telemetry cache.
void SetFieldDefinitionForKey(const std::string &key, const data::discovery::Field &field, bool includeInStatus)
Add field to the schema.
Interface for discovery observers.
A service that uses a periodic background worker to perform its work.
void UnregisterObserver(Observer *observer)
Unregister a status observer.
std::shared_timed_mutex _trackersMutex
Mutex to protect the list of trackers.
data::discovery::Schema _schema
Schema.
std::set< std::string > _statusKeys
List of keys to include in the status broadcast.
data::telemetry::Status GetCachedStatus(const Node *node)
An Awaiter that has a longer lifetime and is updated periodically.
std::shared_timed_mutex _observersMutex
Mutex to protect the list of observers.
Abstract base class for Endpoint implementations.
std::list< Tracker > _trackers
Trackers for each remote subscription.
std::shared_timed_mutex _schemaMutex
Mutex to protect the schema.
void RegisterObserver(Observer *observer)
Register a new status observer.
void RemoveFieldDefinitionForKey(const std::string &key)
Remove a field from the schema.
Service(Endpoint *endpoint, std::chrono::milliseconds period=std::chrono::milliseconds(10))
Construct a new Service object.
Interface for discoverable services.
std::map< std::string, data::Variant > _values
List of published telemetry values.
std::set< Observer * > _observers
List of observers.
Represents a Node the Endpoint knows about and can send messages to.
std::shared_timed_mutex _reportsMutex
Mutex to protect remote status reports.