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

#include <api_handler_common.h>

Inheritance diagram for API_HANDLER_COMMON:
API_HANDLER

Public Types

using OPEN_DOCUMENT_HANDLER
 
using CREATE_DOCUMENT_HANDLER
 
using CLOSE_DOCUMENT_HANDLER
 
using CLOSE_ALL_DOCUMENTS_HANDLER
 

Public Member Functions

 API_HANDLER_COMMON ()
 
 ~API_HANDLER_COMMON () override
 
void SetOpenDocumentHandler (OPEN_DOCUMENT_HANDLER aHandler)
 
void SetCloseDocumentHandler (CLOSE_DOCUMENT_HANDLER aHandler)
 
void SetCloseAllDocumentsHandler (CLOSE_ALL_DOCUMENTS_HANDLER aHandler)
 
void SetCreateDocumentHandler (CREATE_DOCUMENT_HANDLER aHandler)
 
API_RESULT Handle (ApiRequest &aMsg)
 Attempt to handle the given API request, if a handler exists in this class for the message.
 
bool CanHandle (const std::string &aTypeName) const
 
bool AllowsDuringTask (const std::string &aTypeName) const
 
virtual void onNetSettingsChanged ()
 Called on all registered handlers after project net settings (netclasses or netclass assignments) have been changed via the API.
 
void requestNetSettingsNotification ()
 
bool clearNetSettingsNotification ()
 Returns true if the notification had been requested at the time of the call.
 
void setApiServer (KICAD_API_SERVER *aServer)
 Set by KICAD_API_SERVER::RegisterHandler; null when the handler is not registered.
 
KICAD_API_SERVER * apiServer () const
 

Protected Types

typedef std::function< HANDLER_RESULT< ApiResponse >(ApiRequest &)> REQUEST_HANDLER
 A handler for outer messages (envelopes) that will unpack to inner messages and call a specific handler function.
 

Protected Member Functions

template<class RequestType, class ResponseType, class HandlerType>
void registerHandler (HANDLER_RESULT< ResponseType >(HandlerType::*aHandler)(const HANDLER_CONTEXT< RequestType > &), bool aAllowedDuringTask=false)
 Registers an API command handler for the given message types.
 

Protected Attributes

std::map< std::string, HANDLER_ENTRY > m_handlers
 Maps type name (without the URL prefix) to a handler method.
 
bool m_notifyNetSettings = false
 
KICAD_API_SERVER * m_apiServer = nullptr
 

Static Protected Attributes

static const wxString m_defaultCommitMessage = _( "Modification from API" )
 

Private Member Functions

HANDLER_RESULT< commands::GetVersionResponse > handleGetVersion (const HANDLER_CONTEXT< commands::GetVersion > &aCtx)
 
HANDLER_RESULT< commands::PathResponse > handleGetKiCadBinaryPath (const HANDLER_CONTEXT< commands::GetKiCadBinaryPath > &aCtx)
 
HANDLER_RESULT< commands::GetPathsResponse > handleGetPaths (const HANDLER_CONTEXT< commands::GetPaths > &aCtx)
 
HANDLER_RESULT< commands::NetClassesResponse > handleGetNetClasses (const HANDLER_CONTEXT< commands::GetNetClasses > &aCtx)
 
HANDLER_RESULT< Empty > handleSetNetClasses (const HANDLER_CONTEXT< commands::SetNetClasses > &aCtx)
 
HANDLER_RESULT< commands::NetClassAssignmentsResponse > handleGetNetClassAssignments (const HANDLER_CONTEXT< commands::GetNetClassAssignments > &aCtx)
 
HANDLER_RESULT< Empty > handleSetNetClassAssignments (const HANDLER_CONTEXT< commands::SetNetClassAssignments > &aCtx)
 
HANDLER_RESULT< Empty > handlePing (const HANDLER_CONTEXT< commands::Ping > &aCtx)
 
HANDLER_RESULT< types::Box2 > handleGetTextExtents (const HANDLER_CONTEXT< commands::GetTextExtents > &aCtx)
 
