本文整理汇总了C++中iortable::Table_var::bind方法的典型用法代码示例。如果您正苦于以下问题:C++ Table_var::bind方法的具体用法?C++ Table_var::bind怎么用?C++ Table_var::bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iortable::Table_var
的用法示例。
在下文中一共展示了Table_var::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
try {
// Initialze the ORB.
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
// Get a reference to the RootPOA.
CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
// Get the POA_var object from Object_var.
PortableServer::POA_var root_poa =
PortableServer::POA::_narrow (obj.in ());
// Get the POAManager of the RootPOA.
PortableServer::POAManager_var poa_manager =
root_poa->the_POAManager ();
poa_manager->activate ();
// Policies for the childPOA to be created.
CORBA::PolicyList policies;
policies.length (2);
policies[0] =
root_poa->create_id_assignment_policy (PortableServer::USER_ID);
policies[1] =
root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
// Create the childPOA under the RootPOA.
PortableServer::POA_var child_poa =
root_poa->create_POA ("childPOA",
poa_manager.in (),
policies);
// Destroy the policy objects
for (CORBA::ULong i = 0; i != policies.length (); ++i) {
policies[i]->destroy ();
}
// Create an instance of class Quoter_Stock_Factory_i.
Quoter_Stock_Factory_i stock_factory_i;
// Get the Object ID.
PortableServer::ObjectId_var oid =
PortableServer::string_to_ObjectId ("Stock_Factory");
// Activate the Stock_Factory object.
child_poa->activate_object_with_id (oid.in (),
&stock_factory_i);
// Get the object reference.
CORBA::Object_var stock_factory =
child_poa->id_to_reference (oid.in ());
CORBA::Object_var table_object =
orb->resolve_initial_references ("IORTable");
// Stringify all the object referencs.
CORBA::String_var ior = orb->object_to_string (stock_factory.in ());
IORTable::Table_var adapter =
IORTable::Table::_narrow (table_object.in ());
if (CORBA::is_nil (adapter.in ()))
{
ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
}
else
{
CORBA::String_var ior =
orb->object_to_string (stock_factory.in ());
adapter->bind ("childPOA", ior.in ());
}
orb->run ();
// Destroy POA, waiting until the destruction terminates.
root_poa->destroy (1, 1);
orb->destroy ();
}
catch (const CORBA::Exception &) {
cerr << "CORBA exception raised !" << endl;
}
return 0;
}
示例2: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
// Initialize the ORB
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
// Get the POA from the ORB.
CORBA::Object_var poa_obj = orb->resolve_initial_references ("RootPOA");
// Narrow to the POA interface
PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_obj.in ());
// Create a Stock Quoter implementation object
Stock_Quoter_i* stock_quoter = new Stock_Quoter_i (orb.in ());
UDPTest_i* UDP = new UDPTest_i ();
// Activate the Stock Quoter in the RootPOA.
PortableServer::ObjectId_var oid = root_poa->activate_object (stock_quoter);
CORBA::Object_var sq_obj = root_poa->id_to_reference (oid.in());
PortableServer::ObjectId_var oid1 = root_poa->activate_object (UDP);
CORBA::Object_var udp_obj1 = root_poa->id_to_reference (oid1.in());
CORBA::String_var ior =
orb->object_to_string (udp_obj1.in ());
ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
// Also make the Stock Quoter object available via corbaloc
// ObjectURL by binding it to a simple ObjectKey in the IORTable.
CORBA::Object_var table_obj = orb->resolve_initial_references ("IORTable");
IORTable::Table_var table = IORTable::Table::_narrow (table_obj.in());
CORBA::String_var quoter_ior_string = orb->object_to_string (sq_obj.in());
CORBA::String_var UDP_ior_string = orb->object_to_string (udp_obj1.in());
table->bind ("UDPTest", UDP_ior_string.in());
table->bind ("MyStockQuoter", quoter_ior_string.in());
// Activate the POA Manager
PortableServer::POAManager_var poa_mgr = root_poa->the_POAManager ();
poa_mgr->activate ();
cout << "Server ready" << endl;
orb->run ();
if (!UDP->received_send_)
{
ACE_ERROR_RETURN ((LM_ERROR, "Not received send\n"), 1);
}
}
catch (const CORBA::Exception& e)
{
e._tao_print_exception ("Exception caught:");
return 1;
}
return 0;
}
示例3: catch
// Add the ObjectID:IOR mapping to the IOR table of
// the ORB. Ignore this method if you are not testing for
// the InterOperable Naming Service.
template <class Servant> int
Server<Servant>::test_for_ins (const char *ior)
{
CORBA::ORB_var orb = this->orb_manager_.orb ();
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Adding (KEY:IOR) %s:%C\n"),
this->ins_,
ior));
try
{
CORBA::Object_var table_object =
orb->resolve_initial_references ("IORTable");
IORTable::Table_var adapter =
IORTable::Table::_narrow (table_object.in ());
if (CORBA::is_nil (adapter.in ()))
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Nil IORTable\n")),
-1);
}
adapter->bind (ACE_TEXT_ALWAYS_CHAR (this->ins_), ior);
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("ERROR: test_for_ins failed\n");
return -1;
}
return 0;
}
示例4: Test_i
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try {
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
PortableServer::POAManager_var mgr = root_poa->the_POAManager();
const char* poa_name = "TestService";
PortableServer::POA_var test_poa = createPOA(root_poa.in(), poa_name);
Terminator terminator;
if (terminator.open (0) == -1)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("main Error opening terminator\n")),-1);
PortableServer::Servant_var<Test_i> test_servant =
new Test_i(terminator);
PortableServer::ObjectId_var object_id =
PortableServer::string_to_ObjectId("test_object");
test_poa->activate_object_with_id(object_id.in(), test_servant.in());
TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
obj = tpoa->id_to_reference_i(object_id.in(), false);
CORBA::String_var test_ior = orb->object_to_string(obj.in());
obj = orb->resolve_initial_references("IORTable");
IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
table->bind(poa_name, test_ior.in());
mgr->activate();
std::cout << "Test server ready." << std::endl;
orb->run();
std::cout << "Test server shutting down." << std::endl;
root_poa->destroy(1,1);
orb->destroy();
ACE_Message_Block *mb;
ACE_NEW_RETURN(mb, ACE_Message_Block(0, ACE_Message_Block::MB_HANGUP), -1);
terminator.putq(mb);
terminator.wait();
}
catch(const CORBA::Exception& ex) {
std::cerr << "Server main() Caught CORBA::Exception" << ex << std::endl;
return 1;
}
return 0;
}
示例5: get_opts
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
int ec = 0;
try {
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
int max_run = 0;
int server_num = 0;
int init_delay_secs = 0;
const ACE_TCHAR *ior_file_name = ACE_TEXT ("");
ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("d:m:n:o:?"));
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'd':
init_delay_secs = ACE_OS::atoi (get_opts.opt_arg ());
break;
case 'm':
max_run = ACE_OS::atoi (get_opts.opt_arg ());
break;
case 'n':
server_num = ACE_OS::atoi (get_opts.opt_arg ());
break;
case 'o':
ior_file_name = get_opts.opt_arg ();
break;
case '?':
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("usage: %s ")
ACE_TEXT ("-d <seconds to delay before initializing POA> ")
ACE_TEXT ("-n Number of the server\n"),
argv[0]));
return 1;
break;
}
ACE_OS::sleep (init_delay_secs);
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
PortableServer::POAManager_var mgr = root_poa->the_POAManager();
ACE_CString poa_name = ACE_CString("TestObject_") + toStr (server_num);
PortableServer::POA_var test_poa = createPOA(root_poa.in(), poa_name.c_str ());
Test_i *impl = new Test_i(orb.in());
PortableServer::Servant_var<Test_i> test_servant = impl;
PortableServer::ObjectId_var object_id =
PortableServer::string_to_ObjectId("test_object");
//
// Activate the servant with the test POA,
// obtain its object reference, and get a
// stringified IOR.
//
test_poa->activate_object_with_id(object_id.in(), test_servant.in());
//
// Create binding between "TestService" and
// the test object reference in the IOR Table.
// Use a TAO extension to get the non imrified poa
// to avoid forwarding requests back to the ImR.
TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
obj = tpoa->id_to_reference_i(object_id.in(), false);
CORBA::String_var test_ior = orb->object_to_string(obj.in());
obj = orb->resolve_initial_references("IORTable");
IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
table->bind(poa_name.c_str (), test_ior.in());
if (ACE_OS::strlen (ior_file_name) > 0)
{
obj = test_poa->id_to_reference (object_id.in ());
test_ior = orb->object_to_string (obj.in ());
FILE *f = ACE_OS::fopen (ior_file_name, ACE_TEXT ("w"));
ACE_OS::fprintf (f, "%s", test_ior.in ());
ACE_OS::fclose (f);
}
//
// This server is now ready to run.
// This version does not create an IOR
// file as demonstrated in the
// Developer's Guide. It assumes that
// users create IORs for the client using
// the tao_imr utility.
//
//
// Stop discarding requests.
//
mgr->activate();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Started Server <%C> pid = %d\n"),
//.........这里部分代码省略.........
示例6: policies
int
Airplane_Server_i::init (int argc, ACE_TCHAR** argv)
{
try
{
// Initialize the ORB
this->orb_ = CORBA::ORB_init (argc, argv);
// Save pointers to the command line arguments
this->argc_ = argc;
this->argv_ = argv;
// Now check the arguments for our options
int retval = this->parse_args ();
if (retval != 0)
return retval;
// Get the POA from the ORB.
CORBA::Object_var obj =
this->orb_->resolve_initial_references ("RootPOA");
ACE_ASSERT(! CORBA::is_nil (obj.in ()));
// Narrow the object to a POA.
root_poa_ = PortableServer::POA::_narrow (obj.in ());
// Get the POA_Manager.
this->poa_manager_ = this->root_poa_->the_POAManager ();
// We now need to create a POA with the persistent and user_id policies,
// since they are need for use with the Implementation Repository.
CORBA::PolicyList policies (2);
policies.length (2);
policies[0] =
this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID);
policies[1] =
this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT);
// Since the Implementation Repository keys off of the POA name, we need
// to use the server_name_ as the POA's name.
this->airplane_poa_ =
this->root_poa_->create_POA (this->server_name_.c_str(),
this->poa_manager_.in (),
policies);
// Creation of the new POA is over, so destroy the Policy_ptr's.
for (CORBA::ULong i = 0; i < policies.length (); ++i)
{
CORBA::Policy_ptr policy = policies[i];
policy->destroy ();
}
ACE_NEW_RETURN (this->server_impl_, Airplane_i, -1);
PortableServer::ObjectId_var server_id =
PortableServer::string_to_ObjectId ("server");
this->airplane_poa_->activate_object_with_id (server_id.in (),
this->server_impl_);
obj = this->airplane_poa_->id_to_reference (server_id.in ());
CORBA::String_var ior =
this->orb_->object_to_string (obj.in ());
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG, "The ImRified IOR is: <%C>\n", ior.in ()));
TAO_Root_POA* tmp_poa = dynamic_cast<TAO_Root_POA*>(airplane_poa_.in());
obj = tmp_poa->id_to_reference_i (server_id.in (), false);
CORBA::String_var plain_ior =
this->orb_->object_to_string (obj.in ());
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG, "The plain IOR is: <%C>\n", plain_ior.in ()));
// Note : The IORTable will only be used for those clients who try to
// invoke indirectly using a simple object_key reference
// like "corbaloc::localhost:8888/airplane_server".
obj = this->orb_->resolve_initial_references ("IORTable");
IORTable::Table_var adapter =
IORTable::Table::_narrow (obj.in ());
ACE_ASSERT(! CORBA::is_nil (adapter.in ()));
adapter->bind (this->server_name_.c_str(), plain_ior.in ());
this->poa_manager_->activate ();
if (this->ior_output_file_)
{
ACE_OS::fprintf (this->ior_output_file_, "%s", ior.in ());
ACE_OS::fclose (this->ior_output_file_);
}
if (this->pid_output_file_)
{
int pid = static_cast<int> (ACE_OS::getpid ());
ACE_OS::fprintf (this->pid_output_file_, "%d\n", pid);
ACE_OS::fclose (this->pid_output_file_);
}
//.........这里部分代码省略.........
示例7: Hello
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try
{
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
if (parse_args(argc, argv) != 0)
return 1;
CORBA::Object_var poa_object =
orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa =
PortableServer::POA::_narrow (poa_object.in ());
if (CORBA::is_nil (root_poa.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Panic: nil RootPOA\n"),
1);
Hello *hello_impl = 0;
ACE_NEW_RETURN (hello_impl,
Hello (orb.in ()),
1);
PortableServer::ObjectId_var id =
root_poa->activate_object (hello_impl);
CORBA::Object_var object = root_poa->id_to_reference (id.in ());
Test::Hello_var hello = Test::Hello::_narrow (object.in ());
CORBA::Object_var table_obj = orb->resolve_initial_references("IORTable");
IORTable::Table_var table = IORTable::Table::_narrow(table_obj.in());
for (int i = 1; i <= cache_size; ++i)
{
CORBA::String_var ior_string = orb->object_to_string (object.in());
ACE_DEBUG((LM_DEBUG, ACE_TEXT("Registering object %d with IOR string: %C\n"),
i, ior_string.in ()));
char identifier[256];
ACE_OS::sprintf (identifier, "TransportCacheTest%d", i);
table->bind(identifier, ior_string.in());
}
PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
poa_manager->activate ();
orb->run ();
ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
root_poa->destroy (1, 1);
orb->destroy ();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Exception caught:");
return 1;
}
return 0;
}
示例8: server_impl
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try
{
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
CORBA::Object_var poa_object =
orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa =
PortableServer::POA::_narrow (poa_object.in ());
if (CORBA::is_nil (root_poa.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the POA.\n"),
1);
PortableServer::POAManager_var poa_manager =
root_poa->the_POAManager ();
if (parse_args (argc, argv) != 0)
return 1;
Simple_Server_i server_impl (orb.in ());
PortableServer::ObjectId_var id =
root_poa->activate_object (&server_impl);
CORBA::Object_var object = root_poa->id_to_reference (id.in ());
Simple_Server_var server =
Simple_Server::_narrow (object.in ());
CORBA::String_var ior =
orb->object_to_string (server.in ());
CORBA::Object_var table_object =
orb->resolve_initial_references("IORTable");
IORTable::Table_var table =
IORTable::Table::_narrow (table_object.in ());
if (CORBA::is_nil (table.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the IORTable.\n"),
1);
table->bind ("Simple_Server", ior.in ());
//ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot open output file for writing IOR: %s",
ior_output_file),
1);
ACE_OS::fprintf (output_file, "%s", ior.in ());
ACE_OS::fclose (output_file);
poa_manager->activate ();
orb->run ();
ACE_DEBUG ((LM_DEBUG, "(%P|%t)server: event loop finished\n"));
// If expect_servant_calls is 0, it means it's the request forward looping case so the
// servant continue receiving calls from a single request. We can not determine how many
// servant calls but it should be more than the number of requests.
if ((expect_servant_calls == 0 && (server_impl.ncalls () > num_requests))
|| (expect_servant_calls > 0 && (server_impl.ncalls () == expect_servant_calls)))
{
return 0;
}
else
ACE_ERROR_RETURN ((LM_ERROR,
"server: Test failed - expected %d servant calls but got %d calls \n",
expect_servant_calls, server_impl.ncalls ()),
1);
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Exception caught:");
return 1;
}
return 0;
}
示例9: tie_safety
int
TAO_IFR_Server::create_repository (void)
{
TAO_ComponentRepository_i *impl = 0;
ACE_NEW_THROW_EX (
impl,
TAO_ComponentRepository_i (
this->orb_.in (),
this->root_poa_,
this->config_
),
CORBA::NO_MEMORY ()
);
auto_ptr<TAO_ComponentRepository_i> safety (impl);
TAO_IFR_Service_Utils::repo_ = impl;
POA_CORBA::ComponentIR::Repository_tie<TAO_ComponentRepository_i> *impl_tie
= 0;
ACE_NEW_THROW_EX (
impl_tie,
POA_CORBA::ComponentIR::Repository_tie<TAO_ComponentRepository_i> (
impl,
this->repo_poa_,
1
),
CORBA::NO_MEMORY ()
);
PortableServer::ServantBase_var tie_safety (impl_tie);
safety.release ();
this->repo_poa_->set_servant (impl_tie);
PortableServer::ObjectId_var oid =
PortableServer::string_to_ObjectId ("");
CORBA::Object_var obj =
this->repo_poa_->create_reference_with_id (
oid.in (),
"IDL:omg.org/CORBA/ComponentIR/ComponentRepository:1.0"
);
CORBA::Repository_ptr repo_ref =
CORBA::Repository::_narrow (obj.in ());
// Initialize the repository.
int status = impl->repo_init (repo_ref,
this->repo_poa_);
if (status != 0)
{
return -1;
}
// Save and output the IOR string.
this->ifr_ior_ =
this->orb_->object_to_string (repo_ref);
CORBA::Object_var table_object =
this->orb_->resolve_initial_references ("IORTable");
IORTable::Table_var adapter =
IORTable::Table::_narrow (table_object.in ());
if (CORBA::is_nil (adapter.in ()))
{
ORBSVCS_ERROR_RETURN ((LM_ERROR, "Nil IORTable\n"), -1);
}
else
{
adapter->bind ("InterfaceRepository",
this->ifr_ior_.in ());
}
// Add the repository to the ORB's table of initialized object references.
this->orb_->register_initial_reference ("InterfaceRepository",
repo_ref);
// Write our IOR to a file.
FILE *output_file_ =
ACE_OS::fopen (OPTIONS::instance ()->ior_output_file (),
ACE_TEXT ("w"));
if (output_file_ == 0)
{
ORBSVCS_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("TAO_IFR_Server::create_repository - ")
ACE_TEXT ("can't open IOR output ")
ACE_TEXT ("file for writing\n")),
-1);
}
ACE_OS::fprintf (output_file_,
"%s\n",
this->ifr_ior_.in ());
//.........这里部分代码省略.........
示例10: Messenger_i
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try {
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
PortableServer::POAManager_var mgr = root_poa->the_POAManager();
const char* poa_name = "MessengerService";
PortableServer::POA_var messenger_poa = createPOA(root_poa.in(), poa_name);
Terminator terminator;
if (terminator.open (0) == -1)
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("main Error opening terminator\n")),-1);
PortableServer::Servant_var<Messenger_i> messenger_servant =
new Messenger_i(orb.in(), terminator);
PortableServer::ObjectId_var object_id =
PortableServer::string_to_ObjectId("messenger_object");
//
// Activate the servant with the messenger POA,
// obtain its object reference, and get a
// stringified IOR.
//
messenger_poa->activate_object_with_id(object_id.in(), messenger_servant.in());
//
// Create binding between "MessengerService" and
// the messenger object reference in the IOR Table.
// Use a TAO extension to get the non imrified poa
// to avoid forwarding requests back to the ImR.
TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(messenger_poa.in());
obj = tpoa->id_to_reference_i(object_id.in(), false);
CORBA::String_var messenger_ior = orb->object_to_string(obj.in());
obj = orb->resolve_initial_references("IORTable");
IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
table->bind(poa_name, messenger_ior.in());
//
// This server is now ready to run.
// This version does not create an IOR
// file as demonstrated in the
// Developer's Guide. It assumes that
// users create IORs for the client using
// the tao_imr utility.
//
//
// Stop discarding requests.
//
mgr->activate();
std::cout << "Messenger server ready." << std::endl;
orb->run();
std::cout << "Messenger server shutting down." << std::endl;
root_poa->destroy(1,1);
orb->destroy();
ACE_Message_Block *mb;
ACE_NEW_RETURN(mb, ACE_Message_Block(0, ACE_Message_Block::MB_HANGUP), -1);
terminator.putq(mb);
terminator.wait();
}
catch(const CORBA::Exception& ex) {
std::cerr << "Server main() Caught CORBA::Exception" << ex << std::endl;
return 1;
}
return 0;
}
示例11: server_impl
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try
{
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
CORBA::Object_var poa_object =
orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa =
PortableServer::POA::_narrow (poa_object.in ());
if (CORBA::is_nil (root_poa.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the POA.\n"),
1);
PortableServer::POAManager_var poa_manager =
root_poa->the_POAManager ();
if (parse_args (argc, argv) != 0)
return 1;
Simple_Server_i server_impl (orb.in ());
PortableServer::ObjectId_var id =
root_poa->activate_object (&server_impl);
CORBA::Object_var object = root_poa->id_to_reference (id.in ());
Simple_Server_var server =
Simple_Server::_narrow (object.in ());
CORBA::String_var ior =
orb->object_to_string (server.in ());
CORBA::Object_var table_object =
orb->resolve_initial_references("IORTable");
IORTable::Table_var table =
IORTable::Table::_narrow (table_object.in ());
if (CORBA::is_nil (table.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the IORTable.\n"),
1);
table->bind ("Simple_Server", ior.in ());
//ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot open output file for writing IOR: %s",
ior_output_file),
1);
ACE_OS::fprintf (output_file, "%s", ior.in ());
ACE_OS::fclose (output_file);
poa_manager->activate ();
orb->run ();
ACE_DEBUG ((LM_DEBUG, "(%P|%t)server: event loop finished\n"));
root_poa->destroy (1, 1);
orb->destroy ();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Exception caught:");
return 1;
}
return 0;
}
示例12: cvt
//.........这里部分代码省略.........
CORBA::String_var federator_ior;
if (federator_.id().overridden()) {
oid = PortableServer::string_to_ObjectId("Federator");
info_poa->activate_object_with_id(oid, &federator_);
obj = info_poa->id_to_reference(oid);
federator = OpenDDS::Federator::Manager::_narrow(obj);
federator_ior = orb_->object_to_string(federator);
// Add a local repository reference that can be returned via a
// remote call to a peer.
this->federator_.localRepo(info_repo);
// It should be safe to initialize the federation mechanism at this
// point. What we really needed to wait for is the initialization of
// the service components - like the DomainParticipantFactory and the
// repository bindings.
// N.B. This is done *before* being added to the IOR table to avoid any
// races with an eager client.
this->federator_.orb(this->orb_);
//
// Add the federator to the info_servant update manager as an
// additional updater interface to be called.
// N.B. This needs to be done *after* the call to load_domains()
// since that is where the update manager is initialized in the
// info startup sequencing.
this->info_servant_->add(&this->federator_);
}
// Grab the IOR table.
CORBA::Object_var table_object =
this->orb_->resolve_initial_references("IORTable");
IORTable::Table_var adapter = IORTable::Table::_narrow(table_object);
if (CORBA::is_nil(adapter)) {
ACE_ERROR((LM_ERROR, ACE_TEXT("Nil IORTable\n")));
} else {
adapter->bind(OpenDDS::Federator::REPOSITORY_IORTABLE_KEY, objref_str);
if (this->federator_.id().overridden()) {
// Bind to '/Federator'
adapter->bind(OpenDDS::Federator::FEDERATOR_IORTABLE_KEY, federator_ior);
// Bind to '/Federator/1382379631'
std::stringstream buffer(OpenDDS::Federator::FEDERATOR_IORTABLE_KEY);
buffer << "/" << std::dec << this->federatorConfig_.federationDomain();
adapter->bind(buffer.str().c_str(), federator_ior);
}
}
FILE* output_file = ACE_OS::fopen(this->ior_file_.c_str(), ACE_TEXT("w"));
if (output_file == 0) {
ACE_ERROR((LM_ERROR, ACE_TEXT("ERROR: Unable to open IOR file: %s\n"),
ior_file_.c_str()));
throw InitError("Unable to open IOR file.");
}
ACE_OS::fprintf(output_file, "%s", objref_str.in());
ACE_OS::fclose(output_file);
// Initial federation join if specified on command line.
if (this->federator_.id().overridden()
&& !this->federatorConfig_.federateIor().empty()) {
if (OpenDDS::DCPS::DCPS_debug_level > 0) {
ACE_DEBUG((LM_DEBUG,
ACE_TEXT("(%P|%t) INFO: DCPSInfoRepo::init() - ")
ACE_TEXT("joining federation with repository %s\n"),
this->federatorConfig_.federateIor().c_str()));
}
obj = this->orb_->string_to_object(
this->federatorConfig_.federateIor().c_str());
if (CORBA::is_nil(obj)) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: could not resolve %s for initial federation.\n"),
this->federatorConfig_.federateIor().c_str()));
throw InitError("Unable to resolve IOR for initial federation.");
}
OpenDDS::Federator::Manager_var peer =
OpenDDS::Federator::Manager::_narrow(obj);
if (CORBA::is_nil(peer)) {
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: could not narrow %s.\n"),
this->federatorConfig_.federateIor().c_str()));
throw InitError("Unable to narrow peer for initial federation.");
}
// Actually join.
peer->join_federation(federator,
this->federatorConfig_.federationDomain());
}
}
示例13: owner_transfer
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
try
{
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
CORBA::Object_var poa_object =
orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa =
PortableServer::POA::_narrow (poa_object.in ());
if (CORBA::is_nil (root_poa.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Panic: nil RootPOA\n"),
1);
PortableServer::POAManager_var poa_manager =
root_poa->the_POAManager ();
if (parse_args (argc, argv) != 0)
return 1;
Hello *hello_impl;
ACE_NEW_RETURN (hello_impl,
Hello (orb.in ()),
1);
PortableServer::ServantBase_var owner_transfer(hello_impl);
PortableServer::ObjectId_var id =
root_poa->activate_object (hello_impl);
CORBA::Object_var object = root_poa->id_to_reference (id.in ());
Test::Hello_var hello =
Test::Hello::_narrow (object.in ());
CORBA::String_var ior =
orb->object_to_string (hello.in ());
// Output the IOR to the <ior_output_file>
FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot open output file for writing IOR: %s",
ior_output_file),
1);
ACE_OS::fprintf (output_file, "%s", ior.in ());
ACE_OS::fclose (output_file);
CORBA::Object_var table_object =
orb->resolve_initial_references ("IORTable");
IORTable::Table_var adapter =
IORTable::Table::_narrow (table_object.in ());
if (CORBA::is_nil (adapter.in ()))
{
ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
}
else
{
adapter->bind ("pcs_test", ior.in());
}
poa_manager->activate ();
orb->run ();
ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
root_poa->destroy (1, 1);
orb->destroy ();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Exception caught:");
return 1;
}
return 0;
}
示例14: main
//.........这里部分代码省略.........
policy_list[2] = root_poa->create_id_assignment_policy(PortableServer::USER_ID);
policy_list[3] = root_poa->create_servant_retention_policy(PortableServer::NON_RETAIN);
policy_list[4] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
// create a ACSDaemon POA with policies
PortableServer::POA_var poa = root_poa->create_POA("DaemonCallback", poa_manager.in(), policy_list);
// destroy policies
for (CORBA::ULong i = 0; i < policy_list.length(); ++i)
{
CORBA::Policy_ptr policy = policy_list[i];
policy->destroy();
}
// set as default servant
poa->set_servant(sc);
// create reference
PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("DaemonCallback");
pobj = poa->create_reference_with_id (oid.in(), sc->_interface_repository_id());
CORBA::String_var m_ior = orb->object_to_string(pobj.in());
// bind to IOR table
CORBA::Object_var table_object = orb->resolve_initial_references("IORTable");
IORTable::Table_var adapter = IORTable::Table::_narrow(table_object.in());
if (CORBA::is_nil(adapter.in()))
{
ACS_SHORT_LOG ((LM_ERROR, "Nil IORTable"));
return -1;
}
else
{
adapter->bind("DaemonCallback", m_ior.in());
}
// activate POA
poa_manager->activate();
ACS_SHORT_LOG((LM_INFO, "%s is waiting for incoming requests.", "DaemonCallback"));
// construct default one
if (daemonRef.length() == 0) {
if (hostName.length() == 0) {
hostName = ACSPorts::getIP();
}
daemonRef = "corbaloc::";
daemonRef =
daemonRef + hostName + ":" +
ACSPorts::getServicesDaemonPort().c_str() +
"/" + ::acsdaemon::servicesDaemonServiceName;
ACS_SHORT_LOG((LM_INFO,
"Using local ACS Services Daemon reference: '%s'",
daemonRef.c_str()));
} else {
ACS_SHORT_LOG((LM_INFO,
"ACS Services Daemon reference obtained via command line: '%s'",
daemonRef.c_str()));
}
CORBA::Object_var obj = orb->string_to_object(daemonRef.c_str());
if (CORBA::is_nil(obj.in())) {
ACS_SHORT_LOG((LM_INFO, "Failed to resolve reference '%s'.",
daemonRef.c_str()));
示例15: if
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
int server_num = 0;
int die_on_ping = 1;
int ping_count = 0;
for (int i = 1; i < argc; i++)
{
ACE_TCHAR *c = argv[i];
if (ACE_OS::strcasecmp (ACE_TEXT ("-n"), c) == 0)
{
server_num = ACE_OS::atoi (argv[++i]);
}
else if (ACE_OS::strcasecmp (ACE_TEXT ("-?"),c) == 0)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("usage: %C ")
ACE_TEXT ("-n Number of the server\n"),
argv[0]));
return 1;
}
}
Server_ORBInitializer * temp_initializer;
ACE_NEW_RETURN (temp_initializer,
Server_ORBInitializer (&ping_count),
-1); // No exceptions yet!
PortableInterceptor::ORBInitializer_var initializer =
temp_initializer;
PortableInterceptor::register_orb_initializer (initializer.in ());
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
PortableServer::POAManager_var mgr = root_poa->the_POAManager();
ACE_CString poa_name_base = ACE_CString("TestObject_") + toStr (server_num);
PortableServer::POA_var test_poa;
test_poa = createPOA(root_poa.in (), true, poa_name_base.c_str ());
temp_initializer->set_poa (test_poa.in());
mgr->activate();
PortableServer::Servant_var<Test_i> test_servant =
new Test_i(server_num);
PortableServer::ObjectId_var object_id =
PortableServer::string_to_ObjectId("test_object");
//
// Activate the servant with the test POA,
// obtain its object reference, and get a
// stringified IOR.
//
test_poa->activate_object_with_id(object_id.in(), test_servant.in());
//
// Create binding between "TestService" and
// the test object reference in the IOR Table.
// Use a TAO extension to get the non imrified poa
// to avoid forwarding requests back to the ImR.
TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
obj = tpoa->id_to_reference_i(object_id.in(), false);
CORBA::String_var test_ior = orb->object_to_string(obj.in());
obj = orb->resolve_initial_references("IORTable");
IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
table->bind(poa_name_base.c_str (), test_ior.in());
ACE_DEBUG ((LM_DEBUG, "Started Server %s \n",
poa_name_base.c_str()));
{
ACE_CString status_file = poa_name_base + ACE_CString(".status");
ofstream out(status_file.c_str ());
out << "started" << endl;
}
while (ping_count < die_on_ping)
{
orb->perform_work ();
}
root_poa->destroy(1,1);
orb->destroy();
}
catch(const CORBA::Exception& ex) {
ex._tao_print_exception ("Server main()");
return 1;
}
return 0;
//.........这里部分代码省略.........