MCPcopy Create free account
hub / github.com/Kitware/VTK / LoadLibrariesInPath

Method LoadLibrariesInPath

Common/Core/vtkObjectFactory.cxx:173–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173void vtkObjectFactory::LoadLibrariesInPath(const std::string& path)
174{
175 vtksys::Directory dir;
176 if (!dir.Load(path))
177 {
178 return;
179 }
180
181 // Attempt to load each file in the directory as a shared library
182 for (unsigned long i = 0; i < dir.GetNumberOfFiles(); i++)
183 {
184 const char* file = dir.GetFile(i);
185 // try to make sure the file has at least the extension
186 // for a shared library in it.
187 if (vtkNameIsSharedLibrary(file))
188 {
189 char* fullpath = CreateFullPath(path, file);
190 vtkLibHandle lib = vtkDynamicLoader::OpenLibrary(fullpath);
191 if (lib)
192 {
193 // Look for the symbol vtkLoad and vtkGetFactoryVersion in the library
194 VTK_LOAD_FUNCTION loadfunction =
195 (VTK_LOAD_FUNCTION)(vtkDynamicLoader::GetSymbolAddress(lib, "vtkLoad"));
196 VTK_VERSION_FUNCTION versionFunction =
197 (VTK_VERSION_FUNCTION)(vtkDynamicLoader::GetSymbolAddress(lib, "vtkGetFactoryVersion"));
198 // if the symbol is found call it to create the factory
199 // from the library
200 if (loadfunction && versionFunction)
201 {
202 const char* version = (*versionFunction)();
203 if (strcmp(version, vtkVersion::GetVTKSourceVersion()) != 0)
204 {
205 vtkGenericWarningMacro(<< "Incompatible factory rejected:"
206 << "\nRunning VTK version: " << vtkVersion::GetVTKSourceVersion()
207 << "\nFactory version: " << version
208 << "\nPath to rejected factory: " << fullpath << "\n");
209 }
210 else
211 {
212 vtkObjectFactory* newfactory = (*loadfunction)();
213 newfactory->LibraryVTKVersion = strcpy(new char[strlen(version) + 1], version);
214 // initialize class members if load worked
215 newfactory->LibraryHandle = static_cast<void*>(lib);
216 newfactory->LibraryPath = strcpy(new char[strlen(fullpath) + 1], fullpath);
217 vtkObjectFactory::RegisterFactory(newfactory);
218 newfactory->Delete();
219 }
220 }
221 // if only the loadfunction is found, then warn
222 else if (loadfunction)
223 {
224 vtkGenericWarningMacro(
225 "Old Style Factory not loaded. Shared object has vtkLoad, but is missing "
226 "vtkGetFactoryVersion. Recompile factory: "
227 << fullpath << ", and use VTK_FACTORY_INTERFACE_IMPLEMENT macro.");
228 }
229 }
230 delete[] fullpath;

Callers

nothing calls this directly

Calls 7

vtkNameIsSharedLibraryFunction · 0.85
CreateFullPathFunction · 0.85
GetVTKSourceVersionFunction · 0.85
DeleteMethod · 0.65
LoadMethod · 0.45
GetNumberOfFilesMethod · 0.45
GetFileMethod · 0.45

Tested by

no test coverage detected