HANDLER_RESULT< commands::GetTextAsShapesResponse > handleGetTextAsShapes (const HANDLER_CONTEXT< commands::GetTextAsShapes > &aCtx)
 
HANDLER_RESULT< commands::ExpandTextVariablesResponse > handleExpandTextVariables (const HANDLER_CONTEXT< commands::ExpandTextVariables > &aCtx)
 
HANDLER_RESULT< commands::StringResponse > handleGetPluginSettingsPath (const HANDLER_CONTEXT< commands::GetPluginSettingsPath > &aCtx)
 
HANDLER_RESULT< project::TextVariables > handleGetTextVariables (const HANDLER_CONTEXT< commands::GetTextVariables > &aCtx)
 
HANDLER_RESULT< Empty > handleSetTextVariables (const HANDLER_CONTEXT< commands::SetTextVariables > &aCtx)
 
HANDLER_RESULT< commands::OpenDocumentResponse > handleOpenDocument (const HANDLER_CONTEXT< commands::OpenDocument > &aCtx)
 
HANDLER_RESULT< commands::OpenDocumentResponse > handleCreateDocument (const HANDLER_CONTEXT< commands::CreateDocument > &aCtx)
 
HANDLER_RESULT< Empty > handleCloseDocument (const HANDLER_CONTEXT< commands::CloseDocument > &aCtx)
 
HANDLER_RESULT< Empty > handleCloseAllDocuments (const HANDLER_CONTEXT< commands::CloseAllDocuments > &aCtx)
 
HANDLER_RESULT< tasks::TaskStatusResponse > handleGetTaskStatus (const HANDLER_CONTEXT< tasks::GetTaskStatus > &aCtx)
 
template<typename MessageType>
bool tryUnpack (ApiRequest &aRequest, ApiResponse &aReply, MessageType &aDest)
 

Static Private Member Functions

static tl::expected< bool, ApiResponseStatus > validateProject (const ProjectSpecifier &aProject, bool aAllowEmpty=false)
 

Private Attributes

OPEN_DOCUMENT_HANDLER m_openDocumentHandler
 
CLOSE_ALL_DOCUMENTS_HANDLER m_closeAllDocumentsHandler
 
CLOSE_DOCUMENT_HANDLER m_closeDocumentHandler
 
CREATE_DOCUMENT_HANDLER m_createDocumentHandler
 

Detailed Description

Definition at line 37 of file api_handler_common.h.

Member Typedef Documentation

◆ CLOSE_ALL_DOCUMENTS_HANDLER

Initial value:
std::function<HANDLER_RESULT<Empty>(
const commands::CloseAllDocuments& )>

Definition at line 46 of file api_handler_common.h.

◆ CLOSE_DOCUMENT_HANDLER

Initial value:
std::function<HANDLER_RESULT<Empty>(
const commands::CloseDocument& )>

Definition at line 44 of file api_handler_common.h.

◆ CREATE_DOCUMENT_HANDLER

Initial value:
std::function<HANDLER_RESULT<commands::OpenDocumentResponse>(
const commands::CreateDocument& )>

Definition at line 42 of file api_handler_common.h.

◆ OPEN_DOCUMENT_HANDLER

Initial value:
std::function<HANDLER_RESULT<commands::OpenDocumentResponse>(
const commands::OpenDocument& )>

Definition at line 40 of file api_handler_common.h.

◆ REQUEST_HANDLER

typedef std::function<HANDLER_RESULT<ApiResponse>( ApiRequest& )> API_HANDLER::REQUEST_HANDLER
protectedinherited

A handler for outer messages (envelopes) that will unpack to inner messages and call a specific handler function.

See also
registerHandler.

Definition at line 112 of file api_handler.h.

Constructor & Destructor Documentation

◆ API_HANDLER_COMMON()

◆ ~API_HANDLER_COMMON()

API_HANDLER_COMMON::~API_HANDLER_COMMON ( )
inlineoverride

Definition at line 52 of file api_handler_common.h.

Member Function Documentation

◆ AllowsDuringTask()

bool API_HANDLER::AllowsDuringTask ( const std::string & aTypeName) const
inlineinherited
Returns
true if the given request message is allowed while an async API task is running.

Definition at line 81 of file api_handler.h.

References m_handlers.

Referenced by BOOST_AUTO_TEST_CASE().

◆ apiServer()

KICAD_API_SERVER * API_HANDLER::apiServer ( ) const
inlineinherited

◆ CanHandle()

bool API_HANDLER::CanHandle ( const std::string & aTypeName) const
inlineinherited
Returns
true if this handler can process the given request message type

Definition at line 73 of file api_handler.h.

References m_handlers.

Referenced by BOOST_AUTO_TEST_CASE().

◆ clearNetSettingsNotification()

bool API_HANDLER::clearNetSettingsNotification ( )
inlineinherited

Returns true if the notification had been requested at the time of the call.

Definition at line 96 of file api_handler.h.

References m_notifyNetSettings.

◆ Handle()

◆ handleCloseAllDocuments()

HANDLER_RESULT< Empty > API_HANDLER_COMMON::handleCloseAllDocuments ( const HANDLER_CONTEXT< commands::CloseAllDocuments > & aCtx)
private

◆ handleCloseDocument()

HANDLER_RESULT< Empty > API_HANDLER_COMMON::handleCloseDocument ( const HANDLER_CONTEXT< commands::CloseDocument > & aCtx)
private

◆ handleCreateDocument()

HANDLER_RESULT< OpenDocumentResponse > API_HANDLER_COMMON::handleCreateDocument ( const HANDLER_CONTEXT< commands::CreateDocument > & aCtx)
private

◆ handleExpandTextVariables()

HANDLER_RESULT< ExpandTextVariablesResponse > API_HANDLER_COMMON::handleExpandTextVariables ( const HANDLER_CONTEXT< commands::ExpandTextVariables > & aCtx)
private

◆ handleGetKiCadBinaryPath()

HANDLER_RESULT< PathResponse > API_HANDLER_COMMON::handleGetKiCadBinaryPath ( const HANDLER_CONTEXT< commands::GetKiCadBinaryPath > & aCtx)
private

◆ handleGetNetClassAssignments()

HANDLER_RESULT< NetClassAssignmentsResponse > API_HANDLER_COMMON::handleGetNetClassAssignments ( const HANDLER_CONTEXT< commands::GetNetClassAssignments > & aCtx)
private

◆ handleGetNetClasses()

HANDLER_RESULT< NetClassesResponse > API_HANDLER_COMMON::handleGetNetClasses ( const HANDLER_CONTEXT< commands::GetNetClasses > & aCtx)
private

◆ handleGetPaths()

◆ handleGetPluginSettingsPath()

HANDLER_RESULT< StringResponse > API_HANDLER_COMMON::handleGetPluginSettingsPath ( const HANDLER_CONTEXT< commands::GetPluginSettingsPath > & aCtx)
private

◆ handleGetTaskStatus()

HANDLER_RESULT< tasks::TaskStatusResponse > API_HANDLER_COMMON::handleGetTaskStatus ( const HANDLER_CONTEXT< tasks::GetTaskStatus > & aCtx)
private

◆ handleGetTextAsShapes()

HANDLER_RESULT< GetTextAsShapesResponse > API_HANDLER_COMMON::handleGetTextAsShapes ( const HANDLER_CONTEXT< commands::GetTextAsShapes > & aCtx)
private

◆ handleGetTextExtents()

HANDLER_RESULT< types::Box2 > API_HANDLER_COMMON::handleGetTextExtents ( const HANDLER_CONTEXT< commands::GetTextExtents > & aCtx)
private

◆ handleGetTextVariables()

HANDLER_RESULT< project::TextVariables > API_HANDLER_COMMON::handleGetTextVariables ( const HANDLER_CONTEXT< commands::GetTextVariables > & aCtx)
private

◆ handleGetVersion()

HANDLER_RESULT< GetVersionResponse > API_HANDLER_COMMON::handleGetVersion ( const HANDLER_CONTEXT< commands::GetVersion > & aCtx)
private

Definition at line 85 of file api_handler_common.cpp.

References GetBuildVersion(), GetMajorMinorPatchTuple(), and ToStdString().

Referenced by API_HANDLER_COMMON().

◆ handleOpenDocument()

HANDLER_RESULT< OpenDocumentResponse > API_HANDLER_COMMON::handleOpenDocument ( const HANDLER_CONTEXT< commands::OpenDocument > & aCtx)
private

◆ handlePing()

HANDLER_RESULT< Empty > API_HANDLER_COMMON::handlePing ( const HANDLER_CONTEXT< commands::Ping > & aCtx)
private

Definition at line 367 of file api_handler_common.cpp.

Referenced by API_HANDLER_COMMON().

◆ handleSetNetClassAssignments()

◆ handleSetNetClasses()

◆ handleSetTextVariables()

HANDLER_RESULT< Empty > API_HANDLER_COMMON::handleSetTextVariables ( const HANDLER_CONTEXT< commands::SetTextVariables > & aCtx)
private

◆ onNetSettingsChanged()

virtual void API_HANDLER::onNetSettingsChanged ( )
inlinevirtualinherited

Called on all registered handlers after project net settings (netclasses or netclass assignments) have been changed via the API.

Reimplemented in API_HANDLER_PCB, and API_HANDLER_SCH.

Definition at line 91 of file api_handler.h.

◆ registerHandler()

template<class RequestType, class ResponseType, class HandlerType>
void API_HANDLER::registerHandler ( HANDLER_RESULT< ResponseType >(HandlerType::* aHandler )(const HANDLER_CONTEXT< RequestType > &),
bool aAllowedDuringTask = false )
inlineprotectedinherited

Registers an API command handler for the given message types.

When an API request matching the given type comes in, the handler will be called and its response will be packed into an envelope for sending back to the API client.

If the given message does not unpack into the request type, an envelope is returned with status AS_BAD_REQUEST, which probably indicates corruption in the message.

Template Parameters
RequestTypeis a protobuf message type containing a command
ResponseTypeis a protobuf message type containing a command response
HandlerTypeis the implied type of the API_HANDLER subclass
Parameters
aHandleris the handler function for the given request and response types
aAllowedDuringTaskmarks the command as safe to serve while an async task is running

Definition at line 136 of file api_handler.h.

References HANDLER_CONTEXT< RequestMessageType >::ClientName, m_handlers, HANDLER_CONTEXT< RequestMessageType >::Request, and tryUnpack().

Referenced by API_HANDLER_BOARD::API_HANDLER_BOARD(), API_HANDLER_COMMON::API_HANDLER_COMMON(), API_HANDLER_EDITOR::API_HANDLER_EDITOR(), API_HANDLER_FOOTPRINT::API_HANDLER_FOOTPRINT(), API_HANDLER_LIBRARIES::API_HANDLER_LIBRARIES(), API_HANDLER_PCB::API_HANDLER_PCB(), API_HANDLER_SCH::API_HANDLER_SCH(), and API_HANDLER_SYMBOL::API_HANDLER_SYMBOL().

◆ requestNetSettingsNotification()

void API_HANDLER::requestNetSettingsNotification ( )
inlineinherited

◆ setApiServer()

void API_HANDLER::setApiServer ( KICAD_API_SERVER * aServer)
inlineinherited

Set by KICAD_API_SERVER::RegisterHandler; null when the handler is not registered.

Definition at line 104 of file api_handler.h.

References m_apiServer.

Referenced by KICAD_API_SERVER::DeregisterHandler(), and KICAD_API_SERVER::RegisterHandler().

◆ SetCloseAllDocumentsHandler()

