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

#include <api_handler_pcb.h>

Inheritance diagram for API_HANDLER_PCB:
API_HANDLER_EDITOR API_HANDLER

Public Member Functions

 API_HANDLER_PCB (PCB_EDIT_FRAME *aFrame)
 
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

std::unique_ptr< COMMITcreateCommit () override
 Override this to create an appropriate COMMIT subclass for the frame in question.
 
kiapi::common::types::DocumentType thisDocumentType () const override
 Override this to specify which document type this editor handles.
 
bool validateDocumentInternal (const DocumentSpecifier &aDocument) const override
 
void deleteItemsInternal (std::map< KIID, ItemDeletionStatus > &aItemsToDelete, const HANDLER_CONTEXT &aCtx) override
 
std::optional< EDA_ITEM * > getItemFromDocument (const DocumentSpecifier &aDocument, const KIID &aId) override
 
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)
 
COMMITgetCurrentCommit (const HANDLER_CONTEXT &aCtx)
 
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)
 
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_FRAMEm_frame
 
std::map< std::string, REQUEST_HANDLERm_handlers
 Maps type name (without the URL prefix) to a handler method.
 

Static Protected Attributes

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

Private Types

typedef std::map< std::string, PROPERTY_BASE * > PROTO_PROPERTY_MAP
 

Private Member Functions

HANDLER_RESULT< commands::RunActionResponse > handleRunAction (commands::RunAction &aMsg, const HANDLER_CONTEXT &aCtx)
 
HANDLER_RESULT< commands::GetOpenDocumentsResponse > handleGetOpenDocuments (commands::GetOpenDocuments &aMsg, const HANDLER_CONTEXT &aCtx)
 
HANDLER_RESULT< commands::GetItemsResponse > handleGetItems (commands::GetItems &aMsg, const HANDLER_CONTEXT &aCtx)
 
HANDLER_RESULT< BoardStackupResponse > handleGetStackup (GetBoardStackup &aMsg, const HANDLER_CONTEXT &aCtx)
 
HANDLER_RESULT< GraphicsDefaultsResponse > handleGetGraphicsDefaults (GetGraphicsDefaults &aMsg, const HANDLER_CONTEXT &aCtx)
 
HANDLER_RESULT< commands::BoundingBoxResponse > handleGetTextExtents (GetTextExtents &aMsg, const HANDLER_CONTEXT &aCtx)
 
HANDLER_RESULT< Empty > handleInteractiveMoveItems (InteractiveMoveItems &aMsg, const HANDLER_CONTEXT &aCtx)
 
HANDLER_RESULT< NetsResponse > handleGetNets (GetNets &aMsg, const HANDLER_CONTEXT &aCtx)
 
HANDLER_RESULT< Empty > handleRefillZones (RefillZones &aMsg, const HANDLER_CONTEXT &aCtx)
 
PCB_EDIT_FRAMEframe () const
 
void pushCurrentCommit (const HANDLER_CONTEXT &aCtx, const wxString &aMessage) override
 
std::optional< BOARD_ITEM * > getItemById (const KIID &aId) const
 
HANDLER_RESULT< types::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) override
 
template<typename MessageType >
bool tryUnpack (ApiRequest &aRequest, ApiResponse &aReply, MessageType &aDest)
 

Static Private Member Functions

static HANDLER_RESULT< std::unique_ptr< BOARD_ITEM > > createItemForType (KICAD_T aType, BOARD_ITEM_CONTAINER *aContainer)
 

Detailed Description

Definition at line 49 of file api_handler_pcb.h.

Member Typedef Documentation

◆ PROTO_PROPERTY_MAP

typedef std::map<std::string, PROPERTY_BASE*> API_HANDLER_PCB::PROTO_PROPERTY_MAP
private

Definition at line 55 of file api_handler_pcb.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 74 of file api_handler.h.

Constructor & Destructor Documentation

◆ API_HANDLER_PCB()

Member Function Documentation

◆ checkForBusy()

