本文整理汇总了C++中portableserver::POA_ptr::activate_object_with_id方法的典型用法代码示例。如果您正苦于以下问题:C++ POA_ptr::activate_object_with_id方法的具体用法?C++ POA_ptr::activate_object_with_id怎么用?C++ POA_ptr::activate_object_with_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类portableserver::POA_ptr
的用法示例。
在下文中一共展示了POA_ptr::activate_object_with_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestException
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 ();
}
示例2: temp
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 ();
}
示例3: servant
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");
//.........这里部分代码省略.........
示例4: NO_MEMORY
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 ();
}
示例5: catch
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);
}
示例6: TestException
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);
}
}