mm_radio.cpp
Go to the documentation of this file.
00001 
00006 /*****************************************************************************
00007 ** Includes
00008 *****************************************************************************/
00009 
00010 #include <ecl/command_line/xor_handler.hpp>
00011 #include <ecl/command_line/cmd_line.hpp>
00012 #include <ecl/command_line/value_arg.hpp>
00013 #include <ecl/command_line/switch_arg.hpp>
00014 #include <ecl/time.hpp>
00015 #include <mm_core_msgs/test_identifiers.hpp>
00016 #include <mm_core_msgs/string.hpp>
00017 #include <string>
00018 #include "../../include/mm_radio/publisher.hpp"
00019 #include "../../include/mm_radio/radio.hpp"
00020 #include "../../include/mm_radio/subscriber.hpp"
00021 
00022 /*****************************************************************************
00023 ** Methods
00024 *****************************************************************************/
00025 
00026 void oldtimer_foo(std::string data) {
00027   std::cout << "oldtimer_foo : processing data: " << data << std::endl;
00028 }
00029 
00030 void oldman_foo(std::string data) {
00031   std::cout << "oldman_foo : processing data: " << data << std::endl;
00032 }
00033 
00034 /*****************************************************************************
00035 ** Main
00036 *****************************************************************************/
00037 
00038 int main(int argc, char **argv)
00039 {
00040   /****************************************
00041    ** Args
00042    ****************************************/
00043   ecl::CmdLine cmd("Radio multiplexing, by default tests both sides on inproc, use the options to choose otherwise.");
00044   ecl::SwitchArg oldman("m", "oldman", "Run the publisher only", false);
00045   ecl::SwitchArg oldtimer("t", "oldtimer", "Run the subscriber only", false);
00046   ecl::SwitchArg both("b", "both", "Run both the oldman and oldtimer inproc (instead of iproc)", false);
00047   std::vector<ecl::Arg*> xorlist;
00048   xorlist.push_back(&oldman);
00049   xorlist.push_back(&oldtimer);
00050   xorlist.push_back(&both);
00051   cmd.xorAdd(xorlist);
00052   cmd.parse(argc, argv);
00053 
00054   const std::string inproc_address = "inproc://radio";
00055   const std::string ipc_address = "ipc:///tmp/radio.ipc";
00056   //bool result = mm_messages::MessageRegistry::add<mm_core_msgs::TestStrings, std::string>("mm_radio teststrings packet");
00057   if ( oldman.isSet() ) {
00058     mm_radio::Radio::startServer("oldman", ipc_address, mm_messages::Verbosity::QUIET);
00059     mm_radio::Subscriber<mm_core_msgs::TestStrings, std::string> oldman_subscriber("oldman", oldman_foo);
00060     mm_radio::Publisher oldman_publisher("oldman");
00061     while(true) {
00062       oldman_publisher.publish(mm_core_msgs::TestStrings, std::string("aye carumba"));
00063       ecl::MilliSleep()(500);
00064     }
00065   } else if ( oldtimer.isSet() ) {
00066     mm_radio::Radio::startClient("oldtimer", ipc_address, mm_messages::Verbosity::QUIET);
00067     mm_radio::Subscriber<mm_core_msgs::TestStrings, std::string> oldtimer_subscriber("oldtimer", oldtimer_foo);
00068     mm_radio::Publisher oldtimer_publisher("oldtimer");
00069     while(true) {
00070       oldtimer_publisher.publish(mm_core_msgs::TestStrings, std::string("hello old man"));
00071       ecl::MilliSleep()(500);
00072     }
00073     mm_radio::Radio::shutdown(); // shutdown all named radios
00074   } else if ( both.isSet() ) {
00075     mm_radio::Radio::startServer("oldman", inproc_address);
00076     mm_radio::Radio::startClient("oldtimer", inproc_address);
00077     mm_radio::Subscriber<mm_core_msgs::TestStrings, std::string> oldtimer_subscriber("oldtimer", oldtimer_foo);
00078     mm_radio::Subscriber<mm_core_msgs::TestStrings, std::string> oldman_subscriber("oldman", oldman_foo);
00079     mm_radio::Publisher oldtimer_publisher("oldtimer");
00080     mm_radio::Publisher oldman_publisher("oldman");
00081     ecl::MilliSleep()(200); // let the connection establish itself
00082     for ( unsigned int i = 0; i < 4; ++i ) {
00083       oldtimer_publisher.publish(mm_core_msgs::TestStrings, std::string("hello old man"));
00084       ecl::MilliSleep()(500);
00085       oldman_publisher.publish(mm_core_msgs::TestStrings, std::string("aye carumba"));
00086       ecl::MilliSleep()(500);
00087     }
00088     mm_radio::Radio::shutdown(); // shutdown all named radios
00089   }
00090   return 0;
00091 }


mm_radio
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:13:24