mm_pubsub.cpp
Go to the documentation of this file.
1 
6 /*****************************************************************************
7 ** Includes
8 *****************************************************************************/
9 
14 #include <ecl/time.hpp>
16 #include <mm_core_msgs/string.hpp>
17 #include <string>
18 #include "../../include/mm_mux_demux/publisher.hpp"
19 #include "../../include/mm_mux_demux/demux.hpp"
20 #include "../../include/mm_mux_demux/subscriber.hpp"
21 
22 /*****************************************************************************
23 ** Methods
24 *****************************************************************************/
25 
26 void foo(std::string data) {
27  std::cout << "foo is processing data: " << data << std::endl;
28 }
29 /*****************************************************************************
30 ** Main
31 *****************************************************************************/
32 
33 int main(int argc, char **argv)
34 {
35  /****************************************
36  ** Args
37  ****************************************/
38  ecl::CmdLine cmd("Pub-sub testing with nanomsg.");
39  ecl::SwitchArg pub("p", "pub", "Run the publisher only", false);
40  ecl::SwitchArg sub("s", "sub", "Run the subscriber only", false);
41  ecl::SwitchArg both("b", "both", "Run both the publisher and the subscriber", false);
42  std::vector<ecl::Arg*> xorlist;
43  xorlist.push_back(&pub);
44  xorlist.push_back(&sub);
45  xorlist.push_back(&both);
46  cmd.xorAdd(xorlist);
47  ecl::UnlabeledValueArg<std::string> ip("ip","Ip to use (e.g. ipc:///tmp/pubsub.ipc, tcp://192.168.1.3:5555)", false,"ipc:///tmp/pubsub.ipc","string", cmd);
48  cmd.parse(argc, argv);
49 
50  //bool result = mm_messages::MessageRegistry::add<mm_core_msgs::TestStrings, std::string>("unused_description");
51  if ( pub.isSet() ) {
53  std::cout << "Creating publisher" << std::endl;
54  mm_mux_demux::Publisher publisher("dude");
55  ecl::MilliSleep()(200); // let the connection establish itself
56  while(true) {
57  std::cout << "Publishing 'dude'" << std::endl;
58  publisher.publish(mm_core_msgs::TestStrings, std::string("dude"));
59  ecl::MilliSleep()(500);
60  }
61  } else if ( sub.isSet() ) {
63  std::cout << "Creating demux"<< std::endl;
65  while(true) {
66  ecl::MilliSleep()(200);
67  }
69  } else if ( both.isSet() ) {
73  mm_mux_demux::Publisher publisher("dude");
74  ecl::MilliSleep()(200); // let the connection establish itself
75  publisher.publish(mm_core_msgs::TestStrings, std::string("dude"));
76  ecl::MilliSleep()(500);
78  } else {
79  // should never get here because tclap will throw up the usage page.
80  }
81  return 0;
82 }
void publish(const unsigned int &id, const T &msg)
static void shutdown()
Definition: demux.cpp:187
static void start(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET, const bool bind=false)
Definition: demux.cpp:170
bool isSet() const
int main(int argc, char **argv)
Definition: mm_pubsub.cpp:33
static void start(const std::string &name, const std::string &url, const mm_messages::Verbosity::Level &verbosity=mm_messages::Verbosity::QUIET, const bool bind=true)
Pre-establish named connections.
Definition: mux.cpp:107
void parse(int argc, char **argv)
void xorAdd(Arg &a, Arg &b)
void foo(std::string data)
Definition: mm_pubsub.cpp:26


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