Advertisement
Guest User

publisher.cpp

a guest
Feb 27th, 2015
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. /*
  2.  * Publisher
  3.  */
  4.  
  5. #include "publisher.hpp"
  6.  
  7. #include <zmq.hpp>
  8. #include <sstream>
  9. #include <iostream>
  10.  
  11. Publisher* Publisher::initialize(zmq::context_t* z_ctx)
  12. {
  13.   Publisher* pub = getInstance();
  14.  
  15.   pub->connectToBoxoffice(z_ctx);
  16.  
  17.   return pub;
  18. }
  19.  
  20. int Publisher::connectToBoxoffice(zmq::context_t* z_ctx)
  21. {
  22.   // since the publisher is a singleton, we can simply use two ZMQ_PAIRs
  23.   z_pub_to_bo = new zmq::socket_t(*z_ctx, ZMQ_PAIR);
  24.   z_bo_to_pub = new zmq::socket_t(*z_ctx, ZMQ_PAIR);
  25.   z_pub_to_bo->connect("inproc://sb_pub_to_bo_pair");
  26.   z_bo_to_pub->bind("inproc://sb_bo_to_pub_pair");
  27.  
  28.   // send a heartbeat to boxoffice, so it knows the publisher is ready
  29.   zmq::message_t z_msg;
  30.   snprintf((char*) z_msg.data(), 4, "%d %d", 0, 1);
  31.   z_pub_to_bo->send(z_msg);
  32.  
  33.   return 0;
  34. }
  35.  
  36. int Publisher::sendExitSignal()
  37. {
  38.   // send exit signal to boxoffice
  39.   std::cout << "pub: sending exit signal" << std::endl;
  40.   zmq::message_t z_msg;
  41.   snprintf((char*) z_msg.data(), 4, "%d %d", 0, 0);
  42.   z_pub_to_bo->send(z_msg);
  43.  
  44.   z_pub_to_bo->close();
  45.  
  46.   std::cout << "pub: exit signal sent, exiting..." << std::endl;
  47.  
  48.   return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement