From f2702b223c200e342af506df4ee0e21707d770eb Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Wed, 27 Dec 2023 20:39:29 +0000 Subject: [PATCH] Introduce base IO_MGR class and unify RELEASER objects The IO_RELEASER is a thin-wrapper around a std::unique_ptr, but done this way to allow easier addition of a custom deleter in the future if something needs to call back into the IO_MGR. --- common/fp_lib_table.cpp | 20 +++---- eeschema/dialogs/dialog_sheet_properties.cpp | 2 +- eeschema/dialogs/panel_sym_lib_table.cpp | 12 ++--- eeschema/eeschema_helpers.cpp | 3 +- eeschema/files-io.cpp | 13 +++-- eeschema/project_rescue.cpp | 2 +- eeschema/sch_io/altium/sch_io_altium.cpp | 2 +- eeschema/sch_io/altium/sch_io_altium.h | 4 +- .../sch_io/cadstar/sch_io_cadstar_archive.cpp | 3 +- eeschema/sch_io/eagle/sch_io_eagle.cpp | 2 +- eeschema/sch_io/eagle/sch_io_eagle.h | 4 +- .../sch_io/easyedapro/sch_io_easyedapro.cpp | 3 +- eeschema/sch_io/sch_io.h | 51 ------------------ eeschema/sch_io/sch_io_mgr.cpp | 14 +---- eeschema/sch_io/sch_io_mgr.h | 17 ++---- eeschema/sheet.cpp | 2 +- .../symbol_editor_import_export.cpp | 6 +-- eeschema/symbol_lib_table.cpp | 5 +- eeschema/symbol_lib_table.h | 6 +-- eeschema/symbol_library_manager.cpp | 3 +- eeschema/tools/sch_editor_control.cpp | 2 +- include/fp_lib_table.h | 4 +- include/io/io_mgr.h | 43 +++++++++++++++ pcbnew/dialogs/dialog_board_setup.cpp | 4 +- pcbnew/dialogs/panel_fp_lib_table.cpp | 8 +-- pcbnew/files.cpp | 29 +++++------ pcbnew/footprint_libraries_utils.cpp | 10 ++-- pcbnew/load_select_footprint.cpp | 4 +- pcbnew/pcb_io/pcb_io.h | 52 ------------------- pcbnew/pcb_io/pcb_io_mgr.cpp | 24 +++------ pcbnew/pcb_io/pcb_io_mgr.h | 16 ++---- pcbnew/python/swig/pcbnew.i | 3 -- pcbnew/tools/pcb_control.cpp | 4 +- qa/qa_utils/pcb_test_frame.cpp | 2 +- qa/schematic_utils/eeschema_test_utils.h | 8 +-- qa/tests/eeschema/test_eagle_plugin.cpp | 9 ++-- .../eeschema/test_netlist_exporter_kicad.cpp | 2 +- qa/tests/pcbnew/test_io_mgr.cpp | 2 +- qa/tools/pns/pns_log_viewer_frame.cpp | 4 +- 39 files changed, 144 insertions(+), 260 deletions(-) create mode 100644 include/io/io_mgr.h diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 0ed088046c..35a0d69ba0 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -303,7 +303,7 @@ void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxS bool aBestEfforts ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts, row->GetProperties() ); } @@ -312,7 +312,7 @@ void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxS void FP_LIB_TABLE::PrefetchLib( const wxString& aNickname ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() ); } @@ -369,7 +369,7 @@ const FOOTPRINT* FP_LIB_TABLE::GetEnumeratedFootprint( const wxString& aNickname const wxString& aFootprintName ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); return row->plugin->GetEnumeratedFootprint( row->GetFullURI( true ), aFootprintName, row->GetProperties() ); @@ -381,7 +381,7 @@ bool FP_LIB_TABLE::FootprintExists( const wxString& aNickname, const wxString& a try { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName, row->GetProperties() ); @@ -397,7 +397,7 @@ FOOTPRINT* FP_LIB_TABLE::FootprintLoad( const wxString& aNickname, const wxString& aFootprintName, bool aKeepUUID ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); FOOTPRINT* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName, aKeepUUID, row->GetProperties() ); @@ -412,7 +412,7 @@ FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave( const wxString& aNickname, const FOOTPRINT* aFootprint, bool aOverwrite ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); if( !aOverwrite ) { @@ -438,7 +438,7 @@ FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave( const wxString& aNickname, void FP_LIB_TABLE::FootprintDelete( const wxString& aNickname, const wxString& aFootprintName ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName, row->GetProperties() ); } @@ -447,7 +447,7 @@ void FP_LIB_TABLE::FootprintDelete( const wxString& aNickname, const wxString& a bool FP_LIB_TABLE::IsFootprintLibWritable( const wxString& aNickname ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); return row->plugin->IsLibraryWritable( row->GetFullURI( true ) ); } @@ -455,7 +455,7 @@ bool FP_LIB_TABLE::IsFootprintLibWritable( const wxString& aNickname ) void FP_LIB_TABLE::FootprintLibDelete( const wxString& aNickname ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); row->plugin->DeleteLibrary( row->GetFullURI( true ), row->GetProperties() ); } @@ -463,7 +463,7 @@ void FP_LIB_TABLE::FootprintLibDelete( const wxString& aNickname ) void FP_LIB_TABLE::FootprintLibCreate( const wxString& aNickname ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - wxASSERT( (PCB_IO*) row->plugin ); + wxASSERT( row->plugin ); row->plugin->CreateLibrary( row->GetFullURI( true ), row->GetProperties() ); } diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index c2f9b71ebf..056b022d18 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -561,7 +561,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena if( renameFile ) { - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); // If the associated screen is shared by more than one sheet, do not // change the filename of the corresponding screen here. diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index 385b313483..49cb403da1 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -172,7 +172,7 @@ protected: STRING_UTF8_MAP choices; SCH_IO_MGR::SCH_FILE_T pi_type = SCH_IO_MGR::EnumFromStr( row->GetType() ); - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( pi_type ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( pi_type ) ); pi->GetLibraryOptions( &choices ); DIALOG_PLUGIN_OPTIONS dlg( m_dialog, row->GetNickName(), choices, options, &result ); @@ -256,7 +256,7 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P for( const SCH_IO_MGR::SCH_FILE_T& type : SCH_IO_MGR::SCH_FILE_T_vector ) { - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( type ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( type ) ); if( !pi ) continue; @@ -308,7 +308,7 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P auto* libTable = static_cast( grid->GetTable() ); auto* tableRow = static_cast( libTable->at( row ) ); - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( tableRow->GetFileType() ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( tableRow->GetFileType() ) ); if( pi ) { @@ -585,7 +585,7 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector ) { - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); if( !pi ) continue; @@ -936,8 +936,8 @@ bool PANEL_SYM_LIB_TABLE::convertLibrary( STRING_UTF8_MAP* aOldFileProps, const if( oldFileType == SCH_IO_MGR::SCH_FILE_UNKNOWN ) return false; - SCH_IO::SCH_IO_RELEASER oldFilePI( SCH_IO_MGR::FindPlugin( oldFileType ) ); - SCH_IO::SCH_IO_RELEASER kicadPI( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); + IO_RELEASER oldFilePI( SCH_IO_MGR::FindPlugin( oldFileType ) ); + IO_RELEASER kicadPI( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); std::vector symbols; std::vector newSymbols; std::map symbolMap; diff --git a/eeschema/eeschema_helpers.cpp b/eeschema/eeschema_helpers.cpp index 56767601e0..850966e0ed 100644 --- a/eeschema/eeschema_helpers.cpp +++ b/eeschema/eeschema_helpers.cpp @@ -121,8 +121,7 @@ SCHEMATIC* EESCHEMA_HELPERS::LoadSchematic( wxString& aFileName, SCH_IO_MGR::SCH if( !project ) project = GetDefaultProject(); - SCH_IO* plugin = SCH_IO_MGR::FindPlugin( aFormat ); - SCH_IO::SCH_IO_RELEASER pi( plugin ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( aFormat ) ); SCHEMATIC* schematic = new SCHEMATIC( project ); diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 89ff215647..3db890c329 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -248,8 +248,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in SetScreen( nullptr ); - SCH_IO* plugin = SCH_IO_MGR::FindPlugin( schFileType ); - SCH_IO::SCH_IO_RELEASER pi( plugin ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( schFileType ) ); pi->SetProgressReporter( &progressReporter ); @@ -670,7 +669,7 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent ) if( fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY ) continue; // this is "Import non-KiCad schematic" - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); if( !pi ) continue; @@ -725,7 +724,7 @@ void SCH_EDIT_FRAME::OnImportProject( wxCommandEvent& aEvent ) for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector ) { - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); if( !pi ) continue; @@ -798,7 +797,7 @@ bool SCH_EDIT_FRAME::saveSchematicFile( SCH_SHEET* aSheet, const wxString& aSave if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN ) pluginType = SCH_IO_MGR::SCH_KICAD; - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) ); try { @@ -1331,12 +1330,12 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType, try { - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); DIALOG_HTML_REPORTER errorReporter( this ); WX_PROGRESS_REPORTER progressReporter( this, _( "Importing Schematic" ), 1 ); PROJECT_CHOOSER_PLUGIN* projectChooserPlugin = - dynamic_cast( (SCH_IO*) pi ); + dynamic_cast( pi.get() ); if( projectChooserPlugin ) { diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index b39db4e114..428dac913b 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -862,7 +862,7 @@ bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( wxWindow *aParent ) try { - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); for( const std::unique_ptr& symbol : m_rescueLibSymbols ) pi->SaveSymbol( fn.GetFullPath(), new LIB_SYMBOL( *symbol.get() ), m_properties.get() ); diff --git a/eeschema/sch_io/altium/sch_io_altium.cpp b/eeschema/sch_io/altium/sch_io_altium.cpp index 1a2507c0bd..67a256bba7 100644 --- a/eeschema/sch_io/altium/sch_io_altium.cpp +++ b/eeschema/sch_io/altium/sch_io_altium.cpp @@ -355,7 +355,7 @@ SCH_SHEET* SCH_IO_ALTIUM::LoadSchematicFile( const wxString& aFileName, SCHEMATI wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." ); - m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); + m_pi.reset( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); /// @note No check is being done here to see if the existing symbol library exists so this /// will overwrite the existing one. diff --git a/eeschema/sch_io/altium/sch_io_altium.h b/eeschema/sch_io/altium/sch_io_altium.h index cbfc5cedd9..89697c660e 100644 --- a/eeschema/sch_io/altium/sch_io_altium.h +++ b/eeschema/sch_io/altium/sch_io_altium.h @@ -178,8 +178,8 @@ private: wxString m_libName; // Library name to save symbols bool m_isIntLib; // Flag to indicate Integrated Library - SCH_IO::SCH_IO_RELEASER m_pi; // Plugin to create KiCad symbol library. - std::unique_ptr m_properties; // Library plugin properties. + IO_RELEASER m_pi; // Plugin to create KiCad symbol library. + std::unique_ptr m_properties; // Library plugin properties. std::unique_ptr m_currentTitleBlock; // Will be assigned at the end of parsing // a sheet diff --git a/eeschema/sch_io/cadstar/sch_io_cadstar_archive.cpp b/eeschema/sch_io/cadstar/sch_io_cadstar_archive.cpp index 4debde89fb..c60775e098 100644 --- a/eeschema/sch_io/cadstar/sch_io_cadstar_archive.cpp +++ b/eeschema/sch_io/cadstar/sch_io_cadstar_archive.cpp @@ -115,8 +115,7 @@ SCH_SHEET* SCH_IO_CADSTAR_ARCHIVE::LoadSchematicFile( const wxString& aFi wxFileName libFileName( aSchematic->Prj().GetProjectPath(), libName, FILEEXT::KiCadSymbolLibFileExtension ); - SCH_IO::SCH_IO_RELEASER sch_plugin; - sch_plugin.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); + IO_RELEASER sch_plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); if( !libTable->HasLibrary( libName ) ) { diff --git a/eeschema/sch_io/eagle/sch_io_eagle.cpp b/eeschema/sch_io/eagle/sch_io_eagle.cpp index 4ff3898d58..9b95377df6 100644 --- a/eeschema/sch_io/eagle/sch_io_eagle.cpp +++ b/eeschema/sch_io/eagle/sch_io_eagle.cpp @@ -455,7 +455,7 @@ SCH_SHEET* SCH_IO_EAGLE::LoadSchematicFile( const wxString& aFileName, SCHEMATIC wxCHECK_MSG( libTable, nullptr, wxT( "Could not load symbol lib table." ) ); - m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); + m_pi.reset( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); m_properties = std::make_unique(); ( *m_properties )[SCH_IO_KICAD_LEGACY::PropBuffering] = ""; diff --git a/eeschema/sch_io/eagle/sch_io_eagle.h b/eeschema/sch_io/eagle/sch_io_eagle.h index 01de580ce4..0a42dfd91c 100644 --- a/eeschema/sch_io/eagle/sch_io_eagle.h +++ b/eeschema/sch_io/eagle/sch_io_eagle.h @@ -247,8 +247,8 @@ private: std::map m_eagleLibs; std::unordered_map m_userValue; ///< deviceset/@uservalue for device. - SCH_IO::SCH_IO_RELEASER m_pi; ///< PI to create KiCad symbol library. - std::unique_ptr m_properties; ///< Library plugin properties. + IO_RELEASER m_pi; ///< PI to create KiCad symbol library. + std::unique_ptr m_properties; ///< Library plugin properties. unsigned m_doneCount; unsigned m_lastProgressCount; diff --git a/eeschema/sch_io/easyedapro/sch_io_easyedapro.cpp b/eeschema/sch_io/easyedapro/sch_io_easyedapro.cpp index 463b6ce19a..1e6cbf845a 100644 --- a/eeschema/sch_io/easyedapro/sch_io_easyedapro.cpp +++ b/eeschema/sch_io/easyedapro/sch_io_easyedapro.cpp @@ -540,8 +540,7 @@ SCH_SHEET* SCH_IO_EASYEDAPRO::LoadSchematicFile( const wxString& aFileName, }; EASYEDAPRO::IterateZipFiles( aFileName, cbs ); - SCH_IO::SCH_IO_RELEASER sch_plugin; - sch_plugin.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); + IO_RELEASER sch_plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); if( !libTable->HasLibrary( libName ) ) { diff --git a/eeschema/sch_io/sch_io.h b/eeschema/sch_io/sch_io.h index aa339db59b..10453d309b 100644 --- a/eeschema/sch_io/sch_io.h +++ b/eeschema/sch_io/sch_io.h @@ -356,57 +356,6 @@ public: */ virtual ~SCH_IO() { } - - /** - * Helper object to release a #SCH_IO in the context of a potential thrown exception - * through its destructor. - */ - class SCH_IO_RELEASER - { - SCH_IO* plugin; - - // private assignment operator so it's illegal - SCH_IO_RELEASER& operator=( SCH_IO_RELEASER& aOther ) { return *this; } - - // private copy constructor so it's illegal - SCH_IO_RELEASER( const SCH_IO_RELEASER& aOther ) {} - - public: - SCH_IO_RELEASER( SCH_IO* aPlugin = nullptr ) : - plugin( aPlugin ) - { - } - - ~SCH_IO_RELEASER() - { - if( plugin ) - release(); - } - - void release() - { - SCH_IO_MGR::ReleasePlugin( plugin ); - plugin = nullptr; - } - - void set( SCH_IO* aPlugin ) - { - if( plugin ) - release(); - plugin = aPlugin; - } - - operator SCH_IO* () const - { - return plugin; - } - - SCH_IO* operator -> () const - { - return plugin; - } - }; - protected: SCH_IO( const wxString& aName ) : IO_BASE( aName ) diff --git a/eeschema/sch_io/sch_io_mgr.cpp b/eeschema/sch_io/sch_io_mgr.cpp index fd0c87f0ed..f5c849f5d7 100644 --- a/eeschema/sch_io/sch_io_mgr.cpp +++ b/eeschema/sch_io/sch_io_mgr.cpp @@ -79,16 +79,6 @@ SCH_IO* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType ) } -void SCH_IO_MGR::ReleasePlugin( SCH_IO* aPlugin ) -{ - // This function is a place holder for a future point in time where - // the plugin is a DLL/DSO. It could do reference counting, and then - // unload the DLL/DSO when count goes to zero. - - delete aPlugin; -} - - const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType ) { // keep this function in sync with EnumFromStr() relative to the @@ -158,7 +148,7 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& a if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad ) continue; - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); if( !pi ) continue; @@ -184,7 +174,7 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromSchPath( const wxString& a if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad ) continue; - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); if( !pi ) continue; diff --git a/eeschema/sch_io/sch_io_mgr.h b/eeschema/sch_io/sch_io_mgr.h index 2aeecc8361..4cf4cadcfb 100644 --- a/eeschema/sch_io/sch_io_mgr.h +++ b/eeschema/sch_io/sch_io_mgr.h @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -47,7 +48,7 @@ class PROGRESS_REPORTER; /** * A factory which returns an instance of a #SCH_IO. */ -class SCH_IO_MGR +class SCH_IO_MGR : public IO_MGR { public: @@ -78,26 +79,14 @@ public: * Return a #SCH_IO which the caller can use to import, export, save, or load * design documents. * - * The returned #SCH_IO, may be reference counted, so please call PluginRelease() - * when you are done using the returned #SCH_IO. It may or may not be code running - * from a DLL/DSO. - * * @param aFileType is from #SCH_FILE_T and tells which plugin to find. * * @return the plugin corresponding to aFileType or NULL if not found. - * Caller owns the returned object, and must call PluginRelease when done using it. + * Caller owns the returned object. */ APIEXPORT static SCH_IO* FindPlugin( SCH_FILE_T aFileType ); - /** - * Release a #SCH_IO back to the system, and may cause it to be unloaded from memory. - * - * @param aPlugin is the one to be released, and which is no longer usable - * after calling this. - */ - static void ReleasePlugin( SCH_IO* aPlugin ); - /** * Return a brief name for a plugin, given aFileType enum. */ diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index bd15fded71..e0689170d1 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -169,7 +169,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier if( schFileType == SCH_IO_MGR::SCH_FILE_UNKNOWN ) schFileType = SCH_IO_MGR::SCH_KICAD; - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( schFileType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( schFileType ) ); std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique( &Schematic() ); // This will cause the sheet UUID to be set to the UUID of the aSheet argument. This is diff --git a/eeschema/symbol_editor/symbol_editor_import_export.cpp b/eeschema/symbol_editor/symbol_editor_import_export.cpp index cefba6c8e5..35ade64a23 100644 --- a/eeschema/symbol_editor/symbol_editor_import_export.cpp +++ b/eeschema/symbol_editor/symbol_editor_import_export.cpp @@ -56,7 +56,7 @@ void SYMBOL_EDIT_FRAME::ImportSymbol() if( fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY ) continue; // this is "Import non-KiCad schematic" - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) ); if( !pi ) continue; @@ -98,7 +98,7 @@ void SYMBOL_EDIT_FRAME::ImportSymbol() return; } - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( piType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( piType ) ); // TODO dialog to select the symbol to be imported if there is more than one try @@ -173,7 +173,7 @@ void SYMBOL_EDIT_FRAME::ExportSymbol() if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN ) pluginType = SCH_IO_MGR::SCH_KICAD; - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) ); if( fn.FileExists() ) { diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 1a86660498..e0b5dff749 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -82,7 +82,7 @@ bool SYMBOL_LIB_TABLE_ROW::Refresh() { wxArrayString dummyList; - plugin.set( SCH_IO_MGR::FindPlugin( type ) ); + plugin.reset( SCH_IO_MGR::FindPlugin( type ) ); SetLoaded( false ); plugin->SetLibTable( static_cast( GetParent() ) ); plugin->EnumerateSymbolLib( dummyList, GetFullURI( true ), GetProperties() ); @@ -110,8 +110,7 @@ void SYMBOL_LIB_TABLE_ROW::ShowSettingsDialog( wxWindow* aParent ) const if( type != SCH_IO_MGR::SCH_DATABASE ) return; - DIALOG_DATABASE_LIB_SETTINGS dlg( aParent, - static_cast( ( SCH_IO* )plugin ) ); + DIALOG_DATABASE_LIB_SETTINGS dlg( aParent, static_cast( plugin.get() ) ); dlg.ShowModal(); } diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index c0216a8b04..e5b04e1b8c 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -133,11 +133,11 @@ private: void setPlugin( SCH_IO* aPlugin ) { - plugin.set( aPlugin ); + plugin.reset( aPlugin ); } - SCH_IO::SCH_IO_RELEASER plugin; - LIB_T type; + IO_RELEASER plugin; + LIB_T type; }; diff --git a/eeschema/symbol_library_manager.cpp b/eeschema/symbol_library_manager.cpp index 9517fb63ce..7cd39944bc 100644 --- a/eeschema/symbol_library_manager.cpp +++ b/eeschema/symbol_library_manager.cpp @@ -173,7 +173,8 @@ bool SYMBOL_LIBRARY_MANAGER::SaveLibrary( const wxString& aLibrary, const wxStri wxCHECK( aFileType != SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY && LibraryExists( aLibrary ), false ); wxFileName fn( aFileName ); wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false ); - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( aFileType ) ); + + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( aFileType ) ); bool res = true; // assume all libraries are successfully saved STRING_UTF8_MAP properties; diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 5f2f9b765e..8c7250692b 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -422,7 +422,7 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent ) SYMBOL_LIB_TABLE_ROW* row = mgr.GetLibrary( targetLib ); SCH_IO_MGR::SCH_FILE_T type = SCH_IO_MGR::EnumFromStr( row->GetType() ); - SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( type ) ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( type ) ); wxFileName dest = row->GetFullURI( true ); dest.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS ); diff --git a/include/fp_lib_table.h b/include/fp_lib_table.h index e24a5c326b..3e83c4de46 100644 --- a/include/fp_lib_table.h +++ b/include/fp_lib_table.h @@ -84,13 +84,13 @@ private: void setPlugin( PCB_IO* aPlugin ) { - plugin.set( aPlugin ); + plugin.reset( aPlugin ); } friend class FP_LIB_TABLE; private: - PCB_IO::RELEASER plugin; + IO_RELEASER plugin; PCB_IO_MGR::PCB_FILE_T type; }; diff --git a/include/io/io_mgr.h b/include/io/io_mgr.h new file mode 100644 index 0000000000..dddc69e639 --- /dev/null +++ b/include/io/io_mgr.h @@ -0,0 +1,43 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + + +#ifndef IO_MGR_H_ +#define IO_MGR_H_ + +#include + +/** + * Helper to hold and release an #IO_BASE object when exceptions are thrown. + * + * (Wrapper around a std::unique_ptr, but created to allow possible custom deleters + * in the future). + */ +template +using IO_RELEASER = std::unique_ptr; + + +class IO_MGR +{ +public: + +}; + + +#endif // IO_MGR_H_ diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index f53784f8ff..5f5b6618dd 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -284,8 +284,8 @@ void DIALOG_BOARD_SETUP::onAuxiliaryAction( wxCommandEvent& aEvent ) PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() ); - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); - BOARD* otherBoard = nullptr; + IO_RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); + BOARD* otherBoard = nullptr; try { diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index e4279e371a..cd8a694725 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -240,7 +240,7 @@ protected: STRING_UTF8_MAP choices; PCB_IO_MGR::PCB_FILE_T pi_type = PCB_IO_MGR::EnumFromStr( row->GetType() ); - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( pi_type ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( pi_type ) ); pi->GetLibraryOptions( &choices ); DIALOG_PLUGIN_OPTIONS dlg( m_dialog, row->GetNickName(), choices, options, &result ); @@ -514,7 +514,7 @@ void PANEL_FP_LIB_TABLE::populatePluginList() { for( const auto& plugin : PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins() ) { - PCB_IO::RELEASER pi( plugin.m_createFunc() ); + IO_RELEASER pi( plugin.m_createFunc() ); if( !pi ) continue; @@ -899,8 +899,8 @@ bool PANEL_FP_LIB_TABLE::convertLibrary( STRING_UTF8_MAP* aOldFileProps, return false; - PCB_IO::RELEASER oldFilePI( PCB_IO_MGR::PluginFind( oldFileType ) ); - PCB_IO::RELEASER kicadPI( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); + IO_RELEASER oldFilePI( PCB_IO_MGR::PluginFind( oldFileType ) ); + IO_RELEASER kicadPI( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); wxArrayString fpNames; wxFileName newFileName( aNewFilePath ); diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index de4b26930d..d0634dead9 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -107,8 +107,7 @@ bool AskLoadBoardFileName( PCB_EDIT_FRAME* aParent, wxString* aFileName, int aCt if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad ) continue; - // release the PLUGIN even if an exception is thrown. - PCB_IO::RELEASER pi( plugin.m_createFunc() ); + IO_RELEASER pi( plugin.m_createFunc() ); wxCHECK( pi, false ); const IO_BASE::IO_FILE_DESC& desc = pi->GetBoardFileDesc(); @@ -606,24 +605,22 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in } else { - BOARD* loadedBoard = nullptr; // it will be set to non-NULL if loaded OK - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( pluginType ) ); + BOARD* loadedBoard = nullptr; // it will be set to non-NULL if loaded OK + IO_RELEASER pi( PCB_IO_MGR::PluginFind( pluginType ) ); - LAYER_REMAPPABLE_PLUGIN* layerRemappablePlugin = - dynamic_cast< LAYER_REMAPPABLE_PLUGIN* >( (PCB_IO*) pi ); + LAYER_REMAPPABLE_PLUGIN* layerRemappableIO = dynamic_cast( pi.get() ); - if( layerRemappablePlugin ) + if( layerRemappableIO ) { - layerRemappablePlugin->RegisterLayerMappingCallback( + layerRemappableIO->RegisterLayerMappingCallback( std::bind( DIALOG_IMPORTED_LAYERS::GetMapModal, this, std::placeholders::_1 ) ); } - PROJECT_CHOOSER_PLUGIN* projectChooserPlugin = - dynamic_cast( (PCB_IO*) pi ); + PROJECT_CHOOSER_PLUGIN* projectChooserIO = dynamic_cast( pi.get() ); - if( projectChooserPlugin ) + if( projectChooserIO ) { - projectChooserPlugin->RegisterChooseProjectCallback( + projectChooserIO->RegisterChooseProjectCallback( std::bind( DIALOG_IMPORT_CHOOSE_PROJECT::GetSelectionsModal, this, std::placeholders::_1 ) ); } @@ -802,7 +799,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // which prompts the user to continue with overwrite or abort) if( newLibPath.Length() > 0 ) { - PCB_IO::RELEASER piSexpr( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); + IO_RELEASER piSexpr( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); for( FOOTPRINT* footprint : loadedFootprints ) { @@ -992,7 +989,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory, try { - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); pi->SaveBoard( tempFile, GetBoard(), nullptr ); } @@ -1092,7 +1089,7 @@ bool PCB_EDIT_FRAME::SavePcbCopy( const wxString& aFileName, bool aCreateProject try { - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::KICAD_SEXP ) ); wxASSERT( pcbFileName.IsAbsolute() ); @@ -1273,7 +1270,7 @@ void PCB_EDIT_FRAME::GenIPC2581File( wxCommandEvent& event ) { try { - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::IPC2581 ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( PCB_IO_MGR::IPC2581 ) ); pi->SetProgressReporter( &reporter ); pi->SaveBoard( tempFile, GetBoard(), &props ); return true; diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 87c46e45e7..8f186c15cd 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -90,7 +90,7 @@ FOOTPRINT* FOOTPRINT_EDIT_FRAME::ImportFootprint( const wxString& aName ) for( const auto& plugin : PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins() ) { - PCB_IO::RELEASER pi( plugin.m_createFunc() ); + IO_RELEASER pi( plugin.m_createFunc() ); if( !pi ) continue; @@ -148,7 +148,7 @@ FOOTPRINT* FOOTPRINT_EDIT_FRAME::ImportFootprint( const wxString& aName ) for( const auto& plugin : PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins() ) { - PCB_IO::RELEASER pi( plugin.m_createFunc() ); + IO_RELEASER pi( plugin.m_createFunc() ); if( !pi ) continue; @@ -174,7 +174,7 @@ FOOTPRINT* FOOTPRINT_EDIT_FRAME::ImportFootprint( const wxString& aName ) try { - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( fileType ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( fileType ) ); footprint = pi->ImportFootprint( fn.GetFullPath(), footprintName); @@ -346,7 +346,7 @@ wxString PCB_BASE_EDIT_FRAME::createNewLibrary( const wxString& aLibName, try { - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( piType ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( piType ) ); bool writable = false; bool exists = false; @@ -658,7 +658,7 @@ void PCB_EDIT_FRAME::ExportFootprintsToLibrary( bool aStoreInNewLib, const wxStr } PCB_IO_MGR::PCB_FILE_T piType = PCB_IO_MGR::KICAD_SEXP; - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( piType ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( piType ) ); for( FOOTPRINT* footprint : GetBoard()->Footprints() ) { diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index 2ddc1875d4..dee03372c6 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -337,8 +337,8 @@ bool FOOTPRINT_EDIT_FRAME::SaveLibraryAs( const wxString& aLibraryPath ) try { - PCB_IO::RELEASER cur( PCB_IO_MGR::PluginFind( curType ) ); - PCB_IO::RELEASER dst( PCB_IO_MGR::PluginFind( dstType ) ); + IO_RELEASER cur( PCB_IO_MGR::PluginFind( curType ) ); + IO_RELEASER dst( PCB_IO_MGR::PluginFind( dstType ) ); if( !cur ) { diff --git a/pcbnew/pcb_io/pcb_io.h b/pcbnew/pcb_io/pcb_io.h index 8be2f0de90..56e9c3b1c1 100644 --- a/pcbnew/pcb_io/pcb_io.h +++ b/pcbnew/pcb_io/pcb_io.h @@ -333,58 +333,6 @@ public: virtual ~PCB_IO() {}; - -#ifndef SWIG - /** - * Releases a PLUGIN in the context of a potential thrown exception through its destructor. - */ - class RELEASER - { - PCB_IO* plugin; - - // private assignment operator so it's illegal - RELEASER& operator=( RELEASER& aOther ) { return *this; } - - // private copy constructor so it's illegal - RELEASER( const RELEASER& aOther ) : plugin( nullptr ) {} - - public: - RELEASER( PCB_IO* aPlugin = nullptr ) : - plugin( aPlugin ) - { - } - - ~RELEASER() - { - if( plugin ) - release(); - } - - void release() - { - PCB_IO_MGR::PluginRelease( plugin ); - plugin = nullptr; - } - - void set( PCB_IO* aPlugin ) - { - if( plugin ) - release(); - plugin = aPlugin; - } - - operator PCB_IO* () const - { - return plugin; - } - - PCB_IO* operator -> () const - { - return plugin; - } - }; -#endif - protected: PCB_IO( const wxString& aName ) : IO_BASE( aName ), m_board( nullptr ), diff --git a/pcbnew/pcb_io/pcb_io_mgr.cpp b/pcbnew/pcb_io/pcb_io_mgr.cpp index 899729bd00..1bbf8e6789 100644 --- a/pcbnew/pcb_io/pcb_io_mgr.cpp +++ b/pcbnew/pcb_io/pcb_io_mgr.cpp @@ -71,16 +71,6 @@ PCB_IO* PCB_IO_MGR::PluginFind( PCB_FILE_T aFileType ) } -void PCB_IO_MGR::PluginRelease( PCB_IO* aPlugin ) -{ - // This function is a place holder for a future point in time where - // the plugin is a DLL/DSO. It could do reference counting, and then - // unload the DLL/DSO when count goes to zero. - - delete aPlugin; -} - - const wxString PCB_IO_MGR::ShowType( PCB_FILE_T aType ) { const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins(); @@ -129,7 +119,7 @@ PCB_IO_MGR::PCB_FILE_T PCB_IO_MGR::FindPluginTypeFromBoardPath( const wxString& if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad ) continue; - PCB_IO::RELEASER pi( plugin.m_createFunc() ); + IO_RELEASER pi( plugin.m_createFunc() ); if( pi->CanReadBoard( aFileName ) ) return plugin.m_type; @@ -153,7 +143,7 @@ PCB_IO_MGR::PCB_FILE_T PCB_IO_MGR::GuessPluginTypeFromLibPath( const wxString& a if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad ) continue; - PCB_IO::RELEASER pi( plugin.m_createFunc() ); + IO_RELEASER pi( plugin.m_createFunc() ); if( pi->CanReadLibrary( aLibPath ) ) return plugin.m_type; @@ -167,10 +157,9 @@ BOARD* PCB_IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* const STRING_UTF8_MAP* aProperties, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter ) { - // release the PLUGIN even if an exception is thrown. - PCB_IO::RELEASER pi( PluginFind( aFileType ) ); + IO_RELEASER pi( PluginFind( aFileType ) ); - if( (PCB_IO*) pi ) // test pi->plugin + if( pi ) // test pi->plugin { pi->SetProgressReporter( aProgressReporter ); return pi->LoadBoard( aFileName, aAppendToMe, aProperties, aProject ); @@ -183,10 +172,9 @@ BOARD* PCB_IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* void PCB_IO_MGR::Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aBoard, const STRING_UTF8_MAP* aProperties ) { - // release the PLUGIN even if an exception is thrown. - PCB_IO::RELEASER pi( PluginFind( aFileType ) ); + IO_RELEASER pi( PluginFind( aFileType ) ); - if( (PCB_IO*) pi ) // test pi->plugin + if( pi ) { pi->SaveBoard( aFileName, aBoard, aProperties ); // virtual return; diff --git a/pcbnew/pcb_io/pcb_io_mgr.h b/pcbnew/pcb_io/pcb_io_mgr.h index b5c2e4d349..8c3785c029 100644 --- a/pcbnew/pcb_io/pcb_io_mgr.h +++ b/pcbnew/pcb_io/pcb_io_mgr.h @@ -31,6 +31,7 @@ #include #include #include +#include class BOARD; class PCB_IO; @@ -42,7 +43,7 @@ class PROGRESS_REPORTER; /** * A factory which returns an instance of a #PLUGIN. */ -class PCB_IO_MGR +class PCB_IO_MGR : public IO_MGR { public: @@ -154,24 +155,13 @@ public: * Return a #PLUGIN which the caller can use to import, export, save, or load * design documents. * - * The returned #PLUGIN, may be reference counted, so please call PluginRelease() when you - * are done using the returned #PLUGIN. It may or may not be code running from a DLL/DSO. - * - * @note The caller owns the returned object and must call PluginRelease when done using it. + * @note The caller owns the returned object. * * @param aFileType is from #PCB_FILE_T and tells which plugin to find. * @return the plug in corresponding to \a aFileType or NULL if not found. */ static PCB_IO* PluginFind( PCB_FILE_T aFileType ); - /** - * Release a #PLUGIN back to the system and may cause it to be unloaded from memory. - * - * @param aPlugin is the one to be released, and which is no longer usable - * after calling this. - */ - static void PluginRelease( PCB_IO* aPlugin ); - /** * Return a brief name for a plugin given \a aFileType enum. */ diff --git a/pcbnew/python/swig/pcbnew.i b/pcbnew/python/swig/pcbnew.i index e200c5b303..68819469c5 100644 --- a/pcbnew/python/swig/pcbnew.i +++ b/pcbnew/python/swig/pcbnew.i @@ -86,9 +86,6 @@ wxArrayString GetFootprints(const wxString& aNickName); %include - -// ignore RELEASER as nested classes are still unsupported by swig -%ignore IO_MGR::RELEASER; %include diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index 4ad508651a..c728b9b0c3 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -1049,7 +1049,7 @@ int PCB_CONTROL::AppendBoardFromFile( const TOOL_EVENT& aEvent ) PCB_IO_MGR::PCB_FILE_T pluginType = PCB_IO_MGR::FindPluginTypeFromBoardPath( fileName, KICTL_KICAD_ONLY ); - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( pluginType ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( pluginType ) ); if( !pi ) return 1; @@ -1686,7 +1686,7 @@ int PCB_CONTROL::DdAppendBoard( const TOOL_EVENT& aEvent ) wxString filePath = fileName.GetFullPath(); PCB_IO_MGR::PCB_FILE_T pluginType = PCB_IO_MGR::FindPluginTypeFromBoardPath( filePath ); - PCB_IO::RELEASER pi( PCB_IO_MGR::PluginFind( pluginType ) ); + IO_RELEASER pi( PCB_IO_MGR::PluginFind( pluginType ) ); if( !pi ) return 1; diff --git a/qa/qa_utils/pcb_test_frame.cpp b/qa/qa_utils/pcb_test_frame.cpp index 171a19d497..098cf38e6e 100644 --- a/qa/qa_utils/pcb_test_frame.cpp +++ b/qa/qa_utils/pcb_test_frame.cpp @@ -101,7 +101,7 @@ void PCB_TEST_FRAME_BASE::SetBoard( std::shared_ptr b ) BOARD* PCB_TEST_FRAME_BASE::LoadAndDisplayBoard( const std::string& filename ) { - PCB_IO::RELEASER pi( new PCB_IO_KICAD_SEXPR ); + IO_RELEASER pi( new PCB_IO_KICAD_SEXPR ); BOARD* brd = nullptr; try diff --git a/qa/schematic_utils/eeschema_test_utils.h b/qa/schematic_utils/eeschema_test_utils.h index dfd110a2cf..934feeecd9 100644 --- a/qa/schematic_utils/eeschema_test_utils.h +++ b/qa/schematic_utils/eeschema_test_utils.h @@ -58,16 +58,16 @@ public: virtual ~SCHEMATIC_TEST_FIXTURE() { m_schematic.Reset(); - SCH_IO_MGR::ReleasePlugin( m_pi ); + m_pi.reset(); } protected: virtual void LoadSchematic( const wxString& aRelativePath ); virtual wxFileName GetSchematicPath( const wxString& aBaseName ); - SCHEMATIC m_schematic; - SCH_IO* m_pi; - SETTINGS_MANAGER m_manager; + SCHEMATIC m_schematic; + IO_RELEASER m_pi; + SETTINGS_MANAGER m_manager; }; diff --git a/qa/tests/eeschema/test_eagle_plugin.cpp b/qa/tests/eeschema/test_eagle_plugin.cpp index 4d3142dc64..600b5aa8e5 100644 --- a/qa/tests/eeschema/test_eagle_plugin.cpp +++ b/qa/tests/eeschema/test_eagle_plugin.cpp @@ -35,9 +35,8 @@ */ BOOST_AUTO_TEST_CASE( FindPlugin ) { - SCH_IO* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ); - BOOST_CHECK_NE( pi, nullptr ); - SCH_IO_MGR::ReleasePlugin( pi ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) ); + BOOST_CHECK_NE( pi.get(), nullptr ); } @@ -60,7 +59,7 @@ static wxFileName getEagleTestSchematic( const wxString& sch_file ) */ BOOST_AUTO_TEST_CASE( Load ) { - SCH_IO* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ); + IO_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) ); const auto fn = getEagleTestSchematic( "eagle-import-testfile.sch" ); @@ -70,6 +69,4 @@ BOOST_AUTO_TEST_CASE( Load ) // This doesn't work with a null KiWay. // const SCH_SHEET* sheet = pi->Load( fn.GetFullPath(), nullptr ); // BOOST_CHECK_NE( nullptr, sheet ); - - SCH_IO_MGR::ReleasePlugin( pi ); } diff --git a/qa/tests/eeschema/test_netlist_exporter_kicad.cpp b/qa/tests/eeschema/test_netlist_exporter_kicad.cpp index 0e0903ae62..dbbef3385f 100644 --- a/qa/tests/eeschema/test_netlist_exporter_kicad.cpp +++ b/qa/tests/eeschema/test_netlist_exporter_kicad.cpp @@ -97,7 +97,7 @@ BOOST_FIXTURE_TEST_SUITE( Netlists, TEST_NETLIST_EXPORTER_KICAD_FIXTURE ) BOOST_AUTO_TEST_CASE( FindPlugin ) { - BOOST_CHECK_NE( m_pi, nullptr ); + BOOST_CHECK_NE( m_pi.get(), nullptr ); } diff --git a/qa/tests/pcbnew/test_io_mgr.cpp b/qa/tests/pcbnew/test_io_mgr.cpp index af46060e6d..b62db56c9b 100644 --- a/qa/tests/pcbnew/test_io_mgr.cpp +++ b/qa/tests/pcbnew/test_io_mgr.cpp @@ -298,7 +298,7 @@ BOOST_AUTO_TEST_CASE( CheckCanReadBoard ) { BOOST_TEST_CONTEXT( entry.m_name ) { - auto plugin = PCB_IO::RELEASER( PCB_IO_MGR::PluginFind( entry.m_type ) ); + auto plugin = IO_RELEASER( PCB_IO_MGR::PluginFind( entry.m_type ) ); bool expectValidHeader = c.m_expected_type == entry.m_type; BOOST_CHECK_EQUAL( plugin->CanReadBoard( dataPath ), expectValidHeader ); diff --git a/qa/tools/pns/pns_log_viewer_frame.cpp b/qa/tools/pns/pns_log_viewer_frame.cpp index 2f952d4ce9..e9870fd2b8 100644 --- a/qa/tools/pns/pns_log_viewer_frame.cpp +++ b/qa/tools/pns/pns_log_viewer_frame.cpp @@ -893,8 +893,8 @@ void PNS_LOG_VIEWER_FRAME::updatePnsPreviewItems( int iter ) static BOARD* loadBoard( const std::string& filename ) { - PLUGIN::RELEASER pi( new PCB_IO_KICAD_SEXPR ); - BOARD* brd = nullptr; + IO_RELEASER pi( new PCB_IO_KICAD_SEXPR ); + BOARD* brd = nullptr; try {