zmqpp  4.1.2
C++ bindings for 0mq (libzmq)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 "socket.hpp"
15 
16 namespace zmqpp
17 {
18 
43  class actor
44  {
45  public:
49  typedef std::function<bool (socket *pipe) > ActorStartRoutine;
50 
59  actor(ActorStartRoutine routine);
60  actor(const actor&) = delete;
61 
66  actor(actor &&o);
67 
72  actor &operator=(actor &&o);
73 
74  virtual ~actor();
75 
79  socket *pipe();
80 
84  const socket *pipe() const;
85 
100  bool stop(bool block = false);
101 
102  private:
112  void start_routine(socket *child, ActorStartRoutine routine);
113 
119  std::string bind_parent();
120 
126 
132 
138 
142  bool stopped_;
143 
144  bool retval_;
145  };
146 }
void start_routine(socket *child, ActorStartRoutine routine)
Call a user defined function and performs cleanup once it returns.
Definition: actor.cpp:102
bool stopped_
Keeps track of the status of the actor thread.
Definition: actor.hpp:142
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:79
bool retval_
Definition: actor.hpp:144
actor(ActorStartRoutine routine)
Create a new actor.
Definition: actor.cpp:32
socket * child_pipe_
The child end of the pipe.
Definition: actor.hpp:131
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:137
socket * parent_pipe_
The parent thread socket.
Definition: actor.hpp:125
actor & operator=(actor &&o)
Move-assignment operator.
Definition: actor.cpp:63
std::string bind_parent()
Bind the parent socket and return the endpoint used.
Definition: actor.cpp:121
socket * pipe()
Definition: actor.cpp:111
std::function< bool(socket *pipe) > ActorStartRoutine
The user defined function type.
Definition: actor.hpp:49
The context class represents internal zmq context and io threads.
Definition: context.hpp:46
An actor is a thread with a pair socket connected to its parent.
Definition: actor.hpp:43
virtual ~actor()
Definition: actor.cpp:73