vtkPVPluginLoader.h 5.27 KB
Newer Older
1 2 3
/*=========================================================================

  Program:   ParaView
4
  Module:    vtkPVPluginLoader.h
5 6 7 8 9 10 11 12 13 14

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
15 16 17 18 19 20 21 22 23 24 25
/**
 * @class   vtkPVPluginLoader
 * @brief   Used to load ParaView plugins.
 *
 * vtkPVPluginLoader can be used to load plugins for ParaView. vtkPVPluginLoader
 * loads the plugin on the local process. For verbose details during the process
 * of loading the plugin, try setting the environment variable PV_PLUGIN_DEBUG.
 * This class only needed when loading plugins from shared libraries
 * dynamically. For statically importing plugins, one directly uses
 * PV_PLUGIN_IMPORT() macro defined in vtkPVPlugin.h.
*/
26

27 28
#ifndef vtkPVPluginLoader_h
#define vtkPVPluginLoader_h
29

30
#include "vtkObject.h"
31
#include "vtkPVClientServerCoreCoreModule.h" //needed for exports
Clinton Stimpson's avatar
Clinton Stimpson committed
32

33 34
class vtkIntArray;
class vtkPVPlugin;
Clinton Stimpson's avatar
Clinton Stimpson committed
35
class vtkStringArray;
36
class vtkPVPlugin;
37

38 39
typedef bool (*vtkPluginLoadFunction)(const char*);

40
class VTKPVCLIENTSERVERCORECORE_EXPORT vtkPVPluginLoader : public vtkObject
41 42
{
public:
43
  static vtkPVPluginLoader* New();
44
  vtkTypeMacro(vtkPVPluginLoader, vtkObject);
Cory Quammen's avatar
Cory Quammen committed
45
  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
46

47 48 49
  /**
   * Tries to the load the plugin given the path to the plugin file.
   */
Kitware Robot's avatar
Kitware Robot committed
50 51
  bool LoadPlugin(const char* filename) { return this->LoadPluginInternal(filename, false); }
  bool LoadPluginSilently(const char* filename) { return this->LoadPluginInternal(filename, true); }
52

53 54 55 56 57
  /**
   * Simply forwards the call to
   * vtkPVPluginLoader::LoadPluginConfigurationXMLFromString to load
   * configuration xml.
   */
58 59
  void LoadPluginConfigurationXMLFromString(const char* xmlcontents);

60 61 62
  /**
   * Loads all plugins under the directories mentioned in the SearchPaths.
   */
63 64
  void LoadPluginsFromPluginSearchPath();

65 66 67 68 69 70
  /**
   * Use PV_PLUGIN_CONFILE_FILE xml file to load specified plugins
   * It can contain path to multiples xml pluginc config files
   * sperated by env separator.
   * It allow user to fine pick which plugins to load, instead of using PV_PLUGIN_PATH
   * the format a xml plugin file should be the following :
Ben Boeckel's avatar
Ben Boeckel committed
71 72
   *
   * \code{.xml}
73 74 75 76 77
   * <?xml version="1.0"?>
   * <Plugins>
   * <Plugin name="MyPlugin" filename="absolute/path/to/libMyPlugin.so"/>
   * ...
   * </Plugins>
Ben Boeckel's avatar
Ben Boeckel committed
78
   * \endcode
79
   */
80 81
  void LoadPluginsFromPluginConfigFile();

82 83 84
  /**
   * Loads all plugin libraries at a path.
   */
85 86
  void LoadPluginsFromPath(const char* path);

87 88 89 90 91
  //@{
  /**
   * Returns the full filename for the plugin attempted to load most recently
   * using LoadPlugin().
   */
92
  vtkGetStringMacro(FileName);
93
  //@}
94

95 96 97 98 99
  //@{
  /**
   * Get the plugin name. This returns a valid name only after the plugin has
   * been loaded.
   */
100
  vtkGetStringMacro(PluginName);
101
  //@}
102

103 104 105 106 107
  //@{
  /**
   * Get the plugin version string. This returns a valid version string only
   * after the plugin has been loaded.
   */
108
  vtkGetStringMacro(PluginVersion);
109
  //@}
110

111 112 113 114 115
  //@{
  /**
   * Get the error string if the plugin failed to load. Returns NULL if the
   * plugin was loaded successfully.
   */
116
  vtkGetStringMacro(ErrorString);
117 118 119 120 121 122 123 124
  //@}

  //@{
  /**
   * Get a string of standard search paths (path1;path2;path3)
   * search paths are based on PV_PLUGIN_PATH,
   * plugin dir relative to executable.
   */
125
  vtkGetStringMacro(SearchPaths);
126
  //@}
127

128 129 130 131
  //@{
  /**
   * Returns the status of most recent LoadPlugin call.
   */
132
  vtkGetMacro(Loaded, bool);
133
  //@}
134

135 136 137
  /**
   * Sets the function used to load static plugins.
   */
138 139
  static void SetStaticPluginLoadFunction(vtkPluginLoadFunction function);

140 141 142 143 144
  /**
   * Internal method used in pqParaViewPlugin.cxx.in to tell the
   * vtkPVPluginLoader that a library was unloaded so it doesn't try to unload
   * it again.
   */
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
145 146
  static void PluginLibraryUnloaded(const char* pluginname);

147
protected:
148
  vtkPVPluginLoader();
149
  ~vtkPVPluginLoader() override;
150

151 152
  bool LoadPluginInternal(const char* filename, bool no_errors);

153 154 155 156
  /**
   * Called by LoadPluginInternal() to do the final steps in loading of a
   * plugin.
   */
Kitware Robot's avatar
Kitware Robot committed
157
  bool LoadPlugin(const char* file, vtkPVPlugin* plugin);
158

159 160 161 162 163 164 165 166 167 168 169
  vtkSetStringMacro(ErrorString);
  vtkSetStringMacro(PluginName);
  vtkSetStringMacro(PluginVersion);
  vtkSetStringMacro(FileName);
  vtkSetStringMacro(SearchPaths);

  char* ErrorString;
  char* PluginName;
  char* PluginVersion;
  char* FileName;
  char* SearchPaths;
170
  bool DebugPlugin;
171
  bool Loaded;
Kitware Robot's avatar
Kitware Robot committed
172

173
private:
174 175
  vtkPVPluginLoader(const vtkPVPluginLoader&) = delete;
  void operator=(const vtkPVPluginLoader&) = delete;
176 177

  static vtkPluginLoadFunction StaticPluginLoadFunction;
178 179
};

180 181 182 183 184 185 186 187
// Implementation of Schwartz counter idiom to ensure that the plugin library
// unloading doesn't happen before the ParaView application is finalized.
static class VTKPVCLIENTSERVERCORECORE_EXPORT vtkPVPluginLoaderCleanerInitializer
{
public:
  vtkPVPluginLoaderCleanerInitializer();
  ~vtkPVPluginLoaderCleanerInitializer();
} vtkPVPluginLoaderCleanerInitializerInstance; // object here in header.
188

189
#endif