helics 3.7.0
Loading...
Searching...
No Matches
helicsWebServer.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-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
19namespace helics::apps {
20
21class IocWrapper;
22
25 public:
27 static constexpr int defaultHttpPort{43542};
29 static constexpr int defaultWebSocketPort{43543};
30 WebServer() = default;
31 explicit WebServer(std::string_view server_name): mName(server_name) {}
33 virtual void startServer(const nlohmann::json* val,
34 const std::shared_ptr<TypedBrokerServer>& ptr) override;
36 virtual void stopServer() override;
38 virtual void processArgs(std::string_view args) override;
40 void enableHttpServer(bool enabled) { mHttpEnabled = enabled; }
42 void enableWebSocketServer(bool enabled) { mWebsocketEnabled = enabled; }
43
44 private:
45 void mainLoop(std::shared_ptr<WebServer> keepAlive);
46 std::atomic<bool> running{false};
47 std::shared_ptr<IocWrapper> context;
48 std::thread mainLoopThread;
49 std::mutex threadGuard;
50
51 const nlohmann::json* config{nullptr};
52 const std::string mName;
53 std::string mArgs;
54 std::string mHttpAddress;
55 int mHttpPort{defaultHttpPort};
56 std::string mWebsocketAddress;
57 int mWebsocketPort{defaultWebSocketPort};
58 bool mHttpEnabled{false};
59 bool mWebsocketEnabled{false};
60 int mInterfaceNetwork{0};
61 std::atomic<bool> executing{false};
62};
63} // namespace helics::apps
Definition TypedBrokerServer.hpp:24
Definition helicsWebServer.hpp:24
static constexpr int defaultHttpPort
default port for the HTTP web server
Definition helicsWebServer.hpp:27
static constexpr int defaultWebSocketPort
default port for the Websocket server
Definition helicsWebServer.hpp:29
virtual void stopServer() override
Definition helicsWebServer.cpp:1052
void enableHttpServer(bool enabled)
Definition helicsWebServer.hpp:40
virtual void startServer(const nlohmann::json *val, const std::shared_ptr< TypedBrokerServer > &ptr) override
Definition helicsWebServer.cpp:1026
virtual void processArgs(std::string_view args) override
Definition helicsWebServer.cpp:970
void enableWebSocketServer(bool enabled)
Definition helicsWebServer.hpp:42