Esempio n. 1
0
void
Task::internal_initialize()
{
	acewrapper::scoped_mutex_t<> lock( mutex_ );

	acewrapper::ORBServant< tofcontroller::tofSession_i >
		* pServant = tofcontroller::singleton::tofSession_i::instance();
	CORBA::ORB_var orb = pServant->orb();

    Broker::Manager_var manager;
    try {
        CORBA::Object_var obj = orb->string_to_object( singleton::tofSession_i::instance()->broker_manager_ior() );
        manager = Broker::Manager::_narrow( obj.in() );
    } catch ( CORBA::Exception& ) {
    }

	if ( ! CORBA::is_nil( manager.in() ) ) {
		logger_ = manager->getLogger();

		if ( ! CORBA::is_nil( logger_.in() ) ) {
			std::wostringstream o;
			o << L"tofcontroller task id(" << ACE_OS::getpid() << L") initialized";
			Broker::LogMessage msg;
            msg.tv_sec = msg.tv_usec = 0;
			msg.text = o.str().c_str();
			logger_->log( msg );
		}
	}
	internal_initialize_timer();
	internal_initialize_mcast();
}
Esempio n. 2
0
bool
ServantPlugin::initialize(const QStringList &arguments, QString *error_message)
{
    Q_UNUSED(arguments);
    int nErrors = 0;

    do { adportable::debug(__FILE__, __LINE__) << "<----- ServantPlugin::initialize() ..."; } while(0);

    OutputWindow * outputWindow = new OutputWindow;
    addAutoReleasedObject( outputWindow );
    pImpl_ = new internal::ServantPluginImpl( outputWindow );

    ///////////////////////////////////
    Core::ICore * core = Core::ICore::instance();
    QList<int> context;
    if ( core ) {
        Core::UniqueIDManager * uidm = core->uniqueIDManager();
        if ( uidm ) {
            context.append( uidm->uniqueIdentifier( QLatin1String("Servant.MainView") ) );
            context.append( uidm->uniqueIdentifier( Core::Constants::C_NAVIGATION_PANE ) );
        }
    } else
        return false;
    
    // ACE initialize
    // acewrapper::instance_manager::initialize();
    // <------
    
	boost::filesystem::path plugindir;
    do {
        std::wstring apppath = qtwrapper::application::path( L".." ); // := "~/qtplatz/bin/.."
		std::wstring configFile = adplugin::loader::config_fullpath( apppath, L"/MS-Cheminformatics/does-not-exist.adplugin" );
		plugindir = boost::filesystem::path( configFile ).branch_path();
    } while(0);

	// populate .adplugin files under given folder.
	adplugin::loader::populate( plugindir.generic_wstring().c_str() );

	std::vector< adplugin::plugin_ptr > spectrometers;
	if ( adplugin::loader::select_iids( ".*\\.adplugins\\.massSpectrometer\\..*", spectrometers ) ) {
		std::for_each( spectrometers.begin(), spectrometers.end(), []( const adplugin::plugin_ptr& d ){ 
			adcontrols::massspectrometer_factory * factory = d->query_interface< adcontrols::massspectrometer_factory >();
			if ( factory )
				adcontrols::massSpectrometerBroker::register_factory( factory, factory->name() );
		});
	}
    // ------------ Broker::Manager initialize first --------------------
    adorbmgr::orbmgr * pMgr = adorbmgr::orbmgr::instance();
	if ( pMgr ) {
		pMgr->init( 0, 0 );
		pMgr->spawn();
	}
    //--------------------------------------------------------------------
    //--------------------------------------------------------------------
    Broker::Manager_var bmgr;
	adplugin::plugin_ptr adbroker = adplugin::loader::select_iid( ".*\\.orbfactory\\.adbroker" );
	if ( adbroker ) {
		internal::orbServantCreator broker_creator;
		adplugin::orbServant * adBroker = broker_creator( adbroker, orbServants_ );
        if ( adBroker ) {
            bmgr = Broker::Manager::_narrow( broker_creator.obj );
            if ( CORBA::is_nil( bmgr ) ) {
                *error_message = "Broker::Manager cannot be created";
                return false;
            }
        } else {
            *error_message = broker_creator.errmsg.str().empty() ? 
                "adplugin for Broker::Manager did not loaded." : broker_creator.errmsg.str().c_str();
            return false;
        }
		adorbmgr::orbmgr::instance()->setBrokerManager( bmgr );
        size_t nTrial = 3;
        while ( nTrial-- ) {
            try {
                bmgr->register_ior( adBroker->object_name(), broker_creator.ior.c_str() );
            } catch ( CORBA::Exception& ex ) {
                if ( /* ex.get_id() == CORBA::TRANSIENT && */ nTrial )
                    std::this_thread::sleep_for( std::chrono::milliseconds(10) );
                else {
                    *error_message = QString( "CORBA::Exception : " ) + ex._info().c_str();
                    return false;
                }
            }
        }
    }
    pImpl_->init_debug_adbroker( bmgr );

    // ----------------------- initialize corba servants ------------------------------
    std::vector< adplugin::plugin_ptr > factories;
    adplugin::loader::select_iids( ".*\\.adplugins\\.orbfactory\\..*", factories );
    for ( const adplugin::plugin_ptr& ptr: factories ) {

        if ( ptr->iid() == adbroker->iid() )
            continue;

        internal::orbServantCreator creator;
        adplugin::orbServant * servant = creator( ptr, orbServants_ );
        if ( servant ) {
            BrokerClient::Accessor_var accessor = BrokerClient::Accessor::_narrow( creator.obj );
            if ( !CORBA::is_nil( accessor ) ) {
                accessor->setBrokerManager( bmgr.in() );
				accessor->adpluginspec( ptr->clsid(), ptr->adpluginspec() );
            }
            try {
                bmgr->register_ior( servant->object_name(), creator.ior.c_str() );
                bmgr->register_object( servant->object_name(), creator.obj );
            } catch ( CORBA::Exception& ex ) {
                *error_message = ex._info().c_str();
                return false;
            }
        }
    }

    using namespace acewrapper::constants;
    ControlServer::Manager_var cmgr ( internal::findObject< ControlServer::Manager >::find( bmgr.in(), adcontroller::manager::_name() ) );
	if ( ! CORBA::is_nil( cmgr ) ) {
        ControlServer::Session_var session = cmgr->getSession( L"debug" );
        if ( ! CORBA::is_nil( session ) )
			pImpl_->init_debug_adcontroller( session );
	}

    // 
    ControlServer::Session_var session;
    std::vector< Instrument::Session_var > i8t_sessions;

    do { adportable::debug(__FILE__, __LINE__) << "<-- ServantPlugin::initialize() ### 3 ##"; } while(0);

    if ( ! CORBA::is_nil( session ) )
        session->configComplete();

    Logger log;
    log( ( nErrors ? L"Servant iitialized with errors" : L"Servernt initialized successfully") );
    
    do { adportable::debug() << "----> ServantPlugin::initialize() completed."; } while(0);
    return true;
}