// //////////////////////////////////////////////////////// // Lecture on the CORBA Component Model, summer term 2003 // Assignment 6, Stephan Brumme, 702544 // // CORBA CCM HomeFinder (Implementation) // #include "HomeFinder_Impl.h" // the Corba Naming Service is invoked #include // note: a very handsome guy was born on 12/27/1978 ... CORBA::Long HomeFinder_Impl::uniqueId = 271278; // look for the first entry in the directory where comp_repid matched // else throw a HomeNotFound exception CCMHome_ptr HomeFinder_Impl::find_home_by_component_type( const char* comp_repid ) { for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++) if (iteDirectory->compRepId == comp_repid) // match ! return CCMHome::_narrow(orb->string_to_object(iteDirectory->homeName.c_str())); // not found ... throw new HomeNotFound; } // look for the first entry in the directory where home_repid matched // else throw a HomeNotFound exception CCMHome_ptr HomeFinder_Impl::find_home_by_home_type( const char* home_repid ) { for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++) if (iteDirectory->homeRepId == home_repid) // match ! return CCMHome::_narrow(orb->string_to_object(iteDirectory->homeName.c_str())); // not found ... throw new HomeNotFound; } // resolve the home_name using the Corba naming service // else throw a HomeNotFound exception CCMHome_ptr HomeFinder_Impl::find_home_by_name( const char* home_name ) { // resolve naming service CORBA::Object_var namingService = orb->resolve_initial_references("NameService"); // get the naming context CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService); // not connected ? if(CORBA::is_nil(namingContext)) { cout << "Couldn't locate the Naming Service." << endl; throw new HomeNotFound; } // ask naming service CosNaming::Name findName; findName.length(1); findName[0].id = CORBA::string_dup(home_name); findName[0].kind = CORBA::string_dup(""); // resolve CORBA::Object_var home = namingContext->resolve(findName); // not found ? if(CORBA::is_nil(home)) throw new HomeNotFound; return CCMHome::_narrow(home); } // add a new home to the directory CORBA::Long HomeFinder_Impl::_cxx_register( const char* comp_repid, const char* home_repid, ::Components::CCMHome_ptr the_home ) { // provides enough "uniqueness" for my purposes uniqueId++; // construction of a new entry Entry entry; entry.compRepId = comp_repid; entry.homeRepId = home_repid; entry.homeName = orb->object_to_string(the_home); entry.uniqueId = uniqueId; // add to the directory directory.push_back(entry); return uniqueId; } // remove an entry from the directory // else throw a HomeNotFound exception void HomeFinder_Impl::unregister( CORBA::Long cookie ) { for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++) if (iteDirectory->uniqueId == cookie) { directory.erase(iteDirectory, iteDirectory++); return; } // entry not part of the directory ? throw new HomeNotFound; }