Cat
DLL.h
Go to the documentation of this file.
1 // $Id: $
2 #ifndef INC_DLL_H
3 #define INC_DLL_H 1
4 
5 // Include files
6 #include <string>
7 #include <vector>
8 
9 #ifndef WIN32
10 #include <unistd.h>
11 #include <dlfcn.h>
12 #else
13 #include "windows.h"
14 #include <direct.h>
15 #endif
16 
17 // CATKernel
18 #include "StatusCode.h"
19 #include "Tools.h"
20 #include "Element.h"
21 #include "Processus.h"
22 
23 #define DECLARE_DLL(x) \
24 extern "C" void x##_dll( DLL* dll )
25 
26 #define DECLARE_ELEMENT(x,y) \
27  dll->addElement (#x,#y);
28 
29 #define DECLARE_PROCESSUS(x,y) \
30  dll->addProcessus (#x,#y);
31 
32 #define DECLARE_OBJECT(x,y) \
33  dll->addObject (#x,#y);
34 /*
35 #define FACTORY(type,x) \
36 extern "C" type##* x##_create() { \
37  return (new x) ; \
38 } \
39 extern "C" void x##_destroy(type##* p) { \
40  delete p; \
41 }
42 */
43 #define FACTORY(type,x) \
44 extern "C" type* x##_create() { \
45  return (new x) ; \
46 } \
47 extern "C" void x##_destroy(type* p) { \
48  delete p; \
49 }
50 
57 class DLL {
58 
59 public:
60 
61 #ifdef WIN32
62  typedef HMODULE ImageHandle;
63 #else
64  typedef void* ImageHandle;
65 #endif
66 
67  typedef void (*EntryPoint) (DLL*);
68 
69  typedef Element* (*ConstructorElement) ( );
70  typedef void (*DestructorElement) (Element*);
71  typedef Processus* (*ConstructorProcessus) ( );
72  typedef void (*DestructorProcessus) (Processus*);
73  typedef Object* (*ConstructorObject) ( );
74  typedef void (*DestructorObject) (Object*);
75 
76  typedef std::pair<std::string,std::string> identification;
77  typedef std::vector<identification> listOfElements ;
78  typedef std::vector<identification> listOfProcessus ;
79  typedef std::vector<identification> listOfObjects ;
80 
82  DLL( );
83 
84  virtual ~DLL( );
85 
89  StatusCode load ( std::string );
90 
94  StatusCode unload ( );
95 
100  void setName (std::string name) {
101  m_name = name;
102  }
103 
108  std::string name () {
109  return m_name;
110  }
111 
116  listOfElements listElements () {
117  return m_listElements;
118  }
119 
124  listOfProcessus listProcessus () {
125  return m_listProcessus;
126  }
127 
132  listOfObjects listObjects () {
133  return m_listObjects;
134  }
135 
139  void addElement( std::string element ,
140  std::string description = std::string ("") )
141  {
142  identification id ( element , description );
143  m_listElements.push_back( id );
144  }
145 
149  void addProcessus( std::string proc ,
150  std::string description = std::string ("") )
151  {
152  identification id ( proc , description );
153  m_listProcessus.push_back( id );
154  }
155 
159  void addObject( std::string proc ,
160  std::string description = std::string ("") )
161  {
162  identification id ( proc , description );
163  m_listObjects.push_back( id );
164  }
165 
169  bool containsObject ( std::string );
170 
174  std::vector<std::string> objectList ( );
175 
179  StatusCode init () ;
180 
184  Element* createElement (std::string );
185 
189  Processus* createProcessus (std::string );
190 
194  Object* createObject (std::string );
195 
200 
205 
210 
214  void print();
215 
216 protected:
217 
218 private:
220  std::string m_name;
221  ImageHandle m_handle;
222  listOfElements m_listElements;
223  listOfProcessus m_listProcessus;
224  listOfObjects m_listObjects;
225  std::vector<ConstructorElement> m_elementConstructors;
226  std::vector<DestructorElement> m_elementDestructors;
227  std::vector<ConstructorProcessus> m_processusConstructors;
228  std::vector<DestructorProcessus> m_processusDestructors;
229  std::vector<ConstructorObject> m_objectConstructors;
230  std::vector<DestructorObject> m_objectDestructors;
231 
232  void msg ( std::string mymsg ) { m_log.msgSvc (MsgSvc::NONE , mymsg, m_name ); }
233  void verbose ( std::string mymsg ) { m_log.msgSvc (MsgSvc::VERBOSE , mymsg, m_name ); }
234  void debug ( std::string mymsg ) { m_log.msgSvc (MsgSvc::DEBUG , mymsg, m_name ); }
235  void info ( std::string mymsg ) { m_log.msgSvc (MsgSvc::INFO , mymsg, m_name ); }
236  void warning ( std::string mymsg ) { m_log.msgSvc (MsgSvc::WARNING , mymsg, m_name ); }
237  void fatal ( std::string mymsg ) { m_log.msgSvc (MsgSvc::FATAL , mymsg, m_name ); }
238 
239  void msg ( std::string mymsg , std::string name ) { m_log.msgSvc (MsgSvc::NONE , mymsg, name ); }
240  void verbose ( std::string mymsg , std::string name ) { m_log.msgSvc (MsgSvc::VERBOSE , mymsg, name ); }
241  void debug ( std::string mymsg , std::string name ) { m_log.msgSvc (MsgSvc::DEBUG , mymsg, name ); }
242  void info ( std::string mymsg , std::string name ) { m_log.msgSvc (MsgSvc::INFO , mymsg, name ); }
243  void warning ( std::string mymsg , std::string name ) { m_log.msgSvc (MsgSvc::WARNING , mymsg, name ); }
244  void fatal ( std::string mymsg , std::string name ) { m_log.msgSvc (MsgSvc::FATAL , mymsg, name ); }
245 
246 };
247 #endif // INC_DLL_H
Definition: Object.h:21
void msg(std::string mymsg)
Definition: DLL.h:232
std::vector< std::string > objectList()
Definition: DLL.cpp:55
listOfElements m_listElements
Definition: DLL.h:222
std::vector< identification > listOfElements
Definition: DLL.h:77
listOfProcessus m_listProcessus
Definition: DLL.h:223
StatusCode init()
Definition: DLL.cpp:172
std::vector< ConstructorElement > m_elementConstructors
Definition: DLL.h:225
std::vector< DestructorProcessus > m_processusDestructors
Definition: DLL.h:228
std::vector< DestructorElement > m_elementDestructors
Definition: DLL.h:226
std::string name()
Definition: DLL.h:108
std::vector< ConstructorProcessus > m_processusConstructors
Definition: DLL.h:227
void info(std::string mymsg)
Definition: DLL.h:235
void verbose(std::string mymsg)
Definition: DLL.h:233
void(* EntryPoint)(DLL *)
Definition: DLL.h:67
void addElement(std::string element, std::string description=std::string(""))
Definition: DLL.h:139
void * ImageHandle
Definition: DLL.h:64
std::pair< std::string, std::string > identification
Definition: DLL.h:76
void print()
Definition: DLL.cpp:74
virtual ~DLL()
Destructor.
Definition: DLL.cpp:27
void fatal(std::string mymsg)
Definition: DLL.h:237
Element * createElement(std::string)
Definition: DLL.cpp:278
void(* DestructorObject)(Object *)
Definition: DLL.h:74
void addObject(std::string proc, std::string description=std::string(""))
Definition: DLL.h:159
listOfElements listElements()
Definition: DLL.h:116
bool containsObject(std::string)
Definition: DLL.cpp:32
Processus * createProcessus(std::string)
Definition: DLL.cpp:297
void info(std::string mymsg, std::string name)
Definition: DLL.h:242
std::vector< ConstructorObject > m_objectConstructors
Definition: DLL.h:229
DLL()
Standard constructor.
Definition: DLL.cpp:20
std::string m_name
Definition: DLL.h:220
void warning(std::string mymsg)
Definition: DLL.h:236
void msg(std::string mymsg, std::string name)
Definition: DLL.h:239
void fatal(std::string mymsg, std::string name)
Definition: DLL.h:244
listOfObjects m_listObjects
Definition: DLL.h:224
void verbose(std::string mymsg, std::string name)
Definition: DLL.h:240
std::vector< DestructorObject > m_objectDestructors
Definition: DLL.h:230
std::vector< identification > listOfObjects
Definition: DLL.h:79
Definition: DLL.h:57
StatusCode destroy(Element *)
Definition: DLL.cpp:316
void addProcessus(std::string proc, std::string description=std::string(""))
Definition: DLL.h:149
std::vector< identification > listOfProcessus
Definition: DLL.h:78
void debug(std::string mymsg)
Definition: DLL.h:234
listOfProcessus listProcessus()
Definition: DLL.h:124
MsgSvc m_log
Definition: DLL.h:219
void setName(std::string name)
Definition: DLL.h:100
void warning(std::string mymsg, std::string name)
Definition: DLL.h:243
void(* DestructorProcessus)(Processus *)
Definition: DLL.h:72
Definition: proc.py:1
void(* DestructorElement)(Element *)
Definition: DLL.h:70
Object * createObject(std::string)
StatusCode load(std::string)
Definition: DLL.cpp:118
ImageHandle m_handle
Definition: DLL.h:221
StatusCode unload()
Definition: DLL.cpp:263
listOfObjects listObjects()
Definition: DLL.h:132
Definition: MsgSvc.h:21
void msgSvc(MsgSvc::MsgLevel, std::string, std::string call=std::string(""))
Definition: MsgSvc.cpp:42
void debug(std::string mymsg, std::string name)
Definition: DLL.h:241