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

Base class for API handlers related to library management. More...

#include <api_handler_libraries.h>

Inheritance diagram for API_HANDLER_LIBRARIES:
API_HANDLER API_HANDLER_FP_LIBRARIES API_HANDLER_SCH_LIBRARIES

Public Member Functions

 API_HANDLER_LIBRARIES (LIBRARY_TABLE_TYPE aType=LIBRARY_TABLE_TYPE::DESIGN_BLOCK)
 
 ~API_HANDLER_LIBRARIES () override
 
void SetKiway (KIWAY *aKiway)
 
void SetLibraryHandlerRegistrar (std::function< void(KIFACE *)> aRegistrar)
 Set a callback to register the handler on the API server in headless mode.
 
API_RESULT Handle (ApiRequest &aMsg)
 Attempt to handle the given API request, if a handler exists in this class for the message.
 
virtual void onNetSettingsChanged ()
 Called on all registered handlers after project net settings (netclasses or netclass assignments) have been changed via the API.
 
void requestNetSettingsNotification ()
 
bool clearNetSettingsNotification ()
 Returns true if the notification had been requested at the time of the call.
 
void setApiServer (KICAD_API_SERVER *aServer)
 Set by KICAD_API_SERVER::RegisterHandler; null when the handler is not registered.
 
KICAD_API_SERVER * apiServer () const
 

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< kiapi::common::commands::LibraryItemsResponse > handleGetLibraryItems (const HANDLER_CONTEXT< kiapi::common::commands::GetLibraryItems > &aCtx)
 
HANDLER_RESULT< kiapi::common::commands::LibraryStatusResponse > handleGetLibraryStatuses (const HANDLER_CONTEXT< kiapi::common::commands::GetLibraryStatuses > &aCtx)
 
HANDLER_RESULT< kiapi::common::types::LibraryCommandStatus > handleReloadLibrary (const HANDLER_CONTEXT< kiapi::common::commands::ReloadLibrary > &aCtx)
 
HANDLER_RESULT< kiapi::common::types::LibraryCommandStatus > handleLoadAllLibraries (const HANDLER_CONTEXT< kiapi::common::commands::LoadAllLibraries > &aCtx)
 
kiapi::common::types::LibraryCommandStatus loadAllLibraries ()
 Starts a background load of all libraries of this handler's type.
 
HANDLER_RESULT< kiapi::common::commands::GetItemsResponse > handleGetItemsFromLibrary (const HANDLER_CONTEXT< kiapi::common::commands::GetItemsFromLibrary > &aCtx)
 
virtual bool packLibraryItem (const LIB_ID &aId, google::protobuf::Any &aOutput) const
 
LIBRARY_TABLE_TYPE libraryType () const
 
virtual LIBRARY_MANAGER_ADAPTER * adapterForProject (PROJECT &aProject) const
 
virtual std::vector< wxString > getItemNames (LIBRARY_MANAGER_ADAPTER &aAdapter, const wxString &aNickname) const
 Returns the names of all entries in the given library, or an empty vector if the library is not loaded (or cannot be enumerated).
 
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_HANDLER > m_handlers
 Maps type name (without the URL prefix) to a handler method.
 
bool m_notifyNetSettings = false
 
KICAD_API_SERVER * m_apiServer = nullptr
 

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)
 

Private Attributes

LIBRARY_TABLE_TYPE m_type
 
KIWAY * m_kiway = nullptr
 Used to lazily load kifaces for LoadAllLibraries in headless; null in GUI mode.
 
std::function< void(KIFACE *)> m_handlerRegisterCallback
 Invoked with a lazily-loaded KIFACE so its handlers can be registered on the server.
 

Detailed Description

Base class for API handlers related to library management.

These are separate from the API_HANDLER_EDITOR derived classes because libraries (other than design blocks) need to be opened in a kiface context, but not associated with one particular frame.

Definition at line 46 of file api_handler_libraries.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 97 of file api_handler.h.

