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 (bool aAutoStart=true)
 
 ~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)
 
void SetSocketPath (const wxString &aSocketPath)
 
std::string SocketPath () const
 
const std::string & Token () const
 
void NotifyNetSettingsChanged ()
 Calls onNetSettingsChanged() on every registered handler, so that editors can update state derived from project net settings after they are changed via the API.
 
void NotifyDocumentRenamed (kiapi::common::types::DocumentType aType, const wxString &aOldPath, const wxString &aNewPath)
 Notifies the host application that a document was saved to a new path.
 
void SetRenameListener (std::function< void(kiapi::common::types::DocumentType, const wxString &, const wxString &)> aListener)
 Installs a callback to be invoked by NotifyDocumentRenamed.
 

Static Public Member Functions

static wxFileName StandardSocketPath ()
 Return the default API socket path (without the ipc:// scheme).
 
static std::string StandardSocketUrl ()
 Return the default API socket URL (including the ipc:// scheme).
 

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 handleApiRequestString (std::string &aRequestString)
 
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
 
std::atomic< bool > m_readyToReply
 
std::function< void(kiapi::common::types::DocumentType, const wxString &, const wxString &)> m_renameListener
 
wxString m_socketPathOverride
 
wxFileName m_logFilePath
 

Static Private Attributes

static wxString s_logFileName = "api.log"
 

Detailed Description

Definition at line 44 of file api_server.h.

Constructor & Destructor Documentation

◆ KICAD_API_SERVER()

KICAD_API_SERVER::KICAD_API_SERVER ( bool aAutoStart = true)

Definition at line 53 of file api_server.cpp.

References m_readyToReply, m_token, Pgm(), and Start().

◆ ~KICAD_API_SERVER()

KICAD_API_SERVER::~KICAD_API_SERVER ( )

Definition at line 71 of file api_server.cpp.

References Stop().

Member Function Documentation

◆ DeregisterHandler()

◆ 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 263 of file api_server.cpp.

References handleApiRequestString().

Referenced by Start(), and Stop().

◆ handleApiRequestString()

void KICAD_API_SERVER::handleApiRequestString ( std::string & aRequestString)
private

◆ log()

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

Definition at line 356 of file api_server.cpp.

References m_logFilePath, and TO_UTF8.

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

◆ NotifyDocumentRenamed()

void KICAD_API_SERVER::NotifyDocumentRenamed ( kiapi::common::types::DocumentType aType,
const wxString & aOldPath,
const wxString & aNewPath )

Notifies the host application that a document was saved to a new path.

Must be called from the main thread.

Definition at line 227 of file api_server.cpp.

References m_renameListener.

◆ NotifyNetSettingsChanged()

void KICAD_API_SERVER::NotifyNetSettingsChanged ( )

Calls onNetSettingsChanged() on every registered handler, so that editors can update state derived from project net settings after they are changed via the API.

Must be called from the main thread.

Definition at line 220 of file api_server.cpp.

References m_handlers.

Referenced by handleApiRequestString().

◆ 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 241 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 202 of file api_server.cpp.

References m_handlers, and API_HANDLER::setApiServer().

Referenced by EVT_UPDATE_UI_RANGE(), FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME(), SCH::IFACE::HandleApiOpenDocument(), PCB::IFACE::handleCreatePcb(), SCH::IFACE::handleCreateSchematic(), PCB::IFACE::handleOpenFootprint(), PCB::IFACE::handleOpenPcb(), SCH::IFACE::handleOpenSymbol(), PCB::IFACE::OnKifaceStart(), SCH::IFACE::OnKifaceStart(), PCB::IFACE::RegisterLibraryHandlers(), SCH::IFACE::RegisterLibraryHandlers(), SCH_EDIT_FRAME::SCH_EDIT_FRAME(), and SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME().

◆ Running()

◆ SetReadyToReply()

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

Definition at line 71 of file api_server.h.

References m_readyToReply.

◆ SetRenameListener()

void KICAD_API_SERVER::SetRenameListener ( std::function< void(kiapi::common::types::DocumentType, const wxString &, const wxString &)> aListener)
inline

Installs a callback to be invoked by NotifyDocumentRenamed.

Definition at line 112 of file api_server.h.

References m_renameListener.

◆ SetSocketPath()

void KICAD_API_SERVER::SetSocketPath ( const wxString & aSocketPath)
inline

Definition at line 76 of file api_server.h.

References m_socketPathOverride.

◆ SocketPath()

std::string KICAD_API_SERVER::SocketPath ( ) const

◆ StandardSocketPath()

wxFileName KICAD_API_SERVER::StandardSocketPath ( )
static

Return the default API socket path (without the ipc:// scheme).

Definition at line 77 of file api_server.cpp.

Referenced by StandardSocketUrl(), and Start().

◆ StandardSocketUrl()

std::string KICAD_API_SERVER::StandardSocketUrl ( )
static

Return the default API socket URL (including the ipc:// scheme).

Definition at line 94 of file api_server.cpp.

References StandardSocketPath().

Referenced by CROSS_PROBE_CLIENT::AnnounceToPrimary(), CROSS_PROBE_CLIENT::IsOnStandardSocketPath(), and CROSS_PROBE_CLIENT::SendToFrame().

◆ Start()

◆ Stop()

void KICAD_API_SERVER::Stop ( )

◆ Token()

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

Definition at line 83 of file api_server.h.

References m_token.

Referenced by CROSS_PROBE_CLIENT::AnnounceToPrimary(), and API_PLUGIN_MANAGER::doInvokeAction().

Member Data Documentation

◆ m_handlers

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

◆ m_logFilePath

wxFileName KICAD_API_SERVER::m_logFilePath
private

Definition at line 153 of file api_server.h.

Referenced by log(), and Start().

◆ m_readyToReply

std::atomic<bool> KICAD_API_SERVER::m_readyToReply
private

Definition at line 145 of file api_server.h.

Referenced by KICAD_API_SERVER(), onApiRequest(), and SetReadyToReply().

◆ m_renameListener

std::function<void( kiapi::common::types::DocumentType, const wxString&, const wxString& )> KICAD_API_SERVER::m_renameListener
private

Definition at line 147 of file api_server.h.

Referenced by NotifyDocumentRenamed(), and SetRenameListener().

◆ m_server

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

Definition at line 139 of file api_server.h.

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

◆ m_socketPathOverride

wxString KICAD_API_SERVER::m_socketPathOverride
private

Definition at line 149 of file api_server.h.

Referenced by SetSocketPath(), and Start().

◆ m_token

std::string KICAD_API_SERVER::m_token
private

Definition at line 143 of file api_server.h.

Referenced by handleApiRequestString(), KICAD_API_SERVER(), and Token().

◆ s_logFileName

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

Definition at line 151 of file api_server.h.

Referenced by Start().


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