Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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 "tao/Resource_Factory.h"
00022 #include "tao/debug.h"
00023 #include "ace/Auto_Ptr.h"
00024 #include "ace/Dynamic_Service.h"
00025
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027
00028 namespace TAO
00029 {
00030 namespace details
00031 {
00032 template<typename T>
00033 int
00034 load_protocol_factory (TAO_ProtocolFactorySet &protocol_set,
00035 const char *name)
00036 {
00037 TAO_Protocol_Factory *protocol_factory = 0;
00038 auto_ptr<TAO_Protocol_Factory> safe_protocol_factory;
00039
00040 TAO_Protocol_Item *item = 0;
00041
00042
00043
00044
00045 bool transfer_ownership = false;
00046
00047 protocol_factory =
00048 ACE_Dynamic_Service<TAO_Protocol_Factory>::instance (
00049 ACE_TEXT_CHAR_TO_TCHAR (name));
00050
00051 if (protocol_factory == 0)
00052 {
00053 if (TAO_debug_level > 0)
00054 ACE_ERROR ((LM_WARNING,
00055 ACE_TEXT("(%P|%t) WARNING - No <%C> found in Service")
00056 ACE_TEXT(" Repository. Using default instance.\n"),
00057 name));
00058
00059 ACE_NEW_RETURN (protocol_factory,
00060 T,
00061 -1);
00062
00063 ACE_AUTO_PTR_RESET (safe_protocol_factory,
00064 protocol_factory,
00065 TAO_Protocol_Factory);
00066
00067 transfer_ownership = true;
00068 }
00069 else
00070 {
00071 transfer_ownership = false;
00072 }
00073
00074 ACE_NEW_RETURN (item, TAO_Protocol_Item (name), -1);
00075
00076
00077
00078
00079
00080
00081
00082 item->factory ((transfer_ownership ?
00083 safe_protocol_factory.release () :
00084 protocol_factory),
00085 transfer_ownership);
00086
00087 if (protocol_set.insert (item) == -1)
00088 {
00089 ACE_ERROR ((LM_ERROR,
00090 ACE_TEXT("TAO (%P|%t) Unable to add ")
00091 ACE_TEXT("<%C> to protocol factory set.\n"),
00092 item->protocol_name ().c_str ()));
00093
00094 delete item;
00095
00096 if (transfer_ownership == false)
00097 delete protocol_factory;
00098
00099 return -1;
00100 }
00101
00102 if (TAO_debug_level > 0)
00103 {
00104 ACE_DEBUG ((LM_DEBUG,
00105 ACE_TEXT("TAO (%P|%t) - Loaded default ")
00106 ACE_TEXT("protocol <%C>\n"),
00107 name));
00108 }
00109
00110 return 0;
00111 }
00112 }
00113 }
00114
00115 TAO_END_VERSIONED_NAMESPACE_DECL
00116
00117 #include "ace/post.h"
00118
00119 #endif