9 #include "helics/core/ActionMessage.hpp"
12 #include <boost/interprocess/ipc/message_queue.hpp>
13 #include <boost/interprocess/shared_memory_object.hpp>
14 #include <boost/interprocess/sync/interprocess_mutex.hpp>
23 using ipc_queue = boost::interprocess::message_queue;
24 using ipc_state = boost::interprocess::shared_memory_object;
30 inline std::string stringTranslateToCppName(std::string in)
33 in.begin(), in.end(), [](
auto c) { return !(std::isalnum(c) || (c ==
'_')); },
'_');
37 enum class queue_state_t : int {
50 using ipcmutex = boost::interprocess::interprocess_mutex;
51 mutable ipcmutex data_lock;
52 queue_state_t state = queue_state_t::startup;
55 queue_state_t getState()
const
58 boost::interprocess::scoped_lock<ipcmutex> lock(data_lock);
61 catch (
const boost::interprocess::lock_exception&) {
62 return queue_state_t::unknown;
65 bool setState(queue_state_t newState)
71 boost::interprocess::scoped_lock<ipcmutex> lock(data_lock);
75 catch (
const boost::interprocess::lock_exception&) {
76 std::this_thread::sleep_for(std::chrono::milliseconds(100));
79 std::cout <<
"error in connecting to process lock\n";
92 std::unique_ptr<ipc_queue> rqueue;
93 std::unique_ptr<ipc_state> queue_state;
94 std::string connectionNameOrig;
95 std::string connectionName;
96 std::string stateName;
97 std::string errorString;
98 std::vector<char> buffer;
100 bool connected =
false;
105 bool connect(
const std::string& connection,
int maxMessages,
int maxSize);
107 void changeState(queue_state_t newState);
109 std::optional<ActionMessage> getMessage(
int timeout);
112 const std::string& getError()
const {
return errorString; }
118 std::unique_ptr<ipc_queue> txqueue;
119 std::string connectionNameOrig;
122 std::string errorString;
123 std::vector<char> buffer;
124 bool connected =
false;
129 bool connect(
const std::string& connection,
bool initOnly,
int retries);
133 const std::string& getError()
const {
return errorString; }
Definition: ActionMessage.hpp:30
Definition: IpcQueueHelper.h:90
Definition: IpcQueueHelper.h:116
Definition: IpcQueueHelper.h:48
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14