helics  3.0.1
Echo.hpp
1 /*
2 Copyright (c) 2017-2021,
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 <memory>
13 #include <mutex>
14 #include <string>
15 #include <vector>
16 
17 namespace helics {
18 namespace apps {
26  class HELICS_CXX_EXPORT Echo: public App {
27  public:
29  Echo() = default;
33  explicit Echo(std::vector<std::string> args);
38  Echo(int argc, char* argv[]);
43  explicit Echo(const std::string& name, const FederateInfo& fi);
49  Echo(const std::string& name, const std::shared_ptr<Core>& core, const FederateInfo& fi);
55  Echo(const std::string& name, CoreApp& core, const FederateInfo& fi);
60  Echo(const std::string& name, const std::string& jsonString);
61 
63  Echo(Echo&& other_echo) noexcept;
65  Echo& operator=(Echo&& other_echo) noexcept;
66 
70  virtual void runTo(Time stopTime_input) override;
71 
76  void addEndpoint(const std::string& endpointName, const std::string& endpointType = "");
77 
79  auto echoCount() const { return echoCounter; }
83  void setEchoDelay(Time delay);
84 
86  auto endpointCount() const { return endpoints.size(); }
87 
88  private:
90  virtual void loadJsonFile(const std::string& jsonFile) override;
92  void echoMessage(const Endpoint& ept, Time currentTime);
93 
94  private:
96  void processArgs();
97  std::vector<Endpoint> endpoints;
98  Time delayTime = timeZero;
99  size_t echoCounter = 0;
100  std::mutex delayTimeLock; // mutex protecting delayTime
101  };
102 } // namespace apps
103 } // namespace helics
helics::timeZero
constexpr Time timeZero
Definition: helicsTime.hpp:31
helics::apps::Echo
Definition: Echo.hpp:26
helics::apps::App::operator=
App & operator=(App &&app)=default
helics::apps::Echo::echoCount
auto echoCount() const
Definition: Echo.hpp:79
helics::apps::Echo::runTo
virtual void runTo(Time stopTime_input) override
Definition: Echo.cpp:83
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:41
helics::apps::App::masterFileName
std::string masterFileName
the name of the master file used to do the construction
Definition: helicsApp.hpp:129
helics::apps::App::loadJsonFileConfiguration
void loadJsonFileConfiguration(const std::string &appName, const std::string &jsonString)
Definition: helicsApp.cpp:159
helics::apps::Echo::addEndpoint
void addEndpoint(const std::string &endpointName, const std::string &endpointType="")
Definition: Echo.cpp:116
helics::FederateInfo
Definition: FederateInfo.hpp:20
helics::Endpoint::getMessage
std::unique_ptr< Message > getMessage() const
Definition: Endpoints.cpp:149
HELICS_FLAG_EVENT_TRIGGERED
@ HELICS_FLAG_EVENT_TRIGGERED
Definition: helics_enums.h:137
helics::apps::Echo::endpointCount
auto endpointCount() const
Definition: Echo.hpp:86
helics::apps::Echo::operator=
Echo & operator=(Echo &&other_echo) noexcept
Definition: Echo.cpp:73
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:197
helics::apps::App::fed
std::shared_ptr< CombinationFederate > fed
the federate created for the Player
Definition: helicsApp.hpp:127
helics::apps::App
Definition: helicsApp.hpp:28
helics::Federate::Modes::STARTUP
@ STARTUP
helics::apps::App::loadFile
void loadFile(const std::string &filename)
Definition: helicsApp.cpp:124
helics::apps::Echo::Echo
Echo()=default
helics::apps::Echo::setEchoDelay
void setEchoDelay(Time delay)
Definition: Echo.cpp:100
helics::Federate::Modes::EXECUTING
@ EXECUTING