Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:59

0001 // -*- C++ -*-
0002 //
0003 // Package:     PluginManager
0004 // Class  :     SharedLibrary
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Thu Apr  5 15:30:15 EDT 2007
0011 //
0012 
0013 // system include files
0014 #include <string> /*needed by the following include*/
0015 #include <dlfcn.h>
0016 #include <cerrno>
0017 
0018 // user include files
0019 #include "FWCore/PluginManager/interface/SharedLibrary.h"
0020 #include "FWCore/Utilities/interface/Exception.h"
0021 
0022 namespace edmplugin {
0023   //
0024   // constants, enums and typedefs
0025   //
0026 
0027   //
0028   // static data member definitions
0029   //
0030 
0031   //
0032   // constructors and destructor
0033   //
0034   SharedLibrary::SharedLibrary(const std::filesystem::path& iName)
0035       : libraryHandle_(::dlopen(iName.string().c_str(), RTLD_LAZY | RTLD_GLOBAL)), path_(iName) {
0036     if (libraryHandle_ == nullptr) {
0037       char const* err = dlerror();
0038       if (err == nullptr) {
0039         throw cms::Exception("PluginLibraryLoadError") << "unable to load " << iName.string();
0040       }
0041       throw cms::Exception("PluginLibraryLoadError") << "unable to load " << iName.string() << " because " << err;
0042     }
0043   }
0044 
0045   // SharedLibrary::SharedLibrary(const SharedLibrary& rhs)
0046   // {
0047   //    // do actual copying here;
0048   // }
0049 
0050   SharedLibrary::~SharedLibrary() {}
0051 
0052   //
0053   // assignment operators
0054   //
0055   // const SharedLibrary& SharedLibrary::operator=(const SharedLibrary& rhs)
0056   // {
0057   //   //An exception safe implementation is
0058   //   SharedLibrary temp(rhs);
0059   //   swap(rhs);
0060   //
0061   //   return *this;
0062   // }
0063 
0064   //
0065   // member functions
0066   //
0067 
0068   //
0069   // const member functions
0070   //
0071   bool SharedLibrary::symbol(const std::string& iSymbolName, void*& iSymbol) const {
0072     if (libraryHandle_ == nullptr) {
0073       return false;
0074     }
0075     iSymbol = dlsym(libraryHandle_, iSymbolName.c_str());
0076     return (iSymbol != nullptr);
0077   }
0078 
0079   //
0080   // static member functions
0081   //
0082 }  // namespace edmplugin