◆ createCommit()

std::unique_ptr< COMMIT > API_HANDLER_PCB::createCommit ( )
overrideprotectedvirtual

Override this to create an appropriate COMMIT subclass for the frame in question.

Returns
a new COMMIT, bound to the editor frame

Implements API_HANDLER_EDITOR.

Definition at line 132 of file api_handler_pcb.cpp.

References frame().

◆ createItemForType()

HANDLER_RESULT< std::unique_ptr< BOARD_ITEM > > API_HANDLER_PCB::createItemForType ( KICAD_T  aType,
BOARD_ITEM_CONTAINER aContainer 
)
staticprivate

◆ deleteItemsInternal()

void API_HANDLER_PCB::deleteItemsInternal ( std::map< KIID, ItemDeletionStatus > &  aItemsToDelete,
const HANDLER_CONTEXT aCtx 
)
overrideprotectedvirtual

◆ frame()

◆ getCurrentCommit()

◆ getItemById()

std::optional< BOARD_ITEM * > API_HANDLER_PCB::getItemById ( const KIID aId) const
private

◆ getItemFromDocument()

std::optional< EDA_ITEM * > API_HANDLER_PCB::getItemFromDocument ( const DocumentSpecifier &  aDocument,
const KIID aId 
)
overrideprotectedvirtual

Implements API_HANDLER_EDITOR.

Definition at line 476 of file api_handler_pcb.cpp.

References getItemById(), and API_HANDLER_EDITOR::validateDocument().

◆ Handle()

API_RESULT API_HANDLER::Handle ( ApiRequest &  aMsg)
inherited

Attempt to handle the given API request, if a handler exists in this class for the message.

Parameters
aMsgis a request to attempt to handle
Returns
a response to send to the client, or an appropriate error

Definition at line 30 of file api_handler.cpp.

References API_HANDLER::m_handlers.

◆ handleBeginCommit()

HANDLER_RESULT< BeginCommitResponse > API_HANDLER_EDITOR::handleBeginCommit ( commands::BeginCommit &  aMsg,
const HANDLER_CONTEXT aCtx 
)
protectedinherited

◆ handleCreateItems()

HANDLER_RESULT< CreateItemsResponse > API_HANDLER_EDITOR::handleCreateItems ( commands::CreateItems &  aMsg,
const HANDLER_CONTEXT aCtx 
)
protectedinherited

◆ handleCreateUpdateItemsInternal()

HANDLER_RESULT< ItemRequestStatus > API_HANDLER_PCB::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 
)
overrideprivatevirtual

◆ handleDeleteItems()

HANDLER_RESULT< DeleteItemsResponse > API_HANDLER_EDITOR::handleDeleteItems ( commands::DeleteItems &  aMsg,
const HANDLER_CONTEXT aCtx 
)
protectedinherited

◆ handleEndCommit()

HANDLER_RESULT< EndCommitResponse > API_HANDLER_EDITOR::handleEndCommit ( commands::EndCommit &  aMsg,
const HANDLER_CONTEXT aCtx 
)
protectedinherited

◆ handleGetGraphicsDefaults()

◆ handleGetItems()

HANDLER_RESULT< GetItemsResponse > API_HANDLER_PCB::handleGetItems ( commands::GetItems &  aMsg,
const HANDLER_CONTEXT aCtx 
)
private

◆ handleGetNets()

HANDLER_RESULT< NetsResponse > API_HANDLER_PCB::handleGetNets ( GetNets &  aMsg,
const HANDLER_CONTEXT aCtx 
)
private

◆ handleGetOpenDocuments()

HANDLER_RESULT< GetOpenDocumentsResponse > API_HANDLER_PCB::handleGetOpenDocuments ( commands::GetOpenDocuments &  aMsg,
const HANDLER_CONTEXT aCtx 
)
private

Definition at line 98 of file api_handler_pcb.cpp.

References frame(), and Prj().

Referenced by API_HANDLER_PCB().

