Skip to content

Commit

Permalink
Core PluginControl: differentiate between internal staged meta-data a…
Browse files Browse the repository at this point in the history
…dd vs external which needs different behaviour
  • Loading branch information
LiberatorUSA committed Sep 8, 2024
1 parent 5b4fe59 commit a020d3c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
5 changes: 5 additions & 0 deletions platform/gucefCORE/include/CPluginControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ class GUCEF_CORE_PUBLIC_CPP CPluginControl : public CTSGNotifier ,

TPluginGroupPtr GetOrCreatePluginGroup( const CString& groupName, UInt32 priorityIfNotExist = GUCEF_UINT32MAX );

bool AddPluginMetaDataImpl( TPluginMetaDataStoragePtr pluginMetaData ,
const CString& groupName ,
bool loadImmediately ,
bool registerImmediately = true );

bool LoadPlugin( TPluginMetaDataStoragePtr& pluginMetaData ,
CPluginGroup& pluginGroup ,
const CString& groupName ,
Expand Down
51 changes: 37 additions & 14 deletions platform/gucefCORE/src/CPluginControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,9 @@ CPluginControl::RegisterAll( bool registerOnlyIfLoadImmediatelySet )
while ( n != pluginGroups.end() )
{
TPluginGroupPtr& pluginGroup = (*n).second;
CPluginGroup::TPluginMetaDataSet& pluginMetaDataSet = pluginGroup->GetPluginMetaData();


// note that we need to pull a copy of the plugin group info, it will get altered as we register invalidating the collection
CPluginGroup::TPluginMetaDataSet pluginMetaDataSet = pluginGroup->GetPluginMetaData();
CPluginGroup::TPluginMetaDataSet::iterator m = pluginMetaDataSet.begin();
while ( m != pluginMetaDataSet.end() )
{
Expand Down Expand Up @@ -1373,10 +1374,10 @@ CPluginControl::GetOrCreatePluginGroup( const CString& groupName, UInt32 priorit
/*-------------------------------------------------------------------------*/

bool
CPluginControl::AddPluginMetaData( const CIPluginMetaData& pluginMetaData ,
const CString& groupName ,
bool loadImmediately ,
bool registerImmediately )
CPluginControl::AddPluginMetaDataImpl( TPluginMetaDataStoragePtr pluginMetaData ,
const CString& groupName ,
bool loadImmediately ,
bool registerImmediately )
{GUCEF_TRACE;

bool success = true;
Expand All @@ -1388,16 +1389,12 @@ CPluginControl::AddPluginMetaData( const CIPluginMetaData& pluginMetaData ,
return false;

// Add the metadata
TPluginMetaDataStoragePtr pluginMetaDataCopy( CPluginMetaData::CreateSharedObjWithParam( pluginMetaData ) );
if ( pluginMetaDataCopy.IsNULL() )
return false;
pluginMetaDataCopy->SetLoadImmediately( loadImmediately );
pluginGroup->GetPluginMetaData().insert( pluginMetaDataCopy );
pluginGroup->GetPluginMetaData().insert( pluginMetaData );

// If an immediate load is desired we invoke the load function as well
if ( loadImmediately )
{
success = LoadPlugin( pluginMetaDataCopy ,
success = LoadPlugin( pluginMetaData ,
*pluginGroup ,
groupName ,
registerImmediately );
Expand All @@ -1408,6 +1405,32 @@ CPluginControl::AddPluginMetaData( const CIPluginMetaData& pluginMetaData ,

/*-------------------------------------------------------------------------*/

bool
CPluginControl::AddPluginMetaData( const CIPluginMetaData& pluginMetaData ,
const CString& groupName ,
bool loadImmediately ,
bool registerImmediately )
{GUCEF_TRACE;

bool success = true;

// Create a copy which plugin control will own
TPluginMetaDataStoragePtr pluginMetaDataCopy( CPluginMetaData::CreateSharedObjWithParam( pluginMetaData ) );
if ( pluginMetaDataCopy.IsNULL() )
return false;

// set the load immediately flag which may differ from what the original meta-data had
pluginMetaDataCopy->SetLoadImmediately( loadImmediately );

// Now call our internal implementation for the rest of the work
return AddPluginMetaDataImpl( pluginMetaDataCopy ,
groupName ,
loadImmediately ,
registerImmediately );
}

/*-------------------------------------------------------------------------*/

bool
CPluginControl::AdjustGroupPriority( const CString& groupName , UInt32 newPriority )
{GUCEF_TRACE;
Expand Down Expand Up @@ -1463,7 +1486,7 @@ CPluginControl::LoadConfig( const CDataNode& treeroot )

// first parse relevant information from the config
// Note that group loading priority is determined by order of appearance in the config unless otherwise specified in the config

UInt32 groupPriorityPerConfigOrder = 1;
CDataNode::TConstDataNodeSet pluginGroupNodes( treeroot.FindChildrenOfType( "PluginGroup", true ) );
CDataNode::TConstDataNodeSet::iterator i = pluginGroupNodes.begin();
Expand Down Expand Up @@ -1544,7 +1567,7 @@ CPluginControl::LoadConfig( const CDataNode& treeroot )
{
TPluginMetaDataStoragePtr& metaData = (*e);

if ( AddPluginMetaData( *metaData, groupName, false, false ) )
if ( AddPluginMetaDataImpl( metaData, groupName, false, false ) )
{
GUCEF_DEBUG_LOG( LOGLEVEL_NORMAL, "PluginControl: Loaded meta-data for plugin in group \"" + groupName + "\" with filename: " + metaData->GetModuleFilename() );
}
Expand Down

0 comments on commit a020d3c

Please sign in to comment.