Commit d144e47e authored by whitlocb's avatar whitlocb

Changed the plugin managers so they are not singletons anymore. This enables...

Changed the plugin managers so they are not singletons anymore. This enables multiple types of plugins to be loaded into the same application. Mainly, this was done to enable scripting and engine plugins to exist in the same executable as when you have imported the VisIt module into an application that is instrumented with libsim.


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@4541 18c085ea-50e0-402c-830e-de6fd14e8384
parent 931c8285
......@@ -260,10 +260,14 @@ avtDatabaseFactory::SetDefaultFileOpenOptions(const FileOpenOptions &opts)
// Jeremy Meredith, Wed Apr 2 12:46:52 EDT 2008
// Adding a little debug info for watching format attempts.
//
// Brad Whitlock, Tue Jun 24 15:33:58 PDT 2008
// Pass in the database plugin manager since it's no longer a singleton.
//
// ****************************************************************************
avtDatabase *
avtDatabaseFactory::FileList(const char * const * filelist, int filelistN,
avtDatabaseFactory::FileList(DatabasePluginManager *dbmgr,
const char * const * filelist, int filelistN,
int timestep, vector<string> &plugins,
const char *format,
bool forceReadAllCyclesAndTimes,
......@@ -296,8 +300,6 @@ avtDatabaseFactory::FileList(const char * const * filelist, int filelistN,
//
CheckPermissions(filelist[fileIndex]);
DatabasePluginManager *dbmgr = DatabasePluginManager::Instance();
//
// If we were specifically told which format to use, then try that now.
//
......@@ -608,10 +610,15 @@ avtDatabaseFactory::SetupDatabase(CommonDatabasePluginInfo *info,
//
// Mark C. Miller, Thu Jun 14 10:26:37 PDT 2007
// Added support to treat all databases as time varying
//
// Brad Whitlock, Tue Jun 24 15:33:58 PDT 2008
// Pass in the database plugin manager since it's no longer a singleton.
//
// ****************************************************************************
avtDatabase *
avtDatabaseFactory::VisitFile(const char *visitFile, int timestep,
avtDatabaseFactory::VisitFile(DatabasePluginManager *dbmgr,
const char *visitFile, int timestep,
vector<string> &plugins,
const char *format,
bool forceReadAllCyclesAndTimes,
......@@ -670,7 +677,7 @@ avtDatabaseFactory::VisitFile(const char *visitFile, int timestep,
//
// Create a database using the list of files.
//
avtDatabase *rv = FileList(reallist, listcount, timestep, plugins, format,
avtDatabase *rv = FileList(dbmgr, reallist, listcount, timestep, plugins, format,
forceReadAllCyclesAndTimes, treatAllDBsAsTimeVarying);
//
......
......@@ -54,7 +54,7 @@
class avtDatabase;
class CommonDatabasePluginInfo;
class DatabasePluginManager;
// ****************************************************************************
// Class: avtDatabaseFactory
......@@ -108,16 +108,21 @@ class CommonDatabasePluginInfo;
// Jeremy Meredith, Wed Mar 19 14:06:16 EDT 2008
// Renamed default format to fallback format for clarity.
//
// Brad Whitlock, Tue Jun 24 15:49:33 PDT 2008
// Pass the database plugin manager in because it's no longer a singleton.
//
// ****************************************************************************
class DATABASE_API avtDatabaseFactory
{
public:
static avtDatabase *FileList(const char * const *, int, int,
static avtDatabase *FileList(DatabasePluginManager *,
const char * const *, int, int,
std::vector<std::string> &,
const char * = NULL, bool = false,
bool = false);
static avtDatabase *VisitFile(const char *, int,
static avtDatabase *VisitFile(DatabasePluginManager *,
const char *, int,
std::vector<std::string> &,
const char * = NULL, bool = false,
bool = false);
......
......@@ -73,7 +73,8 @@ static const char *const allComponentNames[] = {
};
static ErrorFunction errorFunction = NULL;
static void *errorFunctionArgs = NULL;
static bool initializeCalled = false;
static bool finalizeCalled = false;
// ****************************************************************************
// Function: striparg
......@@ -198,11 +199,22 @@ NewHandler(void)
// Cyrus Harrison, Wed Jan 23 09:23:19 PST 2008
// Changed set_new_handler to std::set_new_handler b/c of change from
// deprecated <new.h> to <new>
//
// Brad Whitlock, Wed Jun 25 10:42:58 PDT 2008
// Added check to return early in case this function gets called multiple
// times as when you include multiple VisIt components in a single
// executable.
//
// ****************************************************************************
void
Init::Initialize(int &argc, char *argv[], int r, int n, bool strip, bool sigs)
{
// Return if Initialize has already been called.
if(initializeCalled)
return;
initializeCalled = true;
int i, debuglevel = 0;
#if defined(_WIN32)
bool usePid = true;
......@@ -506,11 +518,20 @@ Init::ComponentIssueError(const char *msg)
// Mark C. Miller, Tue Jul 25 18:26:10 PDT 2006
// Pushed timer dump and finalization down into TimingsManager::Finalize
//
// Brad Whitlock, Wed Jun 25 10:44:24 PDT 2008
// Added check to return early if Finalize has already been called, which
// can happen when multiple VisIt components are part of the same executable.
//
// ****************************************************************************
void
Init::Finalize(void)
{
// Return if Finalize has already been called.
if(finalizeCalled)
return;
finalizeCalled = true;
TimingsManager::Finalize();
#if defined(_WIN32)
......
......@@ -43,7 +43,7 @@
#include <DatabasePluginInfo.h>
#include <DBOptionsAttributes.h>
#include <DatabasePluginManager.h>
// ****************************************************************************
// Method: CommonDatabasePluginInfo constructor
......@@ -57,6 +57,7 @@ CommonDatabasePluginInfo::CommonDatabasePluginInfo()
{
readOptions = NULL;
writeOptions = NULL;
pluginManager = 0;
}
......@@ -149,4 +150,53 @@ CommonDatabasePluginInfo::SetWriteOptions(DBOptionsAttributes *wo)
writeOptions = wo;
}
// ****************************************************************************
// Method: CommonDatabasePluginInfo::SetPluginManager
//
// Purpose:
// Set the database plugin manager that is associated with this info.
//
// Arguments:
// ptr : The database plugin manager that read the info.
//
// Returns:
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Tue Jun 24 16:29:03 PDT 2008
//
// Modifications:
//
// ****************************************************************************
void
CommonDatabasePluginInfo::SetPluginManager(DatabasePluginManager *ptr)
{
pluginManager = ptr;
}
// ****************************************************************************
// Method: CommonDatabasePluginInfo::GetPluginManager
//
// Purpose:
// Get the plugin manager that read this info.
//
// Arguments:
//
// Returns: The plugin manager that read this info.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Tue Jun 24 16:29:38 PDT 2008
//
// Modifications:
//
// ****************************************************************************
DatabasePluginManager *
CommonDatabasePluginInfo::GetPluginManager() const
{
return pluginManager;
}
......@@ -61,6 +61,7 @@ enum DatabaseType
class avtDatabase;
class avtDatabaseWriter;
class DBOptionsAttributes;
class DatabasePluginManager;
// ****************************************************************************
// Class: *DatabasePluginInfo
......@@ -100,6 +101,13 @@ class DBOptionsAttributes;
// obtain this information instead of GetDefaultExtensions and GetFilenames
// on CommonDatabasePluginInfo. Note, however, we will leave the older
// methods around for backward compatibility for plugins VisIt does not own.
//
// Brad Whitlock, Tue Jun 24 16:22:13 PDT 2008
// Added a pointer back to the plugin manager in the common info because
// certain database readers need to access the plugin manager and it's
// no longer a singleton. The plugin manager will add a pointer to itself
// into the common info when it reads the info.
//
// ****************************************************************************
class PLUGIN_API GeneralDatabasePluginInfo
......@@ -136,9 +144,12 @@ class PLUGIN_API CommonDatabasePluginInfo : public virtual GeneralDatabasePlugin
virtual void SetReadOptions(DBOptionsAttributes *);
virtual void SetWriteOptions(DBOptionsAttributes *);
void SetPluginManager(DatabasePluginManager *ptr);
DatabasePluginManager *GetPluginManager() const;
protected:
DBOptionsAttributes *readOptions;
DBOptionsAttributes *writeOptions;
DatabasePluginManager *pluginManager;
};
class PLUGIN_API MDServerDatabasePluginInfo : public virtual CommonDatabasePluginInfo
......
......@@ -54,11 +54,6 @@
using std::string;
using std::vector;
//
// Storage for static data elements.
//
DatabasePluginManager *DatabasePluginManager::instance=0;
// ****************************************************************************
// Method: DatabasePluginManager constructor
//
......@@ -87,11 +82,14 @@ DatabasePluginManager::DatabasePluginManager() : PluginManager("database")
// Creation: August 22, 2002
//
// Modifications:
// Brad Whitlock, Wed Jun 25 10:27:17 PDT 2008
// Call UnloadPlugins here since it calls virtual methods for this class.
//
// ****************************************************************************
DatabasePluginManager::~DatabasePluginManager()
{
UnloadPlugins();
}
// ****************************************************************************
......@@ -108,51 +106,24 @@ DatabasePluginManager::~DatabasePluginManager()
// Creation: August 22, 2002
//
// Modifications:
// Sean Ahern, Thu Jan 17 16:10:00 EST 2008
// Added SetPluginDir so that we can find plugins correctly. Arguably,
// this is better here than the constructor.
// Sean Ahern, Thu Jan 17 16:10:00 EST 2008
// Added SetPluginDir so that we can find plugins correctly. Arguably,
// this is better here than the constructor.
//
// Brad Whitlock, Tue Jun 24 11:13:19 PDT 2008
// Removed plugin characteristics.
//
// ****************************************************************************
void
DatabasePluginManager::Initialize(const PluginCategory pluginCategory,
bool parallel,
bool par,
const char * pluginDir)
{
Instance();
instance->category = pluginCategory;
instance->parallel = parallel;
instance->SetPluginDir(pluginDir);
instance->ReadPluginInfo();
}
// ****************************************************************************
// Method: DatabasePluginManager::Instance
//
// Purpose:
// Return a pointer to the sole instance of the DatabasePluginManager
// class.
//
// Returns: A pointer to the sole instance of the DatabasePluginManager
// class.
//
// Programmer: Jeremy Meredith
// Creation: August 22, 2002
//
// ****************************************************************************
DatabasePluginManager *
DatabasePluginManager::Instance()
{
//
// If the sole instance hasn't been instantiated, then instantiate it.
//
if (instance == 0)
{
instance = new DatabasePluginManager;
}
return instance;
category = pluginCategory;
parallel = par;
SetPluginDir(pluginDir);
ReadPluginInfo();
}
// ****************************************************************************
......@@ -171,11 +142,14 @@ DatabasePluginManager::Instance()
// Creation: February 22, 2005
//
// Modifications:
//
// Mark C. Miller, Mon Aug 6 13:36:16 PDT 2007
// Fixed problem where calling this method in a situation where the given
// plugin had not already been loaded would result in defining it in
// loadedindexmap with an index of 0.
//
// Brad Whitlock, Tue Jun 24 16:24:25 PDT 2008
// Added a pointer to this in the info.
//
// ****************************************************************************
EngineDatabasePluginInfo *
......@@ -183,7 +157,9 @@ DatabasePluginManager::GetEnginePluginInfo(const string &id)
{
if (!PluginLoaded(id))
return 0;
return enginePluginInfo[loadedindexmap[id]];
EngineDatabasePluginInfo *info = enginePluginInfo[loadedindexmap[id]];
info->SetPluginManager(this);
return info;
}
// ****************************************************************************
......@@ -202,11 +178,14 @@ DatabasePluginManager::GetEnginePluginInfo(const string &id)
// Creation: August 22, 2002
//
// Modifications:
//
// Mark C. Miller, Mon Aug 6 13:36:16 PDT 2007
// Fixed problem where calling this method in a situation where the given
// plugin had not already been loaded would result in defining it in
// loadedindexmap with an index of 0.
//
// Brad Whitlock, Tue Jun 24 16:24:25 PDT 2008
// Added a pointer to this in the info.
//
// ****************************************************************************
CommonDatabasePluginInfo *
......@@ -214,7 +193,9 @@ DatabasePluginManager::GetCommonPluginInfo(const string &id)
{
if (!PluginLoaded(id))
return 0;
return commonPluginInfo[loadedindexmap[id]];
CommonDatabasePluginInfo *info = commonPluginInfo[loadedindexmap[id]];
info->SetPluginManager(this);
return info;
}
// ****************************************************************************
......
......@@ -82,18 +82,20 @@ class EngineDatabasePluginInfo;
// Added a pluginDir argument to Initialize to make it conform to the other
// plugin managers.
//
// Brad Whitlock, Tue Jun 24 11:11:24 PDT 2008
// Removed singleton characteristics.
//
// ****************************************************************************
class PLUGIN_API DatabasePluginManager : public PluginManager
{
public:
DatabasePluginManager();
virtual ~DatabasePluginManager();
static void Initialize(const PluginCategory, bool parallel=false,
void Initialize(const PluginCategory, bool parallel=false,
const char *pluginDir=0);
static DatabasePluginManager *Instance();
virtual void ReloadPlugins();
CommonDatabasePluginInfo *GetCommonPluginInfo(const std::string&);
......@@ -106,17 +108,12 @@ class PLUGIN_API DatabasePluginManager : public PluginManager
bool searchAll = false);
private:
DatabasePluginManager();
virtual bool LoadGeneralPluginInfo();
virtual void LoadMDServerPluginInfo();
virtual void LoadEnginePluginInfo();
virtual void FreeCommonPluginInfo();
// the plugin manager instance
static DatabasePluginManager *instance;
// arrays containing all plugins (appends the ones in PluginManager.C)
std::vector<bool> haswriter;
std::vector<std::vector<std::string> > extensions;
......
......@@ -51,11 +51,6 @@
using std::string;
using std::vector;
//
// Storage for static data elements.
//
OperatorPluginManager *OperatorPluginManager::instance=0;
// ****************************************************************************
// Method: OperatorPluginManager constructor
//
......@@ -77,11 +72,14 @@ OperatorPluginManager::OperatorPluginManager() : PluginManager("operator")
// Creation: August 20, 2002
//
// Modifications:
// Brad Whitlock, Wed Jun 25 10:27:17 PDT 2008
// Call UnloadPlugins here since it calls virtual methods for this class.
//
// ****************************************************************************
OperatorPluginManager::~OperatorPluginManager()
{
UnloadPlugins();
}
// ****************************************************************************
......@@ -105,46 +103,19 @@ OperatorPluginManager::~OperatorPluginManager()
// I added the pluginDir flag so applications can tell the plugin
// manager where to look directly without environment vars.
//
// Brad Whitlock, Tue Jun 24 11:08:52 PDT 2008
// Removed singleton characteristics.
//
// ****************************************************************************
void
OperatorPluginManager::Initialize(const PluginCategory pluginCategory,
bool parallel, const char *pluginDir)
{
Instance();
instance->category = pluginCategory;
instance->parallel = parallel;
instance->SetPluginDir(pluginDir);
instance->ReadPluginInfo();
}
// ****************************************************************************
// Method: OperatorPluginManager::Instance
//
// Purpose:
// Return a pointer to the sole instance of the OperatorPluginManager
// class.
//
// Returns: A pointer to the sole instance of the OperatorPluginManager
// class.
//
// Programmer: Jeremy Meredith
// Creation: September 26, 2001
//
// ****************************************************************************
OperatorPluginManager *
OperatorPluginManager::Instance()
bool par, const char *pluginDir)
{
//
// If the sole instance hasn't been instantiated, then instantiate it.
//
if (instance == 0)
{
instance = new OperatorPluginManager;
}
return instance;
category = pluginCategory;
parallel = par;
SetPluginDir(pluginDir);
ReadPluginInfo();
}
// ****************************************************************************
......
......@@ -99,17 +99,20 @@ class ScriptingOperatorPluginInfo;
// purpose (which really is unrelated to FreeCommonPluginInfo and
// GetCommonPluginInfo).
//
// Brad Whitlock, Tue Jun 24 10:48:11 PDT 2008
// Removed singleton characteristics.
//
// ****************************************************************************
class PLUGIN_API OperatorPluginManager : public PluginManager
{
public:
OperatorPluginManager();
virtual ~OperatorPluginManager();
static void Initialize(const PluginCategory pluginCategory,
void Initialize(const PluginCategory pluginCategory,
bool parallel=false,
const char *pluginDir = 0);
static OperatorPluginManager *Instance();
virtual void ReloadPlugins();
......@@ -120,8 +123,6 @@ class PLUGIN_API OperatorPluginManager : public PluginManager
ScriptingOperatorPluginInfo *GetScriptingPluginInfo(const std::string&);
private:
OperatorPluginManager();
virtual bool LoadGeneralPluginInfo();
virtual void LoadGUIPluginInfo();
virtual void LoadViewerPluginInfo();
......@@ -134,9 +135,6 @@ class PLUGIN_API OperatorPluginManager : public PluginManager
virtual void FreeEnginePluginInfo();
virtual void FreeScriptingPluginInfo();
// the plugin manager instance
static OperatorPluginManager *instance;
// arrays containing enabled plugins
std::vector<CommonOperatorPluginInfo*> commonPluginInfo;
std::vector<GUIOperatorPluginInfo*> guiPluginInfo;
......
......@@ -51,11 +51,6 @@
using std::string;
using std::vector;
//
// Storage for static data elements.
//
PlotPluginManager *PlotPluginManager::instance=0;
// ****************************************************************************
// Method: PlotPluginManager constructor
//
......@@ -77,11 +72,14 @@ PlotPluginManager::PlotPluginManager() : PluginManager("plot")
// Creation: August 20, 2002
//
// Modifications:
// Brad Whitlock, Wed Jun 25 10:27:17 PDT 2008
// Call UnloadPlugins here since it calls virtual methods for this class.
//
// ****************************************************************************
PlotPluginManager::~PlotPluginManager()
{
UnloadPlugins();
}
// ****************************************************************************
......@@ -105,46 +103,19 @@ PlotPluginManager::~PlotPluginManager()
// Brad Whitlock, Wed Nov 22 16:29:46 PST 2006
// Added pluginDir.
//
// Brad Whitlock, Tue Jun 24 11:10:16 PDT 2008
// Removed singleton characteristics.
//
// ****************************************************************************
void
PlotPluginManager::Initialize(const PluginCategory pluginCategory,
bool parallel, const char *pluginDir)
{
Instance();
instance->category = pluginCategory;
instance->parallel = parallel;
instance->SetPluginDir(pluginDir);
instance->ReadPluginInfo();
}
// ****************************************************************************
// Method: PlotPluginManager::Instance
//
// Purpose:
// Return a pointer to the sole instance of the PlotPluginManager
// class.
//
// Returns: A pointer to the sole instance of the PlotPluginManager
// class.
//
// Programmer: Jeremy Meredith
// Creation: September 26, 2001
//
// ****************************************************************************