KiCad PCB EDA Suite
|
#include <api_server.h>
Public Member Functions | |
KICAD_API_SERVER () | |
~KICAD_API_SERVER () | |
void | Start () |
void | Stop () |
bool | Running () const |
void | RegisterHandler (API_HANDLER *aHandler) |
Adds a new request handler to the server. | |
void | DeregisterHandler (API_HANDLER *aHandler) |
void | SetReadyToReply (bool aReady=true) |
std::string | SocketPath () const |
const std::string & | Token () const |
Private Member Functions | |
void | onApiRequest (std::string *aRequest) |
Callback that executes on the server thread and generates an event that will be handled by the wxWidgets event loop to process an incoming request. | |
void | handleApiEvent (wxCommandEvent &aEvent) |
Event handler that receives the event on the main thread sent by onApiRequest. | |
void | log (const std::string &aOutput) |
Private Attributes | |
std::unique_ptr< KINNG_REQUEST_SERVER > | m_server |
std::set< API_HANDLER * > | m_handlers |
std::string | m_token |
bool | m_readyToReply |
wxFileName | m_logFilePath |
Static Private Attributes | |
static wxString | s_logFileName = "api.log" |
Definition at line 41 of file api_server.h.
KICAD_API_SERVER::KICAD_API_SERVER | ( | ) |
Definition at line 49 of file api_server.cpp.
KICAD_API_SERVER::~KICAD_API_SERVER | ( | ) |
Definition at line 64 of file api_server.cpp.
void KICAD_API_SERVER::DeregisterHandler | ( | API_HANDLER * | aHandler | ) |
Definition at line 147 of file api_server.cpp.
References m_handlers.
|
private |
Event handler that receives the event on the main thread sent by onApiRequest.
aEvent | will contain a pointer to an incoming API request string in the client data |
Definition at line 181 of file api_server.cpp.
References ADVANCED_CFG::GetCfg(), log(), ADVANCED_CFG::m_EnableAPILogging, m_handlers, m_server, and m_token.
|
private |
Definition at line 259 of file api_server.cpp.
References m_logFilePath, and TO_UTF8.
Referenced by handleApiEvent(), onApiRequest(), and Start().
|
private |
Callback that executes on the server thread and generates an event that will be handled by the wxWidgets event loop to process an incoming request.
Temporarily takes ownership of the request pointer so that it can be passed through the event system.
aRequest | is a pointer to a string containing bytes that came in over the wire |
Definition at line 159 of file api_server.cpp.
References log(), m_readyToReply, and m_server.
Referenced by Start().
void KICAD_API_SERVER::RegisterHandler | ( | API_HANDLER * | aHandler | ) |
Adds a new request handler to the server.
Each handler maintains its own list of API messages that it knows how to handle, and the server will pass every incoming message to all handlers in succession until one of them handles it.
The caller is responsible for the lifetime of the handler and must call DeregisterHandler before the pointer is freed.
aHandler | is a pointer (non-owned) to API_HANDLER |
Definition at line 140 of file api_server.cpp.
References m_handlers.
bool KICAD_API_SERVER::Running | ( | ) | const |
Definition at line 134 of file api_server.cpp.
References m_server.
|
inline |
Definition at line 68 of file api_server.h.
std::string KICAD_API_SERVER::SocketPath | ( | ) | const |
void KICAD_API_SERVER::Start | ( | ) |
Definition at line 69 of file api_server.cpp.
References PATHS::EnsurePathExists(), ADVANCED_CFG::GetCfg(), PATHS::GetLogsPath(), handleApiEvent(), log(), ADVANCED_CFG::m_EnableAPILogging, m_logFilePath, m_server, onApiRequest(), Running(), s_logFileName, SocketPath(), and traceApi.
Referenced by KICAD_API_SERVER().
void KICAD_API_SERVER::Stop | ( | ) |
Definition at line 121 of file api_server.cpp.
References handleApiEvent(), m_server, Running(), and traceApi.
|
inline |
Definition at line 72 of file api_server.h.
|
private |
Definition at line 95 of file api_server.h.
Referenced by DeregisterHandler(), handleApiEvent(), and RegisterHandler().
|
private |
Definition at line 103 of file api_server.h.
|
private |
Definition at line 99 of file api_server.h.
Referenced by onApiRequest().
|
private |
Definition at line 93 of file api_server.h.
Referenced by handleApiEvent(), onApiRequest(), Running(), SocketPath(), Start(), and Stop().
|
private |
Definition at line 97 of file api_server.h.
Referenced by handleApiEvent().
|
staticprivate |
Definition at line 101 of file api_server.h.
Referenced by Start().