Exemplo 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();
}
Exemplo n.º 2
0
// setConfiguration call from iBroker when configComplete is called.
// which is called when qtplatz fire 'extentionInstalled()'
bool
iProxy::initialConfiguration( const adportable::Configuration& c )
{
    config_ = c;
    std::string nsname = config_.attribute( "ns_name" );
    name_ = adportable::string::convert( config_.name() );
    
    if ( config_.attribute( "type" ) == "object_reference" ) { // CORBA Object

        if ( ! nsname.empty() ) {

			Broker::Manager_var bmgr = adcontroller::manager_i::instance()->impl().getBrokerManager();
            if ( CORBA::is_nil( bmgr ) )
                throw std::runtime_error( "iProxy::init_object_ref -- can't get Broker::Manager reference" );
            try {
                CORBA::Object_var obj = bmgr->find_object( nsname.c_str() );
                if ( ! CORBA::is_nil( obj.in() ) ) {
                    impl_ = Instrument::Session::_narrow( obj );
                    if ( ! CORBA::is_nil( impl_ ) ) {
                        if ( impl_->echo( "hello" ) )
                            objref_ = true;
                    }
                } 
            } catch ( CORBA::Exception& ex ) {
                adportable::debug(__FILE__, __LINE__) << "adcontroller::iproxy::setConfiguration '" << nsname << "' " << ex._info().c_str();
            }
        }
    } else {
        adportable::debug(__FILE__, __LINE__) << "iProxy::setConfiguration -- object '" << nsname << "' not registerd";
    }
    return objref_;
}
Exemplo n.º 3
0
void
orb_i::initialize()
{
    Broker::Manager_var mgr = OrbConnection::instance()->brokerManager();

    if ( CORBA::is_nil( mgr ) ) {
        return;
    }

    impl_->brokerSession_ = mgr->getSession( "acquire" );
    if ( CORBA::is_nil( impl_->brokerSession_ ) ) {
        return;
    }

    impl_->initialize_broker_session();

    connect( this, &orb_i::onUpdateUIData, this, &orb_i::handle_update_ui_data );

    task_->threads_.push_back( adportable::asio::thread( [this](){ task_->io_service_.run(); } ) );

}
Exemplo n.º 4
0
void
orb_i::actionConnect()
{
    if ( CORBA::is_nil( session_.in() ) ) {
        
        Broker::Manager_var broker = OrbConnection::instance()->brokerManager();

        if ( ! CORBA::is_nil( broker ) ) {

            using namespace acewrapper::constants;
            CORBA::Object_var obj = broker->find_object( adcontroller::manager::_name() );
            ::ControlServer::Manager_var manager = ::ControlServer::Manager::_narrow( obj );

            if ( !CORBA::is_nil( manager ) ) {
                session_ = manager->getSession( "acquire" );
                if ( !CORBA::is_nil( session_.in() ) ) {
                    
                    receiver_i_.reset( new receiver_i );

                    receiver_i_->assign_message( [this] ( ::Receiver::eINSTEVENT code, uint32_t value ){
                            emit onReceiverMessage( static_cast<unsigned long>(code), value );                            
                        });
                    
                    receiver_i_->assign_log( [this] ( const ::EventLog::LogMessage& log ){ handle_receiver_log( log ); } );
                    
                    receiver_i_->assign_shutdown( [this](){ handle_receiver_shutdown(); } );
                    
                    receiver_i_->assign_debug_print( [this]( int32_t pri, int32_t cat, std::string text ){ handle_receiver_debug_print( pri, cat, text ); } );

                    connect( this, &orb_i::onReceiverMessage, this, &orb_i::handle_controller_message );
                        
                    if ( session_->connect( receiver_i_->_this(), "acquire" ) ) {
                        MainWindow::instance()->handleInstState( adicontroller::Instrument::eStandBy );
                    }
                        
                    if ( session_->status() <= ControlServer::eConfigured )
                        session_->initialize();

                    // Master signal observer
                    observer_ = session_->getObserver();
                    if ( !CORBA::is_nil( observer_.in() ) ) {
                        if ( !sink_ ) {
                            sink_.reset( new adinterface::ObserverEvents_i );
                            
                            sink_->assignConfigChanged( [=] ( uint32_t oid, SignalObserver::eConfigStatus st ){
                                    handle_observer_config_changed( oid, st );
                                } );
                            
                            sink_->assignUpdateData( [=] ( uint32_t oid, int32_t pos ){
                                    handle_observer_update_data( oid, pos );
                                } );
                            
                            sink_->assignMethodChanged( [=] ( uint32_t oid, int32_t pos ){
                                    handle_observer_method_changed( oid, pos );
                                } );
                            sink_->assignEvent( [=] ( uint32_t oid, int32_t pos, int32_t ev ){
                                    handle_observer_event( oid, pos, ev );
                                } );
                            
                            observer_->connect( sink_->_this(), SignalObserver::Frequent, "acquireplugin" );

						}
                        
                        // connect to 1st layer siblings ( := top shadow(cache) observer for each instrument )
                        SignalObserver::Observers_var siblings = observer_->getSiblings();
                        size_t nsize = siblings->length();

                        for ( CORBA::ULong i = 0; i < nsize; ++i ) {
                            SignalObserver::Observer_var var = SignalObserver::Observer::_duplicate( siblings[ i ] );
                            impl_->populate( var );
                        }
                    }
                }
                document::instance()->actionInitRun();
            }
        }
    }

    if ( ! CORBA::is_nil( session_ ) ) {
        MainWindow::instance()->handleInstState( adicontroller::Instrument::eStandBy );        
        document::instance()->fsmStop();
    }
}
Exemplo n.º 5
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;
}