Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PortableServer / LifespanStrategyPersistent.cpp
blob32bb04a343cc94710f8fa3c10bdb719b13773fd3
1 // -*- C++ -*-
2 #include "tao/PortableServer/LifespanStrategyPersistent.h"
3 #include "tao/PortableServer/Root_POA.h"
4 #include "tao/PortableServer/POAManager.h"
5 #include "tao/PortableServer/ImR_Client_Adapter.h"
6 #include "tao/ORB_Core.h"
7 #include "ace/OS_NS_sys_time.h"
8 #include "ace/Dynamic_Service.h"
9 #include "ace/Service_Config.h"
11 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
13 namespace TAO
15 namespace Portable_Server
17 void
18 LifespanStrategyPersistent::strategy_init (TAO_Root_POA *poa)
20 LifespanStrategy::strategy_init (poa);
22 this->use_imr_ = this->poa_->orb_core ().use_implrepo ();
25 bool
26 LifespanStrategyPersistent::validate (
27 CORBA::Boolean is_persistent,
28 const TAO::Portable_Server::Temporary_Creation_Time& /*creation_time*/) const
30 return is_persistent;
33 char
34 LifespanStrategyPersistent::key_type () const
36 return 'P';
39 CORBA::Boolean
40 LifespanStrategyPersistent::is_persistent () const
42 return true;
45 void
46 LifespanStrategyPersistent::create_key (
47 CORBA::Octet *buffer,
48 CORBA::ULong& starting_at)
50 // Copy the persistence byte.
51 buffer[starting_at] = static_cast<CORBA::Octet> (this->key_type ());
52 starting_at += this->key_type_length ();
55 CORBA::ULong
56 LifespanStrategyPersistent::key_length () const
58 return this->key_type_length ();
61 void
62 LifespanStrategyPersistent::notify_startup ()
64 if (this->use_imr_)
66 // The user specified that the ImR should be used.
67 ImR_Client_Adapter *adapter =
68 ACE_Dynamic_Service<ImR_Client_Adapter>::instance (
69 TAO_Root_POA::imr_client_adapter_name ());
71 #if !defined (TAO_AS_STATIC_LIBS)
72 // In case we build shared, try to load the ImR Client library, in a
73 // static build we just can't do this, so don't try it, lower layers
74 // output an error then.
75 if (adapter == 0)
77 ACE_Service_Config::process_directive (
78 ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE(
79 "ImR_Client_Adapter", "TAO_ImR_Client", TAO_VERSION,
80 "_make_ImR_Client_Adapter_Impl", ""));
82 adapter =
83 ACE_Dynamic_Service<ImR_Client_Adapter>::instance (
84 TAO_Root_POA::imr_client_adapter_name ());
86 #endif /* !TAO_AS_STATIC_LIBS */
88 if (adapter != 0)
90 adapter->imr_notify_startup (this->poa_);
92 else
94 // When we don't have a ImR_Client adapter, but the user
95 // has specified that the ImR has to be used we have an
96 // error situation which has to be reported.
97 TAOLIB_ERROR ((LM_ERROR,
98 ACE_TEXT ("(%P|%t) ERROR: No ImR_Client library ")
99 ACE_TEXT ("available but use IMR has been specified.\n")));
101 throw ::CORBA::INTERNAL ();
106 void
107 LifespanStrategyPersistent::notify_shutdown ()
109 ImR_Client_Adapter *adapter =
110 ACE_Dynamic_Service<ImR_Client_Adapter>::instance (
111 TAO_Root_POA::imr_client_adapter_name ());
113 if (adapter != 0)
115 adapter->imr_notify_shutdown (this->poa_);
119 LifespanStrategyPersistent::LifespanStrategyPersistent () :
120 use_imr_ (true)
124 void
125 LifespanStrategyPersistent::check_state ()
127 this->poa_->tao_poa_manager().check_state ();
130 bool
131 LifespanStrategyPersistent::use_imr () const
133 return use_imr_;
136 CORBA::Object_ptr
137 LifespanStrategyPersistent::imr_key_to_object (const TAO::ObjectKey &key,
138 const char *type_id) const
140 if (!this->use_imr_)
142 // not using the imr
143 return CORBA::Object::_nil ();
146 // The user specified that the ImR should be used.
147 ImR_Client_Adapter *adapter =
148 ACE_Dynamic_Service<ImR_Client_Adapter>::instance (
149 TAO_Root_POA::imr_client_adapter_name ());
150 if (adapter == 0)
152 // couldn't load adapter, already reported error
153 return CORBA::Object::_nil ();
156 return adapter->imr_key_to_object (this->poa_, key, type_id);
159 } /* namespace Portable_Server */
160 } /* namespace TAO */
163 TAO_END_VERSIONED_NAMESPACE_DECL