26 #include <condition_variable>
31 #include <unordered_map>
33 #include "observable_evtvar.h"
37 #if (defined(OCPN_GHC_FILESYSTEM) || (defined(__clang_major__) && (__clang_major__ < 15)))
38 #include <ghc/filesystem.hpp>
39 namespace fs = ghc::filesystem;
44 namespace fs = std::filesystem;
48 #include <wx/string.h>
49 #include <wx/thread.h>
51 #include "pugixml.hpp"
62 enum class RestServerResult {
66 DuplicateRejected = 3,
74 enum { ID_STG_CANCEL = 10000, ID_STG_OK, ID_STG_CHECK1, ID_STG_CHOICE_COMM };
98 std::function<wxDialog*(
const std::string& msg,
const std::string& text1)>
106 const wxString& check1msg)>
108 std::function<void()> top_level_refresh;
117 std::function<
Route*(wxString)> find_route_by_guid;
118 std::function<
Track*(wxString)> find_track_by_guid;
119 std::function<
RoutePoint*(wxString)> find_wpt_by_guid;
120 std::function<void(
Route*)> delete_route;
121 std::function<void(
Track*)> delete_track;
122 std::function<void(
RoutePoint*)> delete_waypoint;
225 virtual bool StartServer(
const fs::path& certificate_location) = 0;
252 bool StartServer(
const fs::path& certificate_location)
override;
288 const std::string m_endpoint;
308 virtual ~IoThread() =
default;
311 bool IsRunning() {
return run_flag > 0; }
317 bool WaitUntilStopped();
321 std::atomic_int run_flag;
323 std::string m_server_ip;
330 class Apikeys :
public std::unordered_map<std::string, std::string> {
332 static Apikeys Parse(
const std::string& s);
333 std::string ToString()
const;
341 void HandleWaypoint(pugi::xml_node
object,
const RestIoEvtData& evt_data);
342 void HandleTrack(pugi::xml_node
object,
const RestIoEvtData& evt_data);
343 void HandleRoute(pugi::xml_node
object,
const RestIoEvtData& evt_data);
350 RestServerResult return_status;
352 std::string m_certificate_directory;
354 wxDialog* m_pin_dialog;
357 std::string m_upload_path;
358 std::ofstream m_ul_stream;
359 std::thread m_std_thread;
360 IoThread m_io_thread;
virtual void StopServer()=0
Stop server thread, blocks until completed.
virtual std::string GetEndpoint()=0
Return HTTPS url to local rest server.
EventVar reverse_route
Notified with a string GUID when user wants to reverse a route.
EventVar activate_route
Notified with a string GUID when user wants to activate a route.
virtual bool StartServer(const fs::path &certificate_location)=0
Start the server thread.
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
Adds a std::shared<void> element to wxCommandEvent.
A random generated int value with accessors for string and hashcode.
Callbacks for handling dialogs and RouteManager updates.
RestServerDlgCtx()
All dummy stubs constructor.
std::function< void(void)> update_route_mgr
Update Route manager after updates to underlying nav_object_database.
std::function< AcceptObjectDlgResult(const wxString &msg, const wxString &check1msg)> run_accept_object_dlg
Run the "Accept Object" dialog, returns value from ShowModal().
std::function< wxDialog *(const std::string &msg, const std::string &text1)> run_pincode_dlg
Run the "Server wants a pincode" dialog.
AbstractRestServer implementation and interface to underlying IO thread.
std::string m_cert_file
Semi-static storage used by IoThread C code.
wxSemaphore m_exit_sem
IoThread interface: Binary exit synchronization, released when io thread exits.
std::string m_reply_body
IoThread interface: body of return message, if any.
RestServerResult GetReturnStatus()
IoThread interface.
std::condition_variable return_status_cv
IoThread interface: Guards return_status.
std::mutex ret_mutex
IoThread interface: Guards return_status.
friend class RestServerPingApp
Unit test hook.
friend class RestCheckWriteApp
Unit test hook.
friend class RestPluginMsgApp
Unit test hook.
void StopServer() override
Stop server thread, blocks until completed.
std::string GetEndpoint() override
Return HTTPS url to local rest server.
void UpdateRouteMgr() const
IoThread interface.
void UpdateReturnStatus(RestServerResult r)
IoThread interface.
std::string m_key_file
Semi-static storage used by IoThread C code.
bool StartServer(const fs::path &certificate_location) override
Start the server thread.
friend class RestServerObjectApp
Unit test hook.
Callbacks for handling routes and tracks.
RouteCtx()
Dummy stubs constructor.
std::string RestResultText(RestServerResult result)
RestServerResult string representation.
Returned status from RunAcceptObjectDlg.
AcceptObjectDlgResult(int s, bool b)
Create a struct with given values for status and check1_value.
const bool check1_value
As of GetCheck1Value()
const int status
return value from ShowModal()
AcceptObjectDlgResult()
default constructor, returns empty struct.