KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KICAD_API_SERVER Class Reference

#include <api_server.h>

Inheritance diagram for KICAD_API_SERVER:

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_SERVERm_server
 
std::set< API_HANDLER * > m_handlers
 
std::string m_token
 
bool m_readyToReply
 
std::unique_ptr< API_HANDLER_COMMONm_commonHandler
 
wxFileName m_logFilePath
 

Static Private Attributes

static wxString s_logFileName = "api.log"
 

Detailed Description

Definition at line 42 of file api_server.h.

Constructor & Destructor Documentation

◆ KICAD_API_SERVER()

KICAD_API_SERVER::KICAD_API_SERVER ( )

Definition at line 48 of file api_server.cpp.

References m_commonHandler, Pgm(), RegisterHandler(), Start(), and traceApi.

◆ ~KICAD_API_SERVER()

KICAD_API_SERVER::~KICAD_API_SERVER ( )

Definition at line 66 of file api_server.cpp.

Member Function Documentation

◆ DeregisterHandler()

void KICAD_API_SERVER::DeregisterHandler ( API_HANDLER aHandler)

Definition at line 149 of file api_server.cpp.

References m_handlers.

◆ handleApiEvent()

void KICAD_API_SERVER::handleApiEvent ( wxCommandEvent &  aEvent)
private

Event handler that receives the event on the main thread sent by onApiRequest.

Parameters
aEventwill contain a pointer to an incoming API request string in the client data

Definition at line 183 of file api_server.cpp.

References ADVANCED_CFG::GetCfg(), log(), ADVANCED_CFG::m_EnableAPILogging, m_handlers, m_server, and m_token.

Referenced by Start(), and Stop().

◆ log()

void KICAD_API_SERVER::log ( const std::string &  aOutput)
private

Definition at line 261 of file api_server.cpp.

References m_logFilePath, and TO_UTF8.

Referenced by handleApiEvent(), onApiRequest(), and Start().

◆ onApiRequest()

void KICAD_API_SERVER::onApiRequest ( std::string *  aRequest)
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.

Parameters
aRequestis a pointer to a string containing bytes that came in over the wire

Definition at line 161 of file api_server.cpp.

References log(), m_readyToReply, and m_server.

Referenced by Start().

◆ RegisterHandler()

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.

Parameters
aHandleris a pointer (non-owned) to API_HANDLER

Definition at line 142 of file api_server.cpp.

References m_handlers.

Referenced by KICAD_API_SERVER().

◆ Running()

bool KICAD_API_SERVER::Running ( ) const

Definition at line 136 of file api_server.cpp.

References m_server.

Referenced by Start(), and Stop().

◆ SetReadyToReply()

void KICAD_API_SERVER::SetReadyToReply ( bool  aReady = true)
inline

Definition at line 69 of file api_server.h.

◆ SocketPath()

std::string KICAD_API_SERVER::SocketPath ( ) const

Definition at line 155 of file api_server.cpp.

References m_server.

Referenced by Start().

◆ Start()

◆ Stop()

void KICAD_API_SERVER::Stop ( )

Definition at line 123 of file api_server.cpp.

References handleApiEvent(), m_server, Running(), and traceApi.

◆ Token()

const std::string & KICAD_API_SERVER::Token ( ) const
inline

Definition at line 73 of file api_server.h.

Member Data Documentation

◆ m_commonHandler

std::unique_ptr<API_HANDLER_COMMON> KICAD_API_SERVER::m_commonHandler
private

Definition at line 102 of file api_server.h.

Referenced by KICAD_API_SERVER().

◆ m_handlers

std::set<API_HANDLER*> KICAD_API_SERVER::m_handlers
private

Definition at line 96 of file api_server.h.

Referenced by DeregisterHandler(), handleApiEvent(), and RegisterHandler().

◆ m_logFilePath

wxFileName KICAD_API_SERVER::m_logFilePath
private

Definition at line 106 of file api_server.h.

Referenced by log(), and Start().

◆ m_readyToReply

bool KICAD_API_SERVER::m_readyToReply
private

Definition at line 100 of file api_server.h.

Referenced by onApiRequest().

◆ m_server

std::unique_ptr<KINNG_REQUEST_SERVER> KICAD_API_SERVER::m_server
private

Definition at line 94 of file api_server.h.

Referenced by handleApiEvent(), onApiRequest(), Running(), SocketPath(), Start(), and Stop().

◆ m_token

std::string KICAD_API_SERVER::m_token
private

Definition at line 98 of file api_server.h.

Referenced by handleApiEvent().

◆ s_logFileName

wxString KICAD_API_SERVER::s_logFileName = "api.log"
staticprivate

Definition at line 104 of file api_server.h.

Referenced by Start().


The documentation for this class was generated from the following files: