CORBA_Object_ptr getMasterViaEnv(CORBA_ORB_var& orb) { char *master_ior; if (!(master_ior = getenv("SGE_MASTER_IOR"))) master_ior = getenv("SGE_MASTER_IOR"); if(master_ior) return orb->string_to_object(master_ior); else return CORBA_Object::_nil(); }
ModelLoader_var hrp::getModelLoader(CORBA_ORB_var orb) { CosNaming::NamingContext_var cxt; try { CORBA::Object_var nS = orb->resolve_initial_references("NameService"); cxt = CosNaming::NamingContext::_narrow(nS); } catch(CORBA::SystemException& ex) { std::cerr << "NameService doesn't exist" << std::endl; return NULL; } return getModelLoader(cxt); }
BodyInfo_var hrp::loadBodyInfo(const char* url, CORBA_ORB_var orb) { CosNaming::NamingContext_var cxt; try { CORBA::Object_var nS = orb->resolve_initial_references("NameService"); cxt = CosNaming::NamingContext::_narrow(nS); } catch(CORBA::SystemException& ex) { std::cerr << "NameService doesn't exist" << std::endl; return false; } return loadBodyInfo(url, cxt); }
bool hrp::loadBodyFromModelLoader(BodyPtr body, const char* url, CORBA_ORB_var orb, bool loadGeometryForCollisionDetection) { CosNaming::NamingContext_var cxt; try { CORBA::Object_var nS = orb->resolve_initial_references("NameService"); cxt = CosNaming::NamingContext::_narrow(nS); } catch(CORBA::SystemException& ex) { std::cerr << "NameService doesn't exist" << std::endl; return false; } return loadBodyFromModelLoader(body, url, cxt, loadGeometryForCollisionDetection); }
int loadBodyFromModelLoader(::World* world, const char* name, const char *url, CORBA_ORB_var orb) { CosNaming::NamingContext_var cxt; try { CORBA::Object_var nS = orb->resolve_initial_references("NameService"); cxt = CosNaming::NamingContext::_narrow(nS); } catch(CORBA::SystemException& ex) { std::cerr << "NameService doesn't exist" << std::endl; return 0; } return loadBodyFromModelLoader(world, name, url, cxt); }
CORBA_Object_ptr getMasterViaNameService(CORBA_ORB_var& orb) { char *cell; CORBA_Object_ptr obj = CORBA_Object::_nil(); cell = getenv("SGE_CELL"); if (!cell) cell = "default"; cout << "Resolving name service..."; try { CORBA_Object_var ns_obj = orb->resolve_initial_references("NameService"); if(CORBA_is_nil(ns_obj)) { cerr << "Sorry, no ns_obj" << endl; return obj; } cout << "done" << endl; ns = CosNaming_NamingContext::_narrow(ns_obj); if(CORBA_is_nil(ns)) { cerr << "Sorry, no ns" << endl; return obj; } name = new CosNaming_Name(); name->length(2); name[0].id = CORBA_string_dup(cell); name[0].kind = CORBA_string_dup(""); name[1].id = CORBA_string_dup("cod_qidl"); name[1].kind = CORBA_string_dup(""); cout << "resolving master object..."; obj = ns->resolve(name); cout << "done" << endl; } catch(...) { cout << endl << "master not found via nameservice." << endl; } return obj; }
int main(int argc, char** argv) { try { if(argc < 2) { cerr << "usage: client <action>" << endl; cerr << "where <action> is one of:" << endl; printActions(); return 1; } cout << "initing ORB..."; orb = CORBA_ORB_init(argc, argv); if(!orb) { cerr << "could not init ORB." << endl; return 1; } cout << "done"<< endl; cout << "initing BOA..."; boa = orb->BOA_init(argc, argv); if(!boa) { cerr << "could not init BOA." << endl; return 1; } cout << "done" << endl; // trying to get the master's object reference CORBA_Object_var obj; obj = getMasterViaEnv(orb); if(CORBA_is_nil(obj)) obj = getMasterViaNameService(orb); if(CORBA_is_nil(obj)) obj = getMasterViaFile(orb); if(CORBA_is_nil(obj)) { cerr << "could not get master's object reference." << endl; return 1; } Codine_Master_var master = Codine_Master::_narrow(obj); if(!master) { cerr << "could not narrow." << endl; return 1; } // make context orb->get_default_context(ctx); makeContext(ctx); unsigned int i; for(i=0; i<sizeof(actions)/sizeof(action); i++) if(!strcmp(argv[1], actions[i].name)) { actions[i].func(master); break; } // none found ? if(i == sizeof(actions)/sizeof(action)) { cerr << "Could not find action '" << argv[1] << endl; cerr << "Possible choices are: " << endl; printActions(); } } catch(CORBA_SystemException& x) { OBPrintException(x); } catch(...) { cerr << "Caught exception." << endl; return 1; } return 0; }