OpenCPN Partial API docs
Loading...
Searching...
No Matches
REST_server.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose:
5 * Author: David Register, Alec Leamas
6 *
7 ***************************************************************************
8 * Copyright (C) 2022 by David Register, Alec Leamas *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25
26#ifndef _RESTSERVER_H
27#define _RESTSERVER_H
28
29#include <string>
30#include <unordered_map>
31
32#include <wx/event.h>
33
34typedef enum RESTServerResult {
35 RESULT_NO_ERROR = 0,
36 RESULT_GENERIC_ERROR,
37 RESULT_OBJECT_REJECTED,
38 RESULT_DUPLICATE_REJECTED,
39 RESULT_ROUTE_INSERT_ERROR,
40 RESULT_NEW_PIN_REQUESTED
41} _RESTServerResult;
42
43
44class RESTServerThread; // Internal
45class RESTServerEvent; // Internal
46class PINCreateDialog;
47
48class RESTServer : public wxEvtHandler {
49public:
50 RESTServer();
51
52 virtual ~RESTServer();
53
54 bool StartServer(std::string certificate_location);
55 void StopServer();
56
57 void HandleServerMessage(RESTServerEvent& event);
58
59 // Secondary thread life toggle
60 // Used to inform launching object (this) to determine if the thread can
61 // be safely called or polled, e.g. wxThread->Destroy();
62 void SetSecThreadActive(void) { m_bsec_thread_active = true; }
63 void SetSecThreadInActive(void) { m_bsec_thread_active = false; }
64 bool IsSecThreadActive() const { return m_bsec_thread_active; }
65
66 void SetSecondaryThread(RESTServerThread* secondary_Thread) {
67 m_pSecondary_Thread = secondary_Thread;
68 }
69 RESTServerThread* GetSecondaryThread() {
70 return m_pSecondary_Thread;
71 }
72 void SetThreadRunFlag(int run) { m_Thread_run_flag = run; }
73
74 std::string GetCertificateDirectory(){ return m_certificate_directory; }
75 int m_Thread_run_flag;
76
77 std::string m_cert_file;
78 std::string m_key_file;
79
80private:
81 bool LoadConfig( void );
82 bool SaveConfig( void );
83
84 RESTServerThread* m_pSecondary_Thread;
85 bool m_bsec_thread_active;
86 std::string m_certificate_directory;
87 std::unordered_map<std::string, std::string> m_key_map;
88 PINCreateDialog *m_PINCreateDialog;
89 wxString m_sPIN;
90 int m_dPIN;
91 bool m_b_overwrite;
92
93};
94
95#endif // guard