helics  3.3.0
helicsWebServer.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 
8 #pragma once
9 
10 #include "TypedBrokerServer.hpp"
11 
12 #include <atomic>
13 #include <memory>
14 #include <mutex>
15 #include <string>
16 #include <thread>
17 #include <utility>
18 
19 namespace helics {
20 namespace apps {
21 
22  class IocWrapper;
23 
25  class WebServer: public TypedBrokerServer {
26  public:
27  WebServer() = default;
28  explicit WebServer(std::string_view server_name): name_(server_name) {}
30  virtual void startServer(const Json::Value* val,
31  const std::shared_ptr<TypedBrokerServer>& ptr) override;
33  virtual void stopServer() override;
35  virtual void processArgs(std::string_view args) override;
37  void enableHttpServer(bool enabled) { http_enabled_ = enabled; }
39  void enableWebSocketServer(bool enabled) { websocket_enabled_ = enabled; }
40 
41  private:
42  void mainLoop(std::shared_ptr<WebServer> keepAlive);
43  std::atomic<bool> running{false};
44  std::shared_ptr<IocWrapper> context;
45  std::thread mainLoopThread;
46  std::mutex threadGuard;
47 
48  const Json::Value* config{nullptr};
49  const std::string name_;
50  std::string mArgs;
51  std::string httpAddress_{"127.0.0.1"};
52  int httpPort_{8080};
53  std::string websocketAddress_{"127.0.0.1"};
54  int websocketPort_{8080};
55  bool http_enabled_{false};
56  bool websocket_enabled_{false};
57  std::atomic<bool> executing{false};
58  };
59 } // namespace apps
60 } // namespace helics
helics::timeZero
constexpr Time timeZero
Definition: helicsTime.hpp:31
helics::apps::WebServer::processArgs
virtual void processArgs(std::string_view args) override
Definition: helicsWebServer.cpp:943
helics::Broker::clearTimeBarrier
virtual void clearTimeBarrier()=0
helics::BrokerFactory::getAllBrokers
std::vector< std::shared_ptr< Broker > > getAllBrokers()
Definition: BrokerFactory.cpp:217
helics::CoreType
CoreType
Definition: CoreTypes.hpp:36
helics::BrokerFactory::getConnectedBroker
std::shared_ptr< Broker > getConnectedBroker()
Definition: BrokerFactory.cpp:200
helics::apps::WebServer::enableWebSocketServer
void enableWebSocketServer(bool enabled)
Definition: helicsWebServer.hpp:39
helics::CoreType::DEFAULT
@ DEFAULT
ZMQ if available or UDP.
helics::BrokerFactory::create
std::shared_ptr< Broker > create(CoreType type, std::string_view configureString)
Definition: BrokerFactory.cpp:99
helics::Broker::query
virtual std::string query(std::string_view target, std::string_view queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST)=0
helics::Broker::sendCommand
virtual void sendCommand(std::string_view target, std::string_view commandStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST)=0
helics::BrokerFactory::findBroker
std::shared_ptr< Broker > findBroker(std::string_view brokerName)
Definition: BrokerFactory.cpp:183
helics::Broker::setTimeBarrier
virtual void setTimeBarrier(Time barrierTime)=0
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::apps::WebServer
Definition: helicsWebServer.hpp:25
helics::Broker::disconnect
virtual void disconnect()=0
helics::apps::WebServer::startServer
virtual void startServer(const Json::Value *val, const std::shared_ptr< TypedBrokerServer > &ptr) override
Definition: helicsWebServer.cpp:969
helics::apps::TypedBrokerServer
Definition: TypedBrokerServer.hpp:24
helics::apps::WebServer::enableHttpServer
void enableHttpServer(bool enabled)
Definition: helicsWebServer.hpp:37
helics::apps::WebServer::stopServer
virtual void stopServer() override
Definition: helicsWebServer.cpp:994