MADARA  3.2.3
UdpRegistryServer.cpp
Go to the documentation of this file.
3 
7 
8 #include <iostream>
9 
12  TransportSettings & config, bool launch_transport)
13  : UdpTransport (id, context, config, false)
14 {
15  endpoints_.set_name ("domain." + config.write_domain + ".endpoints", knowledge_);
16 
17  if (launch_transport)
18  setup ();
19 }
20 
21 int
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 
32 long
34  const madara::knowledge::VariableReferenceMap & orig_updates)
35 {
36  if (!settings_.no_sending)
37  {
38  this->endpoints_.sync_keys ();
39 
40  std::vector <std::string> hosts;
41  this->addresses_.resize (server_count_);
42  this->endpoints_.keys (hosts);
43 
44  for (auto &host : hosts)
45  {
46  auto addr_parts = utility::parse_address (std::move(host));
47  auto addr = ip::address::from_string (addr_parts.first);
48  addresses_.emplace_back (addr, addr_parts.second);
49 
51  "UdpRegistryServer::send_data:" \
52  " adding %s:%d\n",
53  addresses_.back ().address ().to_string ().c_str (),
54  addresses_.back ().port ());
55  }
56  }
57  return UdpTransport::send_data (orig_updates);
58 }
knowledge::KnowledgeBase knowledge_
knowledge base for threads to use
QoSTransportSettings settings_
Definition: Transport.h:133
std::pair< std::string, uint16_t > parse_address(std::string addr)
Definition: Utility.cpp:789
void keys(std::vector< std::string > &curkeys) const
Returns the keys within the map.
Definition: Map.cpp:516
This class stores variables and their values for use by any entity needing state information in a thr...
std::vector< std::string > sync_keys(void)
Syncs the keys from the knowledge base.
Definition: Map.cpp:225
Holds basic transport settings.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
Definition: Logger.h:20
int setup(void) override
all subclasses should call this method at the end of its setup
knowledge::containers::Map endpoints_
static struct madara::knowledge::tags::string_t string
std::string write_domain
All class members are accessible to users for easy setup.
long send_data(const madara::knowledge::VariableReferenceMap &updates) override
Sends a list of knowledge updates to listeners.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, bool sync=true)
Sets the variable name that this refers to.
Definition: Map.cpp:415
bool no_sending
if true, never send over transport
UdpRegistryServer(const std::string &id, madara::knowledge::ThreadSafeContext &context, TransportSettings &config, bool launch_transport)
Constructor.
std::vector< udp::endpoint > addresses_
holds all multicast addresses we are sending to
std::map< const char *, VariableReference, VariableReferenceMapCompare > VariableReferenceMap
a map of variable references
int setup() override
all subclasses should call this method at the end of its setup
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
UDP-based transport for knowledge.
Definition: UdpTransport.h:37
long send_data(const madara::knowledge::VariableReferenceMap &updates) override
Sends a list of knowledge updates to listeners.
madara::knowledge::ThreadSafeContext & context_
Definition: Transport.h:136