DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
PluginManager.cpp
Go to the documentation of this file.
1#ifndef __rtems__
2#include <dlfcn.h>
3#endif
4
5#include <vector>
6
10
11namespace
12{
13 const char * const SEPARATOR = ":";
14 const char * const DefaultLibraryName = "ers_AbortStream_ersStream:ers_ExitStream_ersStream:ers_FilterStream_ersStream:ers_GlobalLockStream_ersStream:ers_LockStream_ersStream:ers_NullStream_ersStream:ers_RFilterStream_ersStream:ers_StandardStream_ersStream:ers_ThrottleStream_ersStream:ers_ThrowStream_ersStream";
15 const char * const EnvironmentName = "DUNEDAQ_ERS_STREAM_LIBS";
16}
17
18namespace ers
19{
20
22 {
23#ifndef __rtems__
24 std::string library = "lib" + name + ".so" ;
25
26 handle_ = dlopen( library.c_str(), RTLD_LAZY|RTLD_GLOBAL );
27 char * error = dlerror();
28
29 if ( !handle_ )
30 {
31 throw PluginException( error );
32 }
33#endif
34 }
35
37 {
39 // Library should be unloaded, but with some compilers (e.g gcc323)
40 // this results in crash of program, because it is not recognized
41 // that the library is still in use
43
44 //dlclose( handle_ );
45 }
46
48 {
49 LibMap::iterator it = libraries_.begin();
50 for ( ; it != libraries_.end(); )
51 {
52 delete it->second;
53 libraries_.erase( it++ );
54 }
55 }
56
58 {
59 const char * env = ::getenv( EnvironmentName );
60 std::string config( env ? std::string( env ) + SEPARATOR + DefaultLibraryName : DefaultLibraryName );
61
62 std::vector<std::string> libs;
63 ers::tokenize( config, SEPARATOR, libs );
64
65
66 for ( size_t i = 0; i < libs.size(); i++ )
67 {
68 LibMap::iterator it = libraries_.find( libs[i] );
69 if ( it == libraries_.end() )
70 {
71 try
72 {
73 libraries_[libs[i]] = new SharedLibrary( libs[i] );
74 }
75 catch( PluginException & ex )
76 {
77 ERS_INTERNAL_ERROR( "Library " << libs[i] << " can not be loaded because " << ex.reason() )
78 }
79 }
80 }
81 }
82}
const std::string & reason() const
SharedLibrary(const std::string &name)
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:52
void tokenize(const std::string &text, const std::string &separators, std::vector< std::string > &tokens)
Definition Util.cpp:7
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34