| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# Converter.cpp

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/Converter.cpp,v 1.17 2007/12/12 16:02:32 marcocle Exp $
    00002
    00003 // Include Files
    00004 #include "GaudiKernel/Converter.h"
    00005 #include "GaudiKernel/ISvcLocator.h"
    00006 #include "GaudiKernel/IMessageSvc.h"
    00007 #include "GaudiKernel/IDataManagerSvc.h"
    00008 #include "GaudiKernel/IDataProviderSvc.h"
    00009 #include "GaudiKernel/GaudiException.h"
    00010 #include "GaudiKernel/ServiceLocatorHelper.h"
    00011 #include "GaudiKernel/ThreadGaudi.h"
    00012 #include "GaudiKernel/ConversionSvc.h"
    00013
    00014 //--- IInterface::addRef
    00015 unsigned long Converter::addRef()   {
    00016   m_refCount++;
    00017   return m_refCount;
    00018 }
    00019
    00020 //--- IInterface::release
    00021 unsigned long Converter::release()   {
    00022   long count = --m_refCount;
    00023   if ( count <= 0 ) {
    00024     delete this;
    00025   }
    00026   return count;
    00027 }
    00028
    00029 //--- IInterface::queryInterface
    00030 StatusCode Converter::queryInterface(const InterfaceID& riid, void** ppvInterface)  {
    00031   if ( IID_IInterface.versionMatch(riid) )   {
    00032     *ppvInterface = (IInterface*)this;
    00033   }
    00034   else if ( IID_IConverter.versionMatch(riid) )  {
    00035     *ppvInterface = (IConverter*)this;
    00036   }
    00037   else   {
    00038      return NO_INTERFACE;
    00039   }
    00040   addRef();
    00041   return StatusCode::SUCCESS;
    00042 }
    00043
    00045 const CLID& Converter::objType() const    {
    00046   return m_classType;
    00047 }
    00048
    00050 long Converter::i_repSvcType() const   {
    00051   return m_storageType;
    00052 }
    00053
    00055 StatusCode Converter::createObj(IOpaqueAddress*, DataObject*&)   {
    00056   return StatusCode::SUCCESS;
    00057 }
    00058
    00059
    00061 StatusCode Converter::fillObjRefs(IOpaqueAddress*, DataObject*)    {
    00062   return StatusCode::SUCCESS;
    00063 }
    00064
    00066 StatusCode Converter::updateObj(IOpaqueAddress*, DataObject*)   {
    00067   return StatusCode::SUCCESS;
    00068 }
    00069
    00071 StatusCode Converter::updateObjRefs(IOpaqueAddress*, DataObject*)  {
    00072   return StatusCode::SUCCESS;
    00073 }
    00074
    00076 StatusCode Converter::createRep(DataObject*, IOpaqueAddress*&)  {
    00077   return StatusCode::SUCCESS;
    00078 }
    00079
    00081 StatusCode Converter::fillRepRefs(IOpaqueAddress*, DataObject*)  {
    00082   return StatusCode::SUCCESS;
    00083 }
    00084
    00086 StatusCode Converter::updateRep(IOpaqueAddress*, DataObject*)  {
    00087   return StatusCode::SUCCESS;
    00088 }
    00089
    00091 StatusCode Converter::updateRepRefs(IOpaqueAddress*, DataObject*)    {
    00092   return StatusCode::SUCCESS;
    00093 }
    00094
    00096 StatusCode Converter::initialize()    {
    00097   StatusCode status = StatusCode::SUCCESS;
    00098   // Get a reference to the Message Service
    00099   status = serviceLocator()->service("MessageSvc",m_messageSvc, true );
    00100   if ( status.isFailure() )   {
    00101     return status;
    00102   }
    00103   return status;
    00104 }
    00105
    00107 StatusCode Converter::finalize()    {
    00108   if ( 0 != m_messageSvc )    {
    00109     m_messageSvc->release();
    00110     m_messageSvc = 0;
    00111   }
    00112   if ( 0 != m_dataManager )  {
    00113     m_dataManager->release();
    00114     m_dataManager = 0;
    00115   }
    00116   if ( 0 != m_dataProvider )  {
    00117     m_dataProvider->release();
    00118     m_dataProvider = 0;
    00119   }
    00120   return StatusCode::SUCCESS;
    00121 }
    00122
    00124 StatusCode Converter::setDataProvider(IDataProviderSvc* svc)  {
    00125   IDataManagerSvc* oldDataManager = m_dataManager;
    00126   IDataProviderSvc* oldDataProvider = m_dataProvider;
    00127   m_dataProvider = svc;
    00128   m_dataManager  = 0;
    00129   if ( 0 != m_dataProvider )  {
    00130     m_dataProvider->addRef();
    00131     svc->queryInterface(IDataManagerSvc::interfaceID(), pp_cast<void>(&m_dataManager)).ignore();
    00132   }
    00133   if ( oldDataManager )  {
    00134     oldDataManager->release();
    00135   }
    00136   if ( oldDataProvider )  {
    00137     oldDataProvider->release();
    00138   }
    00139   return StatusCode::SUCCESS;
    00140 }
    00141
    00143 IDataProviderSvc* Converter::dataProvider()  const    {
    00144   return m_dataProvider;
    00145 }
    00146
    00148 IDataManagerSvc* Converter::dataManager()  const    {
    00149   return m_dataManager;
    00150 }
    00151
    00153 StatusCode Converter::setConversionSvc(IConversionSvc* svc)   {
    00154   m_conversionSvc = svc;
    00155   return StatusCode::SUCCESS;
    00156 }
    00157
    00159 IConversionSvc* Converter::conversionSvc()  const    {
    00160   return m_conversionSvc;
    00161 }
    00162
    00164 StatusCode Converter::setAddressCreator(IAddressCreator* creator)   {
    00165   m_addressCreator = creator;
    00166   return StatusCode::SUCCESS;
    00167 }
    00168
    00170 IAddressCreator* Converter::addressCreator()  const   {
    00171   return m_addressCreator;
    00172 }
    00173
    00175 ISvcLocator* Converter::serviceLocator()  const     {
    00176   return m_svcLocator;
    00177 }
    00178
    00180 IMessageSvc* Converter::msgSvc()  const   {
    00181   if ( 0 == m_messageSvc ) {
    00182     StatusCode sc = serviceLocator()->service( "MessageSvc", m_messageSvc, true );
    00183     if( sc.isFailure() ) {
    00184       throw GaudiException("Service [MessageSvc] not found", "Converter", sc);
    00185     }
    00186   }
    00187   return m_messageSvc;
    00188 }
    00189
    00190 // Obsoleted name, kept due to the backwards compatibility
    00191 IMessageSvc* Converter::messageService()  const   {
    00192   return m_messageSvc;
    00193 }
    00194
    00196 Converter::Converter(long storage_type, const CLID& class_type, ISvcLocator* svc=0) :
    00197   m_refCount(0),
    00198   m_storageType(storage_type),
    00199   m_classType(class_type),
    00200   m_dataProvider(0),
    00201   m_dataManager(0),
    00202   m_conversionSvc(0),
    00203   m_svcLocator(svc),
    00204   m_messageSvc(0)
    00205 {
    00206   if ( 0 != m_svcLocator ) m_svcLocator->addRef();
    00207 }
    00208
    00210 Converter::~Converter()   {
    00211   if ( 0 != m_svcLocator ) m_svcLocator->release();
    00212 }
    00213
    00214 StatusCode
    00215 Converter::service_i(const std::string& svcName, bool createIf,
    00216                      const InterfaceID& iid, void** ppSvc) const {
    00217   StatusCode sc(StatusCode::FAILURE);
    00218   // Check for name of conversion service
    00219   ConversionSvc* cnvsvc =
    00220     dynamic_cast<ConversionSvc*> (Converter::conversionSvc());
    00221   if( cnvsvc != 0 ) {
    00222     MsgStream log(msgSvc(),"Converter");
    00223     ServiceLocatorHelper helper(*serviceLocator(), log, cnvsvc->name());
    00224     sc = helper.getService(svcName, createIf, iid, ppSvc);
    00225   }
    00226   return sc;
    00227 }
    00228
    00229 StatusCode
    00230 Converter::service_i(const std::string& svcType, const std::string& svcName,
    00231                      const InterfaceID& iid, void** ppSvc) const {
    00232   StatusCode sc(StatusCode::FAILURE);
    00233   // Check for name of conversion service
    00234   ConversionSvc* cnvsvc =
    00235     dynamic_cast<ConversionSvc*> (Converter::conversionSvc());
    00236   if( cnvsvc != 0 ) {
    00237     MsgStream log(msgSvc(),"Converter");
    00238     ServiceLocatorHelper helper(*serviceLocator(), log, cnvsvc->name());
    00239     sc = helper.createService(svcType, svcName, iid, ppSvc);
    00240   }
    00241   return sc;
    00242 }