taoadderserver.cpp

来自「C++实现的CORBA分布式程序」· C++ 代码 · 共 70 行

CPP
70
字号
#include "ExampleInterfaces_i.h"#include <orbsvcs/CosNamingC.h>#include <orbsvcs/Naming/Naming_Client.h>#include <ace/streams.h>int main( int argc, char *argv[] ){  try   {	// Initialize CORBA Object Request Broker	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	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;	}	// Bind the Naming Context to a well known name so clients can find it by name.	// Interested parties can see the "well known" namespace's and interfaces that might 	// be available on a given NameService using a utility like nslist or nslister.	// It makes sense to use the IDL-defined Module (namespace) for the first entry...	CosNaming::Name name;    name.length(1);    name[0].id = CORBA::string_dup("ExampleInterfaces");	// Namespace "SLB.ExampleInterfaces"    try 	{      CORBA::Object_var dummy = root->resolve(name);    }    catch (CosNaming::NamingContext::NotFound& ) 	{	  // If the binding for that name does not already exist on NameService, then create it...      CosNaming::NamingContext_var dummy = root->bind_new_context(name);    }           // ... and to use the IDL-defined Interface (interface or class) for the second entry.    name.length(2);    name[1].id = CORBA::string_dup( "IAdder" );	// (interface) class "IAdder"	// Create a Servant (of the implimentation class), and bind the servant object type to the name.    ExampleInterfaces_IAdder_i adderServant;      PortableServer::ObjectId_var oid = poa->activate_object(&adderServant);	CORBA::Object_var adderServant_obj = poa->id_to_reference(oid.in());	root->rebind(name,adderServant_obj.in());        cout << "IAdder interface has been registered on the Naming Service" << endl;    // Accept requests    orb->run();    orb->destroy();  }  catch( CORBA::Exception& ex )   {    cerr << "Caught a CORBA exception: " << ex << endl;    return 1;  }  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?