OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimSharedPluginRegistry.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*************************************************************************
9 // $Id: ossimSharedPluginRegistry.cpp 23326 2015-05-27 13:07:51Z dburken $
10 #include <algorithm>
11 #include <iterator>
14 #include <ossim/base/ossimTrace.h>
18 
19 //ossimSharedPluginRegistry* ossimSharedPluginRegistry::theInstance = NULL;
20 //ossimPluginBridgeStructure ossimSharedPluginRegistry::thePluginBridgeFactoryPointers;
21 
22 static ossimTrace traceDebug("ossimSharedPluginRegistry:debug");
23 
25 {
26 }
27 
29 {
30  theLibraryList.clear();
31 }
32 
34 {
35  static ossimSharedPluginRegistry sharedInstance;
36 
37  return &sharedInstance;//theInstance;
38 }
39 
40 bool ossimSharedPluginRegistry::registerPlugin(const ossimFilename& filename, const ossimString& options)//, bool insertFrontFlag)
41 {
42  bool result = false;
43  if(!getPlugin(filename))
44  {
46  if(lib->load(filename))
47  {
48  lib->setOptions(options);
49  if(lib->getSymbol("ossimSharedLibraryInitialize"))
50  {
51  lib->initialize();
52 // if(!insertFrontFlag)
53 // {
54  theLibraryList.push_back(lib);
55 // }
56 // else
57 // {
58 // theLibraryList.insert(theLibraryList.begin(), lib);
59  // }
60  result = true;
61  }
62  else if (traceDebug())
63  {
65  << "ossimSharedPluginRegistry DEBUG:"
66  << "ossimSharedLibraryInitialize symbol not found\n"
67  << std::endl;
68  }
69  }
70 
71  if ( !result )
72  {
73  delete lib;
74  lib = 0;
75  }
76 
77  }
78  else
79  {
81  << "WARNING: Plugin with the name " << filename << std::endl
82  << "Already registered with OSSIM" << std::endl;
83  }
84 
85  return result;
86 }
87 
89 {
90  ossimPluginLibrary* lib = getPlugin(idx);
91 
92  return unregisterPlugin(lib);
93 }
94 
96 {
97  std::vector<ossimRefPtr<ossimPluginLibrary> >::iterator iter = theLibraryList.begin();
98  while(iter!=theLibraryList.end())
99  {
100  if((*iter).get() == library)
101  {
102  theLibraryList.erase(iter);
103  return true;
104  }
105  ++iter;
106  }
107  return false;
108 }
109 
111 {
112  ossim_uint32 idx = 0;
113  ossimFilename fileOnly = filename.file();
114  for(idx = 0; idx < theLibraryList.size();++idx)
115  {
116  if(fileOnly == ossimFilename(theLibraryList[idx]->getName()).file())
117  {
118  return theLibraryList[idx].get();
119  }
120  }
121 
122  return 0;
123 }
124 
126 {
127  ossim_uint32 idx = 0;
128  ossimFilename fileOnly = filename.file();
129 
130  for(idx = 0; idx < theLibraryList.size();++idx)
131  {
132  if(fileOnly == ossimFilename(theLibraryList[idx]->getName()).file())
133  {
134  return theLibraryList[idx].get();
135  }
136  }
137 
138  return 0;
139 }
140 
142 {
143  ossim_uint32 idx = 0;
144 
145  for(idx = 0; idx < theLibraryList.size(); ++idx)
146  {
147  if(theLibraryList[idx] == lib)
148  {
149  return idx;
150  }
151  }
152 
153  return idx;
154 }
155 
157 {
158  ossimPluginLibrary* result = 0;
159 
160  if(idx < theLibraryList.size())
161  {
162  result = theLibraryList[idx].get();
163  }
164 
165  return result;
166 }
167 
169 {
170  const ossimPluginLibrary* result = 0;
171 
172  if(idx < theLibraryList.size())
173  {
174  result = theLibraryList[idx].get();
175  }
176 
177  return result;
178 }
179 
181 {
182  return (ossim_uint32)theLibraryList.size();
183 }
184 
185 
187 
188 {
189  ossimFilename fileOnly = filename.file();
190  bool result = false;
192  for (ossim_uint32 i = 0; i < count; ++i)
193  {
194  const ossimPluginLibrary* pi = getPlugin(i);
195  if (pi)
196  {
197  if (fileOnly == ossimFilename(pi->getName()).file())
198  {
199  result = true;
200  break;
201  }
202  }
203  }
204  return result;
205 }
206 
208 {
210  ossim_uint32 idx = 0;
211 
212  for(idx = 0; idx < count; ++idx)
213  {
214  std::vector<ossimString> classNames;
215  const ossimPluginLibrary* pi = getPlugin(idx);
216  if(pi)
217  {
218  pi->getClassNames(classNames);
219  out << "Plugin: " << pi->getName() << std::endl;
220  out << "DESCRIPTION: \n";
221  out << pi->getDescription() << "\n";
222  out << "CLASSES SUPPORTED\n ";
223  std::copy(classNames.begin(),
224  classNames.end(),
225  std::ostream_iterator<ossimString>(out, "\n "));
226  out << "\n";
227  }
228  }
229 }
void printAllPluginInformation(std::ostream &out)
void setOptions(const ossimString &options)
bool load(const ossimString &name)
void * getSymbol(const ossimString &name) const
ossim_uint32 getIndex(const ossimPluginLibrary *lib) const
std::vector< ossimRefPtr< ossimPluginLibrary > > theLibraryList
static ossimSharedPluginRegistry * instance()
unsigned int ossim_uint32
const ossimString & getName() const
void getClassNames(std::vector< ossimString > &classNames) const
ossimString getDescription() const
bool isLoaded(const ossimFilename &filename) const
Checks if filename is already loaded to avoid duplication.
bool registerPlugin(const ossimFilename &filename, const ossimString &options="")
const ossimPluginLibrary * getPlugin(const ossimFilename &filename) const
ossimFilename file() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23