| helics 3.6.1

CallbackFederate.hpp
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
9 #include "CombinationFederate.hpp"
10
11 #include <memory>
12 #include <string>
13 #include <utility>
14
15 namespace helics {
16 class CallbackFederateOperator;
17
19 class HELICS_CXX_EXPORT CallbackFederate: public CombinationFederate {
20 public:
22 CallbackFederate();
23
29 explicit CallbackFederate(std::string_view fedName, const FederateInfo& fedInfo);
30
37 CallbackFederate(std::string_view fedName,
38 const std::shared_ptr<Core>& core,
39 const FederateInfo& fedInfo = FederateInfo{});
40
47 CallbackFederate(std::string_view fedName,
48 CoreApp& core,
49 const FederateInfo& fedInfo = FederateInfo{});
50
56 CallbackFederate(std::string_view fedName, const std::string& configString);
57
62 explicit CallbackFederate(const std::string& configString);
63
65 CallbackFederate(CallbackFederate&& fed) noexcept;
67 virtual ~CallbackFederate();
69 CallbackFederate& operator=(CallbackFederate&& fed) noexcept;
71 CallbackFederate(const CallbackFederate& fed) = delete;
73 CallbackFederate& operator=(const CallbackFederate& fed) = delete;
74 void setInitializeCallback(std::function<IterationRequest()> initializeCallback)
75 {
76 initializationOperation = std::move(initializeCallback);
77 }
78 void setNextTimeIterativeCallback(
79 std::function<std::pair<Time, IterationRequest>(iteration_time)> nextTimeCallback)
80 {
81 nextTimeOperation1 = std::move(nextTimeCallback);
82 }
83 void setNextTimeCallback(std::function<Time(Time)> nextTimeCallback)
84 {
85 nextTimeOperation2 = std::move(nextTimeCallback);
86 nextTimeOperation1 = nullptr;
87 }
88 void clearNextTimeCallback()
89 {
90 nextTimeOperation1 = nullptr;
91 nextTimeOperation2 = nullptr;
92 }
93 virtual void setFlagOption(int32_t property, bool val) override;
94
95 private:
96 void loadOperator();
97 // pointer for the
98 std::shared_ptr<CallbackFederateOperator> op;
99 friend CallbackFederateOperator;
100 bool mEventTriggered{false};
101 std::function<IterationRequest()> initializationOperation;
102 std::function<std::pair<Time, IterationRequest>(iteration_time)> nextTimeOperation1;
103 std::function<Time(Time)> nextTimeOperation2;
105 IterationRequest initializeOperationsCallback();
106
107 std::pair<Time, IterationRequest> operateCallback(iteration_time newTime);
108
109 void finalizeCallback();
110 void errorHandlerCallback(int errorCode, std::string_view errorString);
111 };
112 } // namespace helics
helics::CallbackFederate
Definition: CallbackFederate.hpp:19
helics::CallbackFederate::operator=
CallbackFederate & operator=(const CallbackFederate &fed)=delete
helics::CallbackFederate::operator=
CallbackFederate & operator=(CallbackFederate &&fed) noexcept
helics::CallbackFederate::CallbackFederate
CallbackFederate(const CallbackFederate &fed)=delete
helics::CallbackFederate::CallbackFederate
CallbackFederate(CallbackFederate &&fed) noexcept
helics::CallbackFederate::~CallbackFederate
virtual ~CallbackFederate()
helics::CombinationFederate
Definition: application_api/CombinationFederate.hpp:18
helics::CoreApp
Definition: application_api/CoreApp.hpp:25
helics::FederateInfo
Definition: FederateInfo.hpp:28
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::IterationRequest
IterationRequest
Definition: CoreTypes.hpp:103
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::iteration_time
Definition: helicsTime.hpp:43