KiCad PCB EDA Suite
|
Base class for API handlers related to editor frames. More...
#include <api_handler_editor.h>
Public Member Functions | |
API_HANDLER_EDITOR (EDA_BASE_FRAME *aFrame=nullptr) | |
API_RESULT | Handle (ApiRequest &aMsg) |
Attempt to handle the given API request, if a handler exists in this class for the message. | |
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 | |
HANDLER_RESULT< std::optional< KIID > > | validateItemHeaderDocument (const kiapi::common::types::ItemHeader &aHeader) |
If the header is valid, returns the item container. | |
HANDLER_RESULT< bool > | validateDocument (const DocumentSpecifier &aDocument) |
virtual std::optional< ApiResponseStatus > | checkForBusy () |
Checks if the editor can accept commands. | |
HANDLER_RESULT< commands::BeginCommitResponse > | handleBeginCommit (commands::BeginCommit &aMsg, const HANDLER_CONTEXT &aCtx) |
HANDLER_RESULT< commands::EndCommitResponse > | handleEndCommit (commands::EndCommit &aMsg, const HANDLER_CONTEXT &aCtx) |
COMMIT * | getCurrentCommit (const HANDLER_CONTEXT &aCtx) |
virtual void | pushCurrentCommit (const HANDLER_CONTEXT &aCtx, const wxString &aMessage) |
HANDLER_RESULT< commands::CreateItemsResponse > | handleCreateItems (commands::CreateItems &aMsg, const HANDLER_CONTEXT &aCtx) |
HANDLER_RESULT< commands::UpdateItemsResponse > | handleUpdateItems (commands::UpdateItems &aMsg, const HANDLER_CONTEXT &aCtx) |
HANDLER_RESULT< commands::DeleteItemsResponse > | handleDeleteItems (commands::DeleteItems &aMsg, const HANDLER_CONTEXT &aCtx) |
HANDLER_RESULT< commands::HitTestResponse > | handleHitTest (commands::HitTest &aMsg, const HANDLER_CONTEXT &aCtx) |
virtual std::unique_ptr< COMMIT > | createCommit ()=0 |
Override this to create an appropriate COMMIT subclass for the frame in question. | |
virtual kiapi::common::types::DocumentType | thisDocumentType () const =0 |
Override this to specify which document type this editor handles. | |
virtual bool | validateDocumentInternal (const DocumentSpecifier &aDocument) const =0 |
virtual HANDLER_RESULT< ItemRequestStatus > | handleCreateUpdateItemsInternal (bool aCreate, const HANDLER_CONTEXT &aCtx, const types::ItemHeader &aHeader, const google::protobuf::RepeatedPtrField< google::protobuf::Any > &aItems, std::function< void(commands::ItemStatus, google::protobuf::Any)> aItemHandler)=0 |
virtual void | deleteItemsInternal (std::map< KIID, ItemDeletionStatus > &aItemsToDelete, const HANDLER_CONTEXT &aCtx)=0 |
virtual std::optional< EDA_ITEM * > | getItemFromDocument (const DocumentSpecifier &aDocument, const KIID &aId)=0 |
template<class RequestType , class ResponseType , class HandlerType > | |
void | registerHandler (HANDLER_RESULT< ResponseType >(HandlerType::*aHandler)(RequestType &, const HANDLER_CONTEXT &)) |
Registers an API command handler for the given message types. | |
Protected Attributes | |
std::map< std::string, std::pair< KIID, std::unique_ptr< COMMIT > > > | m_commits |
std::set< std::string > | m_activeClients |
EDA_BASE_FRAME * | m_frame |
std::map< std::string, REQUEST_HANDLER > | m_handlers |
Maps type name (without the URL prefix) to a handler method. | |
Static Protected Attributes | |
static const wxString | m_defaultCommitMessage = _( "Modification from API" ) |
Private Member Functions | |
template<typename MessageType > | |
bool | tryUnpack (ApiRequest &aRequest, ApiResponse &aReply, MessageType &aDest) |
Base class for API handlers related to editor frames.
Definition at line 39 of file api_handler_editor.h.
|
protectedinherited |
A handler for outer messages (envelopes) that will unpack to inner messages and call a specific handler function.
Definition at line 74 of file api_handler.h.
API_HANDLER_EDITOR::API_HANDLER_EDITOR | ( | EDA_BASE_FRAME * | aFrame = nullptr | ) |
Definition at line 30 of file api_handler_editor.cpp.
References handleBeginCommit(), handleCreateItems(), handleDeleteItems(), handleEndCommit(), handleHitTest(), and handleUpdateItems().
|
protectedvirtual |
Checks if the editor can accept commands.
Definition at line 205 of file api_handler_editor.cpp.
References EDA_BASE_FRAME::CanAcceptApiCommands(), and m_frame.
Referenced by handleBeginCommit(), handleCreateItems(), handleDeleteItems(), handleEndCommit(), API_HANDLER_PCB::handleGetBoundingBox(), API_HANDLER_PCB::handleGetGraphicsDefaults(), API_HANDLER_PCB::handleGetItems(), API_HANDLER_PCB::handleGetNets(), API_HANDLER_PCB::handleGetStackup(), handleHitTest(), API_HANDLER_PCB::handleInteractiveMoveItems(), API_HANDLER_PCB::handleRefillZones(), API_HANDLER_PCB::handleRunAction(), and handleUpdateItems().
|
protectedpure virtual |
Override this to create an appropriate COMMIT subclass for the frame in question.
Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.
Referenced by getCurrentCommit(), and handleBeginCommit().
|
protectedpure virtual |
Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.
Referenced by handleDeleteItems().
|
protected |
Definition at line 129 of file api_handler_editor.cpp.
References HANDLER_CONTEXT::ClientName, createCommit(), and m_commits.
Referenced by API_HANDLER_PCB::deleteItemsInternal(), API_HANDLER_SCH::handleCreateUpdateItemsInternal(), API_HANDLER_PCB::handleCreateUpdateItemsInternal(), and API_HANDLER_PCB::handleInteractiveMoveItems().
|
protectedpure virtual |
Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.
Referenced by handleHitTest().
|
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 API_HANDLER::m_handlers.
|
protected |
Definition at line 43 of file api_handler_editor.cpp.
References checkForBusy(), HANDLER_CONTEXT::ClientName, createCommit(), m_activeClients, and m_commits.
Referenced by API_HANDLER_EDITOR().
|
protected |
Definition at line 219 of file api_handler_editor.cpp.
References checkForBusy(), and handleCreateUpdateItemsInternal().
Referenced by API_HANDLER_EDITOR().
|
protectedpure virtual |
Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.
Referenced by handleCreateItems(), and handleUpdateItems().
|
protected |
Definition at line 271 of file api_handler_editor.cpp.
References checkForBusy(), deleteItemsInternal(), and validateItemHeaderDocument().
Referenced by API_HANDLER_EDITOR().
|
protected |
Definition at line 72 of file api_handler_editor.cpp.
References checkForBusy(), HANDLER_CONTEXT::ClientName, m_activeClients, m_commits, and pushCurrentCommit().
Referenced by API_HANDLER_EDITOR().
|
protected |
Definition at line 320 of file api_handler_editor.cpp.
References checkForBusy(), getItemFromDocument(), kiapi::common::UnpackVector2(), and validateItemHeaderDocument().
Referenced by API_HANDLER_EDITOR().
|
protected |
Definition at line 245 of file api_handler_editor.cpp.
References checkForBusy(), and handleCreateUpdateItemsInternal().
Referenced by API_HANDLER_EDITOR().
|
protectedvirtual |
Reimplemented in API_HANDLER_PCB.
Definition at line 141 of file api_handler_editor.cpp.
References HANDLER_CONTEXT::ClientName, m_activeClients, m_commits, and API_HANDLER::m_defaultCommitMessage.
Referenced by API_HANDLER_SCH::handleCreateUpdateItemsInternal(), handleEndCommit(), and API_HANDLER_PCB::pushCurrentCommit().
|
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 91 of file api_handler.h.
References HANDLER_CONTEXT::ClientName.
|
protectedpure virtual |
Override this to specify which document type this editor handles.
Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.
Referenced by validateItemHeaderDocument().
|
inlineprivateinherited |
Definition at line 136 of file api_handler.h.
|
protected |
Definition at line 154 of file api_handler_editor.cpp.
References validateDocumentInternal().
Referenced by API_HANDLER_SCH::getItemFromDocument(), API_HANDLER_PCB::getItemFromDocument(), API_HANDLER_PCB::handleGetGraphicsDefaults(), API_HANDLER_PCB::handleGetNets(), API_HANDLER_PCB::handleGetPadShapeAsPolygon(), API_HANDLER_PCB::handleGetStackup(), API_HANDLER_PCB::handleGetTitleBlockInfo(), API_HANDLER_PCB::handleInteractiveMoveItems(), API_HANDLER_PCB::handleRefillZones(), and validateItemHeaderDocument().
|
protectedpure virtual |
Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.
Referenced by validateDocument(), and validateItemHeaderDocument().
|
protected |
If the header is valid, returns the item container.
Definition at line 170 of file api_handler_editor.cpp.
References thisDocumentType(), validateDocument(), and validateDocumentInternal().
Referenced by API_HANDLER_SCH::handleCreateUpdateItemsInternal(), API_HANDLER_PCB::handleCreateUpdateItemsInternal(), handleDeleteItems(), API_HANDLER_PCB::handleGetBoundingBox(), API_HANDLER_PCB::handleGetItems(), and handleHitTest().
|
protected |
Definition at line 110 of file api_handler_editor.h.
Referenced by API_HANDLER_PCB::deleteItemsInternal(), handleBeginCommit(), API_HANDLER_SCH::handleCreateUpdateItemsInternal(), API_HANDLER_PCB::handleCreateUpdateItemsInternal(), handleEndCommit(), and pushCurrentCommit().
|
protected |
Definition at line 108 of file api_handler_editor.h.
Referenced by getCurrentCommit(), handleBeginCommit(), handleEndCommit(), and pushCurrentCommit().
|
staticprotectedinherited |
Definition at line 131 of file api_handler.h.
Referenced by pushCurrentCommit().
|
protected |
Definition at line 112 of file api_handler_editor.h.
Referenced by checkForBusy(), and API_HANDLER_PCB::frame().
|
protectedinherited |
Maps type name (without the URL prefix) to a handler method.
Definition at line 129 of file api_handler.h.
Referenced by API_HANDLER::Handle().