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

#include <api_handler_sch.h>

Inheritance diagram for API_HANDLER_SCH:
API_HANDLER_EDITOR API_HANDLER

Public Member Functions

 API_HANDLER_SCH (SCH_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
 
HANDLER_RESULT< std::unique_ptr< EDA_ITEM > > createItemForType (KICAD_T aType, EDA_ITEM *aContainer)
 
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
 
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)
 
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)
 
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
 
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

HANDLER_RESULT< commands::GetOpenDocumentsResponse > handleGetOpenDocuments (commands::GetOpenDocuments &aMsg, const HANDLER_CONTEXT &aCtx)
 
template<typename MessageType >
bool tryUnpack (ApiRequest &aRequest, ApiResponse &aReply, MessageType &aDest)
 

Private Attributes

SCH_EDIT_FRAMEm_frame
 

Detailed Description

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

Constructor & Destructor Documentation

◆ API_HANDLER_SCH()

API_HANDLER_SCH::API_HANDLER_SCH ( SCH_EDIT_FRAME aFrame)

Definition at line 37 of file api_handler_sch.cpp.

References handleGetOpenDocuments().

Member Function Documentation

◆ checkForBusy()

◆ createCommit()

std::unique_ptr< COMMIT > API_HANDLER_SCH::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 46 of file api_handler_sch.cpp.

References m_frame.

◆ createItemForType()

HANDLER_RESULT< std::unique_ptr< EDA_ITEM > > API_HANDLER_SCH::createItemForType ( KICAD_T  aType,
EDA_ITEM aContainer 
)
protected

◆ deleteItemsInternal()

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

Implements API_HANDLER_EDITOR.

Definition at line 285 of file api_handler_sch.cpp.

◆ getCurrentCommit()

◆ getItemFromDocument()

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

Implements API_HANDLER_EDITOR.

Definition at line 292 of file api_handler_sch.cpp.

References 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_SCH::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 
)
overrideprotectedvirtual

◆ 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

◆ handleGetOpenDocuments()

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

Definition at line 64 of file api_handler_sch.cpp.

References SCH_EDIT_FRAME::GetCurrentFileName(), and m_frame.

Referenced by API_HANDLER_SCH().

◆ handleHitTest()

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

◆ handleUpdateItems()

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

◆ pushCurrentCommit()

void API_HANDLER_EDITOR::pushCurrentCommit ( const HANDLER_CONTEXT aCtx,
const wxString &  aMessage 
)
protectedvirtualinherited

◆ 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_SCH::thisDocumentType ( ) const
inlineoverrideprotectedvirtual

Override this to specify which document type this editor handles.

Implements API_HANDLER_EDITOR.

Definition at line 43 of file api_handler_sch.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_SCH::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 52 of file api_handler_sch.cpp.

◆ 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

SCH_EDIT_FRAME* API_HANDLER_SCH::m_frame
private

◆ 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: