zmqpp  4.1.2
C++ bindings for 0mq (libzmq)
actor.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  *
6  * This file is part of zmqpp.
7  * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file.
8  */
9 
10 #pragma once
11 
12 #include <thread>
13 #include <functional>
14 #include <mutex>
15 #include "context.hpp"
16 #include "socket.hpp"
17 
18 namespace zmqpp
19 {
20 
52  class actor
53  {
54  public:
58  typedef std::function<bool(socket *pipe)> ActorStartRoutine;
59 
69  actor(ActorStartRoutine routine);
70  actor(const actor &) = delete;
71 
76  actor(actor &&o);
77 
82  actor &operator=(actor &&o);
83 
84  virtual ~actor();
85 
89  socket *pipe();
90 
94  const socket *pipe() const;
95 
117  bool stop(bool block = false);
118 
119  private:
131  void start_routine(socket *child, ActorStartRoutine routine);
132 
138  std::string bind_parent();
139 
145 
151 
157 
158  mutable std::mutex mutex_;
159 
160  std::exception_ptr eptr_;
161 
165  bool stopped_;
166 
167  bool retval_;
168  };
169 }
std::mutex mutex_
Definition: actor.hpp:158
void start_routine(socket *child, ActorStartRoutine routine)
Call a user defined function and performs cleanup once it returns.
Definition: actor.cpp:118
bool stopped_
Keeps track of the status of the actor thread.
Definition: actor.hpp:165
C++ wrapper around zmq.
Definition: actor.cpp:29
The socket class represents the zmq sockets.
Definition: socket.hpp:75
bool stop(bool block=false)
Sends signal::stop to the actor thread.
Definition: actor.cpp:94
std::exception_ptr eptr_
Definition: actor.hpp:160
bool retval_
Definition: actor.hpp:167
actor(ActorStartRoutine routine)
Create a new actor.
Definition: actor.cpp:32
socket * child_pipe_
The child end of the pipe.
Definition: actor.hpp:150
static context actor_pipe_ctx_
This static, per process zmqpp::context, is used to connect PAIR socket between Actor and their paren...
Definition: actor.hpp:156
socket * parent_pipe_
The parent thread socket.
Definition: actor.hpp:144
actor & operator=(actor &&o)
Move-assignment operator.
Definition: actor.cpp:78
std::string bind_parent()
Bind the parent socket and return the endpoint used.
Definition: actor.cpp:148
socket * pipe()
Definition: actor.cpp:138
The context class represents internal zmq context and io threads.
Definition: context.hpp:46
std::function< bool(socket *pipe)> ActorStartRoutine
The user defined function type.
Definition: actor.hpp:58
An actor is a thread with a pair socket connected to its parent.
Definition: actor.hpp:52
virtual ~actor()
Definition: actor.cpp:88