TimingAwaiter.cpp
Go to the documentation of this file.
2 #include <swarmio/Exception.h>
3 #include <cstdio>
4 
5 using namespace swarmio;
6 using namespace swarmio::services;
7 using namespace swarmio::services::ping;
8 
9 std::chrono::nanoseconds TimingAwaiter::ExtractResponse(const Node* node, const data::Message* message)
10 {
11  if (message->content_case() == data::Message::ContentCase::kEcho)
12  {
13  auto now = std::chrono::high_resolution_clock::now();
14  return std::chrono::duration_cast<std::chrono::nanoseconds>(now - _start);
15  }
16  else
17  {
18  throw Exception("Invalid response type");
19  }
20 }
21 
23 {
24  std::chrono::duration<double, std::milli> response = GetResponse();
25  return response.count();
26 }
double GetResponseInMilliseconds()
Translate the precise response to a floating point number of milliseconds.
Exception class thrown by all library classes.
std::chrono::nanoseconds GetResponse()
Get the response value. Will throw an exception if called before the response is received.
Definition: Awaiter.h:127
virtual std::chrono::nanoseconds ExtractResponse(const Node *node, const data::Message *message) override
Called when a response for the original message has been received.
Represents a Node the Endpoint knows about and can send messages to.
std::chrono::time_point< std::chrono::high_resolution_clock > _start
When the ping request was sent.
Definition: TimingAwaiter.h:20


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