Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Publisher
- */
- #include "publisher.hpp"
- #include <zmq.hpp>
- #include <sstream>
- #include <iostream>
- Publisher* Publisher::initialize(zmq::context_t* z_ctx)
- {
- Publisher* pub = getInstance();
- pub->connectToBoxoffice(z_ctx);
- return pub;
- }
- int Publisher::connectToBoxoffice(zmq::context_t* z_ctx)
- {
- // since the publisher is a singleton, we can simply use two ZMQ_PAIRs
- z_pub_to_bo = new zmq::socket_t(*z_ctx, ZMQ_PAIR);
- z_bo_to_pub = new zmq::socket_t(*z_ctx, ZMQ_PAIR);
- z_pub_to_bo->connect("inproc://sb_pub_to_bo_pair");
- z_bo_to_pub->bind("inproc://sb_bo_to_pub_pair");
- // send a heartbeat to boxoffice, so it knows the publisher is ready
- zmq::message_t z_msg;
- snprintf((char*) z_msg.data(), 4, "%d %d", 0, 1);
- z_pub_to_bo->send(z_msg);
- return 0;
- }
- int Publisher::sendExitSignal()
- {
- // send exit signal to boxoffice
- std::cout << "pub: sending exit signal" << std::endl;
- zmq::message_t z_msg;
- snprintf((char*) z_msg.data(), 4, "%d %d", 0, 0);
- z_pub_to_bo->send(z_msg);
- z_pub_to_bo->close();
- std::cout << "pub: exit signal sent, exiting..." << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement