ValueAwaiter.cpp
Go to the documentation of this file.
2 #include <swarmio/Exception.h>
3 
4 using namespace swarmio;
5 using namespace swarmio::services;
6 using namespace swarmio::services::keyvalue;
7 
8 data::Variant ValueAwaiter::ExtractResponse(const Node* node, const data::Message* message)
9 {
10  if (message->content_case() == data::Message::ContentCase::kError)
11  {
12  // Ignore
13  if (message->error() != data::Error::NONE)
14  {
15  throw Exception("A remote error has occurred");
16  }
17  else
18  {
19  throw Exception("Unexpected acknowledge received");
20  }
21  }
22  else if (message->content_case() == data::Message::ContentCase::kKvGetResponse)
23  {
24  if (message->kv_get_response().key() == _key)
25  {
26  return message->kv_get_response().value();
27  }
28  else
29  {
30  throw Exception("Invalid key");
31  }
32  }
33  else
34  {
35  throw Exception("Invalid response type");
36  }
37 }
Exception class thrown by all library classes.
virtual data::Variant ExtractResponse(const Node *node, const data::Message *message) override
Called when a response for the original message has been received.
Definition: ValueAwaiter.cpp:8
std::string _key
The expected key in the telemetry response.
Definition: ValueAwaiter.h:20
Represents a Node the Endpoint knows about and can send messages to.


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