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 const std::string identifier_ =
"HI/";
33 const char data_[] = {
'h',
'i',
'\0'};
37 SOCKET_SUBSCRIBE = 240,
41 int main(
int argc,
char* argv[])
53 subscriber_cfg.add_socket();
54 subscriber_socket->set_socket_type(
55 goby::common::protobuf::ZeroMQServiceConfig::Socket::SUBSCRIBE);
56 subscriber_socket->set_transport(goby::common::protobuf::ZeroMQServiceConfig::Socket::IPC);
57 subscriber_socket->set_connect_or_bind(
58 goby::common::protobuf::ZeroMQServiceConfig::Socket::CONNECT);
60 subscriber_socket->set_socket_id(SOCKET_SUBSCRIBE);
61 subscriber_socket->set_socket_name(
"test3_ipc_socket");
62 std::cout << subscriber_socket->DebugString() << std::endl;
67 publisher_cfg.add_socket();
68 publisher_socket->set_socket_type(
69 goby::common::protobuf::ZeroMQServiceConfig::Socket::PUBLISH);
70 publisher_socket->set_transport(goby::common::protobuf::ZeroMQServiceConfig::Socket::IPC);
71 publisher_socket->set_connect_or_bind(
72 goby::common::protobuf::ZeroMQServiceConfig::Socket::BIND);
73 publisher_socket->set_socket_name(
"test3_ipc_socket");
74 publisher_socket->set_socket_id(SOCKET_PUBLISH);
75 std::cout << publisher_socket->DebugString() << std::endl;
78 node1.set_cfg(publisher_cfg);
80 node2.set_cfg(subscriber_cfg);
81 node2.connect_inbox_slot(&node_inbox);
82 node2.subscribe_all(SOCKET_SUBSCRIBE);
87 for (
int i = 0; i < test_count; ++i)
89 std::cout <<
"publishing " << data_ << std::endl;
90 node1.send(goby::common::MARSHALLING_CSTR, identifier_, std::string(data_), SOCKET_PUBLISH);
94 assert(inbox_count_ == test_count);
96 std::cout <<
"all tests passed" << std::endl;
99 void node_inbox(goby::common::MarshallingScheme marshalling_scheme,
const std::string& identifier,
100 const std::string& data,
int socket_id)
102 assert(identifier == identifier_);
103 assert(marshalling_scheme == goby::common::MARSHALLING_CSTR);
104 assert(!strcmp(data.c_str(), data_));
105 assert(socket_id == SOCKET_SUBSCRIBE);
107 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...