helics  2.8.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/Endpoints.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: helics-time.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::Endpoint::getMessage
auto getMessage() const
Definition: Endpoints.hpp:174
loadJsonTime
helics::Time loadJsonTime(const Json::Value &timeElement, time_units defaultUnits=time_units::sec)
Definition: JsonProcessingFunctions.cpp:64
helics::apps::Echo::runTo
virtual void runTo(Time stopTime_input) override
Definition: Echo.cpp:83
helics_flag_event_triggered
@ helics_flag_event_triggered
Definition: helics_enums.h:124
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helics-time.hpp:27
helics::Endpoint
Definition: Endpoints.hpp:18
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
loadJson
Json::Value loadJson(const std::string &jsonString)
Definition: JsonProcessingFunctions.cpp:24
helics::Federate::modes::startup
@ startup
when created the federate is in startup state
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::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::Endpoint::send
void send(const std::string &dest, const char *data, size_t data_size) const
Definition: Endpoints.hpp:89
helics::Federate::modes::finalize
@ finalize
the federate has finished executing normally final values may be retrieved
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
entered after the enterExectuationState call has returned