#include #include "tao/IORTable/IORTable.h" #include "poautil.h" #include "hello_i.h" using namespace std; CORBA::Object_ptr activate_servant( CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, IORTable::Table_ptr iortable, PortableServer::ServantBase *servant, const char *objectName, const char *objectAlias) { // create the object ID from the objectName. PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objectName); // activate the servant in the poa. poa->activate_object_with_id(oid.in(), servant); // get and display the corresponding corba object reference. CORBA::Object_var obj = poa->id_to_reference(oid.in()); CORBA::String_var ior = orb->object_to_string(obj.in()); cout << ior.in() << endl; // register objectAlias as an alias for the full object reference. iortable->bind(objectAlias, ior.in()); return obj._retn(); } int main(int argc, char **argv) { try { PortableServer::ServantBase_var servant1 = new hello_i("terriImpl"); PortableServer::ServantBase_var servant2 = new hello_i("berryImpl"); CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, ""); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(obj.in()); PortableServer::POAManager_var poaManager = rootPOA->the_POAManager(); PortableServer::POA_var myPOA = POAUtil::create_basic_POA( rootPOA.in(), poaManager.in(), "helloPOA", false, // not multi-threaded true); // is persistent cout << "activating poa" << endl; poaManager->activate(); // iortable is needed for using simplified corbaloc names. obj = orb->resolve_initial_references("IORTable"); IORTable::Table_var iortable = IORTable::Table::_narrow(obj.in()); // This activates the object in the poa with "terriImpl" as the object ID. // The last parameter, "StandardImplName/helloPOA/terriImpl", is set as an // alias for the object key, so that clients can use: // corbaloc::host:port/StandardImplName/helloPOA/terriImpl as an ior for // this object. You could also just use something short and simple like // "terriImpl", but the longer name is what a jacorb server would use by // default. CORBA::Object_var obj1 = activate_servant( orb.in(), myPOA.in(), iortable.in(), servant1.in(), "terriImpl", "StandardImplName/helloPOA/terriImpl"); CORBA::Object_var obj2 = activate_servant( orb.in(), myPOA.in(), iortable.in(), servant2.in(), "berryImpl", "StandardImplName/helloPOA/berryImpl"); cout << "calling orb run" << endl; orb->run(); } catch(CORBA::Exception &ex) { cerr << "CORBA Exception: " << ex << endl; } }