3 //=============================================================================
5 * @file Load_Protocol_Factory_T.h
7 * Function templates to load a protocol factory.
9 * @author Johnny Willemsen
11 //=============================================================================
13 #ifndef TAO_LOAD_PROTOCOL_FACTORY_T_H
14 #define TAO_LOAD_PROTOCOL_FACTORY_T_H
16 #include /**/ "ace/pre.h"
18 #include "tao/Protocol_Factory.h"
19 #include "tao/Resource_Factory.h"
20 #include "tao/debug.h"
22 #include "ace/Dynamic_Service.h"
24 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
32 load_protocol_factory (TAO_ProtocolFactorySet
&protocol_set
,
35 TAO_Protocol_Factory
*protocol_factory
= 0;
36 std::unique_ptr
<TAO_Protocol_Factory
> safe_protocol_factory
;
38 TAO_Protocol_Item
*item
= 0;
40 // If a protocol factory is obtained from the Service
41 // Configurator then do not transfer ownership to the
43 bool transfer_ownership
= false;
46 ACE_Dynamic_Service
<TAO_Protocol_Factory
>::instance (
47 ACE_TEXT_CHAR_TO_TCHAR (name
));
49 if (protocol_factory
== 0)
51 if (TAO_debug_level
> 0)
52 TAOLIB_ERROR ((LM_WARNING
,
53 ACE_TEXT("(%P|%t) WARNING - No <%C> found in Service")
54 ACE_TEXT(" Repository. Using default instance.\n"),
57 ACE_NEW_RETURN (protocol_factory
,
61 safe_protocol_factory
.reset (protocol_factory
);
63 transfer_ownership
= true;
67 transfer_ownership
= false;
70 ACE_NEW_RETURN (item
, TAO_Protocol_Item (name
), -1);
71 // If the TAO_Protocol_Item retains ownership of the
72 // TAO_Protocol_Factory then we used an auto_ptr<> above, so
73 // release the TAO_Protocol_Factory from it. Otherwise, we
74 // obtained the TAO_Protocol_Factory from the Service
75 // Configurator so an auto_ptr<> wasn't used since the Service
76 // Configurator retains ownership, hence there was no need to
77 // use an auto_ptr<> in this method.
78 item
->factory ((transfer_ownership
?
79 safe_protocol_factory
.release () :
83 if (protocol_set
.insert (item
) == -1)
85 TAOLIB_ERROR ((LM_ERROR
,
86 ACE_TEXT("TAO (%P|%t) Unable to add ")
87 ACE_TEXT("<%C> to protocol factory set.\n"),
88 item
->protocol_name ().c_str ()));
92 if (transfer_ownership
== false)
93 delete protocol_factory
;
98 if (TAO_debug_level
> 0)
100 TAOLIB_DEBUG ((LM_DEBUG
,
101 ACE_TEXT("TAO (%P|%t) - Loaded default ")
102 ACE_TEXT("protocol <%C>\n"),
111 TAO_END_VERSIONED_NAMESPACE_DECL
113 #include /**/ "ace/post.h"
115 #endif /* TAO_LOAD_PROTOCOL_FACTORY_T_H*/