Loop.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <mutex>
5 #include <replxx.hxx>
6 #include <swarmio/tool/Command.h>
11 #include <swarmio/data/Variant.pb.h>
12 
13 namespace swarmio::tool
14 {
19  class Loop final : private profiles::ClientProfile
20  {
21  private:
22 
27  replxx::Replxx _repl;
28 
33  const Node* _selectedNode = nullptr;
34 
39  LogBuffer* _logBuffer = nullptr;
40 
46  std::string GetPrompt();
47 
52  std::vector<const Node*> _nodes;
53 
58  std::list<services::telemetry::UpdateAwaiter> _subscriptions;
59 
64  std::mutex _mutex;
65 
71  virtual void NodeWasDiscovered(const Node* node) noexcept override;
72 
79  data::Variant ConvertToVariant(const std::string& value);
80 
87  bool ExecuteCommand(const std::string& command);
88 
94  void ExecuteMembersCommand(const Command& command);
95 
101  void ExecuteSelectCommand(const Command& command);
102 
108  void ExecutePingCommand(const Command& command);
109 
115  void ExecuteInfoCommand(const Command& command);
116 
122  void ExecuteEventCommand(const Command& command);
123 
129  void ExecuteSetCommand(const Command& command);
130 
136  void ExecuteGetCommand(const Command& command);
137 
143  void ExecuteRediscoverCommand(const Command& command);
144 
150  void ExecuteSubscriptionsCommand(const Command& command);
151 
157  void ExecuteSubscribeCommand(const Command& command);
158 
164  void ExecuteUnsubscribeCommand(const Command& command);
165 
171  void ExecuteLogCommand(const Command& command);
172 
173  public:
174 
181  Loop(Endpoint* endpoint, LogBuffer* logBuffer);
182 
187  void Run();
188  };
189 
190 }
The command line interface for the tool.
Definition: Loop.h:19
void ExecuteMembersCommand(const Command &command)
Execute a &#39;members&#39; command.
Definition: Loop.cpp:319
std::vector< const Node * > _nodes
Nodes and their indices.
Definition: Loop.h:52
std::mutex _mutex
Mutex to protect nodes vector.
Definition: Loop.h:64
void ExecuteSetCommand(const Command &command)
Execute an &#39;set&#39; command.
Definition: Loop.cpp:201
void ExecuteEventCommand(const Command &command)
Execute an &#39;event&#39; command.
Definition: Loop.cpp:273
Loop(Endpoint *endpoint, LogBuffer *logBuffer)
Construct a new Loop object.
Definition: Loop.cpp:17
std::list< services::telemetry::UpdateAwaiter > _subscriptions
Currently held subscriptions.
Definition: Loop.h:58
void ExecuteLogCommand(const Command &command)
Execute an &#39;log&#39; command.
Definition: Loop.cpp:458
void ExecutePingCommand(const Command &command)
Execute a &#39;ping&#39; command.
Definition: Loop.cpp:236
std::string GetPrompt()
Build prompt string.
Definition: Loop.cpp:33
void ExecuteGetCommand(const Command &command)
Execute an &#39;get&#39; command.
Definition: Loop.cpp:152
const Node * _selectedNode
Selected node.
Definition: Loop.h:33
void Run()
Run the command loop.
Definition: Loop.cpp:45
Abstract base class for Endpoint implementations.
Definition: Endpoint.h:25
void ExecuteSelectCommand(const Command &command)
Execute a &#39;select&#39; command.
Definition: Loop.cpp:339
LogBuffer * _logBuffer
Log buffer.
Definition: Loop.h:39
bool ExecuteCommand(const std::string &command)
Execute a command given by the user.
Definition: Loop.cpp:473
void ExecuteSubscribeCommand(const Command &command)
Execute a &#39;subscribe&#39; command.
Definition: Loop.cpp:410
void ExecuteRediscoverCommand(const Command &command)
Execute an &#39;rediscover&#39; command.
Definition: Loop.cpp:146
data::Variant ConvertToVariant(const std::string &value)
Convert a string parameter to a variant.
Definition: Loop.cpp:572
replxx::Replxx _repl
REPL interface.
Definition: Loop.h:27
void ExecuteSubscriptionsCommand(const Command &command)
Execute a &#39;subscriptions&#39; command.
Definition: Loop.cpp:371
void ExecuteInfoCommand(const Command &command)
Execute an &#39;info&#39; command.
Definition: Loop.cpp:82
Represents a Node the Endpoint knows about and can send messages to.
Parser for commands of the default form.
Definition: Command.h:15
void ExecuteUnsubscribeCommand(const Command &command)
Execute an &#39;unsubscribe&#39; command.
Definition: Loop.cpp:443
Service profile for non-member clients.
Definition: ClientProfile.h:12
virtual void NodeWasDiscovered(const Node *node) noexceptoverride
Called when a new Node has been discovered.
Definition: Loop.cpp:25


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