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         // initialize CORBA
 26         CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
 27
 28         //////////////////////////////////////
 29         // POA related stuff
 30         cout << "Initialize POA ..." << endl;
 31         // first, locate the RootPOA
 32         CORBA::Object_var poaObject = orb->resolve_initial_references("RootPOA");
 33
 34         // gain access to the POA server and its manager
 35         PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObject);
 36         CorbaAssert(poa, "Failed to obtain POA server.");
 37
 38         PortableServer::POAManager_var poaManager = poa->the_POAManager();
 39         CorbaAssert(poaManager, "Failed to obtain POA manager.");
 40
 41         //////////////////////////////////////
 42         // Setup server
 43         cout << "Initialize server ..." << endl;
 44         // new HomeFinderImpl object
 45         HomeFinder_Impl* homeFinder = new HomeFinder_Impl(orb);
 46         // generate unique server ID
 47         PortableServer::ObjectId_var objectId = poa->activate_object(homeFinder);
 48         // extract reference
 49         CORBA::Object_var objectReference = poa->id_to_reference(objectId.in());
 50
 51         // for debug use: print IOR
 52         cout << orb->object_to_string(objectReference.in()) << endl;
 53
 54         //////////////////////////////////////
 55         // Connect to Naming Service
 56         cout << "Resolve Naming Service ..." << endl;
 57         // resolve naming service
 58         CORBA::Object_var namingService = orb->resolve_initial_references("NameService");
 59         // not found ?
 60         CorbaAssert(namingService, "Couldn't locate the Naming Service.");
 61
 62         // get the naming context
 63         CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService);
 64         // not found ?
 65         CorbaAssert(namingContext, "Couldn't locate the Naming Service.");
 66
 67         CosNaming::Name newName;
 68         newName.length(1);
 69         newName[0].id   = CORBA::string_dup("HomeFinder");
 70         newName[0].kind = CORBA::string_dup("CCM");
 71
 72         // register server at the naming service
 73         try         {
 74             //namingContext->bind(newName, objectReference);
 75             namingContext->rebind(newName, objectReference);
 76         }
 77         catch (CosNaming::NamingContext::NotFound&)
 78         {
 79             CorbaError("Naming context not found.");
 80         }
 81         catch (CosNaming::NamingContext::InvalidName&)
 82         {
 83             CorbaError("Invalid name.");
 84         }
 85
 86         cout << "HomeFinder is ready." << endl;
 87
 88         poaManager->activate();
 89         orb->run();
 90
 91         // game over
 92         poa->destroy(true, true);
 93         delete homeFinder;
 94        
 95         return 0;
 96     }
 97     catch (CORBA::Exception&)
 98     {
 99         CorbaError("Corba failed to run properly.");
100     }
101 }
102