📄 corbaorb.cc
字号:
const char* option_src_3 = "argument"; const char* option_src_4 = "option list"; const char* option_src_5 = "-ORB arguments"; const char* option_source= 0; try { orbOptions::singleton().reset(); // Look for -ORBtraceLevel arg first option_source = option_src_5; orbOptions::singleton().getTraceLevel(argc,argv); { const char* f = getenv(CONFIG_ENV); if (f) config_fname = f; } // Configuration file name can be overriden by command line. config_fname = orbOptions::singleton().getConfigFileName(argc, argv, config_fname); // Parse configuration file option_source = option_src_1; if (config_fname) { orbOptions::singleton().importFromFile(config_fname); }#if defined(NTArchitecture) && !defined(__ETS_KERNEL__) else { // Parse configuration from registry on NT if no configuration // file is specified. if (!orbOptions::singleton().importFromRegistry()) { // Failed to read from the registry. Try the default file location. config_fname = CONFIG_DEFAULT_LOCATION; orbOptions::singleton().importFromFile(config_fname); } }#endif // Parse configuration from environment variables option_source = option_src_2; orbOptions::singleton().importFromEnv(); if ( orb_identifier && strlen(orb_identifier) ) { option_source = option_src_3; orbOptions::singleton().addOption("id",orb_identifier); } // Parse configuration from argument <options> if (options) { option_source = option_src_4; orbOptions::singleton().addOptions(options); } // Parse configurations from argv option_source = option_src_5; orbOptions::singleton().extractInitOptions(argc,argv); } catch (const orbOptions::Unknown& ex) { if ( omniORB::trace(1) ) { omniORB::logger l; l << "ORB_init failed: unknown option (" << ex.key << ") in " << option_source << "\n"; } OMNIORB_THROW(INITIALIZE,INITIALIZE_InvalidORBInitArgs, CORBA::COMPLETED_NO); } catch (const orbOptions::BadParam& ex) { if ( omniORB::trace(1) ) { omniORB::logger l; l << "ORB_init failed: Bad parameter (" << ex.value << ") for option " << ((option_source == option_src_5) ? "-ORB" : "") << ex.key << " in " << option_source << ", reason: " << ex.why << "\n"; } OMNIORB_THROW(INITIALIZE,INITIALIZE_InvalidORBInitArgs, CORBA::COMPLETED_NO); } try { orbOptions::singleton().visit(); } catch (const orbOptions::BadParam& ex) { if ( omniORB::trace(1) ) { omniORB::logger l; l << "ORB_init failed: Bad parameter (" << ex.value << ") for ORB configuration option " << ex.key << ", reason: " << ex.why << "\n"; } OMNIORB_THROW(INITIALIZE,INITIALIZE_InvalidORBInitArgs, CORBA::COMPLETED_NO); } if (omniORB::trace(2)) { omniORB::logger l; l << "Distribution date: " OMNIORB_DIST_DATE "\n"; } try { // Call attach method of each initialiser object. // The order of these calls must take into account of the dependency // among the modules. omni_giopEndpoint_initialiser_.attach(); omni_transportRules_initialiser_.attach(); omni_interceptor_initialiser_.attach(); omni_omniInternal_initialiser_.attach(); omni_corbaOrb_initialiser_.attach(); omni_objadpt_initialiser_.attach(); omni_giopStreamImpl_initialiser_.attach(); omni_omniIOR_initialiser_.attach(); omni_ior_initialiser_.attach(); omni_codeSet_initialiser_.attach(); omni_cdrStream_initialiser_.attach(); omni_omniTransport_initialiser_.attach(); omni_giopRope_initialiser_.attach(); omni_giopserver_initialiser_.attach(); omni_giopbidir_initialiser_.attach(); omni_giopStrand_initialiser_.attach(); omni_omniCurrent_initialiser_.attach(); omni_dynamiclib_initialiser_.attach(); omni_ObjRef_initialiser_.attach(); omni_initRefs_initialiser_.attach(); omni_orbOptions_initialiser_.attach(); omni_poa_initialiser_.attach(); omni_uri_initialiser_.attach(); omni_hooked_initialiser_.attach(); if (orbParameters::lcdMode) { enableLcdMode(); } if (omniORB::trace(20) || orbParameters::dumpConfiguration) { orbOptions::sequenceString_var currentSet; currentSet = orbOptions::singleton().dumpCurrentSet(); omniORB::logger l; l << "Current configuration is as follows:\n"; for (CORBA::ULong i = 0; i < currentSet->length(); i++) l << "omniORB: " << (const char*)currentSet[i] << "\n"; } } catch (CORBA::INITIALIZE &ex) { throw; } catch (...) { OMNIORB_THROW(INITIALIZE,INITIALIZE_FailedORBInit,CORBA::COMPLETED_NO); }#if defined(__sunos__) && defined(__sparc__) && __OSVERSION__ >= 5#if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x500 // Sun C++ 5.0 or Forte C++ 6.0 generated code will segv occasionally // when concurrent threads throw an exception. The stack trace points // to a problem in the exception unwinding. The workaround seems to be // to install explicitly an uncaught exception handler, which is what // we do here. set_terminate(omni_abort);#endif#endif the_orb = new omniOrbORB(0); the_orb->_NP_incrRefCount(); orb_count++; return the_orb;}/////////////////////////////////////////////////////////////////////////////////////////////////// omniOrbORB ///////////////////////////////////////////////////////////////////////////////////////////////////#define CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED() \ if( _NP_is_nil() ) _CORBA_invoked_nil_pseudo_ref(); \ if( pd_destroyed ) OMNIORB_THROW(OBJECT_NOT_EXIST,OBJECT_NOT_EXIST_NoMatch, CORBA::COMPLETED_NO); \ if( pd_shutdown ) OMNIORB_THROW(BAD_INV_ORDER, \ BAD_INV_ORDER_ORBHasShutdown, \ CORBA::COMPLETED_NO); \CORBA::BooleanomniOrbORB::all_destroyed(){ return orb_count == 0;}omniOrbORB::~omniOrbORB() {}omniOrbORB::omniOrbORB(int nil) : OMNIORB_BASE_CTOR(CORBA::)ORB(nil), pd_refCount(1), pd_destroyed(0), pd_shutdown(0), pd_shutdown_in_progress(0){}char*omniOrbORB::id(){ return CORBA::string_dup("");}char*omniOrbORB::object_to_string(CORBA::Object_ptr obj){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); return omniURI::objectToString(obj);}CORBA::Object_ptromniOrbORB::string_to_object(const char* uri){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); return omniURI::stringToObject(uri);}CORBA::ORB::ObjectIdList*omniOrbORB::list_initial_services(){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); CORBA::ORB::ObjectIdList* ids = omniInitialReferences::list(); CORBA::ORB::ObjectIdList& idl = *ids; CORBA::ULong len = idl.length(); idl.length(len + 2); idl[len++] = CORBA::string_dup("RootPOA"); idl[len++] = CORBA::string_dup("POACurrent"); return ids;}CORBA::Object_ptromniOrbORB::resolve_initial_references(const char* id){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); return omniInitialReferences::resolve(id);}CORBA::BooleanomniOrbORB::work_pending(){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); omni_thread* self = omni_thread::self(); if (self && self->id() == omni::mainThreadId) return orbAsyncInvoker->work_pending(); return 0;}voidomniOrbORB::perform_work(){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); omni_thread* self = omni_thread::self(); if (self && self->id() == omni::mainThreadId) { unsigned long s, ns; omni_thread::get_time(&s, &ns); orbAsyncInvoker->perform(s, ns); }}voidomniOrbORB::run(){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); omni_thread* self = omni_thread::self(); if (self && self->id() == omni::mainThreadId) { orbAsyncInvoker->perform(); } else { orb_lock.lock(); orb_n_blocked_in_run++; while( !pd_shutdown ) orb_signal.wait(); orb_n_blocked_in_run--; orb_lock.unlock(); }}CORBA::BooleanomniOrbORB::run_timeout(unsigned long secs, unsigned long nanosecs){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); omni_thread* self = omni_thread::self(); if (self && self->id() == omni::mainThreadId) { orbAsyncInvoker->perform(secs, nanosecs); } else { orb_lock.lock(); orb_n_blocked_in_run++; if( !pd_shutdown ) orb_signal.timedwait(secs, nanosecs); orb_n_blocked_in_run--; orb_lock.unlock(); } return pd_shutdown;}voidomniOrbORB::shutdown(CORBA::Boolean wait_for_completion){ omni_tracedmutex_lock sync(orb_lock); CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); if( wait_for_completion ) { // Complain if in the context of an operation invocation omniCurrent* current = omniCurrent::get(); if (current && current->callDescriptor()) { OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_WouldDeadLock, CORBA::COMPLETED_NO); } } do_shutdown(wait_for_completion);}voidomniOrbORB::destroy(){ if( _NP_is_nil() ) _CORBA_invoked_nil_pseudo_ref(); omniOrbORB* orb; { omni_tracedmutex_lock sync(orb_lock); if( pd_destroyed ) OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_ORBHasShutdown, CORBA::COMPLETED_NO); // Complain if in the context of an operation invocation omniCurrent* current = omniCurrent::get(); if (current && current->callDescriptor()) { OMNIORB_THROW(BAD_INV_ORDER, BAD_INV_ORDER_WouldDeadLock, CORBA::COMPLETED_NO); } if( !pd_shutdown ) do_shutdown(1); if( pd_destroyed ) { omniORB::logs(15, "ORB destroyed by another thread."); return; } // Call detach method of the initialisers in reverse order. omni_hooked_initialiser_.detach(); omni_uri_initialiser_.detach(); omni_poa_initialiser_.detach(); omni_orbOptions_initialiser_.detach(); omni_initRefs_initialiser_.detach(); omni_ObjRef_initialiser_.detach(); omni_dynamiclib_initialiser_.detach(); omni_omniCurrent_initialiser_.detach(); omni_giopStrand_initialiser_.detach(); omni_giopbidir_initialiser_.detach(); omni_giopserver_initialiser_.detach(); omni_giopRope_initialiser_.detach(); omni_omniTransport_initialiser_.detach(); omni_cdrStream_initialiser_.detach(); omni_codeSet_initialiser_.detach(); omni_ior_initialiser_.detach(); omni_omniIOR_initialiser_.detach(); omni_giopStreamImpl_initialiser_.detach(); omni_objadpt_initialiser_.detach(); omni_corbaOrb_initialiser_.detach(); omni_omniInternal_initialiser_.detach(); omni_interceptor_initialiser_.detach(); omni_transportRules_initialiser_.detach(); omni_giopEndpoint_initialiser_.detach(); pd_destroyed = 1; orb = the_orb; the_orb = 0; orb_count--; } CORBA::release(orb);}voidomniOrbORB::register_initial_reference(const char* id, CORBA::Object_ptr obj){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); omniInitialReferences::setFromORB(id, obj);}CORBA::BooleanomniOrbORB::_non_existent(){ CHECK_NOT_NIL_SHUTDOWN_OR_DESTROYED(); orb_lock.lock(); CORBA::Boolean ret = pd_destroyed ? 1 : 0; orb_lock.unlock(); return ret;}void*omniOrbORB::_ptrToObjRef(const char* repoId){ OMNIORB_ASSERT(repoId); if( omni::ptrStrMatch(repoId, CORBA::ORB::_PD_repoId) ) return (CORBA::ORB_ptr) this; if( omni::ptrStrMatch(repoId, CORBA::Object::_PD_repoId) ) return (CORBA::Object_ptr) this; return 0;}voidomniOrbORB::_NP_incrRefCount(){ omni::poRcLock->lock(); pd_refCount++; omni::poRcLock->unlock();}voidomniOrbORB::_NP_decrRefCount(){ omni::poRcLock->lock(); int done = --pd_refCount > 0; omni::poRcLock->unlock(); if( done ) return; OMNIORB_USER_CHECK(pd_destroyed); OMNIORB_USER_CHECK(pd_refCount == 0); // If either of these fails then the application has released the // ORB reference too many times. omniORB::logs(15, "No more references to the ORB -- deleted."); delete this;}voidomniOrbORB::actual_shutdown(){ ASSERT_OMNI_TRACEDMUTEX_HELD(orb_lock, 1); OMNIORB_ASSERT(pd_shutdown_in_progress); //?? Is is safe to unlock orb_lock here? orb_lock.unlock(); // Shutdown object adapters. When this returns all // outstanding requests have completed. omniOrbPOA::shutdown(); // Shutdown incoming connections. omniObjAdapter::shutdown(); // Disable object references omniObjRef::_shutdown(); // Wait for all client requests to complete omniIdentity::waitForLastIdentity(); omniORB::logs(10, "ORB shutdown is complete."); orb_lock.lock(); pd_shutdown = 1; // Wake up threads stuck in run(). orb_signal.broadcast(); // Wake up main thread if there is one running shutdownAsyncInvoker();}static voidshutdown_thread_fn(void* arg){ OMNIORB_ASSERT(arg); omniORB::logs(15, "ORB shutdown thread started."); omni_tracedmutex_lock sync(orb_lock); ((omniOrbORB*) arg)->actual_shutdown();}voidomniOrbORB::do_shutdown(CORBA::Boolean wait_for_completion){ ASSERT_OMNI_TRACEDMUTEX_HELD(orb_lock, 1); if( pd_shutdown ) return; if( pd_shutdown_in_progress ) { if( wait_for_completion ) { omniORB::logs(15, "ORB shutdown already in progress -- waiting."); orb_n_blocked_in_run++; while( !pd_shutdown ) orb_signal.wait(); orb_n_blocked_in_run--; omniORB::logs(15, "ORB shutdown complete -- finished waiting."); } else { omniORB::logs(15, "ORB shutdown already in progress -- nothing to do."); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -