|
KiCad PCB EDA Suite
|
#include <api_handler_common.h>
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. | |
| 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 > &)) |
| Registers an API command handler for the given message types. | |
Protected Attributes | |
| std::map< std::string, REQUEST_HANDLER > | 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) |
| 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) |
Definition at line 36 of file api_handler_common.h.
Definition at line 45 of file api_handler_common.h.
Definition at line 43 of file api_handler_common.h.
Definition at line 41 of file api_handler_common.h.
Definition at line 39 of file api_handler_common.h.
|
protectedinherited |
A handler for outer messages (envelopes) that will unpack to inner messages and call a specific handler function.
Definition at line 97 of file api_handler.h.
| API_HANDLER_COMMON::API_HANDLER_COMMON | ( | ) |
Definition at line 47 of file api_handler_common.cpp.
References API_HANDLER::API_HANDLER(), handleCloseAllDocuments(), handleCloseDocument(), handleCreateDocument(), handleExpandTextVariables(), handleGetKiCadBinaryPath(), handleGetNetClassAssignments(), handleGetNetClasses(), handleGetPaths(), handleGetPluginSettingsPath(), handleGetTextAsShapes(), handleGetTextExtents(), handleGetTextVariables(), handleGetVersion(), handleOpenDocument(), handlePing(), handleSetNetClassAssignments(), handleSetNetClasses(), handleSetTextVariables(), and API_HANDLER::registerHandler().
|
inlineoverride |
Definition at line 51 of file api_handler_common.h.
|
inlineinherited |
Definition at line 90 of file api_handler.h.
References m_apiServer.
Referenced by API_HANDLER_PCB::handleSaveDocumentAs(), and API_HANDLER_SCH::handleSaveDocumentAs().
|
inlineinherited |
Returns true if the notification had been requested at the time of the call.
Definition at line 81 of file api_handler.h.
References m_notifyNetSettings.
|
inherited |
Attempt to handle the given API request, if a handler exists in this class for the message.
| aMsg | is a request to attempt to handle |
Definition at line 30 of file api_handler.cpp.
References m_handlers.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
private |
Definition at line 660 of file api_handler_common.cpp.
References m_closeAllDocumentsHandler, and HANDLER_CONTEXT< RequestMessageType >::Request.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 630 of file api_handler_common.cpp.
References m_closeDocumentHandler, and HANDLER_CONTEXT< RequestMessageType >::Request.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 646 of file api_handler_common.cpp.
References m_createDocumentHandler, and HANDLER_CONTEXT< RequestMessageType >::Request.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 465 of file api_handler_common.cpp.
References ExpandEnvVarSubstitutions(), ExpandTextVars(), PGM_BASE::GetSettingsManager(), INTERNAL, Pgm(), SETTINGS_MANAGER::Prj(), HANDLER_CONTEXT< RequestMessageType >::Request, and result.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 98 of file api_handler_common.cpp.
References FindKicadFile(), path, and HANDLER_CONTEXT< RequestMessageType >::Request.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 222 of file api_handler_common.cpp.
References PROJECT::GetProjectFile(), PGM_BASE::GetSettingsManager(), PROJECT_FILE::m_NetSettings, Pgm(), SETTINGS_MANAGER::Prj(), HANDLER_CONTEXT< RequestMessageType >::Request, result, and validateProject().
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 147 of file api_handler_common.cpp.
References PROJECT::GetProjectFile(), PGM_BASE::GetSettingsManager(), PROJECT_FILE::m_NetSettings, Pgm(), SETTINGS_MANAGER::Prj(), HANDLER_CONTEXT< RequestMessageType >::Request, result, and validateProject().
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 674 of file api_handler_common.cpp.
References PATHS::GetStock3dmodelsPath(), PATHS::GetStockDesignBlocksPath(), PATHS::GetStockFootprintsPath(), PATHS::GetStockSymbolsPath(), PATHS::GetStockTemplatesPath(), PATHS::GetUserPluginsPath(), PATHS::GetUserSettingsPath(), and PATHS::GetUserTemplatesPath().
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 493 of file api_handler_common.cpp.
References PATHS::EnsurePathExists(), PATHS::GetUserSettingsPath(), API_PLUGIN::IsValidIdentifier(), path, and HANDLER_CONTEXT< RequestMessageType >::Request.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 387 of file api_handler_common.cpp.
References kiapi::common::PackVector2(), pcbIUScale, HANDLER_CONTEXT< RequestMessageType >::Request, EDA_SHAPE::Serialize(), text, kiapi::common::UnpackVector2(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 355 of file api_handler_common.cpp.
References BOX2< Vec >::GetBoundingBoxRotated(), BOX2< Vec >::GetPosition(), BOX2< Vec >::GetSize(), EDA_ANGLE::IsZero(), pcbIUScale, HANDLER_CONTEXT< RequestMessageType >::Request, text, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 528 of file api_handler_common.cpp.
References PGM_BASE::GetSettingsManager(), Pgm(), SETTINGS_MANAGER::Prj(), HANDLER_CONTEXT< RequestMessageType >::Request, result, and validateProject().
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 82 of file api_handler_common.cpp.
References GetBuildVersion(), GetMajorMinorPatchTuple(), and ToStdString().
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 615 of file api_handler_common.cpp.
References m_openDocumentHandler, and HANDLER_CONTEXT< RequestMessageType >::Request.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 349 of file api_handler_common.cpp.
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 252 of file api_handler_common.cpp.
References NETCLASS::Default, PROJECT::GetProjectFile(), PGM_BASE::GetSettingsManager(), PROJECT_FILE::m_NetSettings, name, Pgm(), SETTINGS_MANAGER::Prj(), HANDLER_CONTEXT< RequestMessageType >::Request, API_HANDLER::requestNetSettingsNotification(), result, and validateProject().
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 172 of file api_handler_common.cpp.
References PROJECT::GetProjectFile(), PGM_BASE::GetSettingsManager(), PROJECT_FILE::m_NetSettings, name, Pgm(), SETTINGS_MANAGER::Prj(), HANDLER_CONTEXT< RequestMessageType >::Request, API_HANDLER::requestNetSettingsNotification(), result, and validateProject().
Referenced by API_HANDLER_COMMON().
|
private |
Definition at line 567 of file api_handler_common.cpp.
References PGM_BASE::GetSettingsManager(), Pgm(), SETTINGS_MANAGER::Prj(), HANDLER_CONTEXT< RequestMessageType >::Request, result, and validateProject().
Referenced by API_HANDLER_COMMON().
|
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 76 of file api_handler.h.
|
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.
| RequestType | is a protobuf message type containing a command |
| ResponseType | is a protobuf message type containing a command response |
| HandlerType | is the implied type of the API_HANDLER subclass |
| aHandler | is the handler function for the given request and response types |
Definition at line 114 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().
|
inlineinherited |
Definition at line 78 of file api_handler.h.
References m_notifyNetSettings.
Referenced by API_HANDLER_COMMON::handleSetNetClassAssignments(), and API_HANDLER_COMMON::handleSetNetClasses().
|
inlineinherited |
Set by KICAD_API_SERVER::RegisterHandler; null when the handler is not registered.
Definition at line 89 of file api_handler.h.
References m_apiServer.
Referenced by KICAD_API_SERVER::DeregisterHandler(), and KICAD_API_SERVER::RegisterHandler().
|
inline |
Definition at line 63 of file api_handler_common.h.
References m_closeAllDocumentsHandler.
Referenced by CLI::API_SERVER_COMMAND::doPerform().
|
inline |
Definition at line 58 of file api_handler_common.h.
References m_closeDocumentHandler.
Referenced by CLI::API_SERVER_COMMAND::doPerform().
|
inline |
Definition at line 68 of file api_handler_common.h.
References m_createDocumentHandler.
Referenced by CLI::API_SERVER_COMMAND::doPerform().
|
inline |
Definition at line 53 of file api_handler_common.h.
References m_openDocumentHandler.
Referenced by CLI::API_SERVER_COMMAND::doPerform().
|
inlineprivateinherited |
Definition at line 161 of file api_handler.h.
Referenced by registerHandler().
|
staticprivate |
Definition at line 113 of file api_handler_common.cpp.
References PROJECT::GetProjectName(), PROJECT::GetProjectPath(), PGM_BASE::GetSettingsManager(), Pgm(), and SETTINGS_MANAGER::Prj().
Referenced by handleGetNetClassAssignments(), handleGetNetClasses(), handleGetTextVariables(), handleSetNetClassAssignments(), handleSetNetClasses(), and handleSetTextVariables().
|
protectedinherited |
Definition at line 154 of file api_handler.h.
Referenced by apiServer(), and setApiServer().
|
private |
Definition at line 132 of file api_handler_common.h.
Referenced by handleCloseAllDocuments(), and SetCloseAllDocumentsHandler().
|
private |
Definition at line 133 of file api_handler_common.h.
Referenced by handleCloseDocument(), and SetCloseDocumentHandler().
|
private |
Definition at line 134 of file api_handler_common.h.
Referenced by handleCreateDocument(), and SetCreateDocumentHandler().
|
staticprotectedinherited |
Definition at line 156 of file api_handler.h.
Referenced by API_HANDLER_EDITOR::pushCurrentCommit().
|
protectedinherited |
Maps type name (without the URL prefix) to a handler method.
Definition at line 150 of file api_handler.h.
Referenced by Handle(), and registerHandler().
|
protectedinherited |
Definition at line 152 of file api_handler.h.
Referenced by clearNetSettingsNotification(), and requestNetSettingsNotification().
|
private |
Definition at line 131 of file api_handler_common.h.
Referenced by handleOpenDocument(), and SetOpenDocumentHandler().