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

#include <api_handler_common.h>

Inheritance diagram for API_HANDLER_COMMON:
API_HANDLER

Public Member Functions

 API_HANDLER_COMMON ()
 
 ~API_HANDLER_COMMON () override
 
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

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_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::GetVersionResponse > handleGetVersion (const HANDLER_CONTEXT< commands::GetVersion > &aCtx)
 
HANDLER_RESULT< commands::NetClassesResponse > handleGetNetClasses (const HANDLER_CONTEXT< commands::GetNetClasses > &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)
 
template<typename MessageType >
bool tryUnpack (ApiRequest &aRequest, ApiResponse &aReply, MessageType &aDest)
 

Detailed Description

Definition at line 33 of file api_handler_common.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_COMMON()

API_HANDLER_COMMON::API_HANDLER_COMMON ( )

◆ ~API_HANDLER_COMMON()

API_HANDLER_COMMON::~API_HANDLER_COMMON ( )
inlineoverride

Definition at line 38 of file api_handler_common.h.

Member Function Documentation

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

◆ handleExpandTextVariables()

HANDLER_RESULT< ExpandTextVariablesResponse > API_HANDLER_COMMON::handleExpandTextVariables ( const HANDLER_CONTEXT< commands::ExpandTextVariables > &  aCtx)
private

◆ handleGetNetClasses()

HANDLER_RESULT< NetClassesResponse > API_HANDLER_COMMON::handleGetNetClasses ( const HANDLER_CONTEXT< commands::GetNetClasses > &  aCtx)
private

◆ handleGetTextAsShapes()

HANDLER_RESULT< GetTextAsShapesResponse > API_HANDLER_COMMON::handleGetTextAsShapes ( const HANDLER_CONTEXT< commands::GetTextAsShapes > &  aCtx)
private

◆ handleGetTextExtents()

HANDLER_RESULT< types::Box2 > API_HANDLER_COMMON::handleGetTextExtents ( const HANDLER_CONTEXT< commands::GetTextExtents > &  aCtx)
private

◆ handleGetVersion()

HANDLER_RESULT< GetVersionResponse > API_HANDLER_COMMON::handleGetVersion ( const HANDLER_CONTEXT< commands::GetVersion > &  aCtx)
private

Definition at line 55 of file api_handler_common.cpp.

References GetBuildVersion(), and GetMajorMinorPatchTuple().

Referenced by API_HANDLER_COMMON().

◆ handlePing()

HANDLER_RESULT< Empty > API_HANDLER_COMMON::handlePing ( const HANDLER_CONTEXT< commands::Ping > &  aCtx)
private

Definition at line 88 of file api_handler_common.cpp.

Referenced by API_HANDLER_COMMON().

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

◆ tryUnpack()

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

Definition at line 136 of file api_handler.h.

Member Data Documentation

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