本文整理汇总了C++中cosnaming::NamingContext_var::resolve方法的典型用法代码示例。如果您正苦于以下问题:C++ NamingContext_var::resolve方法的具体用法?C++ NamingContext_var::resolve怎么用?C++ NamingContext_var::resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cosnaming::NamingContext_var
的用法示例。
在下文中一共展示了NamingContext_var::resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Web_Server::Iterator_Factory_ptr
get_iterator (CORBA::ORB_ptr o)
{
CORBA::ORB_var orb = CORBA::ORB::_duplicate (o);
// Get a reference to the Name Service.
CORBA::Object_var obj =
orb->resolve_initial_references ("NameService");
// Narrow to a Naming Context
CosNaming::NamingContext_var nc =
CosNaming::NamingContext::_narrow (obj.in ());
if (CORBA::is_nil (obj.in ()))
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Nil reference to Name Service\n")));
return Web_Server::Iterator_Factory::_nil ();
}
// Create a name.
CosNaming::Name name;
name.length (1);
name[0].id = CORBA::string_dup ("Iterator_Factory");
name[0].kind = CORBA::string_dup ("");
obj = nc->resolve (name);
Web_Server::Iterator_Factory_ptr factory =
Web_Server::Iterator_Factory::_narrow (obj.in ());
return factory;
}
示例2: throw
void
VOmniORBHelper::nsRegisterObject(CORBA::Object_ptr obj,
const char* program, const char* object,
int telescopenumber)
throw(CORBA::SystemException,
CosNaming::NamingContext::NotFound,
CosNaming::NamingContext::CannotProceed,
CosNaming::NamingContext::InvalidName,
CosNaming::NamingContext::AlreadyBound)
{
ZThread::Guard<ZThread::RecursiveMutex> guard(m_mutex);
CosNaming::NamingContext_var root = nsRootContext();
CosNaming::Name_var name =
nsPathToObjectName(program, object, telescopenumber);
for(unsigned int n=0; n<name->length()-1; n++)
{
CosNaming::Name_var child_name = name;
child_name->length(n+1);
try
{
CORBA::Object_var object = root->resolve(child_name);
}
catch(CosNaming::NamingContext::NotFound)
{
CosNaming::NamingContext_var
child = root->bind_new_context(child_name);
}
}
root->rebind(name,obj);
}
示例3: getOnlineViewer
OnlineViewer_var getOnlineViewer(CosNaming::NamingContext_var cxt)
{
CosNaming::Name ncName;
ncName.length(1);
ncName[0].id = CORBA::string_dup("OnlineViewer");
ncName[0].kind = CORBA::string_dup("");
OnlineViewer_var onlineViewer = NULL;
try {
onlineViewer = OnlineViewer::_narrow(cxt->resolve(ncName));
} catch(const CosNaming::NamingContext::NotFound &exc) {
std::cerr << "OnlineViewer not found: ";
switch(exc.why) {
case CosNaming::NamingContext::missing_node:
std::cerr << "Missing Node" << std::endl;
case CosNaming::NamingContext::not_context:
std::cerr << "Not Context" << std::endl;
break;
case CosNaming::NamingContext::not_object:
std::cerr << "Not Object" << std::endl;
break;
}
return 0;
} catch(CosNaming::NamingContext::CannotProceed &exc) {
std::cerr << "Resolve OnlineViewer CannotProceed" << std::endl;
return 0;
} catch(CosNaming::NamingContext::AlreadyBound &exc) {
std::cerr << "Resolve OnlineViewer InvalidName" << std::endl;
return 0;
}
return onlineViewer;
}
示例4: checkCorbaServer
X_ptr checkCorbaServer(std::string n, CosNaming::NamingContext_var &cxt)
{
CosNaming::Name ncName;
ncName.length(1);
ncName[0].id = CORBA::string_dup(n.c_str());
ncName[0].kind = CORBA::string_dup("");
X_ptr srv = NULL;
try {
srv = X::_narrow(cxt->resolve(ncName));
} catch(const CosNaming::NamingContext::NotFound &exc) {
std::cerr << n << " not found: ";
switch(exc.why) {
case CosNaming::NamingContext::missing_node:
std::cerr << "Missing Node" << std::endl;
case CosNaming::NamingContext::not_context:
std::cerr << "Not Context" << std::endl;
break;
case CosNaming::NamingContext::not_object:
std::cerr << "Not Object" << std::endl;
break;
}
return (X_ptr)NULL;
} catch(CosNaming::NamingContext::CannotProceed &exc) {
std::cerr << "Resolve " << n << " CannotProceed" << std::endl;
} catch(CosNaming::NamingContext::AlreadyBound &exc) {
std::cerr << "Resolve " << n << " InvalidName" << std::endl;
}
return srv;
}
示例5: getModelLoader
ModelLoader_var hrp::getModelLoader(CosNaming::NamingContext_var cxt)
{
CosNaming::Name ncName;
ncName.length(1);
ncName[0].id = CORBA::string_dup("ModelLoader");
ncName[0].kind = CORBA::string_dup("");
ModelLoader_var modelLoader = NULL;
try {
modelLoader = ModelLoader::_narrow(cxt->resolve(ncName));
modelLoader->_non_existent();
} catch(const CosNaming::NamingContext::NotFound &exc) {
std::cerr << "ModelLoader not found: ";
switch(exc.why) {
case CosNaming::NamingContext::missing_node:
std::cerr << "Missing Node" << std::endl;
case CosNaming::NamingContext::not_context:
std::cerr << "Not Context" << std::endl;
break;
case CosNaming::NamingContext::not_object:
std::cerr << "Not Object" << std::endl;
break;
}
modelLoader = ModelLoader::_nil();
} catch(CosNaming::NamingContext::CannotProceed &exc) {
std::cerr << "Resolve ModelLoader CannotProceed" << std::endl;
modelLoader = ModelLoader::_nil();
} catch(CosNaming::NamingContext::AlreadyBound &exc) {
std::cerr << "Resolve ModelLoader InvalidName" << std::endl;
modelLoader = ModelLoader::_nil();
} catch(...){
modelLoader = ModelLoader::_nil();
}
return modelLoader;
}
示例6: 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;
}
示例7: getObjectReference
static CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr orb) {
CosNaming::NamingContext_var rootContext;
try {
// Obtain a reference to the root context of the Name service:
CORBA::Object_var obj;
obj = orb->resolve_initial_references("NameService");
// Narrow the reference returned.
rootContext = CosNaming::NamingContext::_narrow(obj);
if( CORBA::is_nil(rootContext) ) {
cerr << "Failed to narrow the root naming context." << endl;
return CORBA::Object::_nil();
}
} catch (CORBA::NO_RESOURCES&) {
cerr << "Caught NO_RESOURCES exception. You must configure omniORB "
<< "with the location" << endl
<< "of the naming service." << endl;
return 0;
} catch(CORBA::ORB::InvalidName& ex) {
// This should not happen!
cerr << "Service required is invalid [does not exist]." << endl;
return CORBA::Object::_nil();
}
// Create a name object, containing the name test/context:
CosNaming::Name name;
name.length(2);
name[0].id = (const char*) "test"; // string copied
name[0].kind = (const char*) "my_context"; // string copied
name[1].id = (const char*) "IdServer";
name[1].kind = (const char*) "Object";
// Note on kind: The kind field is used to indicate the type
// of the object. This is to avoid conventions such as that used
// by files (name.type -- e.g. test.ps = postscript etc.)
try {
// Resolve the name to an object reference.
return rootContext->resolve(name);
} catch(CosNaming::NamingContext::NotFound& ex) {
// This exception is thrown if any of the components of the
// path [contexts or the object] aren't found:
cerr << "Context not found." << endl;
} catch(CORBA::TRANSIENT& ex) {
cerr << "Caught system exception TRANSIENT -- unable to contact the "
<< "naming service." << endl
<< "Make sure the naming server is running and that omniORB is "
<< "configured correctly." << endl;
} catch(CORBA::SystemException& ex) {
cerr << "Caught a CORBA::" << ex._name()
<< " while using the naming service." << endl;
return 0;
}
return CORBA::Object::_nil();
}
示例8: ACE_TMAIN
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
try
{
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var rootObj =
orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var rootContext =
CosNaming::NamingContext::_narrow(rootObj.in());
CosNaming::Name name;
name.length (1);
name[0].id = CORBA::string_dup ("MessengerService");
CORBA::Object_var messengerObj = rootContext->resolve(name);
if (CORBA::is_nil(messengerObj.in())) {
std::cerr << "Nil Messenger reference" << std::endl;
return 1;
}
// Narrow
Messenger_var messenger = Messenger::_narrow(messengerObj.in());
if (CORBA::is_nil(messenger.in ())) {
std::cerr << "Argument is not a Messenger reference" << std::endl;
return 1;
}
CORBA::String_var message = CORBA::string_dup(
"We are experiencing network problems.");
messenger->send_message ("[email protected]",
"urgent",
message.inout());
message = CORBA::string_dup("Where can I get TAO?");
messenger->send_message ("[email protected]",
"OCI's Distribution of TAO",
message.inout());
message = CORBA::string_dup(
"Please contact [email protected] regarding your request.");
messenger->send_message ("[email protected]",
"OCI's Distribution of TAO",
message.inout());
}
catch(const CORBA::Exception& ex) {
std::cerr << "Caught a CORBA exception: " << ex << std::endl;
return 1;
}
std::cout << "MessengerClient: success" << std::endl;
return 0;
}
示例9: 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;
}
示例10: 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."));
}
}
}
}
示例11: getObjectReference
CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr orb, const char serviceName[])
{
CosNaming::NamingContext_var rootContext;
try
{
// Obtain a reference to the root context of the name service:
CORBA::Object_var initServ;
initServ = orb->resolve_initial_references("NameService");
// Narrow the object returned by resolve_initial_references() to a CosNaming::NamingContext
// object
rootContext = CosNaming::NamingContext::_narrow(initServ);
if (CORBA::is_nil(rootContext))
{
cerr << "Failed to narrow naming context." << endl;
return CORBA::Object::_nil();
}
}
catch (CORBA::ORB::InvalidName&)
{
cerr << "Name service does not exist." << endl;
return CORBA::Object::_nil();
}
// Create a name object, containing the name corejava/SysProp:
CosNaming::Name name;
name.length(1);
name[0].id = serviceName;
name[0].kind = "Object";
CORBA::Object_ptr obj;
try
{
// Resolve the name to an object reference, and assign the returned reference to a
// CORBA::Object:
obj = rootContext->resolve(name);
}
catch (CosNaming::NamingContext::NotFound&)
{
// This exception is thrown if any of the components of the path [contexts or the object]
// aren't found:
cerr << "Context not found." << endl;
return CORBA::Object::_nil();
}
return obj;
}
示例12: 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());
}
示例13: catch
/** Bind a context to the corba root, with a given name.
*/
void CorbaServerGeneric::
createContext( const std::string & contextStrName )
{
try {
/* Obtains a reference to the root context of the Name service
* and narrows the reference returned. */
CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::
_narrow(orb->resolve_initial_references("NameService"));
if( CORBA::is_nil(rootContext) )
{
std::cerr << "Failed to narrow the root naming context." << std::endl;
throw "TODO";
}
/* Create the name of the context. */
CosNaming::Name contextName;
contextName.length(1);
contextName[0].id = CORBA::string_dup(contextStrName.c_str());
contextName[0].kind = CORBA::string_dup("context");
/* Note on kind: The kind field is used to indicate the type
* of the object. This is to avoid conventions such as that used
* by files (name.type -- e.g. hpp.ps = postscript etc.). */
/* Bind a context called <contextName> to the root context. */
try{ hppContext = rootContext->bind_new_context(contextName); }
catch(CosNaming::NamingContext::AlreadyBound& ex)
{
/* If the context already exists, this exception will be raised.
* In this case, just resolve the name and assign hppContext
* to the object returned. */
hppContext = CosNaming::NamingContext::
_narrow(rootContext->resolve(contextName));
if( CORBA::is_nil(hppContext) )
{
std::cerr << "Failed to narrow naming context." << std::endl;
throw "TODO";
}
}
} HPP_RETHROW("Creating context");
return;
}
示例14: loadBodyFromModelLoader
int loadBodyFromModelLoader(::World* world, const char* name, const char *url, CosNaming::NamingContext_var cxt)
{
CosNaming::Name ncName;
ncName.length(1);
ncName[0].id = CORBA::string_dup("ModelLoader");
ncName[0].kind = CORBA::string_dup("");
ModelLoader_var modelLoader = NULL;
try {
modelLoader = ModelLoader::_narrow(cxt->resolve(ncName));
} catch(const CosNaming::NamingContext::NotFound &exc) {
std::cerr << "ModelLoader not found: ";
switch(exc.why) {
case CosNaming::NamingContext::missing_node:
std::cerr << "Missing Node" << std::endl;
case CosNaming::NamingContext::not_context:
std::cerr << "Not Context" << std::endl;
break;
case CosNaming::NamingContext::not_object:
std::cerr << "Not Object" << std::endl;
break;
}
return 0;
} catch(CosNaming::NamingContext::CannotProceed &exc) {
std::cerr << "Resolve ModelLoader CannotProceed" << std::endl;
} catch(CosNaming::NamingContext::AlreadyBound &exc) {
std::cerr << "Resolve ModelLoader InvalidName" << std::endl;
}
BodyInfo_var bodyInfo;
try {
bodyInfo = modelLoader->getBodyInfo(url);
} catch(CORBA::SystemException& ex) {
std::cerr << "CORBA::SystemException raised by ModelLoader: " << ex._rep_id() << std::endl;
return 0;
} catch(ModelLoader::ModelLoaderException& ex){
std::cerr << "ModelLoaderException ( " << ex.description << ") : " << ex.description << std::endl;
}
if(CORBA::is_nil(bodyInfo)){
return 0;
}
return loadBodyFromBodyInfo(world, name, bodyInfo);
}
示例15: name
static CORBA::Object_ptr
get_distributor_reference (CORBA::ORB_ptr orb)
{
if (use_naming)
{
CORBA::Object_var tmp =
orb->resolve_initial_references ("NameService");
CosNaming::NamingContext_var pns =
CosNaming::NamingContext::_narrow (tmp.in ());
CosNaming::Name name (1);
name.length (1);
name[0].id = distributor_name.c_str ();
return pns->resolve (name);
}
else
// Read and destringify the Stock_Distributor object's IOR.
return orb->string_to_object (ior.c_str ());
}