KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_server.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 Jon Evans <[email protected]>
5 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef KICAD_API_SERVER_H
22#define KICAD_API_SERVER_H
23
24#include <memory>
25#include <set>
26#include <string>
27
28#include <wx/event.h>
29#include <wx/filename.h>
30
31#include <kicommon.h>
32
33class API_HANDLER;
36class wxEvtHandler;
37
38
39wxDECLARE_EVENT( API_REQUEST_EVENT, wxCommandEvent );
40
41
42class KICOMMON_API KICAD_API_SERVER : public wxEvtHandler
43{
44public:
46
48
49 void Start();
50
51 void Stop();
52
53 bool Running() const;
54
65 void RegisterHandler( API_HANDLER* aHandler );
66
67 void DeregisterHandler( API_HANDLER* aHandler );
68
69 void SetReadyToReply( bool aReady = true ) { m_readyToReply = aReady; }
70
71 std::string SocketPath() const;
72
73 const std::string& Token() const { return m_token; }
74
75private:
76
84 void onApiRequest( std::string* aRequest );
85
90 void handleApiEvent( wxCommandEvent& aEvent );
91
92 void log( const std::string& aOutput );
93
94 std::unique_ptr<KINNG_REQUEST_SERVER> m_server;
95
96 std::set<API_HANDLER*> m_handlers;
97
98 std::string m_token;
99
101
102 std::unique_ptr<API_HANDLER_COMMON> m_commonHandler;
103
104 static wxString s_logFileName;
105
106 wxFileName m_logFilePath;
107};
108
109#endif //KICAD_API_SERVER_H
wxDECLARE_EVENT(API_REQUEST_EVENT, wxCommandEvent)
std::string m_token
Definition: api_server.h:98
wxFileName m_logFilePath
Definition: api_server.h:106
std::unique_ptr< API_HANDLER_COMMON > m_commonHandler
Definition: api_server.h:102
static wxString s_logFileName
Definition: api_server.h:104
std::set< API_HANDLER * > m_handlers
Definition: api_server.h:96
const std::string & Token() const
Definition: api_server.h:73
void SetReadyToReply(bool aReady=true)
Definition: api_server.h:69
std::unique_ptr< KINNG_REQUEST_SERVER > m_server
Definition: api_server.h:94
#define KICOMMON_API
Definition: kicommon.h:28