sources:
Helper.h (741 bytes)
HomeFinder.cpp (2.9k)
HomeFinder_Impl.cpp (3.2k)
HomeFinder_Impl.h (1.6k)
ccm.cpp (389.7k)
ccm.h (127.0k)
home.idl (11.9k)
home_old.idl (312 bytes)


website:
more info here
studies/corba/Corba-Code6/HomeFinder.cpp
download file

  1 // ////////////////////////////////////////////////////////
  2 // Lecture on the CORBA Component Model, summer term 2003
  3 // Assignment 6, Stephan Brumme, 702544
  4 //
  5 // CORBA CCM HomeFinder (Set up service)
  6 //
  7
  8 #include <iostream>
  9 using namespace std;
 10
 11
 12 // CORBA's naming service
 13 #pragma warning (disable: 4267)
 14 #include <coss/CosNaming.h>
 15 #include "Helper.h"
 16
 17 #include "HomeFinder_Impl.h"
 18 using namespace POA_HPI;
 19
 20
 21 // here we go ...
 22 int main(int argc, char* argv[])
 23 {
 24     try
 25     {
 26         // initialize CORBA
 27         CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
 28
 29         //////////////////////////////////////
 30         // POA related stuff
 31         cout << "Initialize POA ..." << endl;
 32         // first, locate the RootPOA
 33         CORBA::Object_var poaObject = orb->resolve_initial_references("RootPOA");
 34
 35         // gain access to the POA server and its manager
 36         PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObject);
 37         CorbaAssert(poa, "Failed to obtain POA server.");
 38
 39         PortableServer::POAManager_var poaManager = poa->the_POAManager();
 40         CorbaAssert(poaManager, "Failed to obtain POA manager.");
 41
 42         //////////////////////////////////////
 43         // Setup server
 44         cout << "Initialize server ..." << endl;
 45         // new HomeFinderImpl object
 46         HomeFinder_Impl* homeFinder = new HomeFinder_Impl(orb);
 47         // generate unique server ID
 48         PortableServer::ObjectId_var objectId = poa->activate_object(homeFinder);
 49         // extract reference
 50         CORBA::Object_var objectReference = poa->id_to_reference(objectId.in());
 51
 52         // for debug use: print IOR
 53         cout << orb->object_to_string(objectReference.in()) << endl;
 54
 55         //////////////////////////////////////
 56         // Connect to Naming Service
 57         cout << "Resolve Naming Service ..." << endl;
 58         // resolve naming service
 59         CORBA::Object_var namingService = orb->resolve_initial_references("NameService");
 60         // not found ?
 61         CorbaAssert(namingService, "Couldn't locate the Naming Service.");
 62
 63         // get the naming context
 64         CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService);
 65         // not found ?
 66         CorbaAssert(namingContext, "Couldn't locate the Naming Service.");
 67
 68         CosNaming::Name newName;
 69         newName.length(1);
 70         newName[0].id   = CORBA::string_dup("HomeFinder");
 71         newName[0].kind = CORBA::string_dup("CCM");
 72
 73         // register server at the naming service
 74         try
 75         {
 76             //namingContext->bind(newName, objectReference);
 77             namingContext->rebind(newName, objectReference);
 78         }
 79         catch (CosNaming::NamingContext::NotFound&)
 80         {
 81             CorbaError("Naming context not found.");
 82         }
 83         catch (CosNaming::NamingContext::InvalidName&)
 84         {
 85             CorbaError("Invalid name.");
 86         }
 87
 88         cout << "HomeFinder is ready." << endl;
 89
 90         poaManager->activate();
 91         orb->run();
 92
 93         // game over
 94         poa->destroy(true, true);
 95         delete homeFinder;
 96        
 97         return 0;
 98     }
 99     catch (CORBA::Exception&)
100     {
101         CorbaError("Corba failed to run properly.");
102     }
103 }
104