helics  3.3.0
Echo.hpp
1 /*
2 Copyright (c) 2017-2022,
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 "../application_api/MessageFederate.hpp"
10 #include "helicsApp.hpp"
11 
12 #include <deque>
13 #include <memory>
14 #include <mutex>
15 #include <string>
16 #include <vector>
17 
18 namespace helics {
19 namespace apps {
27  class HELICS_CXX_EXPORT Echo: public App {
28  public:
30  Echo() = default;
34  explicit Echo(std::vector<std::string> args);
39  Echo(int argc, char* argv[]);
44  explicit Echo(std::string_view name, const FederateInfo& fi);
50  Echo(std::string_view name, const std::shared_ptr<Core>& core, const FederateInfo& fi);
56  Echo(std::string_view name, CoreApp& core, const FederateInfo& fi);
61  Echo(std::string_view name, const std::string& jsonString);
62 
64  Echo(Echo&& other_echo) noexcept;
66  Echo& operator=(Echo&& other_echo) noexcept;
67 
71  virtual void runTo(Time stopTime_input) override;
72 
77  void addEndpoint(std::string_view endpointName, std::string_view endpointType = "");
78 
80  auto echoCount() const { return echoCounter; }
84  void setEchoDelay(Time delay);
85 
87  auto endpointCount() const { return endpoints.size(); }
88 
89  private:
91  virtual void loadJsonFile(const std::string& jsonFile) override;
93  void echoMessage(const Endpoint& ept, Time currentTime);
94 
95  private:
97  void processArgs();
98  std::deque<Endpoint> endpoints;
99  Time delayTime = timeZero;
100  size_t echoCounter = 0;
101  std::mutex delayTimeLock; // mutex protecting delayTime
102  };
103 } // namespace apps
104 } // namespace helics
helics::timeZero
constexpr Time timeZero
Definition: helicsTime.hpp:31
helics::apps::Echo
Definition: Echo.hpp:27
helics::apps::App::operator=
App & operator=(App &&app)=default
helics::apps::Echo::echoCount
auto echoCount() const
Definition: Echo.hpp:80
helics::apps::Echo::runTo
virtual void runTo(Time stopTime_input) override
Definition: Echo.cpp:89
helics::Federate::Modes::FINALIZE
@ FINALIZE
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::Endpoint
Definition: Endpoints.hpp:21
helics::helicsCLI11App
Definition: helicsCLI11.hpp:42
helics::apps::App::masterFileName
std::string masterFileName
the name of the master file used to do the construction
Definition: helicsApp.hpp:132
helics::apps::App::loadJsonFileConfiguration
void loadJsonFileConfiguration(const std::string &appName, const std::string &jsonString)
Definition: helicsApp.cpp:158
helics::FederateInfo
Definition: FederateInfo.hpp:24
helics::Endpoint::getMessage
std::unique_ptr< Message > getMessage() const
Definition: Endpoints.cpp:138
HELICS_FLAG_EVENT_TRIGGERED
@ HELICS_FLAG_EVENT_TRIGGERED
Definition: helics_enums.h:140
helics::apps::Echo::endpointCount
auto endpointCount() const
Definition: Echo.hpp:87
helics::apps::Echo::addEndpoint
void addEndpoint(std::string_view endpointName, std::string_view endpointType="")
Definition: Echo.cpp:122
helics::apps::Echo::operator=
Echo & operator=(Echo &&other_echo) noexcept
Definition: Echo.cpp:79
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::Endpoint::sendToAt
void sendToAt(const data_view &data, std::string_view dest, Time sendTime) const
Definition: Endpoints.hpp:114
helics::apps::App::initialize
virtual void initialize()
Definition: helicsApp.cpp:196
helics::apps::App::fed
std::shared_ptr< CombinationFederate > fed
the federate created for the Player
Definition: helicsApp.hpp:130
helics::apps::App
Definition: helicsApp.hpp:29
helics::Federate::Modes::STARTUP
@ STARTUP
helics::apps::App::loadFile
void loadFile(const std::string &filename)
Definition: helicsApp.cpp:123
helics::apps::Echo::Echo
Echo()=default
helics::apps::Echo::setEchoDelay
void setEchoDelay(Time delay)
Definition: Echo.cpp:106
helics::Federate::Modes::EXECUTING
@ EXECUTING