UpdateAwaiter.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <chrono>
5 
7 {
12  class SWARMIO_API UpdateAwaiter final : public Awaiter<data::telemetry::Update>
13  {
14  private:
15 
20  const Node* _target;
21 
22  protected:
23 
30  virtual data::telemetry::Update ExtractResponse(const Node* node, const data::Message* message) override
31  {
32  if (message->content_case() == data::Message::ContentCase::kTmUpdate)
33  {
34  return message->tm_update();
35  }
36  else
37  {
38  throw Exception("Last update received is invalid");
39  }
40  }
41 
47  virtual bool IsFinished() override
48  {
49  return false;
50  }
51 
52  public:
53 
60  UpdateAwaiter(Endpoint* endpoint, uint64_t requestIdentifier, const Node* target)
61  : Awaiter(endpoint, requestIdentifier), _target(target)
62  {
63  FinishConstruction();
64  }
65 
71  virtual void MailboxWillBeDisconnected() noexcept override
72  {
73  // Send unsubscribe message
74  data::Message request;
75  request.mutable_tm_unsubscribe_request()->set_identifier(GetIdentifier());
76  GetEndpoint()->Send(&request, _target);
77 
78  // Call base implementation
80  }
81 
87  const Node* GetTarget() const
88  {
89  return _target;
90  }
91  };
92 }
A special mailbox that handles responses to a message.
Definition: Awaiter.h:19
UpdateAwaiter(Endpoint *endpoint, uint64_t requestIdentifier, const Node *target)
Construct a new UpdateAwaiter object.
Definition: UpdateAwaiter.h:60
virtual void MailboxWillBeDisconnected() noexceptoverride
On disconnect, an unsubscribe request is sent in order to stop the flow of messages gracefully...
Definition: UpdateAwaiter.h:71
Exception class thrown by all library classes.
virtual void MailboxWillBeDisconnected() noexcept
Called right before the mailbox is disconnected from its endpoint or if the attached endpoint is abou...
Definition: Mailbox.h:137
An Awaiter that has a longer lifetime and is updated periodically.
Definition: UpdateAwaiter.h:12
Abstract base class for Endpoint implementations.
Definition: Endpoint.h:25
const Node * GetTarget() const
Get target node.
Definition: UpdateAwaiter.h:87
virtual data::telemetry::Update ExtractResponse(const Node *node, const data::Message *message) override
Called when a response for the original message has been received.
Definition: UpdateAwaiter.h:30
virtual bool IsFinished() override
Telemetry update awaiters remain valid for their entire lifetime.
Definition: UpdateAwaiter.h:47
Represents a Node the Endpoint knows about and can send messages to.


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