| helics 3.6.1

TimeoutMonitor.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 #pragma once
8 #include "GlobalFederateId.hpp"
9
10 #include <chrono>
11 #include <vector>
12
13 namespace helics {
14 class CommonCore;
15 class CoreBroker;
16 class ActionMessage;
17
19 struct linkConnection {
20 bool waitingForPingReply{false};
21 bool activeConnection{false};
22 bool disablePing{false};
23 GlobalFederateId connection{0};
24 decltype(std::chrono::steady_clock::now()) lastPing;
25 };
27 class TimeoutMonitor {
28 public:
30 void tick(CommonCore* core);
32 void tick(CoreBroker* brk);
34 void pingReply(const ActionMessage& cmd, CoreBroker* brk = nullptr);
36 void setTimeout(std::chrono::milliseconds to) { timeout = to; }
38 void reset();
40 void pingSub(CoreBroker* brk);
42 void setParentId(GlobalBrokerId parent_id) { parentConnection.connection = parent_id; }
44 void disableParentPing(bool value = true)
45 {
46 parentConnection.disablePing = value;
47 parentConnection.waitingForPingReply = false;
48 }
49
50 private:
51 std::chrono::milliseconds timeout{100'000'000};
52 bool waitingForConnection{false};
53 decltype(std::chrono::steady_clock::now()) startWaiting;
54 linkConnection parentConnection;
55 std::vector<linkConnection> connections;
56
57 // int tickCounter;
58 };
59
60 } // namespace helics
helics::ActionMessage
Definition: ActionMessage.hpp:30
helics::CommonCore
Definition: CommonCore.hpp:74
helics::CoreBroker
Definition: CoreBroker.hpp:98
helics::GlobalBrokerId
Definition: GlobalFederateId.hpp:30
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:75
helics::TimeoutMonitor
Definition: TimeoutMonitor.h:27
helics::TimeoutMonitor::disableParentPing
void disableParentPing(bool value=true)
Definition: TimeoutMonitor.h:44
helics::TimeoutMonitor::setTimeout
void setTimeout(std::chrono::milliseconds to)
Definition: TimeoutMonitor.h:36
helics::TimeoutMonitor::setParentId
void setParentId(GlobalBrokerId parent_id)
Definition: TimeoutMonitor.h:42
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::linkConnection
Definition: TimeoutMonitor.h:19
helics::linkConnection::connection
GlobalFederateId connection
the id of the connection
Definition: TimeoutMonitor.h:23
helics::linkConnection::waitingForPingReply
bool waitingForPingReply
indicator that the connection is waiting
Definition: TimeoutMonitor.h:20
helics::linkConnection::activeConnection
bool activeConnection
indicator that the connection is active
Definition: TimeoutMonitor.h:21
helics::linkConnection::disablePing
bool disablePing
indicator that the connection doesn't respond to pings
Definition: TimeoutMonitor.h:22