GAMS  1.4.0
OscUdp.h
Go to the documentation of this file.
1 
15 #ifndef _GAMS_UTILITY_OSC_HELPER_H_
16 #define _GAMS_UTILITY_OSC_HELPER_H_
17 
18 #ifdef _GAMS_OSC_
19 
20 #include <memory>
21 #include <map>
22 #include <vector>
23 #include <string>
24 
25 #include "madara/transport/udp/UdpTransport.h"
26 #include "madara/transport/multicast/MulticastTransport.h"
27 #include "madara/transport/broadcast/BroadcastTransport.h"
28 #include "madara/utility/EpochEnforcer.h"
29 
30 #include "madara/knowledge/KnowledgeRecord.h"
31 
32 #include "gams/GamsExport.h"
34 
35 #include "osc/OscReceivedElements.h"
36 
37 namespace gams
38 {
39  namespace utility
40  {
41  class GAMS_EXPORT OscUdp
42  {
43  private:
45  std::shared_ptr<madara::transport::UdpTransport> transport_ = 0;
46 
48  madara::transport::QoSTransportSettings settings_;
49 
51  madara::knowledge::KnowledgeBase kb_;
52 
54  madara::utility::ScopedArray<char> buffer_ =
55  new char[64000];
56 
57  public:
58  typedef std::map<std::string,
59  madara::knowledge::KnowledgeRecord> OscMap;
60 
64  OscUdp() = default;
65 
66  ~OscUdp()
67  {
68  // force transport to clear first then kb should clean
69  transport_ = 0;
70  }
71 
78  size_t pack (void* buffer, size_t size, const OscMap& map);
79 
86  void unpack (void* buffer, size_t size, OscMap & map);
87 
91  inline bool has_socket (void)
92  {
93  return transport_.get() != 0;
94  }
95 
102  void create_socket (
103  madara::transport::QoSTransportSettings& settings);
104 
111  int receive (OscMap & values, double max_wait_seconds = 0.5);
112 
118  int send (const OscMap & values);
119 
120 
121  void process_bundle(const osc::ReceivedBundle& b, OscMap & map);
122  void process_message(const osc::ReceivedMessage& m, OscMap & map);
123  };
124  }
125 }
126 
127 #endif // #ifdef _GAMS_OSC_
128 #endif // _GAMS_UTILITY_OSC_HELPER_H_
#define GAMS_EXPORT
Definition: GamsExport.h:20
Contains all GAMS-related tools, classes and code.