Callback_ptr ServerApp::create_callback( PortableServer::POA_ptr poa, const char* servant_name) { PortableServer::ServantBase_var servant = new Callback_i(); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId("callback"); poa->activate_object_with_id(id.in(), servant.in()); CORBA::Object_var obj = poa->id_to_reference(id.in()); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to activate servant (%s).\n", servant_name)); throw TestException(); } Callback_var callback = Callback::_narrow (obj.in ()); return callback._retn (); }
CosNaming::NamingContext_ptr TAO_Transient_Naming_Context::make_new_context (PortableServer::POA_ptr poa, const char *poa_id, size_t context_size) { // Put together a servant for the new Naming Context. TAO_Transient_Naming_Context *context_impl = 0; ACE_NEW_THROW_EX (context_impl, TAO_Transient_Naming_Context (poa, poa_id, context_size), CORBA::NO_MEMORY ()); // Put <context_impl> into the auto pointer temporarily, in case next // allocation fails. ACE_Auto_Basic_Ptr<TAO_Transient_Naming_Context> temp (context_impl); TAO_Naming_Context *context = 0; ACE_NEW_THROW_EX (context, TAO_Naming_Context (context_impl), CORBA::NO_MEMORY ()); // Let <implementation> know about it's <interface>. context_impl->interface (context); // Release auto pointer, and start using reference counting to // control our servant. temp.release (); PortableServer::ServantBase_var s = context; // Register the new context with the POA. #if defined (CORBA_E_MICRO) PortableServer::ObjectId_var id = poa->activate_object (context); #else PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId (poa_id); poa->activate_object_with_id (id.in (), context); #endif /* CORBA_E_MICRO */ CosNaming::NamingContext_var result = context->_this (); return result._retn (); }
void test_poas (CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa, PortableServer::POA_ptr first_poa, PortableServer::POA_ptr second_poa, PortableServer::POA_ptr third_poa, PortableServer::POA_ptr forth_poa, int perform_deactivation_test) { { test_i servant (root_poa); CORBA::Object_var obj = root_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = root_poa->reference_to_id (obj.in ()); root_poa->activate_object_with_id (id.in (), &servant); obj = root_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = root_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = root_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = root_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = root_poa->servant_to_id (&servant); ACE_ASSERT (id_from_servant.in () == id.in ()); root_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { root_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = root_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); root_poa->deactivate_object (id.in ()); } } { test_i servant (root_poa); PortableServer::ObjectId_var id = root_poa->activate_object (&servant); CORBA::Object_var obj = root_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = root_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); root_poa->deactivate_object (id.in ()); } { test_i servant (first_poa); CORBA::Object_var obj = first_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = first_poa->reference_to_id (obj.in ()); first_poa->activate_object_with_id (id.in (), &servant); obj = first_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = first_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = first_poa->id_to_servant (id.in ()); if (servant_from_reference .in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } first_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { first_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = first_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); first_poa->deactivate_object (id.in ()); } } { test_i servant (first_poa); PortableServer::ObjectId_var id = first_poa->activate_object (&servant); CORBA::Object_var obj = first_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = first_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); first_poa->deactivate_object (id.in ()); } { test_i servant (second_poa); CORBA::Object_var obj = second_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = second_poa->reference_to_id (obj.in ()); second_poa->activate_object_with_id (id.in (), &servant); obj = second_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = second_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = second_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = second_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = second_poa->servant_to_id (&servant); ACE_ASSERT (id_from_servant.in () == id.in ()); second_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { second_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = second_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); second_poa->deactivate_object (id.in ()); } } { test_i servant (second_poa); PortableServer::ObjectId_var id = second_poa->activate_object (&servant); CORBA::Object_var obj = second_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = second_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); second_poa->deactivate_object (id.in ()); } { test_i servant (third_poa); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("hello"); CORBA::Object_var obj = third_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_reference = third_poa->reference_to_id (obj.in ()); string = PortableServer::ObjectId_to_string (id_from_reference.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_reference.in () == id.in ()); third_poa->activate_object_with_id (id.in (), &servant); obj = third_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = third_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = third_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = third_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = third_poa->servant_to_id (&servant); string = PortableServer::ObjectId_to_string (id_from_servant.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_servant.in () == id.in ()); third_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { third_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = third_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); third_poa->deactivate_object (id.in ()); } } { test_i servant (forth_poa); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("hello"); CORBA::Object_var obj = forth_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_reference = forth_poa->reference_to_id (obj.in ()); string = PortableServer::ObjectId_to_string (id_from_reference.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_reference.in () == id.in ()); forth_poa->activate_object_with_id (id.in (), &servant); obj = forth_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = forth_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = forth_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } forth_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { forth_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = forth_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); forth_poa->deactivate_object (id.in ()); } } }
CosNaming::NamingContext_ptr TAO_Persistent_Naming_Context::make_new_context (PortableServer::POA_ptr poa, const char *poa_id, size_t context_size, TAO_Persistent_Context_Index * ind) { // Store the stub we will return here. CosNaming::NamingContext_var result; // Put together a servant for the new Naming Context. TAO_Persistent_Naming_Context *context_impl = ind->create_naming_context_impl( poa, poa_id); // Verify that a context implementation was created. If not, throw an exception if (context_impl == 0) throw CORBA::NO_MEMORY (); // Put <context_impl> into the auto pointer temporarily, in case next // allocation fails. ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context> temp (context_impl); if (context_impl->init (context_size) == -1) throw CORBA::NO_MEMORY (); // Insure appropriate cleanup in case of exception conditions ahead. context_impl->set_cleanup_level (1); // Register with the index of Naming Contexts. if (ind->bind (context_impl->poa_id_.c_str (), context_impl->counter_, context_impl->persistent_context_->map ()) == -1) throw CORBA::INTERNAL (); // Insure appropriate cleanup in case of exception conditions ahead. context_impl->set_cleanup_level (2); TAO_Naming_Context *context = 0; ACE_NEW_THROW_EX (context, TAO_Naming_Context (context_impl), CORBA::NO_MEMORY ()); // Let <implementation> know about it's <interface>. context_impl->interface (context); // Release auto pointer, and start using reference counting to // control our servant. temp.release (); PortableServer::ServantBase_var s = context; // Register the new context with the POA. PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId (poa_id); poa->activate_object_with_id (id.in (), context); result = context->_this (); // Everything went smoothly, without errors - we don't need any cleanup. context_impl->set_cleanup_level (0); return result._retn (); }
void test_object_deactivation (PortableServer::POA_ptr poa, const PortableServer::ObjectId &id) { test_i servant; int expected_exception_raised = 0; PortableServer::ObjectId_var invalid_id = PortableServer::string_to_ObjectId ("invalid id"); try { poa->deactivate_object (invalid_id.in ()); } catch (const PortableServer::POA::ObjectNotActive& ) { // This is the correct exception! Ignore expected_exception_raised = 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( "Exception caught of incorrect type"); ACE_ASSERT (0); } // Make sure an exception was raised and it was of the correct // type. ACE_ASSERT (expected_exception_raised); poa->activate_object_with_id (id, &servant); poa->deactivate_object (id); // Reset flag expected_exception_raised = 0; try { poa->deactivate_object (id); } catch (const PortableServer::POA::ObjectNotActive& ) { // This is the correct exception! Ignore expected_exception_raised = 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( "Exception caught of incorrect type"); ACE_ASSERT (0); } // Make sure an exception was raised and it was of the correct // type. ACE_ASSERT (expected_exception_raised); poa->activate_object_with_id (id, &servant); servant.poa_ = PortableServer::POA::_duplicate (poa); servant.id_ = id; CORBA::Object_var object = poa->id_to_reference (id); test_var test = test::_narrow (object.in ()); test->deactivate_self (); // ACE_ASSERT dissappears in non-debug builds ACE_UNUSED_ARG (expected_exception_raised); }
void FooServantList::create_and_activate(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) { poa_ = PortableServer::POA::_duplicate (poa); for (unsigned i = 0; i < this->num_servants_; i++) { ACE_TCHAR buf[32]; ACE_OS::sprintf(buf, ACE_TEXT("%02d"), i + 1); ACE_TString servant_name = this->prefix_ + ACE_TEXT("_") + buf; this->servants_[i] = new Foo_i(ACE_TEXT_ALWAYS_CHAR(servant_name.c_str()),this); this->safe_servants_[i] = this->servants_[i]; PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId(ACE_TEXT_ALWAYS_CHAR(servant_name.c_str())); poa->activate_object_with_id(id.in(), this->safe_servants_[i].in()); CORBA::Object_var obj = poa->id_to_reference(id.in()); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to activate servant (%s).\n", servant_name.c_str())); throw TestException(); } // create the collocated object reference. if (this->collocated_test_ && i == 0) { Foo_var collocated = Foo::_narrow (obj.in ()); // Create the servant object. Callback_i* servant = new Callback_i (); // local smart pointer variable to deal with releasing the reference // to the servant object when the smart pointer object falls out of scope. PortableServer::ServantBase_var safe_servant(servant); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId("callback"); poa->activate_object_with_id(id.in(), safe_servant.in()); CORBA::Object_var obj = poa->id_to_reference(id.in()); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to activate servant (%s).\n", servant_name.c_str())); throw TestException(); } Callback_var callback = Callback::_narrow (obj.in ()); collocated_client_ = new ClientTask(orb, collocated.in (), callback.in (), true); if (collocated_client_->open() != 0) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to open the collocated client.\n")); throw TestException(); } } CORBA::String_var ior = this->orb_->object_to_string(obj.in()); ACE_TString filename = servant_name + ACE_TEXT(".ior"); FILE* ior_file = ACE_OS::fopen(filename.c_str(), "w"); if (ior_file == 0) { ACE_ERROR((LM_ERROR, "(%P|%t) Cannot open output file (%s) for writing IOR.", filename.c_str())); throw TestException(); } else { ACE_DEBUG((LM_DEBUG, "(%P|%t) writing IOR to file %s\n", filename.c_str())); } ACE_OS::fprintf(ior_file, "%s", ior.in()); ACE_OS::fclose(ior_file); } }