📄 initrefs.cc
字号:
OMNIORB_ASSERT(index == the_argsServiceList.length()); the_argsServiceList.length(index+1); the_argsServiceList[index].id = identifier; the_argsServiceList[index].uri = (char*)0; the_argsServiceList[index].ref = CORBA::Object::_duplicate(obj);}voidomniInitialReferences::setDefaultInitRefFromArgs(const char* defInit){ omni_tracedmutex_lock sync(sl_lock); if (the_argsDefaultInitRef) CORBA::string_free(the_argsDefaultInitRef); the_argsDefaultInitRef = CORBA::string_dup(defInit);}voidomniInitialReferences::setDefaultInitRefFromFile(const char* defInit){ omni_tracedmutex_lock sync(sl_lock); if (the_fileDefaultInitRef) CORBA::string_free(the_fileDefaultInitRef); the_fileDefaultInitRef = CORBA::string_dup(defInit);}struct resolvePseudoEntry { const char* id; omniInitialReferences::pseudoObj_fn fn; resolvePseudoEntry(const char* i, omniInitialReferences::pseudoObj_fn f) : id(i), fn(f) {} resolvePseudoEntry() : id(0), fn(0) {} // Using default copy constructor};static omnivector<resolvePseudoEntry>*& thePseudoFnList(){ static omnivector<resolvePseudoEntry>* the_list = 0; if (the_list == 0) the_list = new omnivector<resolvePseudoEntry>; return the_list;}voidomniInitialReferences::registerPseudoObjFn(const char* identifier, pseudoObj_fn fn){ thePseudoFnList()->push_back(resolvePseudoEntry(identifier, fn));}static CORBA::Object_ptrresolvePseudo(const char* id, unsigned int cycles){ // Instantiate the pseudo objects on demand. // NB. No race condition problem here - these fns are thread safe. // We cannot insert the references into the initial references map, // since holding a reference there would prevent the objects from // being released properly when they have been destroyed. omnivector<resolvePseudoEntry>::iterator i = thePseudoFnList()->begin(); omnivector<resolvePseudoEntry>::iterator last = thePseudoFnList()->end(); for (; i != last; i++) { if (!strcmp(id, (*i).id)) return ((*i).fn)(); } return 0;}static CORBA::Object_ptrresolveArgs(const char* id, unsigned int cycles){ CORBA::Object_ptr ref = 0; CORBA::String_var uri; CORBA::ULong i; { omni_tracedmutex_lock sync(sl_lock); for (i=0; i < the_argsServiceList.length(); i++) { if (!strcmp((const char*)the_argsServiceList[i].id, id)) { if (!CORBA::is_nil(the_argsServiceList[i].ref)) { ref = CORBA::Object::_duplicate(the_argsServiceList[i].ref); } else { OMNIORB_ASSERT((char*)(the_argsServiceList[i].uri)); uri = CORBA::string_dup(the_argsServiceList[i].uri); } break; } } } if ((char*)uri) { ref = omniURI::stringToObject(uri, cycles); // Store the object reference in the list, unless another thread has // got there first if (!CORBA::is_nil(ref)) { omni_tracedmutex_lock sync(sl_lock); for (i=0; i < the_argsServiceList.length(); i++) { if (!strcmp((const char*)the_argsServiceList[i].id, id)) { if (CORBA::is_nil(the_argsServiceList[i].ref)) { the_argsServiceList[i].ref = CORBA::Object::_duplicate(ref); the_argsServiceList[i].uri = (char*)0; } break; } } } } if (ref && omniORB::trace(10)) { omniORB::logger l; l << "Initial reference `" << id << "' resolved from -ORBInitRef argument / ORB registration.\n"; } return ref;}static CORBA::Object_ptrresolveFile(const char* id, unsigned int cycles){ CORBA::Object_ptr ref = 0; CORBA::String_var uri; CORBA::ULong i; { omni_tracedmutex_lock sync(sl_lock); for (i=0; i < the_fileServiceList.length(); i++) { if (!strcmp((const char*)the_fileServiceList[i].id, id)) { if (!CORBA::is_nil(the_fileServiceList[i].ref)) { ref = CORBA::Object::_duplicate(the_fileServiceList[i].ref); } else { OMNIORB_ASSERT((char*)(the_fileServiceList[i].uri)); uri = CORBA::string_dup(the_fileServiceList[i].uri); } break; } } } if ((char*)uri) { ref = omniURI::stringToObject(uri, cycles); // Store the object reference in the list, unless another thread has // got there first if (!CORBA::is_nil(ref)) { omni_tracedmutex_lock sync(sl_lock); for (i=0; i < the_fileServiceList.length(); i++) { if (!strcmp((const char*)the_fileServiceList[i].id, id)) { if (CORBA::is_nil(the_fileServiceList[i].ref)) { the_fileServiceList[i].ref = CORBA::Object::_duplicate(ref); the_fileServiceList[i].uri = (char*)0; } break; } } } } if (ref && omniORB::trace(10)) { omniORB::logger l; l << "Initial reference `" << id << "' resolved from configuration file.\n"; } return ref;}static CORBA::Object_ptrresolveArgsDefault(const char* id, unsigned int cycles){ CORBA::String_var uri; { omni_tracedmutex_lock sync(sl_lock); if (!the_argsDefaultInitRef) return 0; uri = CORBA::string_alloc(strlen(the_argsDefaultInitRef) + strlen(id) + 2); strcpy(uri, the_argsDefaultInitRef); strcat(uri, "/"); strcat(uri, id); } try { if (omniORB::trace(10)) { omniORB::logger l; l << "Trying to resolve initial reference `" << id << "'\n"; l << " with default `" << (const char*)uri << "'\n"; } CORBA::Object_ptr obj = omniURI::stringToObject(uri, cycles); // Store the retrieved object in the args list, so future // resolves return the same thing. // Note that there's a race condition here. Another thread might // have been through here just before us, and stored a different // object reference in the list. That's so unlikely that we don't // bother to prevent it. The spec. makes no guarantees about when // initial reference resolution happens anyway. setFromArgs(id, obj); if (omniORB::trace(10)) { omniORB::logger l; l << "Initial reference `" << id << "' resolved with -ORBDefaultInitRef prefix.\n"; } return obj; } catch(...) { } return 0;}static CORBA::Object_ptrresolveFileDefault(const char* id, unsigned int cycles){ CORBA::String_var uri; { omni_tracedmutex_lock sync(sl_lock); if (!the_fileDefaultInitRef) return 0; uri = CORBA::string_alloc(strlen(the_fileDefaultInitRef) + strlen(id) + 2); strcpy(uri, the_fileDefaultInitRef); strcat(uri, "/"); strcat(uri, id); } try { if (omniORB::trace(10)) { omniORB::logger l; l << "Trying to resolve initial reference `" << id << "'\n"; l << " with configuration file default `" << (const char*)uri << "'\n"; } CORBA::Object_ptr obj = omniURI::stringToObject(uri, cycles); // Store the retrieved object in the file list, so future // resolves return the same thing. // Note that there's a race condition here. Another thread might // have been through here just before us, and stored a different // object reference in the list. That's so unlikely that we don't // bother to prevent it. The spec. makes no guarantees about when // initial reference resolution happens anyway. setFromFile(id, obj); if (omniORB::trace(10)) { omniORB::logger l; l << "Initial reference `" << id << "' resolved with configuration file ORBDefaultInitRef prefix.\n"; } return obj; } catch(...) { } return 0;}static CORBA::Object_ptrresolveBootAgent(const char* id, unsigned int cycles){ CORBA::Object_ptr result = 0; CORBA::Boolean update = 0; { omni_tracedmutex_lock sync(sl_lock); if (!the_bootagent || CORBA::is_nil(the_bootagent)) return 0; try { // XXX we will end up in a deadlock if this invocation turns // out to be a chain of invocations and eventually go back // to us. if (omniORB::trace(10)) { CORBA::String_var ior(omniURI::objectToString(the_bootagent)); omniORB::logger l; l << "Trying to resolve initial reference `" << id << "'\n"; l << " with boot agent: " << (const char*)ior << "\n"; } result = the_bootagent->get(id); if (CORBA::is_nil(result)) result = 0; else update = 1; if (omniORB::trace(10)) { omniORB::logger l; l << "Initial reference `" << id << "' resolved with boot agent.\n"; } } catch(...) { if (omniORB::trace(10)) { omniORB::logger l; l << "Caught exception trying to resolve `" << id << "' with boot agent."; } } } if (update) setFromArgs(id, result); return result;}CORBA::Object_ptromniInitialReferences::resolve(const char* id, unsigned int cycles){ if (!id) throw CORBA::ORB::InvalidName(); CORBA::Object_ptr result; // Look for the id in the order prescribed by the CORBA spec, with // extensions for ORBDefaultInitRef in the config file, and the // bootstrap agent. if ((result = resolvePseudo (id, cycles))) return result; if ((result = resolveArgs (id, cycles))) return result; if ((result = resolveFile (id, cycles))) return result; if ((result = resolveArgsDefault(id, cycles))) return result; if ((result = resolveFileDefault(id, cycles))) return result; if ((result = resolveBootAgent (id, cycles))) return result; // No more possibilities. Throw the correct exception to the caller. if (!strcmp(id, "InterfaceRepository") || !strcmp(id, "NameService") || !strcmp(id, "TradingService") || !strcmp(id, "SecurityCurrent") || !strcmp(id, "TransactionCurrent")) // Resource not found. OMNIORB_THROW(NO_RESOURCES,NO_RESOURCES_InitialRefNotFound, CORBA::COMPLETED_NO); // The identifier is not defined. if (omniORB::trace(10)) { omniORB::logger l; l << "resolve_initial_references throws CORBA::ORB::InvalidName\n"; } throw CORBA::ORB::InvalidName(); // Never get here... return 0;}CORBA::ORB::ObjectIdList*omniInitialReferences::list(){ omni_tracedmutex_lock sync(sl_lock); CORBA::ORB::ObjectIdList* result = new CORBA::ORB::ObjectIdList(the_argsServiceList.length() + the_fileServiceList.length()); CORBA::ORB::ObjectIdList& l = *result; l.length(the_argsServiceList.length() + the_fileServiceList.length()); CORBA::ULong i, j; for (i=0,j=0; i < the_argsServiceList.length(); i++,j++) { l[j] = CORBA::string_dup(the_argsServiceList[i].id);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -