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_Impl.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 (Implementation)
  6 //
  7
  8
  9 #include "HomeFinder_Impl.h"
 10 // the Corba Naming Service is invoked
 11 #include <coss/CosNaming.h>
 12
 13
 14
 15 // note: a very handsome guy was born on 12/27/1978 ...
 16 CORBA::Long HomeFinder_Impl::uniqueId = 271278;
 17
 18
 19 // look for the first entry in the directory where comp_repid matched
 20 // else throw a HomeNotFound exception
 21 CCMHome_ptr HomeFinder_Impl::find_home_by_component_type( const char* comp_repid )
 22 {
 23     for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++)
 24         if (iteDirectory->compRepId == comp_repid)
 25             // match !
 26             return CCMHome::_narrow(orb->string_to_object(iteDirectory->homeName.c_str()));
 27
 28     // not found ...
 29     throw new HomeNotFound;
 30 }
 31
 32
 33 // look for the first entry in the directory where home_repid matched
 34 // else throw a HomeNotFound exception
 35 CCMHome_ptr HomeFinder_Impl::find_home_by_home_type( const char* home_repid )
 36 {
 37     for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++)
 38         if (iteDirectory->homeRepId == home_repid)
 39             // match !
 40             return CCMHome::_narrow(orb->string_to_object(iteDirectory->homeName.c_str()));
 41
 42     // not found ...
 43     throw new HomeNotFound;
 44 }
 45
 46
 47 // resolve the home_name using the Corba naming service
 48 // else throw a HomeNotFound exception
 49 CCMHome_ptr HomeFinder_Impl::find_home_by_name( const char* home_name )
 50 {
 51     // resolve naming service
 52     CORBA::Object_var namingService = orb->resolve_initial_references("NameService");
 53     // get the naming context
 54     CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService);
 55
 56     // not connected ?
 57     if(CORBA::is_nil(namingContext))
 58     {
 59         cout << "Couldn't locate the Naming Service." << endl;
 60         throw new HomeNotFound;
 61     }
 62
 63     // ask naming service
 64     CosNaming::Name findName;
 65     findName.length(1);
 66     findName[0].id   = CORBA::string_dup(home_name);
 67     findName[0].kind = CORBA::string_dup("");
 68
 69     // resolve
 70     CORBA::Object_var home = namingContext->resolve(findName);
 71
 72     // not found ?
 73     if(CORBA::is_nil(home))
 74         throw new HomeNotFound;
 75    
 76     return CCMHome::_narrow(home);
 77 }
 78
 79
 80 // add a new home to the directory
 81 CORBA::Long HomeFinder_Impl::_cxx_register( const char* comp_repid, const char* home_repid, ::Components::CCMHome_ptr the_home )
 82 {
 83     // provides enough "uniqueness" for my purposes
 84     uniqueId++;
 85
 86     // construction of a new entry
 87     Entry entry;
 88     entry.compRepId = comp_repid;
 89     entry.homeRepId = home_repid;
 90     entry.homeName  = orb->object_to_string(the_home);
 91     entry.uniqueId  = uniqueId;
 92
 93     // add to the directory
 94     directory.push_back(entry);
 95     return uniqueId;
 96 }
 97
 98
 99 // remove an entry from the directory
100 // else throw a HomeNotFound exception
101 void HomeFinder_Impl::unregister( CORBA::Long cookie )
102 {
103     for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++)
104         if (iteDirectory->uniqueId == cookie)
105         {
106             directory.erase(iteDirectory, iteDirectory++);
107             return;
108         }
109
110     // entry not part of the directory ?
111     throw new HomeNotFound;
112 }
113