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;
35class wxEvtHandler;
36
37
38wxDECLARE_EVENT( API_REQUEST_EVENT, wxCommandEvent );
39
40
41class KICOMMON_API KICAD_API_SERVER : public wxEvtHandler
42{
43public:
45
47
48 void Start();
49
50 void Stop();
51
52 bool Running() const;
53
64 void RegisterHandler( API_HANDLER* aHandler );
65
66 void DeregisterHandler( API_HANDLER* aHandler );
67
68 void SetReadyToReply( bool aReady = true ) { m_readyToReply = aReady; }
69
70 std::string SocketPath() const;
71
72 const std::string& Token() const { return m_token; }
73
74private:
75
83 void onApiRequest( std::string* aRequest );
84
89 void handleApiEvent( wxCommandEvent& aEvent );
90
91 void log( const std::string& aOutput );
92
93 std::unique_ptr<KINNG_REQUEST_SERVER> m_server;
94
95 std::set<API_HANDLER*> m_handlers;
96
97 std::string m_token;
98
100
101 static wxString s_logFileName;
102
103 wxFileName m_logFilePath;
104};
105
106#endif //KICAD_API_SERVER_H
wxDECLARE_EVENT(API_REQUEST_EVENT, wxCommandEvent)
std::string m_token
Definition: api_server.h:97
wxFileName m_logFilePath
Definition: api_server.h:103
static wxString s_logFileName
Definition: api_server.h:101
std::set< API_HANDLER * > m_handlers
Definition: api_server.h:95
const std::string & Token() const
Definition: api_server.h:72
void SetReadyToReply(bool aReady=true)
Definition: api_server.h:68
std::unique_ptr< KINNG_REQUEST_SERVER > m_server
Definition: api_server.h:93
#define KICOMMON_API
Definition: kicommon.h:28