MADARA  3.4.1
TransportSettings.h
Go to the documentation of this file.
1 #ifndef _MADARA_TRANSPORT_SETTINGS_H_
2 #define _MADARA_TRANSPORT_SETTINGS_H_
3 
16 #include <string>
17 #include <sstream>
18 #include <vector>
19 #include <map>
20 #include <ostream>
21 
22 #include "madara/LockType.h"
27 #include "madara/MadaraExport.h"
29 
30 namespace madara
31 {
32 namespace transport
33 {
34 // forward declare for friending
35 class Base;
36 
37 enum Types
38 {
40  SPLICE = 1,
41  NDDS = 2,
42  TCP = 3,
43  UDP = 4,
44  MULTICAST = 5,
45  BROADCAST = 6,
48  ZMQ = 9
49 };
50 
52 {
54  RELIABLE = 1
55 };
56 
58 {
59  ASSIGN = 0,
60  OPERATION = 1,
62  REGISTER = 3,
63  LATENCY = 10,
66  VOTE = 20
67 };
68 
74 MADARA_EXPORT std::string types_to_string(int id);
75 
79 class MADARA_EXPORT TransportSettings
80 {
81 public:
82  // allow transport::Base to alter private/protected members
83  friend class Base;
84 
86 #define DEFAULT_DOMAIN "KaRL"
87 
88  typedef std::vector<std::string> Voters;
89 
92  static const uint32_t DEFAULT_QUEUE_LENGTH = 500000;
93 
95  static const uint32_t DEFAULT_DEADLINE = 0;
96 
98  static const uint32_t DEFAULT_TRANSPORT = NO_TRANSPORT;
99 
101  static const uint32_t DEFAULT_RELIABILITY = RELIABLE;
102 
106 #define DEFAULT_ID 0
107 
111 #define DEFAULT_PROCESSES 1
112 
116 #define MAXIMUM_RESEND_ATTEMPTS 10
117 
119  TransportSettings() = default;
120 
122  TransportSettings(const TransportSettings& settings);
123 
124  virtual ~TransportSettings();
125 
127  void operator=(const TransportSettings& settings);
128 
133  void add_read_domain(const std::string & domain);
134 
144  void add_host(const std::string & host);
145 
152  void clear_hosts(void);
153 
157  void clear_read_domains(void);
158 
163  void get_read_domains(std::vector<std::string>& domains) const;
164 
170  bool is_reading_domain(const std::string domain) const;
171 
176  size_t num_read_domains(void) const;
177 
185  void debug_to_kb(const std::string& prefix = ".transport");
186 
192  virtual void load(
193  const std::string& filename, const std::string& prefix = "transport");
194 
200  virtual void load_text(
201  const std::string& filename, const std::string& prefix = "transport");
202 
208  virtual void save(const std::string& filename,
209  const std::string& prefix = "transport") const;
210 
216  virtual void save_text(const std::string& filename,
217  const std::string& prefix = "transport") const;
218 
220 
224  std::string write_domain = DEFAULT_DOMAIN;
225 
227  uint32_t read_threads = 1;
228 
238  uint32_t queue_length = DEFAULT_QUEUE_LENGTH;
239 
241  uint32_t type = DEFAULT_TRANSPORT;
242 
244  uint32_t max_fragment_size = 62000;
245 
247  int resend_attempts = MAXIMUM_RESEND_ATTEMPTS;
248 
257  uint32_t fragment_queue_length = 100;
258 
261  uint32_t reliability = DEFAULT_RELIABILITY;
262 
264  uint32_t id = DEFAULT_ID;
265 
267  uint32_t processes = DEFAULT_PROCESSES;
268 
271 
273  bool delay_launch = false;
274 
276  bool never_exit = false;
277 
279  bool send_reduced_message_header = false;
280 
283 
285  double slack_time = 0;
286 
291  double read_thread_hertz = 1000.0;
292 
300  double max_send_hertz = 0.0;
301 
308  std::vector<std::string> hosts;
309 
313  bool no_sending = false;
314 
318  bool no_receiving = false;
319 
325  bool send_history = false;
326 
330  std::string debug_to_kb_prefix = "";
331 
332 private:
336  std::map<std::string, int> read_domains_;
337 };
338 
339 inline std::string type_name(const TransportSettings& settings)
340 {
341  std::string name = "none";
342 
343  switch (settings.type)
344  {
345  case 0:
346  name = "None";
347  break;
348  case 1:
349  name = "PrismTech DDS";
350  break;
351  case 2:
352  name = "RTI DDS";
353  break;
354  case 3:
355  name = "TCP (unsupported)";
356  break;
357  case 4:
358  name = "UDP Unicast";
359  break;
360  case 5:
361  name = "UDP Multicast";
362  break;
363  case 6:
364  name = "UDP Broadcast";
365  break;
366  case 7:
367  name = "UDP P2P Registry Server";
368  break;
369  case 8:
370  name = "UDP P2P Registry Client";
371  break;
372  case 9:
373  name = "ZeroMQ Pub/Sub";
374  break;
375  }
376 
377  return name;
378 }
379 }
380 }
381 
382 #include "TransportSettings.inl"
383 
384 #endif // _MADARA_TRANSPORT_SETTINGS_H_
#define DEFAULT_ID
Default id in group.
#define MAXIMUM_RESEND_ATTEMPTS
Default number of processes in group.
#define DEFAULT_PROCESSES
Default number of processes in group.
#define DEFAULT_DOMAIN
Default knowledge domain.
Base class from which all transports must be derived.
Definition: Transport.h:46
Holds basic transport settings.
OriginatorFragmentMap fragment_map
Map of fragments received by originator.
TransportSettings()=default
Constructor for this class.
std::string on_data_received_logic
Logic to be evaluated after every successful update.
std::vector< std::string > hosts
Host information for transports that require it.
uint32_t type
Type of transport. See madara::transport::Types for options.
std::map< std::string, int > read_domains_
Any acceptable read domain is added here.
std::vector< std::string > Voters
constexpr string_t string
std::map< std::string, ClockFragmentMap > OriginatorFragmentMap
Map of originator to a map of clocks to fragments.
MADARA_EXPORT std::string types_to_string(int id)
Converts a transport type enum to a string equivalent.
std::string type_name(const TransportSettings &settings)
Copyright(c) 2020 Galois.