| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 2010

# DLLClassManager.cpp

Go to the documentation of this file.

    00001 // $Id: DLLClassManager.cpp,v 1.17 2007/12/12 16:03:19 marcocle Exp $
    00002
    00003 // Include files
    00004 #include "GaudiKernel/GaudiException.h"
    00005 #include "GaudiKernel/IService.h"
    00006 #include "GaudiKernel/ISvcLocator.h"
    00007 #include "GaudiKernel/IAlgManager.h"
    00008 #include "GaudiKernel/ISvcManager.h"
    00009 #include "GaudiKernel/IIncidentSvc.h"
    00010 #include "GaudiKernel/ModuleIncident.h"
    00011 #include "GaudiKernel/MsgStream.h"
    00012 #include "DLLClassManager.h"
    00013 #include "GaudiKernel/System.h"
    00014
    00015 #include "GaudiKernel/IAlgorithm.h"
    00016
    00017 #include <iostream>
    00018 #include <cassert>
    00019
    00020 // default creator
    00021 DLLClassManager::DLLClassManager( IInterface* iface ) {
    00022   m_pOuter = iface;
    00023   m_svclocator = m_pOuter;
    00024
    00025   assert(m_svclocator.isValid());
    00026
    00027   addRef(); // Initial count set to 1
    00028 }
    00029
    00030 // virtual destructor
    00031 DLLClassManager::~DLLClassManager() {
    00032 }
    00033
    00034 // implementation of IClassManager::loadModule
    00035 StatusCode DLLClassManager::loadModule( const std::string& module,
    00036                                         bool fireIncident ) {
    00037   // Access the message service if not yet done already
    00038   if (!m_msgsvc.isValid()) {
    00039     m_msgsvc = m_svclocator;
    00040   }
    00041   MsgStream log(m_msgsvc, "DllClassManager");
    00042
    00043   std::string mod = module=="" ? System::moduleNameFull() : module;
    00044   if( module == "NONE" ) return StatusCode::SUCCESS;
    00045
    00046   void* libHandle = 0;
    00047   StatusCode status = StatusCode::FAILURE;
    00048   try
    00049   {
    00050     status = System::loadDynamicLib( module, &libHandle);
    00051   }
    00052   catch ( const std::exception & excpt )
    00053   {
    00054     if ( m_msgsvc )
    00055     {
    00056       log << MSG::ERROR << "Exception whilst loading " << module << " : " << excpt.what() << endmsg;
    00057     }
    00058     status = StatusCode::FAILURE;
    00059   }
    00060
    00061   if( status.isFailure() ) {
    00062     // DLL library not loaded
    00063     log << MSG::ERROR << "Could not load module " << module << endmsg;
    00064     log << MSG::ERROR << "System Error: " << System::getLastErrorString() << endmsg;
    00065     return StatusCode::FAILURE;
    00066   }
    00067   //FIXME this is a hack to avoid a very early call to moduleLoad from
    00068   //FIXME AppMgr::i_startup
    00069   if (fireIncident && module != "") {
    00070     //now fire ModuleLoadedIncident
    00071     const bool CREATEIF(true);
    00072     SmartIF<IIncidentSvc> pIncidentSvc(m_svclocator->service("IncidentSvc", CREATEIF));
    00073     if( !pIncidentSvc.isValid() )  {
    00074       log << MSG::FATAL << "Can not locate IncidentSvc" << endmsg;
    00075       throw GaudiException("Error retrieving IncidentSvc",
    00076                            "DLLClassManager::DLLClassManager", StatusCode::FAILURE);
    00077     }
    00078     pIncidentSvc->fireIncident(ModuleLoadedIncident("DLLClassManager",
    00079                                                      module) );
    00080   }
    00081
    00082   return StatusCode::SUCCESS;
    00083 }
    00084
    00085 // implementation of IInterface::queryInterface
    00086 StatusCode DLLClassManager::queryInterface(const InterfaceID& iid, void** pinterface) {
    00087   // try local interfaces
    00088   StatusCode sc = base_class::queryInterface(iid, pinterface);
    00089   if (sc.isSuccess()) return sc;
    00090   // fall back on the owner
    00091   return m_pOuter->queryInterface(iid, pinterface);
    00092 }