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-10-11 15:05:20 Functions: 50.0 % 4 2

            Line data    Source code
       1              : /*
       2              :  * DUNE DAQ modification notice:
       3              :  * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
       4              :  * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
       5              :  * Renamed since fork: yes (from src/PluginManager.cxx to src/PluginManager.cpp).
       6              :  *
       7              :  * Original copyright:
       8              :  * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
       9              :  * Licensed under the Apache License, Version 2.0.
      10              :  */
      11              : 
      12              : #ifndef __rtems__
      13              : #include <dlfcn.h>
      14              : #endif
      15              : 
      16              : #include <vector>
      17              : 
      18              : #include <ers/internal/PluginManager.hpp>
      19              : #include <ers/internal/Util.hpp>
      20              : #include <ers/internal/macro.hpp>
      21              : 
      22              : namespace {
      23              : const char* const SEPARATOR = ":";
      24              : const char* const DefaultLibraryName =
      25              :   "ers_AbortStream_ersStream:ers_ExitStream_ersStream:ers_FilterStream_ersStream:ers_GlobalLockStream_ersStream:ers_"
      26              :   "LockStream_ersStream:ers_NullStream_ersStream:ers_RFilterStream_ersStream:ers_StandardStream_ersStream:ers_"
      27              :   "ThrottleStream_ersStream:ers_ThrowStream_ersStream";
      28              : const char* const EnvironmentName = "DUNEDAQ_ERS_STREAM_LIBS";
      29              : }
      30              : 
      31              : namespace ers {
      32              : 
      33          430 : PluginManager::SharedLibrary::SharedLibrary(const std::string& name)
      34              : {
      35              : #ifndef __rtems__
      36          430 :   std::string library = "lib" + name + ".so";
      37              : 
      38          430 :   handle_ = dlopen(library.c_str(), RTLD_LAZY | RTLD_GLOBAL);
      39          430 :   char* error = dlerror();
      40              : 
      41          430 :   if (!handle_) {
      42            0 :     throw PluginException(error);
      43              :   }
      44              : #endif
      45          430 : }
      46              : 
      47            0 : PluginManager::SharedLibrary::~SharedLibrary()
      48              : {
      49              :   ////////////////////////////////////////////////////////////////////
      50              :   // Library should be unloaded, but with some compilers (e.g gcc323)
      51              :   // this results in crash of program, because it is not recognized
      52              :   // that the library is still in use
      53              :   ////////////////////////////////////////////////////////////////////
      54              : 
      55              :   // dlclose( handle_ );
      56            0 : }
      57              : 
      58            0 : PluginManager::~PluginManager()
      59              : {
      60            0 :   LibMap::iterator it = libraries_.begin();
      61            0 :   for (; it != libraries_.end();) {
      62            0 :     delete it->second;
      63            0 :     libraries_.erase(it++);
      64              :   }
      65            0 : }
      66              : 
      67           43 : PluginManager::PluginManager()
      68              : {
      69           43 :   const char* env = ::getenv(EnvironmentName);
      70           43 :   std::string config(env ? std::string(env) + SEPARATOR + DefaultLibraryName : DefaultLibraryName);
      71              : 
      72           43 :   std::vector<std::string> libs;
      73           43 :   ers::tokenize(config, SEPARATOR, libs);
      74              : 
      75          473 :   for (size_t i = 0; i < libs.size(); i++) {
      76          430 :     LibMap::iterator it = libraries_.find(libs[i]);
      77          430 :     if (it == libraries_.end()) {
      78          430 :       try {
      79          430 :         libraries_[libs[i]] = new SharedLibrary(libs[i]);
      80            0 :       } catch (PluginException& ex) {
      81            0 :         ERS_INTERNAL_ERROR("Library " << libs[i] << " can not be loaded because " << ex.reason())
      82            0 :       }
      83              :     }
      84              :   }
      85           43 : }
      86              : }
        

Generated by: LCOV version 2.0-1