⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controltaskproxy.cpp

📁 机器人开源项目orocos的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                    continue; // previously added.                Expression_var expr = cobj->attributes()->getAttribute( attrs[i].in() );                if ( CORBA::is_nil( expr ) ) {                    log(Error) <<"Attribute "<< string(attrs[i].in()) << " present in getAttributeList() but not accessible."<<endlog();                    continue;                 }                AssignableExpression_var as_expr = AssignableExpression::_narrow( expr.in()  );                // If the type is known, immediately build the correct attribute and datasource,                // otherwise, build a attribute of CORBA::Any.                CORBA::String_var tn = expr->getTypeName();                TypeInfo* ti = TypeInfoRepository::Instance()->type( tn.in() );                log(Info) << "Looking up Attribute " << tn.in();                if ( ti ) {                    Logger::log() <<": found!"<<endlog();                    if ( CORBA::is_nil( as_expr ) ) {                        tobj->attributes()->setValue( ti->buildConstant( attrs[i].in(), ti->buildCorbaProxy( expr.in() ) ) );                    }                    else {                        tobj->attributes()->setValue( ti->buildAttribute( attrs[i].in(), ti->buildCorbaProxy( as_expr.in() ) ) );                    }                } else {                    Logger::log() <<": not found :-("<<endlog();                    if ( CORBA::is_nil( as_expr ) )                        tobj->attributes()->setValue( new Constant<CORBA::Any_ptr>( attrs[i].in(), new CORBAExpression<CORBA::Any_ptr>( expr.in() ) ) );                    else                        tobj->attributes()->setValue( new Attribute<CORBA::Any_ptr>( attrs[i].in(), new CORBAAssignableExpression<CORBA::Any_ptr>( as_expr.in() ) ) );                }                // methods:                log(Info) << plist[i] << ": fetching Methods."<<endlog();                MethodInterface_var mfact = cobj->methods();                if (mfact) {                    MethodList_var objs;                    objs = mfact->getMethods();                    for ( size_t i=0; i < objs->length(); ++i) {                        tobj->methods()->add( objs[i].in(), new CorbaMethodFactory( objs[i].in(), mfact.in(), ProxyPOA() ) );                    }                }                // commands:                log(Info) << plist[i] << ": fetching Commands."<<endlog();                CommandInterface_var cfact = cobj->commands();                if (cfact) {                    CommandList_var objs;                    objs = cfact->getCommands();                    for ( size_t i=0; i < objs->length(); ++i) {                        tobj->commands()->add( objs[i].in(), new CorbaCommandFactory( objs[i].in(), cfact.in(), ProxyPOA() ) );                    }                }                parent->addObject( tobj );                // Recurse:                this->fetchObjects( tobj, cobj.in() );            }        }    }    bool ControlTaskProxy::InitOrb(int argc, char* argv[] ) {        if ( orb.in() )            return false;        try {            // First initialize the ORB, that will remove some arguments...            orb =                CORBA::ORB_init (argc, const_cast<char**>(argv),                                 "" /* the ORB name, it can be anything! */);            // Also activate the POA Manager, since we may get call-backs !            CORBA::Object_var poa_object =                orb->resolve_initial_references ("RootPOA");            rootPOA =                PortableServer::POA::_narrow (poa_object.in ());            PortableServer::POAManager_var poa_manager =                rootPOA->the_POAManager ();            poa_manager->activate ();            return true;        }        catch (CORBA::Exception &e) {            log(Error) << "Orb Init : CORBA exception raised!" << Logger::nl;            Logger::log() << e._info().c_str() << endlog();        }        return false;    }    void ControlTaskProxy::DestroyOrb()    {        try {            // Destroy the POA, waiting until the destruction terminates            //poa->destroy (1, 1);            orb->destroy();            std::cerr <<"Orb destroyed."<<std::endl;        }        catch (CORBA::Exception &e) {            log(Error) << "Orb Init : CORBA exception raised!" << Logger::nl;            Logger::log() << e._info().c_str() << endlog();        }    }    ControlTaskProxy* ControlTaskProxy::Create(std::string name, bool is_ior /*=false*/) {        if ( CORBA::is_nil(orb) || name.empty() )            return 0;        // create new:        try {            ControlTaskProxy* ctp = new ControlTaskProxy( name, is_ior );            return ctp;        }        catch( IllegalServer& is ) {            cerr << is.what() << endl;        }        return 0;    }    ControlTaskProxy* ControlTaskProxy::Create(::RTT::Corba::ControlTask_ptr t) {        if ( CORBA::is_nil(orb) || t == 0 )            return 0;        // proxy present for this object ?        // is_equivalent is actually our best try.        for (PMap::iterator it = proxies.begin(); it != proxies.end(); ++it)            if ( (it->first)->_is_equivalent( t ) )                 return proxies[t];        // create new:        try {            ControlTaskProxy* ctp = new ControlTaskProxy( t );            return ctp;        }        catch( IllegalServer& is ) {            cerr << is.what() << endl;        }        return 0;    }    bool ControlTaskProxy::start() {        if (mtask)            return mtask->start();        return false;    }        bool ControlTaskProxy::stop() {        if (mtask)            return mtask->stop();        return false;    }        bool ControlTaskProxy::isRunning() const {        if (mtask)            return mtask->isRunning();        return false;    }    bool ControlTaskProxy::configure() {        if (mtask)            return mtask->configure();        return false;    }        bool ControlTaskProxy::cleanup() {        if (mtask)            return mtask->cleanup();        return false;    }        bool ControlTaskProxy::isConfigured() const {        if (mtask)            return mtask->isConfigured();        return false;    }    TaskContext::TaskState ControlTaskProxy::getTaskState() const {        if (mtask)            return TaskContext::TaskState( mtask->getTaskState() );        return TaskContext::Init;    }    bool ControlTaskProxy::executeCommand( CommandInterface* c)    {        return false;    }    int ControlTaskProxy::queueCommand( CommandInterface* c)    {        return 0;    }    void ControlTaskProxy::setName(const std::string& n)    {        //mtask->setName( n.c_str() );    }    bool ControlTaskProxy::addPeer( TaskContext* peer, std::string alias /*= ""*/ )    {        if (!mtask)            return false;        // if peer is a proxy, add the proxy, otherwise, create new server.        ControlTaskProxy* ctp = dynamic_cast<ControlTaskProxy*>( peer );        if (ctp) {            if ( mtask->addPeer( ctp->server(), alias.c_str() ) ) {                this->synchronize();                return true;            }            return false;        }        // no server yet, create it.        ControlTaskServer* newpeer = ControlTaskServer::Create(peer);        if ( mtask->addPeer( newpeer->server(), alias.c_str() ) ) {            this->synchronize();            return true;        }        return false;    }    void ControlTaskProxy::removePeer( const std::string& name )    {        if (!mtask)            return;        mtask->removePeer( name.c_str() );    }    void ControlTaskProxy::removePeer( TaskContext* peer )    {        if (!mtask)            return;        mtask->removePeer( peer->getName().c_str() );    }    bool ControlTaskProxy::connectPeers( TaskContext* peer )    {        if (!mtask)            return false;        ControlTaskServer* newpeer = ControlTaskServer::Create(peer);        return mtask->connectPeers( newpeer->server() );    }    void ControlTaskProxy::disconnectPeers( const std::string& name )    {        if (mtask)            mtask->disconnectPeers( name.c_str() );    }    TaskContext::PeerList ControlTaskProxy::getPeerList() const    {        Corba::ControlTask::ControlTaskNames_var plist = mtask->getPeerList();        TaskContext::PeerList vlist;        for( size_t i =0; i != plist->length(); ++i)            vlist.push_back( std::string( plist[i] ) );        return vlist;    }    bool ControlTaskProxy::hasPeer( const std::string& peer_name ) const    {        return mtask && mtask->hasPeer( peer_name.c_str() );    }    TaskContext* ControlTaskProxy::getPeer(const std::string& peer_name ) const    {        if ( !mtask )            return 0;        Corba::ControlTask_ptr ct = mtask->getPeer( peer_name.c_str() );        if ( !ct )            return 0;        return ControlTaskProxy::Create( ct );    }    Corba::ControlTask_ptr ControlTaskProxy::server() const {        if ( !mtask )            return 0;        return Corba::ControlTask::_duplicate(mtask);    }#if 0    CosPropertyService::PropertySet_ptr ControlTaskProxy::propertySet() {        if ( !mtask )            return 0;        return mtask->propertySet();    }#endif    PortableServer::POA_ptr ControlTaskProxy::ProxyPOA() {        if ( !orb.in() )            return 0;        if (!proxy_poa.in() ) {            CORBA::Object_var poa_object =                orb->resolve_initial_references ("RootPOA");            // new POA for the proxies:            // Use default manager, is already activated !            //PortableServer::POAManager_var proxy_manager = poa->the_POAManager ();            //CORBA::PolicyList pol;            //proxy_poa = poa->create_POA( "ProxyPOA", proxy_manager, pol );            proxy_poa =                PortableServer::POA::_narrow (poa_object.in ());        }        // note: do not use _retn(): user must duplicate in constructor.        return proxy_poa.in();    }}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -