Cat
DLLMgr.cpp
Go to the documentation of this file.
1 // $Id: $
2 // Include files
3 
4 #include "DLL.h"
5 #include "Element.h"
6 #include "Processus.h"
7 
8 // local
9 #include "DLLMgr.h"
10 
11 //-----------------------------------------------------------------------------
12 // Implementation file for class : DLLMgr
13 //
14 // 2006-10-25 :
15 //-----------------------------------------------------------------------------
16 
17 //=============================================================================
18 // Standard constructor, initializes variables
19 //=============================================================================
21 
22 }
23 //=============================================================================
24 // Destructor
25 //=============================================================================
27 
28 
29 //=========================================================================
30 //
31 //=========================================================================
32 StatusCode DLLMgr::load ( std::string library ) {
33  // load library
34  info("Loading dll "+library+".","DLLMgr::load");
35 
36  DLL *mydll = new DLL ();
37  // look if we can load the library
38  if ( mydll->load ( library ).isSuccess() ){
39  info("Library "+library+" loaded.");
40  // look for duplication of library
41  if ( 0!=dll(library) ){
42  warning("DLL "+library+" already loaded. Cannot load library.","DLLMgr::loadDLL");
43  delete mydll;
44  return StatusCode::FAILURE;
45  }
46  // look for duplication of objects
47  std::vector<std::string> list = mydll->objectList();
48  std::vector<DLL*>::const_iterator iter ;
49  std::vector<std::string>::const_iterator objs ;
50  for ( objs=list.begin() ;
51  objs!=list.end() ;
52  ++objs ) {
53  for ( iter = m_dlls.begin() ;
54  iter != m_dlls.end() ;
55  ++iter ) {
56  if ( (*iter)->containsObject( *objs ) ){
57  warning("The DLL "+library+" contains an object ("+
58  (*objs) +" which has already been loaded from "+
59  (*iter)->name()+". Cannot load library.",
60  "DLLMgr::loadDLL");
61  delete mydll;
62  return StatusCode::FAILURE;
63  }
64  }
65  }
66  // everything is ok. definitely keep the new library in the manager
67  m_dlls.push_back ( mydll );
68  return StatusCode::SUCCESS;
69  }
70  // could not even find the library
71  warning("The DLL "+library+" could not be properly loaded.","DLLMgr::loadDLL");
72  delete mydll;
73  return StatusCode::FAILURE;
74 }
75 
76 //=========================================================================
77 //
78 //=========================================================================
79 StatusCode DLLMgr::unload ( std::string lib ) {
80  std::vector<DLL*>::iterator dlltoremove;
81  std::vector<DLL*>::iterator iter ;
82  for ( iter = m_dlls.begin() ;
83  iter != m_dlls.end() ;
84  ++iter ) {
85  if ( 0==lib.compare((*iter)->name()) ) {
86  (*iter)->unload();
87  dlltoremove = iter;
88  }
89  delete *dlltoremove;
90  m_dlls.erase(dlltoremove);
91  }
92  return NULL;
93 }
94 
95 //=========================================================================
96 //
97 //=========================================================================
98 DLL* DLLMgr::libraryOfObject ( std::string obj ) {
99  std::vector<DLL*>::const_iterator iter ;
100  for ( iter = m_dlls.begin() ;
101  iter != m_dlls.end() ;
102  ++iter ) {
103  if ( (*iter)->containsObject( obj ) ){
104  return (*iter);
105  }
106  }
107  return NULL;
108 }
109 
110 //=========================================================================
111 //
112 //=========================================================================
113 DLL* DLLMgr::dll ( std::string lib ) {
114  std::vector<DLL*>::const_iterator iter ;
115  for ( iter = m_dlls.begin() ;
116  iter != m_dlls.end() ;
117  ++iter ) {
118  if ( 0==lib.compare( (*iter)->name() ) ){
119  return (*iter);
120  }
121  }
122  return NULL;
123 }
124 
125 //=========================================================================
126 //
127 //=========================================================================
128 Element* DLLMgr::createElement ( std::string name ) {
129  DLL* lib = libraryOfObject(name);
130  if ( 0!=lib ){
131  return lib->createElement( name );
132  }
133  return NULL;
134 }
135 
136 //=========================================================================
137 //
138 //=========================================================================
139 Processus* DLLMgr::createProcessus ( std::string name ) {
140  DLL* lib = libraryOfObject(name);
141  if ( 0!=lib ){
142  return lib->createProcessus( name );
143  }
144  return NULL;
145 }
146 
147 //=========================================================================
148 //
149 //=========================================================================
151  DLL* mydll = libraryOfObject( element->type () );
152  if ( 0 != mydll ) {
153  mydll->destroy(element);
154  return StatusCode::SUCCESS;
155  }
156  return StatusCode::FAILURE;
157 }
158 
159 //=========================================================================
160 //
161 //=========================================================================
163  DLL* mydll = libraryOfObject(proc->type());
164  if ( 0 != mydll ) {
165  mydll->destroy(proc);
166  return StatusCode::SUCCESS;
167  }
168  return StatusCode::FAILURE;
169 }
170 
171 //=========================================================================
172 //
173 //=========================================================================
175 {
176  std::vector<DLL*>::iterator iter ;
177  for ( iter = m_dlls.begin() ;
178  iter != m_dlls.end() ;
179  ++iter ) {(*iter)->print();}
180 }
181 
182 //=============================================================================
std::vector< std::string > objectList()
Definition: DLL.cpp:55
Element * createElement(std::string)
Definition: DLLMgr.cpp:128
StatusCode unload(std::string)
Definition: DLLMgr.cpp:79
void info(std::string msg)
Definition: DLLMgr.h:86
void warning(std::string msg)
Definition: DLLMgr.h:87
StatusCode destroy(Element *)
Definition: DLLMgr.cpp:150
StatusCode load(std::string)
Definition: DLLMgr.cpp:32
Element * createElement(std::string)
Definition: DLL.cpp:278
DLL * libraryOfObject(std::string)
Definition: DLLMgr.cpp:98
std::vector< DLL * > m_dlls
Definition: DLLMgr.h:96
Processus * createProcessus(std::string)
Definition: DLL.cpp:297
virtual ~DLLMgr()
Destructor.
Definition: DLLMgr.cpp:26
Definition: DLL.h:57
StatusCode destroy(Element *)
Definition: DLL.cpp:316
DLLMgr()
Standard constructor.
Definition: DLLMgr.cpp:20
std::string type()
Definition: Object.h:29
Definition: proc.py:1
bool isSuccess() const
Definition: StatusCode.h:64
DLL * dll(std::string)
Definition: DLLMgr.cpp:113
void print()
Definition: DLLMgr.cpp:174
StatusCode load(std::string)
Definition: DLL.cpp:118
def obj()
Definition: shell.py:26
Processus * createProcessus(std::string)
Definition: DLLMgr.cpp:139