LCOV - code coverage report
Current view: top level - ers/src - PluginManager.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 58.6 % 29 17
Test Date: 2026-02-16 10:18:04 Functions: 50.0 % 4 2

            Line data    Source code
       1              : #ifndef __rtems__
       2              : #include <dlfcn.h>
       3              : #endif
       4              : 
       5              : #include <vector>
       6              : 
       7              : #include <ers/internal/Util.hpp>
       8              : #include <ers/internal/PluginManager.hpp>
       9              : #include <ers/internal/macro.hpp>
      10              : 
      11              : namespace
      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              : 
      18              : namespace ers
      19              : {
      20              : 
      21          410 :     PluginManager::SharedLibrary::SharedLibrary( const std::string & name )
      22              :     {
      23              : #ifndef __rtems__
      24          410 :         std::string library = "lib" + name + ".so" ;
      25              : 
      26          410 :         handle_ = dlopen( library.c_str(), RTLD_LAZY|RTLD_GLOBAL );
      27          410 :         char * error = dlerror();
      28              : 
      29          410 :         if ( !handle_ )
      30              :         {
      31            0 :             throw PluginException( error );
      32              :         }
      33              : #endif
      34          410 :     }
      35              : 
      36            0 :     PluginManager::SharedLibrary::~SharedLibrary( )
      37              :     {
      38              :         ////////////////////////////////////////////////////////////////////
      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
      42              :         ////////////////////////////////////////////////////////////////////
      43              : 
      44              :         //dlclose( handle_ );
      45            0 :     }
      46              : 
      47            0 :     PluginManager::~PluginManager()
      48              :     {
      49            0 :         LibMap::iterator it = libraries_.begin();
      50            0 :         for ( ; it != libraries_.end(); )
      51              :         {
      52            0 :             delete it->second;
      53            0 :             libraries_.erase( it++ );
      54              :         }
      55            0 :     }
      56              : 
      57           41 :     PluginManager::PluginManager( )
      58              :     {
      59           41 :         const char * env = ::getenv( EnvironmentName );
      60           41 :         std::string config( env ? std::string( env ) + SEPARATOR + DefaultLibraryName : DefaultLibraryName );
      61              :         
      62           41 :         std::vector<std::string> libs;
      63           41 :         ers::tokenize( config, SEPARATOR, libs );
      64              :         
      65              :         
      66          451 :         for ( size_t i = 0; i < libs.size(); i++ )
      67              :         {
      68          410 :             LibMap::iterator it = libraries_.find( libs[i] );
      69          410 :             if ( it == libraries_.end() )
      70              :             {
      71          410 :                 try
      72              :                 {
      73          410 :                     libraries_[libs[i]] = new SharedLibrary( libs[i] );
      74              :                 }
      75            0 :                 catch( PluginException & ex )
      76              :                 {
      77            0 :                     ERS_INTERNAL_ERROR( "Library " << libs[i] << " can not be loaded because " << ex.reason() )
      78            0 :                 }
      79              :             }
      80              :         }
      81           41 :     }
      82              : }
        

Generated by: LCOV version 2.0-1