void API_HANDLER_COMMON::SetCloseAllDocumentsHandler ( CLOSE_ALL_DOCUMENTS_HANDLER aHandler)
inline

Definition at line 64 of file api_handler_common.h.

References m_closeAllDocumentsHandler.

Referenced by CLI::API_SERVER_COMMAND::doPerform().

◆ SetCloseDocumentHandler()

void API_HANDLER_COMMON::SetCloseDocumentHandler ( CLOSE_DOCUMENT_HANDLER aHandler)
inline

Definition at line 59 of file api_handler_common.h.

References m_closeDocumentHandler.

Referenced by CLI::API_SERVER_COMMAND::doPerform().

◆ SetCreateDocumentHandler()

void API_HANDLER_COMMON::SetCreateDocumentHandler ( CREATE_DOCUMENT_HANDLER aHandler)
inline

Definition at line 69 of file api_handler_common.h.

References m_createDocumentHandler.

Referenced by CLI::API_SERVER_COMMAND::doPerform().

◆ SetOpenDocumentHandler()

void API_HANDLER_COMMON::SetOpenDocumentHandler ( OPEN_DOCUMENT_HANDLER aHandler)
inline

Definition at line 54 of file api_handler_common.h.

References m_openDocumentHandler.

Referenced by CLI::API_SERVER_COMMAND::doPerform().

◆ tryUnpack()

template<typename MessageType>
bool API_HANDLER::tryUnpack ( ApiRequest & aRequest,
ApiResponse & aReply,
MessageType & aDest )
inlineprivateinherited

Definition at line 192 of file api_handler.h.

Referenced by registerHandler().

◆ validateProject()

tl::expected< bool, ApiResponseStatus > API_HANDLER_COMMON::validateProject ( const ProjectSpecifier & aProject,
bool aAllowEmpty = false )
staticprivate

Member Data Documentation

◆ m_apiServer

KICAD_API_SERVER* API_HANDLER::m_apiServer = nullptr
protectedinherited

Definition at line 185 of file api_handler.h.

Referenced by apiServer(), and setApiServer().

◆ m_closeAllDocumentsHandler

CLOSE_ALL_DOCUMENTS_HANDLER API_HANDLER_COMMON::m_closeAllDocumentsHandler
private

Definition at line 136 of file api_handler_common.h.

Referenced by handleCloseAllDocuments(), and SetCloseAllDocumentsHandler().

◆ m_closeDocumentHandler

CLOSE_DOCUMENT_HANDLER API_HANDLER_COMMON::m_closeDocumentHandler
private

Definition at line 137 of file api_handler_common.h.

Referenced by handleCloseDocument(), and SetCloseDocumentHandler().

◆ m_createDocumentHandler

CREATE_DOCUMENT_HANDLER API_HANDLER_COMMON::m_createDocumentHandler
private

Definition at line 138 of file api_handler_common.h.

Referenced by handleCreateDocument(), and SetCreateDocumentHandler().

◆ m_defaultCommitMessage

const wxString API_HANDLER::m_defaultCommitMessage = _( "Modification from API" )
staticprotectedinherited

Definition at line 187 of file api_handler.h.

Referenced by API_HANDLER_EDITOR::pushCurrentCommit().

◆ m_handlers

std::map<std::string, HANDLER_ENTRY> API_HANDLER::m_handlers
protectedinherited

Maps type name (without the URL prefix) to a handler method.

Definition at line 181 of file api_handler.h.

Referenced by AllowsDuringTask(), CanHandle(), Handle(), and registerHandler().

◆ m_notifyNetSettings

bool API_HANDLER::m_notifyNetSettings = false
protectedinherited

Definition at line 183 of file api_handler.h.

Referenced by clearNetSettingsNotification(), and requestNetSettingsNotification().

◆ m_openDocumentHandler

OPEN_DOCUMENT_HANDLER API_HANDLER_COMMON::m_openDocumentHandler
private

Definition at line 135 of file api_handler_common.h.

Referenced by handleOpenDocument(), and SetOpenDocumentHandler().


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