| helics 3.6.1

ZmqContextManager.h
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 /*
9 * LLNS Copyright Start
10 * Copyright (c) 2017, Lawrence Livermore National Security
11 * This work was performed under the auspices of the U.S. Department
12 * of Energy by Lawrence Livermore National Laboratory in part under
13 * Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
14 * Produced at the Lawrence Livermore National Laboratory.
15 * All rights reserved.
16 * For details, see the LICENSE file.
17 * LLNS Copyright End
18 */
19 #pragma once
20
21 #include <atomic>
22 #include <map>
23 #include <memory>
24 #include <string>
25 namespace zmq {
26 class context_t;
27 } // namespace zmq
28
32 class ZmqContextManager {
33 private:
34 static std::map<std::string, std::shared_ptr<ZmqContextManager>>
35 contexts;
36 std::string name;
37 std::unique_ptr<zmq::context_t> zcontext;
38 std::atomic<bool> leakOnDelete{true};
40
42 explicit ZmqContextManager(const std::string& contextName);
43
44 public:
46 static std::shared_ptr<ZmqContextManager>
47 getContextPointer(const std::string& contextName = std::string{});
49 static zmq::context_t& getContext(const std::string& contextName = std::string{});
51 static void startContext(const std::string& contextName = std::string{});
53 static void closeContext(const std::string& contextName = std::string{});
64 static bool setContextToLeakOnDelete(const std::string& contextName = std::string{});
66 static bool setContextToNotLeakOnDelete(const std::string& contextName = std::string{});
68 ~ZmqContextManager();
70 const std::string& getName() const { return name; }
72 zmq::context_t& getBaseContext() const { return *zcontext; }
73 };
ZmqContextManager
Definition: ZmqContextManager.h:32
ZmqContextManager::setContextToNotLeakOnDelete
static bool setContextToNotLeakOnDelete(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:89
ZmqContextManager::closeContext
static void closeContext(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:70
ZmqContextManager::getName
const std::string & getName() const
Definition: ZmqContextManager.h:70
ZmqContextManager::~ZmqContextManager
~ZmqContextManager()
Definition: ZmqContextManager.cpp:98
ZmqContextManager::setContextToLeakOnDelete
static bool setContextToLeakOnDelete(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:79
ZmqContextManager::getContext
static zmq::context_t & getContext(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:55
ZmqContextManager::getBaseContext
zmq::context_t & getBaseContext() const
Definition: ZmqContextManager.h:72
ZmqContextManager::getContextPointer
static std::shared_ptr< ZmqContextManager > getContextPointer(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:39
ZmqContextManager::startContext
static void startContext(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:60