// //////////////////////////////////////////////////////// // Lecture on the CORBA Component Model, summer term 2003 // Assignment 6, Stephan Brumme, 702544 // // CORBA CCM HomeFinder (Set up service) // #include using namespace std; // CORBA's naming service #pragma warning (disable: 4267) #include #include "Helper.h" #include "HomeFinder_Impl.h" using namespace POA_HPI; // here we go ... int main(int argc, char* argv[]) { try { // initialize CORBA CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); ////////////////////////////////////// // POA related stuff cout << "Initialize POA ..." << endl; // first, locate the RootPOA CORBA::Object_var poaObject = orb->resolve_initial_references("RootPOA"); // gain access to the POA server and its manager PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObject); CorbaAssert(poa, "Failed to obtain POA server."); PortableServer::POAManager_var poaManager = poa->the_POAManager(); CorbaAssert(poaManager, "Failed to obtain POA manager."); ////////////////////////////////////// // Setup server cout << "Initialize server ..." << endl; // new HomeFinderImpl object HomeFinder_Impl* homeFinder = new HomeFinder_Impl(orb); // generate unique server ID PortableServer::ObjectId_var objectId = poa->activate_object(homeFinder); // extract reference CORBA::Object_var objectReference = poa->id_to_reference(objectId.in()); // for debug use: print IOR cout << orb->object_to_string(objectReference.in()) << endl; ////////////////////////////////////// // Connect to Naming Service cout << "Resolve Naming Service ..." << endl; // resolve naming service CORBA::Object_var namingService = orb->resolve_initial_references("NameService"); // not found ? CorbaAssert(namingService, "Couldn't locate the Naming Service."); // get the naming context CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService); // not found ? CorbaAssert(namingContext, "Couldn't locate the Naming Service."); CosNaming::Name newName; newName.length(1); newName[0].id = CORBA::string_dup("HomeFinder"); newName[0].kind = CORBA::string_dup("CCM"); // register server at the naming service try { //namingContext->bind(newName, objectReference); namingContext->rebind(newName, objectReference); } catch (CosNaming::NamingContext::NotFound&) { CorbaError("Naming context not found."); } catch (CosNaming::NamingContext::InvalidName&) { CorbaError("Invalid name."); } cout << "HomeFinder is ready." << endl; poaManager->activate(); orb->run(); // game over poa->destroy(true, true); delete homeFinder; return 0; } catch (CORBA::Exception&) { CorbaError("Corba failed to run properly."); } }