diff --git a/common/api/api_handler_common.cpp b/common/api/api_handler_common.cpp index 03f13541a7..6d00b1fae1 100644 --- a/common/api/api_handler_common.cpp +++ b/common/api/api_handler_common.cpp @@ -52,8 +52,8 @@ API_HANDLER_COMMON::API_HANDLER_COMMON() : } -HANDLER_RESULT API_HANDLER_COMMON::handleGetVersion( commands::GetVersion&, - const HANDLER_CONTEXT& ) +HANDLER_RESULT API_HANDLER_COMMON::handleGetVersion( + const HANDLER_CONTEXT& ) { GetVersionResponse reply; @@ -68,8 +68,8 @@ HANDLER_RESULT API_HANDLER_COMMON::handleGetVersion( command } -HANDLER_RESULT API_HANDLER_COMMON::handleGetNetClasses( GetNetClasses& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_COMMON::handleGetNetClasses( + const HANDLER_CONTEXT& aCtx ) { NetClassesResponse reply; @@ -85,18 +85,18 @@ HANDLER_RESULT API_HANDLER_COMMON::handleGetNetClasses( GetN } -HANDLER_RESULT API_HANDLER_COMMON::handlePing( Ping& aMsg, const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_COMMON::handlePing( const HANDLER_CONTEXT& aCtx ) { return Empty(); } -HANDLER_RESULT API_HANDLER_COMMON::handleGetTextExtents( GetTextExtents& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_COMMON::handleGetTextExtents( + const HANDLER_CONTEXT& aCtx ) { EDA_TEXT text( pcbIUScale ); google::protobuf::Any any; - any.PackFrom( aMsg.text() ); + any.PackFrom( aCtx.Request.text() ); if( !text.Deserialize( any ) ) { @@ -124,11 +124,11 @@ HANDLER_RESULT API_HANDLER_COMMON::handleGetTextExtents( GetTextExt HANDLER_RESULT API_HANDLER_COMMON::handleGetTextAsShapes( - GetTextAsShapes& aMsg, const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { GetTextAsShapesResponse reply; - for( const TextOrTextBox& textMsg : aMsg.text() ) + for( const TextOrTextBox& textMsg : aCtx.Request.text() ) { Text dummyText; const Text* textPtr = &textMsg.text(); @@ -202,9 +202,9 @@ HANDLER_RESULT API_HANDLER_COMMON::handleGetTextAsShape HANDLER_RESULT API_HANDLER_COMMON::handleExpandTextVariables( - ExpandTextVariables& aMsg, const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { - if( !aMsg.has_document() || aMsg.document().type() != DocumentType::DOCTYPE_PROJECT ) + if( !aCtx.Request.has_document() || aCtx.Request.document().type() != DOCTYPE_PROJECT ) { ApiResponseStatus e; e.set_status( ApiStatusCode::AS_UNHANDLED ); @@ -215,7 +215,7 @@ HANDLER_RESULT API_HANDLER_COMMON::handleExpandText ExpandTextVariablesResponse reply; PROJECT& project = Pgm().GetSettingsManager().Prj(); - for( const std::string& textMsg : aMsg.text() ) + for( const std::string& textMsg : aCtx.Request.text() ) { wxString result = ExpandTextVars( wxString::FromUTF8( textMsg ), &project ); reply.add_text( result.ToUTF8() ); diff --git a/common/api/api_handler_editor.cpp b/common/api/api_handler_editor.cpp index 58d5f64912..2b2e5f08d1 100644 --- a/common/api/api_handler_editor.cpp +++ b/common/api/api_handler_editor.cpp @@ -40,8 +40,8 @@ API_HANDLER_EDITOR::API_HANDLER_EDITOR( EDA_BASE_FRAME* aFrame ) : } -HANDLER_RESULT API_HANDLER_EDITOR::handleBeginCommit( BeginCommit& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_EDITOR::handleBeginCommit( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); @@ -69,8 +69,8 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleBeginCommit( Begin } -HANDLER_RESULT API_HANDLER_EDITOR::handleEndCommit( EndCommit& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_EDITOR::handleEndCommit( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); @@ -93,7 +93,7 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleEndCommit( EndCommit EndCommitResponse response; // Do not check IDs with drop; it is a safety net in case the id was lost on the client side - switch( aMsg.action() ) + switch( aCtx.Request.action() ) { case kiapi::common::commands::CMA_DROP: { @@ -105,16 +105,16 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleEndCommit( EndCommit case kiapi::common::commands::CMA_COMMIT: { - if( aMsg.id().value().compare( id.AsStdString() ) != 0 ) + if( aCtx.Request.id().value().compare( id.AsStdString() ) != 0 ) { ApiResponseStatus e; e.set_status( ApiStatusCode::AS_BAD_REQUEST ); e.set_error_message( fmt::format( "the id {} does not match the commit in progress", - aMsg.id().value() ) ); + aCtx.Request.id().value() ) ); return tl::unexpected( e ); } - pushCurrentCommit( aCtx, wxString( aMsg.message().c_str(), wxConvUTF8 ) ); + pushCurrentCommit( aCtx.ClientName, wxString( aCtx.Request.message().c_str(), wxConvUTF8 ) ); break; } @@ -126,33 +126,33 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleEndCommit( EndCommit } -COMMIT* API_HANDLER_EDITOR::getCurrentCommit( const HANDLER_CONTEXT& aCtx ) +COMMIT* API_HANDLER_EDITOR::getCurrentCommit( const std::string& aClientName ) { - if( !m_commits.count( aCtx.ClientName ) ) + if( !m_commits.count( aClientName ) ) { KIID id; - m_commits[aCtx.ClientName] = std::make_pair( id, createCommit() ); + m_commits[aClientName] = std::make_pair( id, createCommit() ); } - return m_commits.at( aCtx.ClientName ).second.get(); + return m_commits.at( aClientName ).second.get(); } -void API_HANDLER_EDITOR::pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage ) +void API_HANDLER_EDITOR::pushCurrentCommit( const std::string& aClientName, + const wxString& aMessage ) { - auto it = m_commits.find( aCtx.ClientName ); + auto it = m_commits.find( aClientName ); if( it == m_commits.end() ) return; it->second.second->Push( aMessage.IsEmpty() ? m_defaultCommitMessage : aMessage ); m_commits.erase( it ); - m_activeClients.erase( aCtx.ClientName ); + m_activeClients.erase( aClientName ); } -HANDLER_RESULT API_HANDLER_EDITOR::validateDocument( - const kiapi::common::types::DocumentSpecifier& aDocument ) +HANDLER_RESULT API_HANDLER_EDITOR::validateDocument( const DocumentSpecifier& aDocument ) { if( !validateDocumentInternal( aDocument ) ) { @@ -168,7 +168,7 @@ HANDLER_RESULT API_HANDLER_EDITOR::validateDocument( HANDLER_RESULT> API_HANDLER_EDITOR::validateItemHeaderDocument( - const kiapi::common::types::ItemHeader& aHeader ) + const types::ItemHeader& aHeader ) { if( !aHeader.has_document() || aHeader.document().type() != thisDocumentType() ) { @@ -216,16 +216,17 @@ std::optional API_HANDLER_EDITOR::checkForBusy() } -HANDLER_RESULT API_HANDLER_EDITOR::handleCreateItems( CreateItems& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_EDITOR::handleCreateItems( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); CreateItemsResponse response; - HANDLER_RESULT result = handleCreateUpdateItemsInternal( true, aCtx, - aMsg.header(), aMsg.items(), + HANDLER_RESULT result = handleCreateUpdateItemsInternal( true, + aCtx.ClientName, + aCtx.Request.header(), aCtx.Request.items(), [&]( const ItemStatus& aStatus, const google::protobuf::Any& aItem ) { ItemCreationResult itemResult; @@ -242,16 +243,17 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleCreateItems( Creat } -HANDLER_RESULT API_HANDLER_EDITOR::handleUpdateItems( UpdateItems& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_EDITOR::handleUpdateItems( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); UpdateItemsResponse response; - HANDLER_RESULT result = handleCreateUpdateItemsInternal( false, aCtx, - aMsg.header(), aMsg.items(), + HANDLER_RESULT result = handleCreateUpdateItemsInternal( false, + aCtx.ClientName, + aCtx.Request.header(), aCtx.Request.items(), [&]( const ItemStatus& aStatus, const google::protobuf::Any& aItem ) { ItemUpdateResult itemResult; @@ -268,13 +270,13 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleUpdateItems( Updat } -HANDLER_RESULT API_HANDLER_EDITOR::handleDeleteItems( DeleteItems& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_EDITOR::handleDeleteItems( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - if( !validateItemHeaderDocument( aMsg.header() ) ) + if( !validateItemHeaderDocument( aCtx.Request.header() ) ) { ApiResponseStatus e; // No message needed for AS_UNHANDLED; this is an internal flag for the API server @@ -284,7 +286,7 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleDeleteItems( Delet std::map itemsToDelete; - for( const kiapi::common::types::KIID& kiidBuf : aMsg.item_ids() ) + for( const kiapi::common::types::KIID& kiidBuf : aCtx.Request.item_ids() ) { if( !kiidBuf.value().empty() ) { @@ -301,7 +303,7 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleDeleteItems( Delet return tl::unexpected( e ); } - deleteItemsInternal( itemsToDelete, aCtx ); + deleteItemsInternal( itemsToDelete, aCtx.ClientName ); DeleteItemsResponse response; @@ -317,13 +319,13 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleDeleteItems( Delet } -HANDLER_RESULT API_HANDLER_EDITOR::handleHitTest( HitTest& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_EDITOR::handleHitTest( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - if( !validateItemHeaderDocument( aMsg.header() ) ) + if( !validateItemHeaderDocument( aCtx.Request.header() ) ) { ApiResponseStatus e; // No message needed for AS_UNHANDLED; this is an internal flag for the API server @@ -333,8 +335,8 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleHitTest( HitTest& aMsg HitTestResponse response; - std::optional item = getItemFromDocument( aMsg.header().document(), - KIID( aMsg.id().value() ) ); + std::optional item = getItemFromDocument( aCtx.Request.header().document(), + KIID( aCtx.Request.id().value() ) ); if( !item ) { @@ -344,7 +346,7 @@ HANDLER_RESULT API_HANDLER_EDITOR::handleHitTest( HitTest& aMsg return tl::unexpected( e ); } - if( ( *item )->HitTest( kiapi::common::UnpackVector2( aMsg.position() ), aMsg.tolerance() ) ) + if( ( *item )->HitTest( UnpackVector2( aCtx.Request.position() ), aCtx.Request.tolerance() ) ) response.set_result( HitTestResult::HTR_HIT ); else response.set_result( HitTestResult::HTR_NO_HIT ); diff --git a/eeschema/api/api_handler_sch.cpp b/eeschema/api/api_handler_sch.cpp index e9240c277b..001f5cf67f 100644 --- a/eeschema/api/api_handler_sch.cpp +++ b/eeschema/api/api_handler_sch.cpp @@ -62,9 +62,9 @@ bool API_HANDLER_SCH::validateDocumentInternal( const DocumentSpecifier& aDocume HANDLER_RESULT API_HANDLER_SCH::handleGetOpenDocuments( - GetOpenDocuments& aMsg, const HANDLER_CONTEXT& ) + const HANDLER_CONTEXT& aCtx ) { - if( aMsg.type() != DocumentType::DOCTYPE_SCHEMATIC ) + if( aCtx.Request.type() != DocumentType::DOCTYPE_SCHEMATIC ) { ApiResponseStatus e; // No message needed for AS_UNHANDLED; this is an internal flag for the API server @@ -129,7 +129,7 @@ HANDLER_RESULT> API_HANDLER_SCH::createItemForType( KI HANDLER_RESULT API_HANDLER_SCH::handleCreateUpdateItemsInternal( bool aCreate, - const HANDLER_CONTEXT& aCtx, + const std::string& aClientName, const types::ItemHeader &aHeader, const google::protobuf::RepeatedPtrField& aItems, std::function aItemHandler ) @@ -190,7 +190,7 @@ HANDLER_RESULT API_HANDLER_SCH::handleCreateUpdateItemsIntern } } - COMMIT* commit = getCurrentCommit( aCtx ); + COMMIT* commit = getCurrentCommit( aClientName ); for( const google::protobuf::Any& anyItem : aItems ) { @@ -252,8 +252,8 @@ HANDLER_RESULT API_HANDLER_SCH::handleCreateUpdateItemsIntern item->Serialize( newItem ); commit->Add( item.release() ); - if( !m_activeClients.count( aCtx.ClientName ) ) - pushCurrentCommit( aCtx, _( "Added items via API" ) ); + if( !m_activeClients.count( aClientName ) ) + pushCurrentCommit( aClientName, _( "Added items via API" ) ); } else { @@ -270,8 +270,8 @@ HANDLER_RESULT API_HANDLER_SCH::handleCreateUpdateItemsIntern wxASSERT( false ); } - if( !m_activeClients.count( aCtx.ClientName ) ) - pushCurrentCommit( aCtx, _( "Created items via API" ) ); + if( !m_activeClients.count( aClientName ) ) + pushCurrentCommit( aClientName, _( "Created items via API" ) ); } aItemHandler( status, newItem ); @@ -283,7 +283,7 @@ HANDLER_RESULT API_HANDLER_SCH::handleCreateUpdateItemsIntern void API_HANDLER_SCH::deleteItemsInternal( std::map& aItemsToDelete, - const HANDLER_CONTEXT& aCtx ) + const std::string& aClientName ) { // TODO } diff --git a/eeschema/api/api_handler_sch.h b/eeschema/api/api_handler_sch.h index 63e79c5a6f..4b89d4a122 100644 --- a/eeschema/api/api_handler_sch.h +++ b/eeschema/api/api_handler_sch.h @@ -51,21 +51,21 @@ protected: EDA_ITEM* aContainer ); HANDLER_RESULT handleCreateUpdateItemsInternal( bool aCreate, - const HANDLER_CONTEXT& aCtx, + const std::string& aClientName, const types::ItemHeader &aHeader, const google::protobuf::RepeatedPtrField& aItems, std::function aItemHandler ) override; void deleteItemsInternal( std::map& aItemsToDelete, - const HANDLER_CONTEXT& aCtx ) override; + const std::string& aClientName ) override; std::optional getItemFromDocument( const DocumentSpecifier& aDocument, const KIID& aId ) override; private: HANDLER_RESULT handleGetOpenDocuments( - commands::GetOpenDocuments& aMsg, const HANDLER_CONTEXT& aCtx ); + const HANDLER_CONTEXT& aCtx ); SCH_EDIT_FRAME* m_frame; }; diff --git a/include/api/api_handler.h b/include/api/api_handler.h index 906a88f4cf..7db9f15dca 100644 --- a/include/api/api_handler.h +++ b/include/api/api_handler.h @@ -45,9 +45,11 @@ template using HANDLER_RESULT = tl::expected; +template struct HANDLER_CONTEXT { std::string ClientName; + RequestMessageType Request; }; @@ -88,9 +90,8 @@ protected: * @param aHandler is the handler function for the given request and response types */ template - void registerHandler( - HANDLER_RESULT( HandlerType::* aHandler )( RequestType&, - const HANDLER_CONTEXT& ) ) + void registerHandler( HANDLER_RESULT ( HandlerType::*aHandler )( + const HANDLER_CONTEXT& ) ) { std::string typeName = RequestType().GetTypeName(); @@ -100,17 +101,16 @@ protected: m_handlers[typeName] = [this, aHandler]( ApiRequest& aRequest ) -> API_RESULT { - RequestType cmd; + HANDLER_CONTEXT ctx; ApiResponse envelope; - if( !tryUnpack( aRequest, envelope, cmd ) ) + if( !tryUnpack( aRequest, envelope, ctx.Request ) ) return envelope; - HANDLER_CONTEXT ctx; ctx.ClientName = aRequest.header().client_name(); HANDLER_RESULT response = - std::invoke( aHandler, static_cast( this ), cmd, ctx ); + std::invoke( aHandler, static_cast( this ), ctx ); if( response.has_value() ) { diff --git a/include/api/api_handler_common.h b/include/api/api_handler_common.h index 9659f86846..20028a01cc 100644 --- a/include/api/api_handler_common.h +++ b/include/api/api_handler_common.h @@ -38,22 +38,22 @@ public: ~API_HANDLER_COMMON() override {} private: - HANDLER_RESULT handleGetVersion( commands::GetVersion& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetVersion( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetNetClasses( commands::GetNetClasses& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetNetClasses( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handlePing( commands::Ping& aMsg, const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handlePing( const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetTextExtents( commands::GetTextExtents& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetTextExtents( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT - handleGetTextAsShapes( commands::GetTextAsShapes& aMsg, const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetTextAsShapes( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT - handleExpandTextVariables( commands::ExpandTextVariables& aMsg, const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleExpandTextVariables( + const HANDLER_CONTEXT& aCtx ); }; #endif //KICAD_API_HANDLER_COMMON_H diff --git a/include/api/api_handler_editor.h b/include/api/api_handler_editor.h index f6e47630c5..ad901ab85a 100644 --- a/include/api/api_handler_editor.h +++ b/include/api/api_handler_editor.h @@ -54,27 +54,27 @@ protected: */ virtual std::optional checkForBusy(); - HANDLER_RESULT handleBeginCommit( commands::BeginCommit& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleBeginCommit( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleEndCommit( commands::EndCommit& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleEndCommit( + const HANDLER_CONTEXT& aCtx ); - COMMIT* getCurrentCommit( const HANDLER_CONTEXT& aCtx ); + COMMIT* getCurrentCommit( const std::string& aClientName ); - virtual void pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage ); + virtual void pushCurrentCommit( const std::string& aClientName, const wxString& aMessage ); - HANDLER_RESULT handleCreateItems( commands::CreateItems& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleCreateItems( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleUpdateItems( commands::UpdateItems& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleUpdateItems( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleDeleteItems( commands::DeleteItems& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleDeleteItems( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleHitTest( commands::HitTest& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleHitTest( + const HANDLER_CONTEXT& aCtx ); /** * Override this to create an appropriate COMMIT subclass for the frame in question @@ -85,7 +85,7 @@ protected: /** * Override this to specify which document type this editor handles */ - virtual kiapi::common::types::DocumentType thisDocumentType() const = 0; + virtual types::DocumentType thisDocumentType() const = 0; /** * @return true if the given document is valid for this editor and is currently open @@ -93,13 +93,13 @@ protected: virtual bool validateDocumentInternal( const DocumentSpecifier& aDocument ) const = 0; virtual HANDLER_RESULT handleCreateUpdateItemsInternal( bool aCreate, - const HANDLER_CONTEXT& aCtx, + const std::string& aClientName, const types::ItemHeader &aHeader, const google::protobuf::RepeatedPtrField& aItems, std::function aItemHandler ) = 0; virtual void deleteItemsInternal( std::map& aItemsToDelete, - const HANDLER_CONTEXT& aCtx ) = 0; + const std::string& aClientName ) = 0; virtual std::optional getItemFromDocument( const DocumentSpecifier& aDocument, const KIID& aId ) = 0; diff --git a/pcbnew/api/api_handler_pcb.cpp b/pcbnew/api/api_handler_pcb.cpp index 13ed60fa95..f309ded326 100644 --- a/pcbnew/api/api_handler_pcb.cpp +++ b/pcbnew/api/api_handler_pcb.cpp @@ -97,15 +97,15 @@ PCB_EDIT_FRAME* API_HANDLER_PCB::frame() const } -HANDLER_RESULT API_HANDLER_PCB::handleRunAction( RunAction& aRequest, - const HANDLER_CONTEXT& ) +HANDLER_RESULT API_HANDLER_PCB::handleRunAction( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); RunActionResponse response; - if( frame()->GetToolManager()->RunAction( aRequest.action(), true ) ) + if( frame()->GetToolManager()->RunAction( aCtx.Request.action(), true ) ) response.set_status( RunActionStatus::RAS_OK ); else response.set_status( RunActionStatus::RAS_INVALID ); @@ -115,9 +115,9 @@ HANDLER_RESULT API_HANDLER_PCB::handleRunAction( RunAction& a HANDLER_RESULT API_HANDLER_PCB::handleGetOpenDocuments( - GetOpenDocuments& aMsg, const HANDLER_CONTEXT& ) + const HANDLER_CONTEXT& aCtx ) { - if( aMsg.type() != DocumentType::DOCTYPE_PCB ) + if( aCtx.Request.type() != DocumentType::DOCTYPE_PCB ) { ApiResponseStatus e; // No message needed for AS_UNHANDLED; this is an internal flag for the API server @@ -141,9 +141,9 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetOpenDocuments } -void API_HANDLER_PCB::pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage ) +void API_HANDLER_PCB::pushCurrentCommit( const std::string& aClientName, const wxString& aMessage ) { - API_HANDLER_EDITOR::pushCurrentCommit( aCtx, aMessage ); + API_HANDLER_EDITOR::pushCurrentCommit( aClientName, aMessage ); frame()->Refresh(); } @@ -219,7 +219,7 @@ HANDLER_RESULT> API_HANDLER_PCB::createItemForType( HANDLER_RESULT API_HANDLER_PCB::handleCreateUpdateItemsInternal( bool aCreate, - const HANDLER_CONTEXT& aCtx, + const std::string& aClientName, const types::ItemHeader &aHeader, const google::protobuf::RepeatedPtrField& aItems, std::function aItemHandler ) @@ -271,7 +271,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleCreateUpdateItemsIntern } } - BOARD_COMMIT* commit = static_cast( getCurrentCommit( aCtx ) ); + BOARD_COMMIT* commit = static_cast( getCurrentCommit( aClientName ) ); for( const google::protobuf::Any& anyItem : aItems ) { @@ -371,10 +371,10 @@ HANDLER_RESULT API_HANDLER_PCB::handleCreateUpdateItemsIntern aItemHandler( status, newItem ); } - if( !m_activeClients.count( aCtx.ClientName ) ) + if( !m_activeClients.count( aClientName ) ) { - pushCurrentCommit( aCtx, aCreate ? _( "Created items via API" ) - : _( "Added items via API" ) ); + pushCurrentCommit( aClientName, aCreate ? _( "Created items via API" ) + : _( "Added items via API" ) ); } @@ -382,13 +382,13 @@ HANDLER_RESULT API_HANDLER_PCB::handleCreateUpdateItemsIntern } -HANDLER_RESULT API_HANDLER_PCB::handleGetItems( GetItems& aMsg, - const HANDLER_CONTEXT& ) +HANDLER_RESULT API_HANDLER_PCB::handleGetItems( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - if( !validateItemHeaderDocument( aMsg.header() ) ) + if( !validateItemHeaderDocument( aCtx.Request.header() ) ) { ApiResponseStatus e; // No message needed for AS_UNHANDLED; this is an internal flag for the API server @@ -403,7 +403,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetItems( GetItems& aMsg std::set typesRequested, typesInserted; bool handledAnything = false; - for( int typeRaw : aMsg.types() ) + for( int typeRaw : aCtx.Request.types() ) { auto typeMessage = static_cast( typeRaw ); KICAD_T type = FromProtoEnum( typeMessage ); @@ -514,7 +514,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetItems( GetItems& aMsg void API_HANDLER_PCB::deleteItemsInternal( std::map& aItemsToDelete, - const HANDLER_CONTEXT& aCtx ) + const std::string& aClientName ) { BOARD* board = frame()->GetBoard(); std::vector validatedItems; @@ -531,13 +531,13 @@ void API_HANDLER_PCB::deleteItemsInternal( std::map& a // to add it in the future (and return IDS_IMMUTABLE) } - COMMIT* commit = getCurrentCommit( aCtx ); + COMMIT* commit = getCurrentCommit( aClientName ); for( BOARD_ITEM* item : validatedItems ) commit->Remove( item ); - if( !m_activeClients.count( aCtx.ClientName ) ) - pushCurrentCommit( aCtx, _( "Deleted items via API" ) ); + if( !m_activeClients.count( aClientName ) ) + pushCurrentCommit( aClientName, _( "Deleted items via API" ) ); } @@ -551,13 +551,13 @@ std::optional API_HANDLER_PCB::getItemFromDocument( const DocumentSpe } -HANDLER_RESULT API_HANDLER_PCB::handleGetStackup( GetBoardStackup& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_PCB::handleGetStackup( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -574,13 +574,12 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetStackup( GetBoard HANDLER_RESULT API_HANDLER_PCB::handleGetGraphicsDefaults( - GetGraphicsDefaults& aMsg, - const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -617,13 +616,13 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetGraphicsDefau } -HANDLER_RESULT API_HANDLER_PCB::handleGetBoundingBox( GetBoundingBox& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_PCB::handleGetBoundingBox( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - if( !validateItemHeaderDocument( aMsg.header() ) ) + if( !validateItemHeaderDocument( aCtx.Request.header() ) ) { ApiResponseStatus e; // No message needed for AS_UNHANDLED; this is an internal flag for the API server @@ -632,9 +631,9 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetBoundingBox( Ge } GetBoundingBoxResponse response; - bool includeText = aMsg.mode() == BoundingBoxMode::BBM_ITEM_AND_CHILD_TEXT; + bool includeText = aCtx.Request.mode() == BoundingBoxMode::BBM_ITEM_AND_CHILD_TEXT; - for( const types::KIID& idMsg : aMsg.items() ) + for( const types::KIID& idMsg : aCtx.Request.items() ) { KIID id( idMsg.value() ); std::optional optItem = getItemById( id ); @@ -659,19 +658,18 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetBoundingBox( Ge HANDLER_RESULT API_HANDLER_PCB::handleGetPadShapeAsPolygon( - GetPadShapeAsPolygon& aMsg, - const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); SHAPE_POLY_SET poly; PadShapeAsPolygonResponse response; - PCB_LAYER_ID layer = FromProtoEnum( aMsg.layer() ); + PCB_LAYER_ID layer = FromProtoEnum( aCtx.Request.layer() ); - for( const types::KIID& padRequest : aMsg.pads() ) + for( const types::KIID& padRequest : aCtx.Request.pads() ) { KIID id( padRequest.value() ); std::optional optPad = getItemById( id ); @@ -694,10 +692,9 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetPadShapeAsPo HANDLER_RESULT API_HANDLER_PCB::handleGetTitleBlockInfo( - GetTitleBlockInfo& aMsg, - const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { - HANDLER_RESULT documentValidation = validateDocument( aMsg.document() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.document() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -726,9 +723,9 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetTitleBlockInfo( HANDLER_RESULT API_HANDLER_PCB::handleExpandTextVariables( - ExpandTextVariables& aMsg, const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { - HANDLER_RESULT documentValidation = validateDocument( aMsg.document() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.document() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -743,7 +740,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleExpandTextVar return board->ResolveTextVar( token, 0 ); }; - for( const std::string& textMsg : aMsg.text() ) + for( const std::string& textMsg : aCtx.Request.text() ) { wxString text = ExpandTextVars( wxString::FromUTF8( textMsg ), &textResolver ); reply.add_text( text.ToUTF8() ); @@ -753,13 +750,13 @@ HANDLER_RESULT API_HANDLER_PCB::handleExpandTextVar } -HANDLER_RESULT API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMoveItems& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_PCB::handleInteractiveMoveItems( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -767,7 +764,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMo TOOL_MANAGER* mgr = frame()->GetToolManager(); std::vector toSelect; - for( const kiapi::common::types::KIID& id : aMsg.items() ) + for( const kiapi::common::types::KIID& id : aCtx.Request.items() ) { if( std::optional item = getItemById( KIID( id.value() ) ) ) toSelect.emplace_back( static_cast( *item ) ); @@ -778,7 +775,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMo ApiResponseStatus e; e.set_status( ApiStatusCode::AS_BAD_REQUEST ); e.set_error_message( fmt::format( "None of the given items exist on the board", - aMsg.board().board_filename() ) ); + aCtx.Request.board().board_filename() ) ); return tl::unexpected( e ); } @@ -788,20 +785,19 @@ HANDLER_RESULT API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMo mgr->RunAction( PCB_ACTIONS::selectionClear ); mgr->RunAction( PCB_ACTIONS::selectItems, &toSelect ); - COMMIT* commit = getCurrentCommit( aCtx ); + COMMIT* commit = getCurrentCommit( aCtx.ClientName ); mgr->PostAction( PCB_ACTIONS::move, commit ); return Empty(); } -HANDLER_RESULT API_HANDLER_PCB::handleGetNets( GetNets& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_PCB::handleGetNets( const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -811,7 +807,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetNets( GetNets& aMsg, std::set netclassFilter; - for( const std::string& nc : aMsg.netclass_filter() ) + for( const std::string& nc : aCtx.Request.netclass_filter() ) netclassFilter.insert( wxString( nc.c_str(), wxConvUTF8 ) ); for( NETINFO_ITEM* net : board->GetNetInfo() ) @@ -830,18 +826,17 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetNets( GetNets& aMsg, } -HANDLER_RESULT API_HANDLER_PCB::handleRefillZones( RefillZones& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_PCB::handleRefillZones( const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); - if( aMsg.zones().empty() ) + if( aCtx.Request.zones().empty() ) { TOOL_MANAGER* mgr = frame()->GetToolManager(); frame()->CallAfter( [mgr]() @@ -862,15 +857,15 @@ HANDLER_RESULT API_HANDLER_PCB::handleRefillZones( RefillZones& aMsg, HANDLER_RESULT API_HANDLER_PCB::handleSaveDocumentToString( - SaveDocumentToString& aMsg, const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { - HANDLER_RESULT documentValidation = validateDocument( aMsg.document() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.document() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); SavedDocumentResponse response; - response.mutable_document()->CopyFrom( aMsg.document() ); + response.mutable_document()->CopyFrom( aCtx.Request.document() ); CLIPBOARD_IO io; io.SetWriter( @@ -886,7 +881,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleSaveDocumentToStrin HANDLER_RESULT API_HANDLER_PCB::handleSaveSelectionToString( - SaveSelectionToString& aMsg, const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { SavedSelectionResponse response; @@ -909,12 +904,12 @@ HANDLER_RESULT API_HANDLER_PCB::handleSaveSelectionToStr HANDLER_RESULT API_HANDLER_PCB::handleParseAndCreateItemsFromString( - ParseAndCreateItemsFromString& aMsg, const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - HANDLER_RESULT documentValidation = validateDocument( aMsg.document() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.document() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -924,10 +919,10 @@ HANDLER_RESULT API_HANDLER_PCB::handleParseAndCreateItemsFr } -HANDLER_RESULT API_HANDLER_PCB::handleGetVisibleLayers( GetVisibleLayers& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_PCB::handleGetVisibleLayers( + const HANDLER_CONTEXT& aCtx ) { - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -941,13 +936,13 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetVisibleLayers( GetVisibleL } -HANDLER_RESULT API_HANDLER_PCB::handleSetVisibleLayers( SetVisibleLayers& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_PCB::handleSetVisibleLayers( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -955,7 +950,7 @@ HANDLER_RESULT API_HANDLER_PCB::handleSetVisibleLayers( SetVisibleLayers& LSET visible; LSET enabled = frame()->GetBoard()->GetEnabledLayers(); - for( int layerIdx : aMsg.layers() ) + for( int layerIdx : aCtx.Request.layers() ) { PCB_LAYER_ID layer = FromProtoEnum( static_cast( layerIdx ) ); @@ -973,9 +968,9 @@ HANDLER_RESULT API_HANDLER_PCB::handleSetVisibleLayers( SetVisibleLayers& HANDLER_RESULT API_HANDLER_PCB::handleGetActiveLayer( - GetActiveLayer& aMsg, const HANDLER_CONTEXT& aCtx ) + const HANDLER_CONTEXT& aCtx ) { - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); @@ -988,18 +983,18 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetActiveLayer( } -HANDLER_RESULT API_HANDLER_PCB::handleSetActiveLayer( SetActiveLayer& aMsg, - const HANDLER_CONTEXT& aCtx ) +HANDLER_RESULT API_HANDLER_PCB::handleSetActiveLayer( + const HANDLER_CONTEXT& aCtx ) { if( std::optional busy = checkForBusy() ) return tl::unexpected( *busy ); - HANDLER_RESULT documentValidation = validateDocument( aMsg.board() ); + HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); if( !documentValidation ) return tl::unexpected( documentValidation.error() ); - PCB_LAYER_ID layer = FromProtoEnum( aMsg.layer() ); + PCB_LAYER_ID layer = FromProtoEnum( aCtx.Request.layer() ); if( !frame()->GetBoard()->GetEnabledLayers().Contains( layer ) ) { diff --git a/pcbnew/api/api_handler_pcb.h b/pcbnew/api/api_handler_pcb.h index a3709735cc..ab6bc3d676 100644 --- a/pcbnew/api/api_handler_pcb.h +++ b/pcbnew/api/api_handler_pcb.h @@ -58,59 +58,51 @@ private: static HANDLER_RESULT> createItemForType( KICAD_T aType, BOARD_ITEM_CONTAINER* aContainer ); - HANDLER_RESULT handleRunAction( commands::RunAction& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleRunAction( const HANDLER_CONTEXT& aCtx ); HANDLER_RESULT handleGetOpenDocuments( - commands::GetOpenDocuments& aMsg, const HANDLER_CONTEXT& aCtx ); + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetItems( commands::GetItems& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetItems( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetStackup( GetBoardStackup& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetStackup( const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetGraphicsDefaults( GetGraphicsDefaults& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetGraphicsDefaults( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetBoundingBox( commands::GetBoundingBox& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetBoundingBox( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetPadShapeAsPolygon( GetPadShapeAsPolygon& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetPadShapeAsPolygon( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetTitleBlockInfo( commands::GetTitleBlockInfo& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetTitleBlockInfo( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT - handleExpandTextVariables( commands::ExpandTextVariables& aMsg, const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleExpandTextVariables( + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleInteractiveMoveItems( InteractiveMoveItems& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleInteractiveMoveItems( const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetNets( GetNets& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetNets( const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleRefillZones( RefillZones& aMsg, const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleRefillZones( const HANDLER_CONTEXT& aCtx ); HANDLER_RESULT handleSaveDocumentToString( - commands::SaveDocumentToString& aMsg, const HANDLER_CONTEXT& aCtx ); + const HANDLER_CONTEXT& aCtx ); HANDLER_RESULT handleSaveSelectionToString( - commands::SaveSelectionToString& aMsg, const HANDLER_CONTEXT& aCtx ); + const HANDLER_CONTEXT& aCtx ); HANDLER_RESULT handleParseAndCreateItemsFromString( - commands::ParseAndCreateItemsFromString& aMsg, const HANDLER_CONTEXT& aCtx ); + const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleGetVisibleLayers( GetVisibleLayers& aMsg, - const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetVisibleLayers( const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleSetVisibleLayers( const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleSetVisibleLayers( SetVisibleLayers& aMsg, - const HANDLER_CONTEXT& aCtx ); - - HANDLER_RESULT handleGetActiveLayer( GetActiveLayer& aMsg, - const HANDLER_CONTEXT& aCtx ); - HANDLER_RESULT handleSetActiveLayer( SetActiveLayer& aMsg, const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetActiveLayer( const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleSetActiveLayer( const HANDLER_CONTEXT& aCtx ); protected: std::unique_ptr createCommit() override; @@ -123,20 +115,19 @@ protected: bool validateDocumentInternal( const DocumentSpecifier& aDocument ) const override; void deleteItemsInternal( std::map& aItemsToDelete, - const HANDLER_CONTEXT& aCtx ) override; + const std::string& aClientName ) override; - std::optional getItemFromDocument( const DocumentSpecifier& aDocument, - const KIID& aId ) override; + std::optional getItemFromDocument( const DocumentSpecifier& aDocument, const KIID& aId ) override; private: PCB_EDIT_FRAME* frame() const; - void pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage ) override; + void pushCurrentCommit( const std::string& aClientName, const wxString& aMessage ) override; std::optional getItemById( const KIID& aId ) const; HANDLER_RESULT handleCreateUpdateItemsInternal( bool aCreate, - const HANDLER_CONTEXT& aCtx, + const std::string& aClientName, const types::ItemHeader &aHeader, const google::protobuf::RepeatedPtrField& aItems, std::function aItemHandler )