helics  3.5.2
Echo.hpp
1 /*
2 Copyright (c) 2017-2024,
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,
92  bool enableFederateInterfaceRegistration) override;
94  void echoMessage(const Endpoint& ept, Time currentTime);
95 
96  private:
98  void initialSetup();
100  void processArgs();
101  std::deque<Endpoint> endpoints;
102  Time delayTime = timeZero;
103  size_t echoCounter = 0;
104  std::mutex delayTimeLock; // mutex protecting delayTime
105  };
106 } // namespace apps
107 } // namespace helics
Definition: Endpoints.hpp:21
Definition: FederateInfo.hpp:29
Definition: helicsApp.hpp:32
Definition: Echo.hpp:27
auto endpointCount() const
Definition: Echo.hpp:87
auto echoCount() const
Definition: Echo.hpp:80
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
constexpr Time timeZero
Definition: helicsTime.hpp:31
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27