MADARA  3.1.8
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 #include "ace/Thread_Mutex.h"
21 #include "ace/Recursive_Thread_Mutex.h"
22 #include "ace/Condition_T.h"
23 #include "ace/Guard_T.h"
24 
26 #include "madara/MADARA_export.h"
27 #include "ace/High_Res_Timer.h"
29 
30 #include "ReducedMessageHeader.h"
33 
34 #ifdef _USE_CID_
35 
36 #include "madara/cid/CIDSettings.h"
37 #include "madara/cid/CIDConvenience.h"
38 #include "madara/cid/CIDHeuristic.h"
39 #include "madara/cid/CIDGenetic.h"
40 #include "madara/utility/Utility.h"
41 
42 #endif // _USE_CID_
43 
48 
49 namespace madara
50 {
51  namespace transport
52  {
53  typedef ACE_Condition <ACE_Thread_Mutex> Condition;
54 
62  class MADARA_Export Base
63  {
64  public:
68  typedef std::vector <std::string> HostsVector;
69 
76  Base (const std::string & id, TransportSettings & new_settings,
78 
82  virtual ~Base ();
83 
87  int validate_transport (void);
88 
92  virtual int setup (void);
93 
97  int check_transport (void);
98 
103  TransportSettings & settings (void);
104 
105 #ifdef _USE_CID_
106 
111  virtual long start_latency (void)
112  {
113  if (!settings_.latency_enabled)
114  {
116  DLINFO "SpliceDDSTransport::start_latency:" \
117  " Latency enabled is not set in your"
118  " madara::transport::TransportSettings instance. Update your"
119  " program's code and set settings.latency_enabled = true.\n"));
120 
121  return -2;
122  }
123  return check_transport ();
124  }
125 
130  virtual long vote (void)
131  {
132  if (!settings_.latency_enabled)
133  {
135  DLINFO "SpliceDDSTransport::vote:" \
136  " Latency enabled is not set in your"
137  " madara::transport::TransportSettings instance. Update your"
138  " program's code and set settings.latency_enabled = true.\n"));
139 
140  return -2;
141  }
142  return check_transport ();
143  }
144 
145 #endif //_USE_CID_
146 
158  long prep_send (const madara::knowledge::KnowledgeRecords & orig_updates,
159  const char * print_prefix);
160 
166  virtual long send_data (const madara::knowledge::KnowledgeRecords &) = 0;
167 
171  void invalidate_transport (void);
172 
176  virtual void close (void);
177 
178  protected:
179  volatile bool is_valid_;
180  volatile bool shutting_down_;
181  HostsVector hosts;
182  ACE_Thread_Mutex mutex_;
183  Condition valid_setup_;
184 
187 
189 
190  // context for knowledge base
192 
193 #ifndef _MADARA_NO_KARL_
194  madara::expression::ExpressionTree on_data_received_;
196 
197 #endif // _MADARA_NO_KARL_
198 
201 
204 
207 
210  };
211 
243  int MADARA_Export process_received_update (
244  const char * buffer,
245  uint32_t bytes_read,
246  const std::string & id,
248  const QoSTransportSettings & settings,
249  BandwidthMonitor & send_monitor,
250  BandwidthMonitor & receive_monitor,
251  knowledge::KnowledgeMap& rebroadcast_records,
252 #ifndef _MADARA_NO_KARL_
253 
254  knowledge::CompiledExpression & on_data_received,
255 #endif // _MADARA_NO_KARL_
256 
257  const char * print_prefix,
258  const char * remote_host,
259  MessageHeader *& header
260  );
261 
276  int MADARA_Export prep_rebroadcast (
278  char * buffer,
279  int64_t & buffer_remaining,
280  const QoSTransportSettings & settings,
281  const char * print_prefix,
282  MessageHeader * header,
283  const knowledge::KnowledgeMap& records,
284  PacketScheduler & packet_scheduler);
285 
287  }
288 }
289 
290 #include "Transport.inl"
291 
292 #endif // _MADARA_TRANSPORT_H_
volatile bool is_valid_
Definition: Transport.h:179
QoSTransportSettings settings_
Definition: Transport.h:188
utility::ThreadSafeVector< Base * > Transports
Definition: Transport.h:286
#define DLINFO
Definition: LogMacros.h:27
Encapsulates a MADARA KaRL expression into an evaluatable tree.
This class stores variables and their values for use by any entity needing state information in a thr...
Provides scheduler for dropping packets.
MADARA_Export utility::Refcounter< logger::Logger > global_logger
ACE_Thread_Mutex mutex_
Definition: Transport.h:182
Holds basic transport settings.
Compiled, optimized KaRL logic.
BandwidthMonitor receive_monitor_
monitor for receiving bandwidth usage
Definition: Transport.h:203
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
::std::map< std::string, KnowledgeRecord * > KnowledgeRecords
volatile bool shutting_down_
Definition: Transport.h:180
::std::map< std::string, KnowledgeRecord > KnowledgeMap
ACE_Condition< ACE_Thread_Mutex > Condition
Definition: Transport.h:53
const std::string id_
host:port identifier of this process
Definition: Transport.h:186
static constexpr struct madara::knowledge::tags::string_t string
int MADARA_Export 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:112
Container for quality-of-service settings.
int MADARA_Export 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:740
Provides monitoring capability of a transport&#39;s bandwidth.
PacketScheduler packet_scheduler_
scheduler for dropping packets to simulate network issues
Definition: Transport.h:206
std::vector< std::string > HostsVector
Used to define a vector of hosts to contact.
Definition: Transport.h:68
Copyright (c) 2015 Carnegie Mellon University.
madara::utility::ScopedArray< char > buffer_
buffer for sending
Definition: Transport.h:209
Defines a robust message header which is the default for KaRL messages.
Definition: MessageHeader.h:56
Base class from which all transports must be derived.
Definition: Transport.h:62
BandwidthMonitor send_monitor_
monitor for sending bandwidth usage
Definition: Transport.h:200
madara::knowledge::ThreadSafeContext & context_
Definition: Transport.h:191