helics 3.7.0
Loading...
Searching...
No Matches
zmqSocketDescriptor.h
1/*
2Copyright (c) 2017-2018,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. All rights reserved. See LICENSE file and DISCLAIMER for more details.
5*/
6/*
7 * LLNS Copyright Start
8 * Copyright (c) 2017, Lawrence Livermore National Security
9 * This work was performed under the auspices of the U.S. Department
10 * of Energy by Lawrence Livermore National Laboratory in part under
11 * Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
12 * Produced at the Lawrence Livermore National Laboratory.
13 * All rights reserved.
14 * For details, see the LICENSE file.
15 * LLNS Copyright End
16 */
17
18#pragma once
19
20#include "cppzmq/zmq_addon.hpp"
21
22#include <functional>
23#include <memory>
24#include <string>
25#include <utility>
26#include <vector>
27
29enum class socket_ops {
30 bind,
31 connect,
32 unbind,
33 disconnect,
34 subscribe,
35 unsubscribe,
36};
37
38using socketOperation =
39 std::pair<socket_ops, std::string>;
40
43 public:
44 std::string name;
45 zmq::socket_type type = zmq::socket_type::sub;
46 std::vector<socketOperation> ops;
47 std::function<void(const zmq::multipart_t& res)> callback;
48 ZmqSocketDescriptor(std::string socketName = ""):
49 name(std::move(socketName)) {} // purposefully implicit
50 ZmqSocketDescriptor(std::string socketName, zmq::socket_type stype):
51 name(std::move(socketName)), type(stype)
52 {
53 }
54 inline void addOperation(socket_ops op, const std::string& desc) { ops.emplace_back(op, desc); }
55 zmq::socket_t makeSocket(zmq::context_t& ctx) const;
56 std::unique_ptr<zmq::socket_t> makeSocketPtr(zmq::context_t& ctx) const;
57 void modifySocket(zmq::socket_t& sock) const;
58};
Definition zmqSocketDescriptor.h:42
std::function< void(const zmq::multipart_t &res)> callback
the message handler
Definition zmqSocketDescriptor.h:47
zmq::socket_type type
the socket type
Definition zmqSocketDescriptor.h:45
std::string name
name of the socket for later reference
Definition zmqSocketDescriptor.h:44
std::vector< socketOperation > ops
a list of connections of make through bind
Definition zmqSocketDescriptor.h:46
STL namespace.