KiCad PCB EDA Suite
Loading...
Searching...
No Matches
API_HANDLER_EDITOR Class Referenceabstract

Base class for API handlers related to editor frames. More...

#include <api_handler_editor.h>

Inheritance diagram for API_HANDLER_EDITOR:
API_HANDLER API_HANDLER_PCB API_HANDLER_SCH

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 (const HANDLER_CONTEXT< commands::BeginCommit > &aCtx)
 
HANDLER_RESULT< commands::EndCommitResponse > handleEndCommit (const HANDLER_CONTEXT< commands::EndCommit > &aCtx)
 
COMMITgetCurrentCommit (const std::string &aClientName)
 
virtual void pushCurrentCommit (const std::string &aClientName, const wxString &aMessage)
 
HANDLER_RESULT< commands::CreateItemsResponse > handleCreateItems (const HANDLER_CONTEXT< commands::CreateItems > &aCtx)
 
HANDLER_RESULT< commands::UpdateItemsResponse > handleUpdateItems (const HANDLER_CONTEXT< commands::UpdateItems > &aCtx)
 
HANDLER_RESULT< commands::DeleteItemsResponse > handleDeleteItems (const HANDLER_CONTEXT< commands::DeleteItems > &aCtx)
 
HANDLER_RESULT< commands::HitTestResponse > handleHitTest (const HANDLER_CONTEXT< commands::HitTest > &aCtx)
 
virtual std::unique_ptr< COMMITcreateCommit ()=0
 Override this to create an appropriate COMMIT subclass for the frame in question.
 
virtual 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 std::string &aClientName, 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 std::string &aClientName)=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)(const HANDLER_CONTEXT< RequestType > &))
 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 Member Functions

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

Detailed Description

Base class for API handlers related to editor frames.

Definition at line 39 of file api_handler_editor.h.

Member Typedef Documentation

◆ 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 76 of file api_handler.h.

Constructor & Destructor Documentation

◆ API_HANDLER_EDITOR()

API_HANDLER_EDITOR::API_HANDLER_EDITOR ( EDA_BASE_FRAME aFrame = nullptr)

Member Function Documentation

◆ checkForBusy()

◆ createCommit()

virtual std::unique_ptr< COMMIT > API_HANDLER_EDITOR::createCommit ( )
protectedpure virtual

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

Returns
a new COMMIT, bound to the editor frame

Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.

Referenced by getCurrentCommit(), and handleBeginCommit().

◆ deleteItemsInternal()

virtual void API_HANDLER_EDITOR::deleteItemsInternal ( std::map< KIID, ItemDeletionStatus > &  aItemsToDelete,
const std::string &  aClientName 
)
protectedpure virtual

Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.

Referenced by handleDeleteItems().

◆ getCurrentCommit()

COMMIT * API_HANDLER_EDITOR::getCurrentCommit ( const std::string &  aClientName)
protected

◆ getItemFromDocument()

virtual std::optional< EDA_ITEM * > API_HANDLER_EDITOR::getItemFromDocument ( const DocumentSpecifier &  aDocument,
const KIID aId 
)
protectedpure virtual

Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.

Referenced by handleHitTest().

◆ 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 ( const HANDLER_CONTEXT< commands::BeginCommit > &  aCtx)
protected

◆ handleCreateItems()

HANDLER_RESULT< CreateItemsResponse > API_HANDLER_EDITOR::handleCreateItems ( const HANDLER_CONTEXT< commands::CreateItems > &  aCtx)
protected

◆ handleCreateUpdateItemsInternal()

virtual HANDLER_RESULT< ItemRequestStatus > API_HANDLER_EDITOR::handleCreateUpdateItemsInternal ( bool  aCreate,
const std::string &  aClientName,
const types::ItemHeader &  aHeader,
const google::protobuf::RepeatedPtrField< google::protobuf::Any > &  aItems,
std::function< void(commands::ItemStatus, google::protobuf::Any)>  aItemHandler 
)
protectedpure virtual

Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.

Referenced by handleCreateItems(), and handleUpdateItems().

◆ handleDeleteItems()

HANDLER_RESULT< DeleteItemsResponse > API_HANDLER_EDITOR::handleDeleteItems ( const HANDLER_CONTEXT< commands::DeleteItems > &  aCtx)
protected

◆ handleEndCommit()

HANDLER_RESULT< EndCommitResponse > API_HANDLER_EDITOR::handleEndCommit ( const HANDLER_CONTEXT< commands::EndCommit > &  aCtx)
protected

◆ handleHitTest()

HANDLER_RESULT< HitTestResponse > API_HANDLER_EDITOR::handleHitTest ( const HANDLER_CONTEXT< commands::HitTest > &  aCtx)
protected

◆ handleUpdateItems()

HANDLER_RESULT< UpdateItemsResponse > API_HANDLER_EDITOR::handleUpdateItems ( const HANDLER_CONTEXT< commands::UpdateItems > &  aCtx)
protected

◆ pushCurrentCommit()

void API_HANDLER_EDITOR::pushCurrentCommit ( const std::string &  aClientName,
const wxString &  aMessage 
)
protectedvirtual

◆ registerHandler()

template<class RequestType , class ResponseType , class HandlerType >
void API_HANDLER::registerHandler ( HANDLER_RESULT< ResponseType >(HandlerType::*)(const HANDLER_CONTEXT< RequestType > &)  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 93 of file api_handler.h.

References HANDLER_CONTEXT< RequestMessageType >::ClientName, and HANDLER_CONTEXT< RequestMessageType >::Request.

◆ thisDocumentType()

virtual types::DocumentType API_HANDLER_EDITOR::thisDocumentType ( ) const
protectedpure virtual

Override this to specify which document type this editor handles.

Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.

Referenced by validateItemHeaderDocument().

◆ 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()

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

Implemented in API_HANDLER_SCH, and API_HANDLER_PCB.

Referenced by validateDocument(), and validateItemHeaderDocument().

◆ validateItemHeaderDocument()

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

Member Data Documentation

◆ m_activeClients

◆ m_commits

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

◆ m_defaultCommitMessage

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

Definition at line 131 of file api_handler.h.

Referenced by pushCurrentCommit().

◆ m_frame

EDA_BASE_FRAME* API_HANDLER_EDITOR::m_frame
protected

Definition at line 112 of file api_handler_editor.h.

Referenced by checkForBusy(), and API_HANDLER_PCB::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: