mux.hpp
Go to the documentation of this file.
1 
6 /*****************************************************************************
7 ** Ifdefs
8 *****************************************************************************/
9 
10 #ifndef mm_mux_demux_MUX_HPP_
11 #define mm_mux_demux_MUX_HPP_
12 
13 /*****************************************************************************
14 ** Includes
15 *****************************************************************************/
16 
17 #include <map>
18 #include <memory>
19 #include <string>
20 #include <mm_messages.hpp>
21 
22 /*****************************************************************************
23 ** Namespaces
24 *****************************************************************************/
25 
26 namespace mm_mux_demux {
27 namespace impl {
28 
29 /*****************************************************************************
30  ** Interfaces
31  *****************************************************************************/
32 
33 class MessageMux {
34 public:
35  MessageMux(const std::string& name,
36  const std::string& url,
38  const bool bind = true
39  );
40  ~MessageMux();
41  int send(const unsigned int& id, const mm_messages::ByteArray& msg_buffer);
42 
43 private:
44  std::string name, url;
47 };
48 
49 } // namespace impl
50 } // mm_mux_demux
51 
52 /*****************************************************************************
53 ** Namespaces
54 *****************************************************************************/
55 
56 namespace mm_mux_demux {
57 
58 /*****************************************************************************
59 ** Interfaces
60 *****************************************************************************/
61 
62 class MessageMux {
63 public:
64  typedef std::map<std::string, std::shared_ptr<impl::MessageMux>> MuxMap;
65  typedef std::pair<std::string, std::shared_ptr<impl::MessageMux>> MuxMapPair;
66  typedef std::map<std::string, std::shared_ptr<impl::MessageMux>>::iterator MuxMapIterator;
67  typedef std::map<std::string, std::shared_ptr<impl::MessageMux>>::const_iterator MuxMapConstIterator;
68 
69  enum Errors {
70  NotAvailable = -1 // when you try to connect to <name>, but <name> has not yet been started
71  };
72  static void start(const std::string& name,
73  const std::string& url,
75  const bool bind = true
76  );
77  static void shutdown(const std::string& name); // shutdown only this mux
78  static void shutdown(); // shutdown all muxes
79  static MuxMap& multiplexers();
80  static int send(const std::string& name, const unsigned int& id, const mm_messages::ByteArray& msg_buffer);
81 };
82 
83 } // namespace mm_mux_demux
84 
85 #endif /* mm_mux_demux_MUX_HPP_ */
MessageMux(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET, const bool bind=true)
Definition: mux.cpp:29
std::pair< std::string, std::shared_ptr< impl::MessageMux > > MuxMapPair
Definition: mux.hpp:65
int send(const unsigned int &id, const mm_messages::ByteArray &msg_buffer)
Definition: mux.cpp:68
mm_messages::Verbosity::Level verbosity
Definition: mux.hpp:46
std::map< std::string, std::shared_ptr< impl::MessageMux > > MuxMap
Definition: mux.hpp:64
std::map< std::string, std::shared_ptr< impl::MessageMux > >::const_iterator MuxMapConstIterator
Definition: mux.hpp:67
std::vector< unsigned char > ByteArray
std::map< std::string, std::shared_ptr< impl::MessageMux > >::iterator MuxMapIterator
Definition: mux.hpp:66


mm_mux_demux
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:52:14