MADARA  3.4.1
UdpRegistryServer.cpp
Go to the documentation of this file.
3 
7 
8 #include <iostream>
9 
12  bool launch_transport)
13  : UdpTransport(id, context, config, false)
14 {
16  "domain." + config.write_domain + ".endpoints", knowledge_);
17 
18  if (launch_transport)
19  setup();
20 }
21 
23 {
24  // call base setup method to initialize certain common variables
25  int ret = UdpTransport::setup();
26 
27  server_count_ = addresses_.size();
28 
29  return ret;
30 }
31 
33  const madara::knowledge::KnowledgeMap& orig_updates)
34 {
35  if (!settings_.no_sending)
36  {
37  this->endpoints_.sync_keys();
38 
39  std::vector<std::string> hosts;
40  this->addresses_.resize(server_count_);
41  this->endpoints_.keys(hosts);
42 
43  for (auto& host : hosts)
44  {
45  auto addr_parts = utility::parse_address(std::move(host));
46  auto addr = ip::address::from_string(addr_parts.first);
47  addresses_.emplace_back(addr, addr_parts.second);
48 
50  "UdpRegistryServer::send_data:"
51  " adding %s:%d\n",
52  addresses_.back().address().to_string().c_str(),
53  addresses_.back().port());
54  }
55  }
56  return UdpTransport::send_data(orig_updates);
57 }
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
Definition: Logger.h:20
const ThreadSafeContext * context_
This class stores variables and their values for use by any entity needing state information in a thr...
void set_name(const std::string &var_name, KnowledgeBase &knowledge, bool sync=true)
Sets the variable name that this refers to.
Definition: Map.cpp:411
knowledge::KnowledgeBase knowledge_
knowledge base for threads to use
int setup() override
all subclasses should call this method at the end of its setup
Holds basic transport settings.
std::string write_domain
All class members are accessible to users for easy setup.
UdpRegistryServer(const std::string &id, madara::knowledge::ThreadSafeContext &context, TransportSettings &config, bool launch_transport)
Constructor.
int setup(void) override
all subclasses should call this method at the end of its setup
long send_data(const madara::knowledge::KnowledgeMap &updates) override
Sends a list of knowledge updates to listeners.
knowledge::containers::Map endpoints_
UDP-based transport for knowledge.
Definition: UdpTransport.h:39
long send_data(const madara::knowledge::KnowledgeMap &updates) override
Sends a list of knowledge updates to listeners.
constexpr string_t string
::std::map< std::string, KnowledgeRecord > KnowledgeMap
std::pair< std::string, uint16_t > parse_address(std::string addr)
Definition: Utility.cpp:797