Constructor & Destructor Documentation

◆ API_HANDLER_LIBRARIES()

◆ ~API_HANDLER_LIBRARIES()

API_HANDLER_LIBRARIES::~API_HANDLER_LIBRARIES ( )
overridedefault

Member Function Documentation

◆ adapterForProject()

LIBRARY_MANAGER_ADAPTER * API_HANDLER_LIBRARIES::adapterForProject ( PROJECT & aProject) const
protectedvirtual

◆ apiServer()

KICAD_API_SERVER * API_HANDLER::apiServer ( ) const
inlineinherited

◆ clearNetSettingsNotification()

bool API_HANDLER::clearNetSettingsNotification ( )
inlineinherited

Returns true if the notification had been requested at the time of the call.

Definition at line 81 of file api_handler.h.

References m_notifyNetSettings.

◆ getItemNames()

std::vector< wxString > API_HANDLER_LIBRARIES::getItemNames ( LIBRARY_MANAGER_ADAPTER & aAdapter,
const wxString & aNickname ) const
protectedvirtual

Returns the names of all entries in the given library, or an empty vector if the library is not loaded (or cannot be enumerated).

Reimplemented in API_HANDLER_FP_LIBRARIES, and API_HANDLER_SCH_LIBRARIES.

Definition at line 74 of file api_handler_libraries.cpp.

Referenced by handleGetLibraryItems().

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

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ handleGetItemsFromLibrary()

HANDLER_RESULT< GetItemsResponse > API_HANDLER_LIBRARIES::handleGetItemsFromLibrary ( const HANDLER_CONTEXT< kiapi::common::commands::GetItemsFromLibrary > & aCtx)
protected

◆ handleGetLibraryItems()

HANDLER_RESULT< LibraryItemsResponse > API_HANDLER_LIBRARIES::handleGetLibraryItems ( const HANDLER_CONTEXT< kiapi::common::commands::GetLibraryItems > & aCtx)
protected

◆ handleGetLibraryStatuses()

HANDLER_RESULT< LibraryStatusResponse > API_HANDLER_LIBRARIES::handleGetLibraryStatuses ( const HANDLER_CONTEXT< kiapi::common::commands::GetLibraryStatuses > & aCtx)
protected

◆ handleLoadAllLibraries()

HANDLER_RESULT< LibraryCommandStatus > API_HANDLER_LIBRARIES::handleLoadAllLibraries ( const HANDLER_CONTEXT< kiapi::common::commands::LoadAllLibraries > & aCtx)
protected

◆ handleReloadLibrary()

HANDLER_RESULT< LibraryCommandStatus > API_HANDLER_LIBRARIES::handleReloadLibrary ( const HANDLER_CONTEXT< kiapi::common::commands::ReloadLibrary > & aCtx)
protected

◆ libraryType()

LIBRARY_TABLE_TYPE API_HANDLER_LIBRARIES::libraryType ( ) const
inlineprotected

Definition at line 86 of file api_handler_libraries.h.

References m_type.

◆ loadAllLibraries()

LibraryCommandStatus API_HANDLER_LIBRARIES::loadAllLibraries ( )
protected

Starts a background load of all libraries of this handler's type.

Definition at line 407 of file api_handler_libraries.cpp.

References adapterForProject(), LIBRARY_MANAGER_ADAPTER::AsyncLoad(), Pgm(), and Prj().

Referenced by handleLoadAllLibraries().

◆ onNetSettingsChanged()

virtual void API_HANDLER::onNetSettingsChanged ( )
inlinevirtualinherited

Called on all registered handlers after project net settings (netclasses or netclass assignments) have been changed via the API.

Reimplemented in API_HANDLER_PCB, and API_HANDLER_SCH.

Definition at line 76 of file api_handler.h.

◆ packLibraryItem()

virtual bool API_HANDLER_LIBRARIES::packLibraryItem ( const LIB_ID & aId,
google::protobuf::Any & aOutput ) const
inlineprotectedvirtual

