Load_Protocol_Factory_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file Load_Protocol_Factory_T.h
00006  *
00007  *  $Id: Load_Protocol_Factory_T.h 81583 2008-05-02 08:27:32Z johnnyw $
00008  *
00009  *  Function templates to load a protocol factory.
00010  *
00011  *  @author  Johnny Willemsen
00012  */
00013 //=============================================================================
00014 
00015 #ifndef TAO_LOAD_PROTOCOL_FACTORY_T_H
00016 #define TAO_LOAD_PROTOCOL_FACTORY_T_H
00017 
00018 #include /**/ "ace/pre.h"
00019 
00020 #include "tao/Protocol_Factory.h"
00021 #include "ace/Auto_Ptr.h"
00022 #include "ace/Dynamic_Service.h"
00023 
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 namespace TAO
00027 {
00028   namespace details
00029   {
00030     template<typename T>
00031     int
00032     load_protocol_factory (TAO_ProtocolFactorySet &protocol_set,
00033                            const char *name)
00034     {
00035       TAO_Protocol_Factory *protocol_factory = 0;
00036       auto_ptr<TAO_Protocol_Factory> safe_protocol_factory;
00037 
00038       TAO_Protocol_Item *item = 0;
00039 
00040       // If a protocol factory is obtained from the Service
00041       // Configurator then do not transfer ownership to the
00042       // TAO_Protocol_Item.
00043       bool transfer_ownership = false;
00044 
00045       protocol_factory =
00046         ACE_Dynamic_Service<TAO_Protocol_Factory>::instance (
00047           ACE_TEXT_CHAR_TO_TCHAR (name));
00048 
00049       if (protocol_factory == 0)
00050         {
00051           if (TAO_debug_level > 0)
00052             ACE_ERROR ((LM_WARNING,
00053                         ACE_TEXT("(%P|%t) WARNING - No <%C> found in Service")
00054                         ACE_TEXT(" Repository. Using default instance.\n"),
00055                         name));
00056 
00057           ACE_NEW_RETURN (protocol_factory,
00058                           T,
00059                           -1);
00060 
00061           ACE_AUTO_PTR_RESET (safe_protocol_factory,
00062                               protocol_factory,
00063                               TAO_Protocol_Factory);
00064 
00065           transfer_ownership = true;
00066         }
00067       else
00068         {
00069           transfer_ownership = false;
00070         }
00071 
00072       ACE_NEW_RETURN (item, TAO_Protocol_Item (name), -1);
00073       // If the TAO_Protocol_Item retains ownership of the
00074       // TAO_Protocol_Factory then we used an auto_ptr<> above, so
00075       // release the TAO_Protocol_Factory from it.  Otherwise, we
00076       // obtained the TAO_Protocol_Factory from the Service
00077       // Configurator so an auto_ptr<> wasn't used since the Service
00078       // Configurator retains ownership, hence there was no need to
00079       // use an auto_ptr<> in this method.
00080       item->factory ((transfer_ownership ?
00081                       safe_protocol_factory.release () :
00082                       protocol_factory),
00083                       transfer_ownership);
00084 
00085       if (protocol_set.insert (item) == -1)
00086         {
00087           ACE_ERROR ((LM_ERROR,
00088                       ACE_TEXT("TAO (%P|%t) Unable to add ")
00089                       ACE_TEXT("<%C> to protocol factory set.\n"),
00090                       item->protocol_name ().c_str ()));
00091 
00092           delete item;
00093 
00094           if (transfer_ownership == false)
00095             delete protocol_factory;
00096 
00097           return -1;
00098         }
00099 
00100       if (TAO_debug_level > 0)
00101         {
00102           ACE_DEBUG ((LM_DEBUG,
00103                       ACE_TEXT("TAO (%P|%t) Loaded default ")
00104                       ACE_TEXT("protocol <%C>\n"),
00105                       name));
00106         }
00107 
00108       return 0;
00109     }
00110   }
00111 }
00112 
00113 TAO_END_VERSIONED_NAMESPACE_DECL
00114 
00115 #include /**/ "ace/post.h"
00116 
00117 #endif  /* TAO_LOAD_PROTOCOL_FACTORY_T_H*/

Generated on Tue Feb 2 17:37:52 2010 for TAO by  doxygen 1.4.7