helics  3.0.1
helicsWebServer.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 
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 server_name): name_(std::move(server_name)) {}
30  virtual void startServer(const Json::Value* val) override;
32  virtual void stopServer() override;
34  virtual void processArgs(const std::string& args) override;
36  void enableHttpServer(bool enabled) { http_enabled_ = enabled; }
38  void enableWebSocketServer(bool enabled) { websocket_enabled_ = enabled; }
39 
40  private:
41  void mainLoop();
42 
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::Broker::clearTimeBarrier
virtual void clearTimeBarrier()=0
helics::BrokerFactory::getAllBrokers
std::vector< std::shared_ptr< Broker > > getAllBrokers()
Definition: BrokerFactory.cpp:220
helics::CoreType
CoreType
Definition: CoreTypes.hpp:36
helics::BrokerFactory::findBroker
std::shared_ptr< Broker > findBroker(const std::string &brokerName)
Definition: BrokerFactory.cpp:182
helics::BrokerFactory::getConnectedBroker
std::shared_ptr< Broker > getConnectedBroker()
Definition: BrokerFactory.cpp:203
helics::apps::WebServer::enableWebSocketServer
void enableWebSocketServer(bool enabled)
Definition: helicsWebServer.hpp:38
helics::apps::WebServer::startServer
virtual void startServer(const Json::Value *val) override
Definition: helicsWebServer.cpp:917
helics::CoreType::DEFAULT
@ DEFAULT
ZMQ if available or UDP.
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::TypedBrokerServer
Definition: TypedBrokerServer.hpp:24
helics::Broker::query
virtual std::string query(const std::string &target, const std::string &queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST)=0
helics::BrokerFactory::create
std::shared_ptr< Broker > create(CoreType type, const std::string &configureString)
Definition: BrokerFactory.cpp:98
helics::apps::WebServer::processArgs
virtual void processArgs(const std::string &args) override
Definition: helicsWebServer.cpp:891
helics::apps::WebServer::enableHttpServer
void enableHttpServer(bool enabled)
Definition: helicsWebServer.hpp:36
helics::apps::WebServer::stopServer
virtual void stopServer() override
Definition: helicsWebServer.cpp:938