Reimplemented in API_HANDLER_FP_LIBRARIES, and API_HANDLER_SCH_LIBRARIES.

Definition at line 81 of file api_handler_libraries.h.

Referenced by handleGetItemsFromLibrary().

◆ registerHandler()

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

References HANDLER_CONTEXT< RequestMessageType >::ClientName, m_handlers, HANDLER_CONTEXT< RequestMessageType >::Request, and tryUnpack().

Referenced by API_HANDLER_BOARD::API_HANDLER_BOARD(), API_HANDLER_COMMON::API_HANDLER_COMMON(), API_HANDLER_EDITOR::API_HANDLER_EDITOR(), API_HANDLER_FOOTPRINT::API_HANDLER_FOOTPRINT(), API_HANDLER_LIBRARIES::API_HANDLER_LIBRARIES(), API_HANDLER_PCB::API_HANDLER_PCB(), API_HANDLER_SCH::API_HANDLER_SCH(), and API_HANDLER_SYMBOL::API_HANDLER_SYMBOL().

◆ requestNetSettingsNotification()

void API_HANDLER::requestNetSettingsNotification ( )
inlineinherited

◆ setApiServer()

void API_HANDLER::setApiServer ( KICAD_API_SERVER * aServer)
inlineinherited

Set by KICAD_API_SERVER::RegisterHandler; null when the handler is not registered.

Definition at line 89 of file api_handler.h.

References m_apiServer.

Referenced by KICAD_API_SERVER::DeregisterHandler(), and KICAD_API_SERVER::RegisterHandler().

◆ SetKiway()

void API_HANDLER_LIBRARIES::SetKiway ( KIWAY * aKiway)
inline

Definition at line 53 of file api_handler_libraries.h.

References m_kiway.

Referenced by CLI::API_SERVER_COMMAND::doPerform().

◆ SetLibraryHandlerRegistrar()

void API_HANDLER_LIBRARIES::SetLibraryHandlerRegistrar ( std::function< void(KIFACE *)> aRegistrar)
inline

Set a callback to register the handler on the API server in headless mode.

Definition at line 56 of file api_handler_libraries.h.

References m_handlerRegisterCallback.

Referenced by CLI::API_SERVER_COMMAND::doPerform().

◆ tryUnpack()

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

Definition at line 161 of file api_handler.h.

Referenced by registerHandler().

Member Data Documentation

◆ m_apiServer

KICAD_API_SERVER* API_HANDLER::m_apiServer = nullptr
protectedinherited

Definition at line 154 of file api_handler.h.

Referenced by apiServer(), and setApiServer().

◆ m_defaultCommitMessage

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

Definition at line 156 of file api_handler.h.

Referenced by API_HANDLER_EDITOR::pushCurrentCommit().

◆ m_handlerRegisterCallback

std::function<void( KIFACE* )> API_HANDLER_LIBRARIES::m_handlerRegisterCallback
private

Invoked with a lazily-loaded KIFACE so its handlers can be registered on the server.

Definition at line 103 of file api_handler_libraries.h.

Referenced by handleLoadAllLibraries(), and SetLibraryHandlerRegistrar().

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

Referenced by Handle(), and registerHandler().

◆ m_kiway

KIWAY* API_HANDLER_LIBRARIES::m_kiway = nullptr
private

Used to lazily load kifaces for LoadAllLibraries in headless; null in GUI mode.

Definition at line 100 of file api_handler_libraries.h.

Referenced by handleLoadAllLibraries(), and SetKiway().

◆ m_notifyNetSettings

bool API_HANDLER::m_notifyNetSettings = false
protectedinherited

Definition at line 152 of file api_handler.h.

Referenced by clearNetSettingsNotification(), and requestNetSettingsNotification().

◆ m_type

LIBRARY_TABLE_TYPE API_HANDLER_LIBRARIES::m_type
private

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