本文整理汇总了C++中cosnaming::NamingContext_var::in方法的典型用法代码示例。如果您正苦于以下问题:C++ NamingContext_var::in方法的具体用法?C++ NamingContext_var::in怎么用?C++ NamingContext_var::in使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cosnaming::NamingContext_var
的用法示例。
在下文中一共展示了NamingContext_var::in方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnContextPopupBindContext
void CNamingTreeCtrl::OnContextPopupBindContext()
{
// TODO: Add your command handler code here
CBindDialog Dialog(true, m_pORB);
if(Dialog.DoModal() != IDOK)
{
return;
}
try
{
CNamingObject* pObject = GetTreeObject();
CosNaming::NamingContext_var Context = pObject->NamingContext();
if(CORBA::is_nil(Context.in ()))
{
return;
}
CosNaming::NamingContext_var NewContext = CosNaming::NamingContext::_narrow(Dialog.GetObject());
if(CORBA::is_nil(NewContext.in ()))
{
AfxMessageBox(ACE_TEXT ("Object is not a CosNaming::NamingContext"));
return;
}
Context->bind_context(Dialog.GetName(), NewContext);
OnContextPopupRefresh();
}
catch(CORBA::Exception& ex)
{
MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
}
}
示例2: OBJECT_NOT_EXIST
CosNaming::NamingContext_ptr
TAO_Hash_Naming_Context::bind_new_context (const CosNaming::Name& n)
{
// Check to make sure this object didn't have <destroy> method
// invoked on it.
if (this->destroyed_)
throw CORBA::OBJECT_NOT_EXIST ();
// Get the length of the name.
CORBA::ULong name_len = n.length ();
// Check for invalid name.
if (name_len == 0)
throw CosNaming::NamingContext::InvalidName();
// If we received compound name, resolve it to get the context in
// which the binding should take place, then perform the operation on
// target context.
if (name_len > 1)
{
CosNaming::NamingContext_var context = this->get_context (n);
CosNaming::Name simple_name;
simple_name.length (1);
simple_name[0] = n[name_len - 1];
return context->bind_new_context (simple_name);
}
// If we received a simple name, we need to bind it in this context.
// Stores our new Naming Context.
CosNaming::NamingContext_var result = CosNaming::NamingContext::_nil ();
// Create new context.
result = this->new_context ();
// Bind the new context to the name.
try
{
this->bind_context (n, result.in ());
}
catch (const CORBA::Exception&)
{
// If the bind() operation fails we must destroy the recently
// created context, should any exceptions be raised by the
// destroy() operation we want to ignore them.
{
try
{
result->destroy ();
}
catch (const CORBA::Exception&)
{
}
}
// Re-raise the exception in bind_context()
throw;
}
return result._retn ();
}
示例3: OnContextpopupBindnewcontext
void CNamingTreeCtrl::OnContextpopupBindnewcontext()
{
// TODO: Add your command handler code here
HTREEITEM hItem = GetSelectedItem();
CNamingObject* pObject = GetTreeObject(hItem);
CosNaming::NamingContext_var Context = pObject->NamingContext();
if(CORBA::is_nil(Context.in ()))
{
return;
}
CBindNewContext Dialog;
if(Dialog.DoModal() != IDOK)
{
return;
}
try
{
CosNaming::NamingContext_var NewContext = Context->new_context();
Context->bind_context(Dialog.GetName(), NewContext);
OnContextPopupRefresh();
}
catch(CORBA::Exception& ex)
{
MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
}
}
示例4: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
//Get reference to Root POA
CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );
// Activate POA Manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Find the Naming Service
obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow(obj.in());
if (CORBA::is_nil(root.in())) {
std::cerr << "Nil Naming Context reference" << std::endl;
return 1;
}
// Bind the example Naming Context, if necessary
CosNaming::Name name;
name.length( 1 );
name[0].id = CORBA::string_dup("example");
try {
obj = root->resolve(name);
}
catch(const CosNaming::NamingContext::NotFound&) {
CosNaming::NamingContext_var dummy = root->bind_new_context(name);
}
// Bind the Messenger object
name.length(2);
name[1].id = CORBA::string_dup("Messenger");
// Create an object
PortableServer::Servant_var<Messenger_i> servant = new Messenger_i;
PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
obj = poa->id_to_reference(oid.in());
Messenger_var messenger = Messenger::_narrow(obj.in());
root->rebind(name, messenger.in());
std::cout << "Messenger object bound in Naming Service" << std::endl;
// Accept requests
orb->run();
orb->destroy();
}
catch(const CORBA::Exception& ex) {
std::cerr << "server: Caught a CORBA::Exception: " << ex << std::endl;
return 1;
}
return 0;
}
示例5: main
int main( int argc, char *argv[] )
{
try
{
// Initialize the CORBA Object Request Broker
CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
// Find the CORBA Services Naming Service
CORBA::Object_var naming_obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var root = CosNaming::NamingContext::_narrow(naming_obj.in());
if(CORBA::is_nil(root.in()))
{
cerr << "Could not narrow NameService to NamingContext!" << endl;
throw 0;
}
// Resolve the desired object (ExampleInterfaces.IAdder).
// The module and interface bindings need to be the same here in the client as they
// are in the server.
CosNaming::Name name;
name.length(2);
name[0].id = CORBA::string_dup( "ExampleInterfaces" ); // IDL-defined Module (namespace)
name[1].id = CORBA::string_dup( "IAdder" ); // IDL-defined Interface (interface class)
CORBA::Object_var obj = root->resolve(name);
// Narrow to confirm that we have the interface we want.
ExampleInterfaces::IAdder_var iAdder = ExampleInterfaces::IAdder::_narrow(obj.in());
if (CORBA::is_nil(iAdder.in()))
{
cerr << "Could not narrow to an iAdder reference" << endl;
return 1;
}
// Now use the remote object...
cout << "Using a remote object that implements the IAdder interface..." << endl;
cout << endl;
double number1 = 0;
double number2 = 0;
double sum = 0;
while (true)
{
cout << "Enter the first number: ";
cin >> number1;
cout << "Enter the second number: ";
cin >> number2;
sum = iAdder->add(number1, number2);
cout << "The sum is: " << sum << endl;
cout << "------------------" << endl;
}
}
catch ( CORBA::Exception& ex ) {
cerr << "Caught a CORBA::Exception: " << ex << endl;
return 1;
}
return 0;
}
示例6: checkLogging
static void checkLogging(ACSDaemonContext * context, short instance)
{
if (!loggingSystemInitialized)
{
// we need msg_callback to get LoggingProxy
if (ACE_LOG_MSG->msg_callback () != 0 &&
context->hasConfigurationReference(instance, acsServices[NAMING_SERVICE].xmltag))
{
try
{
// we get via NS and not a manager (to support logging when manager is not running)
std::string nsReference = context->getConfigurationReference(instance, acsServices[NAMING_SERVICE].xmltag);
CORBA::Object_var nc_obj = context->getORB()->string_to_object(nsReference.c_str());
if (nc_obj.ptr() != CORBA::Object::_nil())
{
CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(nc_obj.in());
if (nc.ptr() != CosNaming::NamingContext::_nil())
{
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup("Log");
CORBA::Object_var obj = nc->resolve(name);
if (!CORBA::is_nil(obj.in()))
{
Logging::AcsLogService_var logger = Logging::AcsLogService::_narrow(obj.in());
LoggingProxy* lp = static_cast<LoggingProxy*>(ACE_LOG_MSG->msg_callback());
lp->setCentralizedLogger(logger.in());
lp->setNamingContext(nc.in());
loggingSystemInitialized = true;
ACS_SHORT_LOG((LM_DEBUG, "Remote logging system initialized."));
}
else
{
ACS_SHORT_LOG((LM_DEBUG, "Unable to resolve Log from the naming service."));
}
}
else
{
ACS_SHORT_LOG((LM_DEBUG, "Unable to narrow NamingContext."));
}
}
else
{
ACS_SHORT_LOG((LM_ERROR, "Unable to resolve naming service, invalid corbaloc reference: '%s'.", nsReference.c_str()));
}
}
catch (...)
{
ACS_SHORT_LOG((LM_DEBUG, "Unable to initialize logging sytem, unexpected exception caught."));
}
}
}
}
示例7: My_Test_Object
int
MT_Test::execute (TAO_Naming_Client &root_context)
{
if (CORBA::is_nil (this->orb_.in ()))
return -1;
// Create data which will be used by all threads.
// Dummy object instantiation.
My_Test_Object *test_obj_impl =
new My_Test_Object (CosNaming_Client::OBJ1_ID);
try
{
test_ref_ =
test_obj_impl->_this ();
test_obj_impl->_remove_ref ();
// Get the IOR for the Naming Service. Each thread can use it
// in <string_to_object> to create its own stub for the Naming
// Service. This 'trick' is necessary, because multiple threads
// cannot be using the same stub - bad things happen... This is
// just a way to give each thread its own stub.
CosNaming::NamingContext_var context =
root_context.get_context ();
name_service_ior_ =
orb_->object_to_string (context.in ());
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception (
"Unexpected exception while instantiating dummy");
return -1;
}
// Create a name for dummy.
test_name_.length (1);
test_name_[0].id = CORBA::string_dup ("Foo");
// Spawn threads, each of which will be executing svc ().
int status = this->activate (THR_NEW_LWP | THR_JOINABLE,
size_);
if (status == -1)
return -1;
status = this->wait ();
return status;
}
示例8: ClientInterceptor
void
ClientInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
{
// Find the Naming Service
CORBA::Object_var naming_obj =
info->resolve_initial_references("NameService");
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow(naming_obj.in());
if( CORBA::is_nil(root.in())) {
std::cerr << "Nil Naming Context reference" << std::endl;
ACE_ASSERT(false);
}
// Resolve the Messenger object
CosNaming::Name name;
name.length( 1 );
name[0].id = CORBA::string_dup( "Messenger" );
CORBA::Object_var obj = CORBA::Object::_nil();
while ( CORBA::is_nil( obj.in() ) ) {
try {
obj = root->resolve( name );
} catch (const CosNaming::NamingContext::NotFound&) {
// Sleep for a second and try again
ACE_OS::sleep(1);
}
}
Messenger_var messenger = Messenger::_narrow( obj.in() );
if( CORBA::is_nil( messenger.in() ) ) {
std::cerr << "Not a Messenger reference" << std::endl;
ACE_ASSERT(false);
}
// allocate slot
slot_ = info->allocate_slot_id();
// get PICurrent
CORBA::Object_var current_obj = info->resolve_initial_references("PICurrent");
current_ =
PortableInterceptor::Current::_narrow(current_obj.in());
// Create and register the request interceptors.
PortableInterceptor::ClientRequestInterceptor_var ci =
new ClientInterceptor(messenger, current_.in(), slot_);
info->add_client_request_interceptor (ci.in());
}
示例9: comp_name
CosNaming::NamingContext_ptr
TAO_Hash_Naming_Context::get_context (const CosNaming::Name &name)
{
CosNaming::NamingContext_var result =
CosNaming::NamingContext::_nil ();
// Create compound name to be resolved, i.e.,
// (<name> - last component). To avoid copying, we can just reuse
// <name>'s buffer, since we will not be modifying it.
CORBA::ULong name_len = name.length ();
CosNaming::Name comp_name (name.maximum (),
name_len - 1,
const_cast<CosNaming::NameComponent*> (name.get_buffer ()));
try
{
CORBA::Object_var context = this->resolve (comp_name);
// Try narrowing object reference to the NamingContext type.
result = CosNaming::NamingContext::_narrow (context.in ());
}
catch (CosNaming::NamingContext::NotFound& ex)
{
// Add the last component of the name, which was stripped before
// the call to resolve.
CORBA::ULong const rest_len = ex.rest_of_name.length () + 1;
ex.rest_of_name.length (rest_len);
ex.rest_of_name[rest_len - 1] = name[name_len - 1];
throw;
}
if (CORBA::is_nil (result.in ()))
{
CosNaming::Name rest;
rest.length (2);
rest[0] = name[name_len - 2];
rest[1] = name[name_len - 1];
throw CosNaming::NamingContext::NotFound(
CosNaming::NamingContext::not_context,
rest);
}
// Finally, if everything went smoothly, just return the resolved
// context.
return result._retn ();
}
示例10: while
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
ClientInitializer* temp_initializer = new ClientInitializer;
PortableInterceptor::ORBInitializer_var orb_initializer =
temp_initializer;
PortableInterceptor::register_orb_initializer (orb_initializer.in ());
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Client ORB");
// Now that the ORB is initialized (and subsequently the
// PICurrent), we can set the slot data on the PICurrent for our
// interceptor initializer.
temp_initializer->set_slot_data ();
CORBA::Object_var naming_obj =
orb->resolve_initial_references( "NameService" );
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow( naming_obj.in() );
if ( CORBA::is_nil(root.in() ) ) {
std::cerr << "Couldn't find Naming Service." << std::endl;
return 1;
}
// get Messenger
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup( "Messenger" );
CORBA::Object_var obj = CORBA::Object::_nil();
while ( CORBA::is_nil( obj.in() ) ) {
try {
obj = root->resolve( name );
} catch (const CosNaming::NamingContext::NotFound&) {
// Sleep for a second and try again
ACE_OS::sleep(1);
}
}
Messenger_var messenger = Messenger::_narrow( obj.in() );
if( CORBA::is_nil( messenger.in() ) ) {
std::cerr << "Not a Messenger reference" << std::endl;
return 1;
}
CORBA::String_var message = CORBA::string_dup( "Hello!" );
messenger->send_message( "TAO User", "TAO Test", message.inout() );
}
catch(const CORBA::Exception& ex)
{
std::cerr << "Caught CORBA exception: " << ex << std::endl;
return 1;
}
return 0;
}
示例11: CannotInitialize
void
ServerActivatorImpl::initialize()
{
try
{
CORBA::Object_var root_poa_obj = orb_->resolve_initial_references ("RootPOA");
root_poa_ = PortableServer::POA::_narrow (root_poa_obj);
}
catch (CORBA::ORB::InvalidName&)
{
std::cerr << "ServerActivatorImpl: Fatal error - no root POA available." << std::endl;
throw CannotInitialize();
}
catch (CORBA::SystemException&)
{
std::cerr << "ServerActivatorImpl: Fatal error - cannot narrow root POA." << std::endl;
throw CannotInitialize();
}
root_poa_manager_ = root_poa_->the_POAManager();
root_poa_manager_->activate();
//
// register in name service
//
CosNaming::NamingContext_var nameService;
//
// try to get naming service from config values
//
CORBA::Object_var obj;
std::string ns = Qedo::ConfigurationReader::instance()->lookup_config_value( "/General/NameService" );
if( !ns.empty() )
{
try
{
obj = orb_->string_to_object( ns.c_str() );
}
catch(...)
{
std::cerr << "ServerActivatorImpl: can't resolve NameService " << ns << std::endl;
throw CannotInitialize();
}
std::cout << "ServerActivatorImpl: NameService is " << ns << std::endl;
}
//
// try to get naming service from orb
//
else
{
try
{
obj = orb_->resolve_initial_references( "NameService" );
}
catch (const CORBA::ORB::InvalidName&)
{
std::cerr << "ServerActivatorImpl: can't resolve NameService" << std::endl;
throw CannotInitialize();
}
if (CORBA::is_nil(obj.in()))
{
std::cerr << "ServerActivatorImpl: NameService is a nil object reference" << std::endl;
throw CannotInitialize();
}
}
try
{
nameService = CosNaming::NamingContext::_narrow( obj.in() );
}
catch (const CORBA::Exception&)
{
std::cerr << "ServerActivatorImpl: NameService is not running" << std::endl;
throw CannotInitialize();
}
if( CORBA::is_nil(nameService.in()) )
{
std::cerr << "NameService is not a NamingContext object reference" << std::endl;
throw CannotInitialize();
}
CORBA::ULong context_offset;
if (global_context_used_)
{
context_offset = 1;
} else
{
context_offset= 0;
};
// Create the Qedo and Activators naming context
CosNaming::Name current_name;
current_name.length (1);
//.........这里部分代码省略.........
示例12: main
int main (int argc, char** argv) {
if (!init (argc, argv))
return 1;
// --------------------------------------------------------------------------
// Start HTTP server:
// --------------------------------------------------------------------------
for (size_t i = 1; i < argc; ++i) {
std::stringstream key;
key << "arg_" << i;
wspace.p[key.str()] = argv[i];
}
wspace.p["http_port"] = port;
using namespace codeare::service;
MongooseService& mg = MongooseService::Instance();
// --------------------------------------------------------------------------
// Start CORBA server:
// --------------------------------------------------------------------------
try {
streambuf* out;
streambuf* err;
ofstream log (logfile);
if (log.is_open()) {
out = cout.rdbuf(log.rdbuf());
err = cerr.rdbuf(log.rdbuf());
} else {
cout << "Could not open logfile " << logfile << "." << endl;
cout << "Exiting :(" << endl << endl;
return 1;
}
// Initialise ORB
const char* options[][2] = { { (char*)"traceLevel", debug}, /*{ (char*)"traceFile", logfile}, */{ 0, 0 } };
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options);
// Get reference to the RootPOA.
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var _poa = PortableServer::POA::_narrow(obj.in());
// Initialise servant
ReconServant* myReconServant = new ReconServant();
// Activate in RootPDA
PortableServer::ObjectId_var myReconServant_oid
= _poa->activate_object(myReconServant);
// Obtain object reference from servant and register in naming service
CORBA::Object_var SA_obj = myReconServant->_this();
// Obtain a reference to the object, and print it out as string IOR.
CORBA::String_var sior(orb->object_to_string(SA_obj.in()));
// Bind to the name server and lookup
CORBA::Object_var obj1=orb->resolve_initial_references("NameService");
assert(!CORBA::is_nil(obj1.in()));
// Get context
CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(obj1.in());
assert(!CORBA::is_nil(nc.in()));
// Resolve name
CosNaming::Name m_name;
m_name.length(1);
m_name[0].id=CORBA::string_dup(name);
nc->rebind (m_name,SA_obj.in());
// Activate POA manager
PortableServer::POAManager_var pmgr = _poa->the_POAManager();
pmgr->activate();
// Accept requests from clients
orb->run();
orb->destroy();
free(m_name[0].id); // str_dup does a malloc internally
cout.rdbuf(out);
cerr.rdbuf(err);
} catch(CORBA::SystemException&) {
cerr << "Caught CORBA::SystemException." << endl;
throw DS_SystemException();
} catch(CORBA::Exception&) {
cerr << "Caught CORBA::Exception." << endl;
throw DS_Exception();
} catch(omniORB::fatalException& fe) {
cerr << "Caught omniORB::fatalException:" << endl;
cerr << " file: " << fe.file() << endl;
cerr << " line: " << fe.line() << endl;
cerr << " mesg: " << fe.errmsg() << endl;
throw DS_FatalException();
} catch(...) {
cerr << "Caught unknown exception." << endl;
throw DS_Exception();
}
//.........这里部分代码省略.........
示例13: svc
int TestTask::svc()
{
try {
// Start the Naming Service tasks
namingServiceA_.activate();
// Wait for the Naming Service initialized.
namingServiceA_.waitInit();
namingServiceB_.activate();
// Wait for the Naming Service initialized.
namingServiceB_.waitInit();
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: ns.ior\n"),
1);
ACE_OS::fprintf (output_file, "%s", namingServiceA_.ior ());
ACE_OS::fclose (output_file);
// Get reference to Root POA
CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
// Activate POA Manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Find the Naming Service
obj = orb_->string_to_object (namingServiceB_.ior ());
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow(obj.in());
if (CORBA::is_nil(root.in())) {
ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n"));
return 1;
}
// Bind the example Naming Context, if necessary
CosNaming::NamingContext_var example_nc;
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup("example");
try
{
obj = root->resolve(name);
example_nc = CosNaming::NamingContext::_narrow(obj.in());
}
catch (const CosNaming::NamingContext::NotFound&)
{
example_nc = root->bind_new_context(name);
}
// Bind the Test object
name.length(2);
name[1].id = CORBA::string_dup("Hello");
// Create an object
Hello servant(orb_.in ());
PortableServer::ObjectId_var oid = poa->activate_object(&servant);
obj = poa->id_to_reference(oid.in());
root->rebind(name, obj.in());
ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n"));
name.length(1);
obj = orb_->string_to_object (namingServiceA_.ior ());
root = CosNaming::NamingContext::_narrow(obj.in());
root->bind_context (name, example_nc.in ());
ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n"));
if (shutdown_ns_)
{
namingServiceB_.end();
ACE_DEBUG ((LM_INFO, "Naming Service B shut down\n"));
}
// Create shutdown server
NsShutdown shutdown_servant(orb_.in ());
PortableServer::ObjectId_var shutdown_oid = poa->activate_object(&shutdown_servant);
obj = poa->id_to_reference(shutdown_oid.in());
CORBA::String_var ior = orb_->object_to_string (obj.in ());
output_file= ACE_OS::fopen (ior_shutdown_file, "w");
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot open output file %s for writing IOR: %C\n",
ior_shutdown_file,
ior.in ()),
1);
ACE_OS::fprintf (output_file, "%s", ior.in ());
ACE_OS::fclose (output_file);
// Normally we run the orb and the orb is shutdown by
// calling TestTask::end().
// Accept requests
orb_->run();
orb_->destroy();
//.........这里部分代码省略.........
示例14: svc
int MessengerTask::svc()
{
try {
// Get reference to Root POA
CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
// Activate POA Manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Find the Naming Service
obj = orb_->resolve_initial_references("NameService");
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow(obj.in());
if (CORBA::is_nil(root.in())) {
std::cerr << "Nil Naming Context reference" << std::endl;
return 1;
}
// Bind the example Naming Context, if necessary
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup("example");
try {
root->resolve(name);
}
catch(const CosNaming::NamingContext::NotFound&) {
root->bind_new_context(name);
}
// Bind the Messenger object
name.length(2);
name[1].id = CORBA::string_dup("Messenger");
// Create an object
PortableServer::Servant_var<Messenger_i> servant = new Messenger_i;
PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
obj = poa->id_to_reference(oid.in());
root->rebind(name, obj.in());
std::cout << "Messenger object bound in Naming Service" << std::endl;
// Normally we run the orb and the orb is shutdown by
// calling MessengerTask::end(). To simplify the coordination
// between the main thread and this Messenger thread, specify
// the time period to let the Messenger thread finish by itself.
// Accept requests
ACE_Time_Value tv(1);
orb_->run(tv);
orb_->destroy();
return 0;
}
catch(const CORBA::Exception& ex) {
std::cerr << "CORBA exception: " << ex << std::endl;
}
return -1;
}
示例15: name
int
FactoryDriver::start (int argc, ACE_TCHAR *argv [])
{
try
{
orb_ = CORBA::ORB_init (argc, argv);
if (this->parse_args (argc, argv) == -1)
return -1;
// Ref counted servants are on the heap..
ACE_NEW_RETURN (factory_servant_,
TAO_CosEventChannelFactory_i (),
-1);
CORBA::Object_var poa_object =
orb_->resolve_initial_references("RootPOA");
if (CORBA::is_nil (poa_object.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the POA.\n"),
-1);
root_poa_ =
PortableServer::POA::_narrow (poa_object.in ());
PortableServer::POAManager_var poa_manager =
root_poa_->the_POAManager ();
poa_manager->activate ();
// Initialization of the naming service.
if (naming_client_.init (orb_.in ()) != 0)
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Unable to initialize "
"the TAO_Naming_Client.\n"),
1);
CosNaming::NamingContext_var context =
naming_client_.get_context ();
if (factory_servant_->init (root_poa_.in (),
child_poa_name_,
context.in ()) != 0)
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) Unable to initialize "
"the factory.\n"),
1);
// activate the factory in the root poa.
factory_ = factory_servant_->_this ();
// Give the ownership to the POA.
factory_servant_->_remove_ref ();
CORBA::String_var
str = orb_->object_to_string (factory_.in ());
ACE_DEBUG ((LM_DEBUG,
"CosEvent_Service: The Cos Event Channel Factory IOR is <%s>\n",
str.in ()));
CosNaming::Name name (1);
name.length (1);
name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(factoryName_));
naming_client_->rebind (name,
factory_.in ());
ACE_DEBUG ((LM_DEBUG,
"Registered with the naming service as %s\n", factoryName_));
orb_->run ();
}
catch (const CORBA::UserException& ue)
{
ue._tao_print_exception ("cosecfactory: ");
return 1;
}
catch (const CORBA::SystemException& se)
{
se._tao_print_exception ("cosecfactory: ");
return 1;
}
return 0;
}