/*----------------------------------------------------------------------------*/ /* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ /*----------------------------------------------------------------------------*/ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace wpilibws { class HALSimHttpConnection; class HALSimWeb { public: static std::shared_ptr GetInstance() { return g_instance; } static void SetInstance(std::shared_ptr inst) { g_instance = inst; } explicit HALSimWeb(ProviderContainer& providers, HALSimWSProviderSimDevices& simDevicesProvider) : m_providers(providers), m_simDevicesProvider(simDevicesProvider) {} HALSimWeb(const HALSimWeb&) = delete; HALSimWeb& operator=(const HALSimWeb&) = delete; bool Initialize(); static void Main(void*); static void Exit(void*); bool RegisterWebsocket(std::shared_ptr hws); void CloseWebsocket(std::shared_ptr hws); // network -> sim void OnNetValueChanged(const wpi::json& msg); std::string GetServerUri() const { return m_uri; } int GetServerPort() { return m_port; } std::shared_ptr GetLoop() { return m_loop; } private: static std::shared_ptr g_instance; void MainLoop(); // connected http connection that contains active websocket std::weak_ptr m_hws; // list of providers ProviderContainer& m_providers; HALSimWSProviderSimDevices& m_simDevicesProvider; std::shared_ptr m_loop; std::shared_ptr m_server; // Absolute paths of folders to retrieve data from // -> / std::string m_webroot_sys; // -> /user std::string m_webroot_user; std::string m_uri; int m_port; }; } // namespace wpilibws