keyvalue/Service.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <swarmio/Mailbox.h>
8 #include <string>
9 #include <memory>
10 #include <mutex>
11 #include <map>
12 
14 {
20  class SWARMIO_API Service final : public Mailbox, public discovery::Discoverable
21  {
22  private:
23 
28  std::map<std::string, Target*> _targets;
29 
34  std::mutex _mutex;
35 
43  bool HandleGetRequest(const Node* sender, const data::Message* message);
44 
51  bool HandleSetRequest(const Node* sender, const data::Message* message);
52 
53  public:
54 
65  static ValueAwaiter Get(Endpoint* endpoint, const Node* node, const std::string& path);
66 
77  static ErrorAwaiter Set(Endpoint* endpoint, const Node* node, const std::string& path, const data::Variant& value);
78 
84  Service(Endpoint* endpoint)
85  : Mailbox(endpoint)
86  {
87  FinishConstruction();
88  }
89 
98  virtual bool ReceiveMessage(const Node* sender, const data::Message* message) override;
99 
108  void RegisterTarget(const std::string& path, Target* target);
109 
117  void UnregisterTarget(const std::string& path);
118 
126  virtual void DescribeService(data::discovery::Response& descriptor) override;
127  };
128 }
Abstract base class for registered keys.
Definition: Target.h:12
The Key-Value Service is responsible for getting and setting named values.
std::map< std::string, Target * > _targets
Key-target map.
std::mutex _mutex
Mutex to protect target list.
An Awaiter that checks whether the operation was a success.
Definition: ErrorAwaiter.h:11
Abstract base class for Endpoint implementations.
Definition: Endpoint.h:25
An Awaiter that returns the requested value.
Definition: ValueAwaiter.h:12
Interface for discoverable services.
Definition: Discoverable.h:12
Represents a Node the Endpoint knows about and can send messages to.
Service(Endpoint *endpoint)
Construct a new Service object.
Abstract base class for Mailbox implementations.
Definition: Mailbox.h:13


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:48