MADARA  3.4.1
Transport.h
Go to the documentation of this file.
1 #ifndef _MADARA_TRANSPORT_H_
2 #define _MADARA_TRANSPORT_H_
3 
16 #include <string>
17 #include <sstream>
18 #include <vector>
19 #include <ostream>
20 
22 #include "madara/MadaraExport.h"
24 
25 #include "ReducedMessageHeader.h"
28 
33 
34 namespace madara
35 {
36 namespace transport
37 {
45 class MADARA_EXPORT Base
46 {
47 public:
51  typedef std::vector<std::string> HostsVector;
52 
59  Base(const std::string& id, TransportSettings& new_settings,
61 
65  virtual ~Base() = 0;
66 
70  int validate_transport(void);
71 
75  virtual int setup(void);
76 
80  int check_transport(void);
81 
86  TransportSettings& settings(void);
87 
99  long prep_send(const knowledge::KnowledgeMap& orig_updates,
100  const char* print_prefix);
101 
112  virtual long send_data(const knowledge::KnowledgeMap&) = 0;
113 
117  void invalidate_transport(void);
118 
122  virtual void close(void);
123 
124 protected:
125  volatile bool is_valid_;
126  volatile bool shutting_down_;
128 
131 
133 
134  // context for knowledge base
136 
137 #ifndef _MADARA_NO_KARL_
140 
141 #endif // _MADARA_NO_KARL_
142 
145 
148 
151 
154 
156  uint64_t last_toi_sent_ = 0;
157 };
158 
190 int MADARA_EXPORT process_received_update(const char* buffer,
191  uint32_t bytes_read, const std::string& id,
192  knowledge::ThreadSafeContext& context, const QoSTransportSettings& settings,
193  BandwidthMonitor& send_monitor, BandwidthMonitor& receive_monitor,
194  knowledge::KnowledgeMap& rebroadcast_records,
195 #ifndef _MADARA_NO_KARL_
196 
197  knowledge::CompiledExpression& on_data_received,
198 #endif // _MADARA_NO_KARL_
199 
200  const char* print_prefix, const char* remote_host, MessageHeader*& header);
201 
216 int MADARA_EXPORT prep_rebroadcast(knowledge::ThreadSafeContext& context,
217  char* buffer, int64_t& buffer_remaining,
218  const QoSTransportSettings& settings, const char* print_prefix,
219  MessageHeader* header, const knowledge::KnowledgeMap& records,
220  PacketScheduler& packet_scheduler);
221 
227 inline std::string MADARA_EXPORT get_operation_type(int type)
228 {
229  if (type == 0)
230  {
231  return "IDLE_OPERATION";
232  }
233  else if (type == 1)
234  {
235  return "SENDING_OPERATION";
236  }
237  else if (type == 2)
238  {
239  return "RECEIVING_OPERATION";
240  }
241  else if (type == 3)
242  {
243  return "REBROADCASTING_OPERATION";
244  }
245  else
246  {
247  return "UNKNOWN_OPERATION";
248  }
249 }
250 
252 }
253 }
254 
255 #include "Transport.inl"
256 
257 #endif // _MADARA_TRANSPORT_H_
Encapsulates a MADARA KaRL expression into an evaluatable tree.
Compiled, optimized KaRL logic.
This class stores variables and their values for use by any entity needing state information in a thr...
Provides monitoring capability of a transport's bandwidth.
Base class from which all transports must be derived.
Definition: Transport.h:46
madara::utility::ScopedArray< char > buffer_
buffer for sending
Definition: Transport.h:153
QoSTransportSettings settings_
Definition: Transport.h:132
volatile bool is_valid_
Definition: Transport.h:125
madara::knowledge::ThreadSafeContext & context_
Definition: Transport.h:135
const std::string id_
host:port identifier of this process
Definition: Transport.h:130
volatile bool shutting_down_
Definition: Transport.h:126
std::vector< std::string > HostsVector
Used to define a vector of hosts to contact.
Definition: Transport.h:51
virtual long send_data(const knowledge::KnowledgeMap &)=0
Sends a list of updates to the domain.
BandwidthMonitor send_monitor_
monitor for sending bandwidth usage
Definition: Transport.h:144
PacketScheduler packet_scheduler_
scheduler for dropping packets to simulate network issues
Definition: Transport.h:150
BandwidthMonitor receive_monitor_
monitor for receiving bandwidth usage
Definition: Transport.h:147
madara::expression::ExpressionTree on_data_received_
data received rules, defined in Transport settings
Definition: Transport.h:139
Defines a robust message header which is the default for KaRL messages.
Definition: MessageHeader.h:57
Provides scheduler for dropping packets.
Container for quality-of-service settings.
Holds basic transport settings.
Manages a thread safe STL vector.
constexpr string_t string
::std::map< std::string, KnowledgeRecord > KnowledgeMap
utility::ThreadSafeVector< Base * > Transports
Definition: Transport.h:251
std::string MADARA_EXPORT get_operation_type(int type)
Return the type of operation (usually from TransportContext)
Definition: Transport.h:227
int process_received_update(const char *buffer, uint32_t bytes_read, const std::string &id, knowledge::ThreadSafeContext &context, const QoSTransportSettings &settings, BandwidthMonitor &send_monitor, BandwidthMonitor &receive_monitor, knowledge::KnowledgeMap &rebroadcast_records, knowledge::CompiledExpression &on_data_received, const char *print_prefix, const char *remote_host, MessageHeader *&header)
Processes a received update, updates monitors, fills rebroadcast records according to settings filter...
Definition: Transport.cpp:109
int prep_rebroadcast(knowledge::ThreadSafeContext &context, char *buffer, int64_t &buffer_remaining, const QoSTransportSettings &settings, const char *print_prefix, MessageHeader *header, const knowledge::KnowledgeMap &records, PacketScheduler &packet_scheduler)
Preps a buffer for rebroadcasting records to other agents on the network.
Definition: Transport.cpp:791
Copyright(c) 2020 Galois.