runMACS
 All Data Structures Files Functions Variables Enumerations Enumerator Macros
RemoteGrabber.cpp
Go to the documentation of this file.
1 #include <RemoteGrabber.h>
2 #include <iostream>
3 
4 _RemoteGrabberImpl::_RemoteGrabberImpl(const std::string & _deviceName, const std::string & _deviceSource, zmq::context_t & _ctx) :
5  deviceName(_deviceName),
6  deviceSource(_deviceSource),
7  ctx(_ctx)
8 {
9 }
10 
12 
13 }
14 
16  return width;
17 }
18 
20  return height;
21 }
22 
24  return bytesPerPixel;
25 }
26 
28  enableAcquisition = true;
29  acquisitionThread = std::thread(&_RemoteGrabberImpl::acquisition, this);
30 }
31 
33  enableAcquisition = false;
34  if (acquisitionThread.joinable()) {
35  std::cout << "wait for remote grabber thread to join" << std::endl;
36  acquisitionThread.join();
37  }
38 }
39 
40 void _RemoteGrabberImpl::addEndpoint(const std::string & _endpoint) {
41  endpoints.push_back(_endpoint);
42 }
43 
44 void _RemoteGrabberImpl::acquisition() {
45 
46  zmq::socket_t subSocket(ctx, ZMQ_SUB);
47  zmq::socket_t pubSocket(ctx, ZMQ_PUB);
48  subSocket.connect(deviceSource);
49  subSocket.setsockopt(ZMQ_SUBSCRIBE, "", 0);
50  for (const auto & ep : endpoints) {
51  pubSocket.bind(ep.c_str());
52  }
53  while (enableAcquisition) {
54  int64_t more = 1;
55  while (more) {
56  zmq::message_t msg;
57  subSocket.recv(&msg);
58  size_t more_size = sizeof(more);
59  subSocket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
60  pubSocket.send(msg, more?ZMQ_SNDMORE:0);
61  }
62  }
63 }
void addEndpoint(const std::string &_endpoint)
_RemoteGrabberImpl(const std::string &_deviceName, const std::string &_deviceSource, zmq::context_t &_ctx)