◆ handleGetStackup()

HANDLER_RESULT< BoardStackupResponse > API_HANDLER_PCB::handleGetStackup ( GetBoardStackup &  aMsg,
const HANDLER_CONTEXT aCtx 
)
private

◆ handleGetTextExtents()

HANDLER_RESULT< commands::BoundingBoxResponse > API_HANDLER_PCB::handleGetTextExtents ( GetTextExtents &  aMsg,
const HANDLER_CONTEXT aCtx 
)
private

◆ handleHitTest()

HANDLER_RESULT< HitTestResponse > API_HANDLER_EDITOR::handleHitTest ( commands::HitTest &  aMsg,
const HANDLER_CONTEXT aCtx 
)
protectedinherited

◆ handleInteractiveMoveItems()

◆ handleRefillZones()

HANDLER_RESULT< Empty > API_HANDLER_PCB::handleRefillZones ( RefillZones &  aMsg,
const HANDLER_CONTEXT aCtx 
)
private

◆ handleRunAction()

HANDLER_RESULT< RunActionResponse > API_HANDLER_PCB::handleRunAction ( commands::RunAction &  aMsg,
const HANDLER_CONTEXT aCtx 
)
private

Definition at line 81 of file api_handler_pcb.cpp.

References API_HANDLER_EDITOR::checkForBusy(), and frame().

Referenced by API_HANDLER_PCB().

◆ handleUpdateItems()

HANDLER_RESULT< UpdateItemsResponse > API_HANDLER_EDITOR::handleUpdateItems ( commands::UpdateItems &  aMsg,
const HANDLER_CONTEXT aCtx 
)
protectedinherited

◆ pushCurrentCommit()

void API_HANDLER_PCB::pushCurrentCommit ( const HANDLER_CONTEXT aCtx,
const wxString &  aMessage 
)
overrideprivatevirtual

◆ registerHandler()

template<class RequestType , class ResponseType , class HandlerType >
void API_HANDLER::registerHandler ( HANDLER_RESULT< ResponseType >(HandlerType::*)(RequestType &, const HANDLER_CONTEXT &)  aHandler)
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

Definition at line 91 of file api_handler.h.

References HANDLER_CONTEXT::ClientName.

◆ thisDocumentType()

kiapi::common::types::DocumentType API_HANDLER_PCB::thisDocumentType ( ) const
inlineoverrideprotectedvirtual

Override this to specify which document type this editor handles.

Implements API_HANDLER_EDITOR.

Definition at line 89 of file api_handler_pcb.h.

◆ tryUnpack()

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

Definition at line 136 of file api_handler.h.

◆ validateDocument()

◆ validateDocumentInternal()

bool API_HANDLER_PCB::validateDocumentInternal ( const DocumentSpecifier &  aDocument) const
overrideprotectedvirtual
Returns
true if the given document is valid for this editor and is currently open

Implements API_HANDLER_EDITOR.

Definition at line 149 of file api_handler_pcb.cpp.

References frame().

◆ validateItemHeaderDocument()

HANDLER_RESULT< std::optional< KIID > > API_HANDLER_EDITOR::validateItemHeaderDocument ( const kiapi::common::types::ItemHeader &  aHeader)
protectedinherited

Member Data Documentation

◆ m_activeClients

◆ m_commits

std::map<std::string, std::pair<KIID, std::unique_ptr<COMMIT> > > API_HANDLER_EDITOR::m_commits
protectedinherited

◆ m_defaultCommitMessage

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

Definition at line 131 of file api_handler.h.

Referenced by API_HANDLER_EDITOR::pushCurrentCommit().

◆ m_frame

EDA_BASE_FRAME* API_HANDLER_EDITOR::m_frame
protectedinherited

Definition at line 112 of file api_handler_editor.h.

Referenced by API_HANDLER_EDITOR::checkForBusy(), and frame().

◆ m_handlers

std::map<std::string, REQUEST_HANDLER> API_HANDLER::m_handlers
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().


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