summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormk1 <mk1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-06-09 16:33:52 +0000
committermk1 <mk1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-06-09 16:33:52 +0000
commit4af301a06bfc4ee2ee7554282eedacba5f115332 (patch)
treeb702a0d411aede4b757dccb3ca15ad5fe2246cd8
parentc656f473a6d6c729bebbb201697d9aa0f56c1f77 (diff)
downloadATCD-4af301a06bfc4ee2ee7554282eedacba5f115332.tar.gz
Added the move operation.
-rw-r--r--TAO/tests/Quoter/Quoter_Impl.cpp180
-rw-r--r--TAO/tests/Quoter/Quoter_Impl.h9
2 files changed, 168 insertions, 21 deletions
diff --git a/TAO/tests/Quoter/Quoter_Impl.cpp b/TAO/tests/Quoter/Quoter_Impl.cpp
index 84ffda65030..00431ace44d 100644
--- a/TAO/tests/Quoter/Quoter_Impl.cpp
+++ b/TAO/tests/Quoter/Quoter_Impl.cpp
@@ -60,7 +60,8 @@ Quoter_Factory_Impl::create_quoter (const char *name,
// Constructor
-Quoter_Impl::Quoter_Impl (const char *name)
+Quoter_Impl::Quoter_Impl (const char *name, const unsigned char use_LifeCycle_Service)
+ : use_LifeCycle_Service_ (use_LifeCycle_Service)
{
ACE_UNUSED_ARG (name);
}
@@ -99,14 +100,13 @@ Quoter_Impl::copy (CosLifeCycle::FactoryFinder_ptr there,
// The name of the Generic Factory
CosLifeCycle::Key factoryKey (2); // max = 2
- // future enhancement
- /* if (this->useLifeCycleService_ == 1)
+ if (this->useLifeCycleService_ == 1)
{
// use the LifeCycle Service
factoryKey.length(1);
factoryKey[0].id = CORBA::string_dup ("Life_Cycle_Service");
}
- else*/
+ else // which means this->useLifeCycleService_ == 0, default setting
{
// use a Generic Factory
factoryKey.length(2);
@@ -117,7 +117,7 @@ Quoter_Impl::copy (CosLifeCycle::FactoryFinder_ptr there,
// Find an appropriate factory over there.
CosLifeCycle::Factories_ptr factories_ptr =
there->find_factories (factoryKey, _env_there);
-
+
// Only a NoFactory exception might have occured, so if it
// occured, then go immediately back.
if (_env_there.exception() != 0)
@@ -125,34 +125,36 @@ Quoter_Impl::copy (CosLifeCycle::FactoryFinder_ptr there,
// _env_there contains already the exception.
return CosLifeCycle::LifeCycleObject::_nil();
}
-
+
// Now it is known that there is at least one factory.
Stock::Quoter_var quoter_var;
-
+
for (u_int i = 0; i < factories_ptr->length (); i++)
{
// Get the first object reference to a factory.
CORBA::Object_ptr quoter_FactoryObj_ptr = (*factories_ptr)[i];
-
+
// Narrow it to a Quoter Factory.
Stock::Quoter_Factory_var quoter_Factory_var =
Stock::Quoter_Factory::_narrow (quoter_FactoryObj_ptr,
TAO_TRY_ENV);
TAO_CHECK_ENV;
-
+
if (CORBA::is_nil (quoter_Factory_var.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
- "Quoter::copy: Narrow failed. Factory is not valid.\n"),
- 0);
-
+ "Quoter::copy: Narrow failed. Factory is not valid.\n"),
+ 0);
+
// Try to get a Quoter created by this factory.
// and duplicate the pointer to it
quoter_var = Stock::Quoter::_duplicate (
- quoter_Factory_var->create_quoter ("quoter_copied", TAO_TRY_ENV));
-
+ quoter_Factory_var->create_quoter (
+ "quoter_copied",
+ TAO_TRY_ENV));
+
// @@ mk1: The create_quoter should return an exception
TAO_CHECK_ENV;
-
+
if (CORBA::is_nil (quoter_var.in ()))
{
// If we had already our last chance, then give up.
@@ -170,7 +172,7 @@ Quoter_Impl::copy (CosLifeCycle::FactoryFinder_ptr there,
}
else
break;
- // if succeeded in creating a new Quoter over there, then stop trying
+ // if succeeded in creating a new Quoter over there, then stop trying
}
// Return an object reference to the newly created Quoter.
@@ -193,15 +195,146 @@ Quoter_Impl::move (CosLifeCycle::FactoryFinder_ptr there,
const CosLifeCycle::Criteria &the_criteria,
CORBA::Environment &_env_there)
{
+ ACE_DEBUG ((LM_DEBUG,"Quoter_Impl::move: being called\n"));
+
+ TAO_TRY
+ {
+ // Get the location over there as a CORBA::Object_var
+
+ // The name of the Generic Factory
+ CosLifeCycle::Key factoryKey (2); // max = 2
+
+ if (this->useLifeCycleService_ == 1)
+ {
+ // use the LifeCycle Service
+ factoryKey.length(1);
+ factoryKey[0].id = CORBA::string_dup ("Life_Cycle_Service");
+ }
+ else // which means this->useLifeCycleService_ == 0, default setting
+ {
+ // use a Generic Factory
+ factoryKey.length(2);
+ factoryKey[0].id = CORBA::string_dup ("IDL_Quoter");
+ factoryKey[1].id = CORBA::string_dup ("Quoter_Generic_Factory");
+ }
+
+ // Find an appropriate factory over there.
+ CosLifeCycle::Factories_ptr factories_ptr =
+ there->find_factories (factoryKey, _env_there);
+
+ // Only a NoFactory exception might have occured, so if it
+ // occured, then go immediately back.
+ if (_env_there.exception() != 0)
+ {
+ _env_there.exception (new CosLifeCycle::NotMovable());
+ // _env_there contains already the exception.
+ return CosLifeCycle::LifeCycleObject::_nil();
+ }
+
+ // Now it is known that there is at least one factory.
+ Stock::Quoter_var quoter_var;
+
+ for (u_int i = 0; i < factories_ptr->length (); i++)
+ {
+ // Get the first object reference to a factory.
+ CORBA::Object_ptr quoter_FactoryObj_ptr = (*factories_ptr)[i];
+
+ // Narrow it to a Quoter Factory.
+ Stock::Quoter_Factory_var quoter_Factory_var =
+ Stock::Quoter_Factory::_narrow (quoter_FactoryObj_ptr,
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ if (CORBA::is_nil (quoter_Factory_var.in ()))
+ {
+ env_there.exception (new );
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Quoter::move: Narrow failed. Factory is not valid.\n"),
+ 0);
+ }
+
+ // Try to get a Quoter created by this factory.
+ // and duplicate the pointer to it
+ quoter_var = Stock::Quoter::_duplicate (
+ quoter_Factory_var->create_quoter (
+ "quoter_moved",
+ TAO_TRY_ENV));
+
+ // @@ mk1: The create_quoter should return an exception
+ TAO_CHECK_ENV;
+
+ if (CORBA::is_nil (quoter_var.in ()))
+ {
+ // If we had already our last chance, then give up.
+ if (i == factories_ptr->length ())
+ {
+ _env_there.exception (new CosLifeCycle::NoFactory (factoryKey));
+ return CosLifeCycle::LifeCycleObject::_nil();
+ }
+ else
+ {
+ (ew CosLifeCycle::NotMovable());
+ ACE_ERROR ((LM_ERROR,
+ "Quoter::copy: Factory did not create the Quoter properly.\n"));
+ // Else tell what's wrong and try the next factory.
+ }
+ }
+ else
+ break;
+ // if succeeded in creating a new Quoter over there, then stop trying
+ }
+
+ // Return an object reference to the newly created Quoter.
+
+ CORBAL::Object_var forward_to = (CORBA::Object_var) quoter_var;
+
+ if (!CORBA::is_nil (forward_to.in ()))
+ {
+ PortableServer::ObjectId_var oid = this->poa_->servant_to_id (this, env);
+
+ if (env.exception () != 0)
+ return;
+
+ PortableServer::Servant servant = this->poa_->_servant ();
+ if (servant == 0)
+ {
+ _env_there.exception (new CosLifeCycle::NotMovable());
+ return;
+ }
+
+ void *ptr = servant->_downcast ("IDL:PortableServer/POA:1.0");
+ POA_PortableServer::POA *poa = (POA_PortableServer::POA *) ptr;
+ TAO_POA *tao_poa = ACE_dynamic_cast (TAO_POA *, poa);
+
+ tao_poa->forward_object (oid.in (),
+ forward_to.in (),
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV
+ }
+ else
+ {
+ ACE_DEBUG ((LM_DEBUG,"::move: forward_to refenence is nil.\n"));
+ _env_there.exception (new CosLifeCycle::NotMovable());
+ return;
+ }
+
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("SYS_EX");
+ return;
+ }
+ TAO_ENDTRY;
+
// for later
// this->copy (there, the_criteria, _env_there);
-
+
// the move operation is not implemented yet, because of the issue,
// that the object reference has to stay the same. But if it has
// to stay the same this object, the old object, has to forward
// further calls.
-
- _env_there.exception (new CosLifeCycle::NotMovable());
+
+
}
@@ -217,3 +350,12 @@ Quoter_Impl::remove (CORBA::Environment &_tao_environment)
TAO_ORB_Core_instance ()->orb ()->shutdown ();
}
+
+
+
+
+
+
+
+
+
diff --git a/TAO/tests/Quoter/Quoter_Impl.h b/TAO/tests/Quoter/Quoter_Impl.h
index a71f03b3d52..98c496042ca 100644
--- a/TAO/tests/Quoter/Quoter_Impl.h
+++ b/TAO/tests/Quoter/Quoter_Impl.h
@@ -34,8 +34,9 @@ class Quoter_Impl: public POA_Stock::Quoter
// Actual Quoter Implementation class. Returns a quoter for a given stock
// and provides an example for the lifecycle functionality.
public:
- Quoter_Impl (const char *obj_name = "");
- // Constructor
+ Quoter_Impl (const char *obj_name = "", const unsigned char use_LifeCycle_Service = 0);
+ // Constructor (use_LifeCycle_Service is 1 if the LifeCycle_Service should be used
+ // instead of the Quoter Generic_Factory
~Quoter_Impl (void);
// Destructor
@@ -59,6 +60,10 @@ public:
virtual void remove (CORBA::Environment &_tao_environment);
// Removes the object.
+private:
+ unsigned char use_LifeCycle_Service_;
+ // This flag defines if a Generic Factory is used (0 by default) or
+ // the more sophisticated LifeCycle Service
};
// Forward declaration.