24 #include "goby/common/zeromq_service.h" 26 #include <boost/thread.hpp> 28 void node_inbox(goby::common::MarshallingScheme marshalling_scheme,
const std::string& identifier,
29 const std::string& data,
int socket_id);
31 void run_basic_test(
int test_count,
int expected_blackouts,
int ms_wait);
33 const std::string identifier_ =
"HI/";
35 const char data_[] = {
'h',
'i',
'\0'};
43 SOCKET_SUBSCRIBE = 240,
47 int main(
int argc,
char* argv[])
55 subscriber_cfg.add_socket();
56 subscriber_socket->set_socket_type(
57 goby::common::protobuf::ZeroMQServiceConfig::Socket::SUBSCRIBE);
58 subscriber_socket->set_transport(goby::common::protobuf::ZeroMQServiceConfig::Socket::IPC);
59 subscriber_socket->set_connect_or_bind(
60 goby::common::protobuf::ZeroMQServiceConfig::Socket::CONNECT);
62 subscriber_socket->set_socket_id(SOCKET_SUBSCRIBE);
63 subscriber_socket->set_socket_name(
"test3_ipc_socket");
64 std::cout << subscriber_socket->DebugString() << std::endl;
69 publisher_cfg.add_socket();
70 publisher_socket->set_socket_type(
71 goby::common::protobuf::ZeroMQServiceConfig::Socket::PUBLISH);
72 publisher_socket->set_transport(goby::common::protobuf::ZeroMQServiceConfig::Socket::IPC);
73 publisher_socket->set_connect_or_bind(
74 goby::common::protobuf::ZeroMQServiceConfig::Socket::BIND);
75 publisher_socket->set_socket_name(
"test3_ipc_socket");
76 publisher_socket->set_socket_id(SOCKET_PUBLISH);
77 std::cout << publisher_socket->DebugString() << std::endl;
80 node1_.set_cfg(publisher_cfg);
82 node2_.set_cfg(subscriber_cfg);
83 node2_.connect_inbox_slot(&node_inbox);
84 node2_.subscribe_all(SOCKET_SUBSCRIBE);
89 node2_.socket_from_id(SOCKET_SUBSCRIBE)
90 .set_blackout(goby::common::MARSHALLING_CSTR, identifier_,
91 boost::posix_time::milliseconds(6));
92 run_basic_test(3, 1, 5);
93 run_basic_test(8, 4, 4);
96 node2_.socket_from_id(SOCKET_SUBSCRIBE)
97 .clear_blackout(goby::common::MARSHALLING_CSTR, identifier_);
98 run_basic_test(3, 0, 5);
99 run_basic_test(8, 0, 4);
102 node2_.socket_from_id(SOCKET_SUBSCRIBE).set_global_blackout(boost::posix_time::milliseconds(6));
103 run_basic_test(3, 1, 5);
104 run_basic_test(8, 4, 4);
107 node2_.socket_from_id(SOCKET_SUBSCRIBE).clear_global_blackout();
108 run_basic_test(3, 0, 5);
109 run_basic_test(8, 0, 4);
112 node2_.socket_from_id(SOCKET_SUBSCRIBE).set_global_blackout(boost::posix_time::milliseconds(6));
113 node2_.socket_from_id(SOCKET_SUBSCRIBE)
114 .set_blackout(goby::common::MARSHALLING_CSTR, identifier_,
115 boost::posix_time::milliseconds(0));
116 run_basic_test(3, 0, 5);
117 run_basic_test(8, 0, 4);
119 std::cout <<
"all tests passed" << std::endl;
122 void run_basic_test(
int test_count,
int expected_blackouts,
int ms_wait)
125 for (
int i = 0; i < test_count; ++i)
127 std::cout <<
"publishing " << data_ << std::endl;
128 node1_.send(goby::common::MARSHALLING_CSTR, identifier_, std::string(data_),
132 usleep(ms_wait * 1e3);
135 assert(inbox_count_ == test_count - expected_blackouts);
138 void node_inbox(goby::common::MarshallingScheme marshalling_scheme,
const std::string& identifier,
139 const std::string& data,
int socket_id)
141 assert(identifier == identifier_);
142 assert(marshalling_scheme == goby::common::MARSHALLING_CSTR);
143 assert(!strcmp(data.c_str(), data_));
144 assert(socket_id == SOCKET_SUBSCRIBE);
146 std::cout <<
"Received: " << data << std::endl;
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
common::FlexOstream glog
Access the Goby logger through this object.
void add_stream(logger::Verbosity verbosity=logger::VERBOSE, std::ostream *os=0)
Attach a stream object (e.g. std::cout, std::ofstream, ...) to the logger with desired verbosity...