bool ImageDisplayComponent::addDisplaySource(std::string tag, std::string type, DataSourceBase::shared_ptr orig)
    {

        // creates a copy of the data and an update command to
        // update the copy from the original.
        //
        // Added IplImage type
        Logger::In in("ImageDisplayComponent");

        // Check if the type is IplImage, if this fail
        if(orig->getTypeName()!="IplImage"){
            log(Error) << "Could not display '"<< tag <<"': This is not a IplImage type, it the Vision tookkit loaded?" << endlog();
            return false;
        }
        DataSourceBase::shared_ptr clone = orig->getTypeInfo()->buildValue();
        if ( !clone ) {
            log(Error) << "Could not display '"<< tag <<"' : unknown type." << endlog();
            return false;
        }
        try {
            boost::shared_ptr<CommandInterface> comm( clone->updateCommand( orig.get() ) );
            assert( comm );
            root.push_back( boost::make_tuple( tag, orig, comm, clone, type ) );
        } catch ( bad_assignment& ba ) {
            log(Error) << "Could not display '"<< tag <<"' : failed to create Command." << endlog();
            return false;
        }
        return true;
    }
char * RTT_corba_CConfigurationInterface_i::getPropertyTypeName (
    const char * name)
{
    DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
    if (ds)
        return CORBA::string_dup( ds->getTypeName().c_str() );
    return CORBA::string_dup( "na" );
}
    bool ImageDisplayComponent::configureHook(){
        Logger::In in("ImageDisplayComponent");

        // Load config file
        if ( this->marshalling()->readProperties( this->getName() + ".cpf" ) == false)
            return false;

        log(Info) << "Loading Ports to display from file." <<endlog();
        PropertyDemarshaller dem( config.get() );
        PropertyBag bag;
        if (dem.deserialize( bag ) == false ) {
            log(Error) << "Reading file "<< config.get() << " failed."<<endlog();
            return false;
        }

        bool ok = true;
        PropertyBag::const_iterator it = bag.getProperties().begin();
        while ( it != bag.getProperties().end() ){
            Property<std::string>* compName = dynamic_cast<Property<std::string>* >( *it );
            if ( !compName )
                log(Error) << "Expected Property \""
                           << (*it)->getName() <<"\" to be of type string."<< endlog();
            else if ( compName->getName() == "ImagePort" ) {
                string cname = compName->value().substr(0, compName->value().find("."));
                string pname = compName->value().substr( compName->value().find(".")+1, string::npos);
                ok &= this->addDisplayPort(cname, pname);
            }
            else {
                log(Error) << "Expected \"Component\", \"Port\" or \"Data\", got "
                           << compName->getName() << endlog();
                ok = false;
            }
            ++it;
        }
        deleteProperties( bag );

        // Create window for every dataport
        for(Reports::iterator it = root.begin(); it != root.end(); ++it ) {
            // Update the dataport
            (it->get<2>())->execute();
            // Get the base dataport
            DataSourceBase::shared_ptr source = it->get<3>();
            // Convert to Dataport<IplImage>
            DataSource<IplImage>::shared_ptr clone = AdaptDataSource<IplImage>()( source.get() );
            IplImage localImage = clone->get();
            string dataportName = it->get<0>();
            cvNamedWindow(dataportName.data(),CV_WINDOW_AUTOSIZE);
            cvShowImage(dataportName.data(),&localImage);
        }

        // Enter main loop of the window, and update the window if needed
        int key;
        key = cvWaitKey(3);
        // Magic number 3


        return ok;
    }
Example #4
0
bool PropertyBase::compose( const PropertyBag& source)
{
    DataSourceBase::shared_ptr dsb = getDataSource();
    ConstReferenceDataSource<PropertyBag> rds(source);
    rds.ref();
    if (dsb)
        return dsb->getTypeInfo()->composeType( &rds, dsb);
    return false;
}
char * RTT_corba_CConfigurationInterface_i::propertyToString (
    const char * name)
{
    DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
    if (ds) {
        std::string result = ds->toString();
        return CORBA::string_dup( result.c_str() );
    }
    return CORBA::string_dup( "na" );
}
::CORBA::Any * RTT_corba_CConfigurationInterface_i::getAttribute (
    const char * name)
{
    if ( !mar || !mar->hasAttribute( string(name) ) )
        return new CORBA::Any();
    DataSourceBase::shared_ptr ds = mar->getValue( string(name) )->getDataSource();
    const TypeInfo* ti = ds->getTypeInfo();
    CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
    assert( ctt );
    return ctt->createAny( ds );
}
::CORBA::Any * RTT_corba_COperationInterface_i::callOperation (
    const char * operation,
    ::RTT::corba::CAnyArguments & args)
{
    if ( mfact->hasMember( string( operation ) ) == false || mfact->isSynchronous(string(operation)) )
        throw ::RTT::corba::CNoSuchNameException( operation );
    // convert Corba args to C++ args.
    try {
        OperationCallerC orig(mfact->getPart(operation), operation, 0);
        vector<DataSourceBase::shared_ptr> results;
        for (size_t i =0; i != args.length(); ++i) {
            const TypeInfo* ti = mfact->getPart(operation)->getArgumentType( i + 1);
            CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
            // we need to store the results for returning them to caller (args is inout!) after the call()
            results.push_back( ctt->createDataSource( &args[i] ) );
            orig.arg( results[i] );
        }
        if ( orig.ready() ) {
            DataSourceBase::shared_ptr ds = orig.getCallDataSource();
            CORBA::Any* retany;

            // Try to get the return result :
            const TypeInfo* ti = ds->getTypeInfo();
            CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
            if ( !ctt ) {
                log(Warning) << "Could not return results of call to " << operation << ": unknown return type by CORBA transport."<<endlog();
                ds->evaluate(); // equivalent to orig.call()
                retany = new CORBA::Any();
            } else {
                retany =  ctt->createAny( ds ); // call evaluate internally
            }

            // Return results into args:
            for (size_t i =0; i != args.length(); ++i) {
                const TypeInfo* ti = mfact->getPart(operation)->getArgumentType( i + 1);
                CorbaTypeTransporter* ctta = dynamic_cast<CorbaTypeTransporter*> ( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
                ctta->updateAny(results[i], args[i]);
            }
            return retany;
        } else {
            orig.check(); // will throw
        }
    } catch (no_asynchronous_operation_exception& ) {
        throw ::RTT::corba::CNoSuchNameException( operation );
    } catch ( name_not_found_exception& ) {
        throw ::RTT::corba::CNoSuchNameException( operation );
    } catch ( wrong_number_of_args_exception& wna ) {
        throw ::RTT::corba::CWrongNumbArgException( wna.wanted, wna.received );
    } catch (wrong_types_of_args_exception& wta ) {
        throw ::RTT::corba::CWrongTypeArgException( wta.whicharg, wta.expected_.c_str(), wta.received_.c_str() );
    }
    return new ::CORBA::Any();
}
CORBA::Boolean RTT_corba_CConfigurationInterface_i::propertyFromString (
    const char* name, const char* value
  )
{
    DataSourceBase::shared_ptr ds = getPropertyDataSource( name );
    if (!ds)
        return false;
    if ( ds->getTypeInfo()->fromString( value, ds ) ) {
        RTT::log(RTT::Error) << "corba::CConfigurationInterface: Could not assign string to "<< ds->getType() <<"." <<RTT::endlog();
        return false;
    }
    return true;
}
::CORBA::Boolean RTT_corba_CConfigurationInterface_i::setProperty (
    const char * name,
    const ::CORBA::Any & value)
{
    if (mar)
        mbag = mar->properties(); // leave this here to get latest propertybag.
    DataSourceBase::shared_ptr ds = getPropertyDataSource(name);
    if ( !ds )
        return 0;
    const TypeInfo* ti = ds->getTypeInfo();
    CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
    assert( ctt );
    return ctt->updateFromAny( &value, ds );
}
Example #10
0
 /**
  * Update \a target with the contents of \a blob which is an object of a \a protocol.
  */
 virtual bool updateFromAny(const CORBA::Any* blob, DataSourceBase::shared_ptr target) const
 {
     if (warn) {
         Logger::In in("CorbaFallBackProtocol");
         log(Error) << "Could not update type '"<<target->getTypeName()<<"' with received data : data type not known to CORBA Transport." <<Logger::endl;
     }
     return false;
 }
::CORBA::Any * RTT_corba_CConfigurationInterface_i::getProperty (
    const char * name)
{
    if (mar)
        mbag = mar->properties(); // leave this here to get latest propertybag.
    if ( mbag == 0 )
        return new CORBA::Any();
    DataSourceBase::shared_ptr ds = getPropertyDataSource(name);
    if ( !ds ) {
        log(Error) <<"CConfigurationInterface: no such property: " << name << ". Returning empty CORBA::Any."<<endlog();
        return new CORBA::Any();
    }
    const TypeInfo* ti = ds->getTypeInfo();
    CorbaTypeTransporter* ctt = dynamic_cast<CorbaTypeTransporter*>( ti->getProtocol(ORO_CORBA_PROTOCOL_ID) );
    assert( ctt );
    return ctt->createAny( ds );
}
    void ImageDisplayComponent::updateHook()
    {
        // For every dataport
        for(Reports::iterator it = root.begin(); it != root.end(); ++it ) {
            // Update the dataport
            (it->get<2>())->execute();
            // Get the base dataport
            DataSourceBase::shared_ptr source = it->get<3>();
            // Convert to Dataport<IplImage>
            DataSource<IplImage>::shared_ptr clone = AdaptDataSource<IplImage>()( source.get() );
            IplImage localImage = clone->get();
            string dataportName = it->get<0>();
            cvShowImage(dataportName.data(),&localImage);
        }

        // Enter main loop of the window, and update the window if needed
        int key;
        key = cvWaitKey(3);
        // Magic number 3
    }
Example #13
0
    void ConditionParser::seenexpression()
    {
        // get the datasource parsed by the ExpressionParser..
        DataSourceBase::shared_ptr mcurdata =
            expressionparser.getResult();
        expressionparser.dropResult();

        // The reference count is stored in the DataSource itself !
        // so the ref cnt information is not lost in this cast
        ds_bool =
            dynamic_cast<DataSource<bool>*>( mcurdata.get() );
        if ( ds_bool )
            {
                mcurdata = 0;
            }
        else
            {
                // we only want boolean expressions..
                throw parse_exception_semantic_error(
                                                     "Attempt to use a non-boolean value as a condition." );
            }
    }
Example #14
0
 corba::CMethod_ptr ExpressionServer::CreateMethod( DataSourceBase::shared_ptr expr, MethodC* orig, PortableServer::POA_ptr p ) {
     // try to retrieve:
     corba::CMethod_ptr result = MServers[ expr ];
     if ( !CORBA::is_nil(result) )
         return corba::CMethod::_duplicate(result);
     // create new:
     if ( CORBA::is_nil(p) )
         p = ApplicationServer::rootPOA.in();
     Logger::log() <<Logger::Debug<< "Created 'Any' CMethod server for type "<< expr->getType()<<Logger::endl;
     Orocos_AnyMethod_i* newexpr = new Orocos_AnyMethod_i( *orig, expr, p );
     MServers[expr] = newexpr->activate_this();
     EServants[expr] = newexpr;
     EServers[expr] = corba::CExpression::_narrow(MServers[expr]);
     return corba::CMethod::_duplicate( MServers[expr] );
 }
Example #15
0
 corba::CExpression_ptr ExpressionServer::CreateAssignableExpression( DataSourceBase::shared_ptr expr, PortableServer::POA_ptr p ){
     // try to retrieve:
     corba::CAssignableExpression_ptr result = AServers[ expr ];
     if ( !CORBA::is_nil(result) )
         return corba::CExpression::_duplicate(result);
     // create new:
     if ( CORBA::is_nil(p) )
         p = ApplicationServer::rootPOA.in();
     Logger::log() <<Logger::Debug<< "Created 'Any' Assignable CExpression server for type "<< expr->getType()<<Logger::endl;
     Orocos_AnyAssignableExpression_i* newexpr = new Orocos_AnyAssignableExpression_i( expr, p );
     AServers[expr] = newexpr->activate_this();
     EServants[expr] = newexpr;
     EServers[expr] = corba::CExpression::_narrow(AServers[expr]);
     corba::CExpression_var ret = corba::CExpression::_duplicate( EServers[expr] );
     return ret._retn();
 }
Example #16
0
    int StatementProcessor::execute(const std::string& comm)
    {
        Logger::In in("StatementProcessor");
        TaskContext* taskcontext = d->tc;

        // Minor hack : also check if it was an attribute of current TC, for example,
        // if both the object and attribute with that name exist. the if
        // statement after this one would return and not give the expr parser
        // time to evaluate 'comm'.
        if ( taskcontext->provides()->getValue( comm ) ) {
                d->printResult( taskcontext->provides()->getValue( comm )->getDataSource().get(), true );
                return 0;
        }

        Parser _parser;

        Logger::log() <<Logger::Debug << "Trying ValueChange...";
        try {
            // Check if it was a method or datasource :
            DataSourceBase::shared_ptr ds = _parser.parseValueChange( comm, taskcontext );
            // methods and DS'es are processed immediately.
            if ( ds.get() != 0 ) {
                Logger::log() << "ok" << Logger::endl;
                d->printResult( ds.get(), false );
                return 0; // done here
            } else
                Logger::log() <<Logger::Debug << "no"<<Logger::endl;
        } catch ( fatal_semantic_parse_exception& pe ) { // incorr args, ...
            // way to fatal,  must be reported immediately
            Logger::log() << Logger::Debug << "fatal_semantic_parse_exception: ";
            Logger::log() << Logger::Error << pe.what() <<Logger::nl;
            return -1;
        } catch ( syntactic_parse_exception& pe ) { // wrong content after = sign etc..
            // syntactic errors must be reported immediately
            Logger::log() << Logger::Error << "syntactic_parse_exception: ";
            Logger::log() << Logger::Error << pe.what() <<Logger::nl;
            return -1;
        } catch ( parse_exception_parser_fail &pe )
            {
                // ignore, try next parser
                Logger::log() << Logger::Debug << "Ignoring ValueChange exception :"<<Logger::nl;
                Logger::log() << Logger::Debug << pe.what() <<Logger::nl;
        } catch ( parse_exception& pe ) {
            // syntactic errors must be reported immediately
            Logger::log() << Logger::Error << "parse_exception :";
            Logger::log() << Logger::Error << pe.what() <<Logger::nl;
            return -1;
        }
        Logger::log() << Logger::Debug << "Trying Expression..."<<Logger::nl;
        try {
            // Check if it was a method or datasource :
            DataSourceBase::shared_ptr ds = _parser.parseExpression( comm, taskcontext );
            // methods and DS'es are processed immediately.
            if ( ds.get() != 0 ) {
                d->printResult( ds.get(), true );
                return 0; // done here
            } else
                Logger::log() << Logger::Error << "returned zero !"<<Logger::nl;
        } catch ( syntactic_parse_exception& pe ) { // missing brace etc
            // syntactic errors must be reported immediately
            Logger::log() << Logger::Error << "syntactic_parse_exception :";
            Logger::log() << Logger::Error << pe.what() <<Logger::nl;
            return -1;
        } catch ( fatal_semantic_parse_exception& pe ) { // incorr args, ...
            // way to fatal,  must be reported immediately
            Logger::log() << Logger::Error << "fatal_semantic_parse_exception :";
            Logger::log() << Logger::Error << pe.what() <<Logger::nl;
            return -1;
        } catch ( parse_exception_parser_fail &pe ) {
                // ignore, try next parser
                Logger::log() << Logger::Debug << "Ignoring Expression exception :"<<Logger::nl;
                Logger::log() << Logger::Debug << pe.what() <<Logger::nl;
        } catch ( parse_exception& pe ) {
            // ignore, try next parser
            Logger::log() << Logger::Debug << "Ignoring Expression parse_exception :"<<Logger::nl;
            Logger::log() << Logger::Debug << pe.what() <<Logger::nl;
        }
        return -1;
    }
Example #17
0
        void doPrint( DataSourceBase* ds, bool recurse) {
            // this is needed for ds's that rely on initialision.
            // e.g. eval true once or time measurements.
            // becomes only really handy for 'watches' (todo).
            ds->reset();
            /**
             * If this list of types gets to long, we can still add a virtual
             * printOut( std::ostream& ) = 0 to DataSourceBase.
             */
            // this method can print some primitive DataSource<>'s.
            DataSource<bool>* dsb = DataSource<bool>::narrow(ds);
            if (dsb) {
                Logger::log() << dsb->get();
                return;
            }
            DataSource<int>* dsi = DataSource<int>::narrow(ds);
            if (dsi) {
                Logger::log() << dsi->get() ;
                return;
            }
#if 0
            // does not work yet with CORBA layer.
            DataSource<long>* dsl = DataSource<long>::narrow(ds);
            if (dsl) {
                Logger::log() << dsl->get() ;
                return;
            }
#endif
            DataSource<unsigned int>* dsui = DataSource<unsigned int>::narrow(ds);
            if (dsui) {
                Logger::log() << dsui->get() ;
                return;
            }
            DataSource<std::string>* dss = DataSource<std::string>::narrow(ds);
            if (dss) {
                Logger::log() <<'"'<< dss->get() << '"' ;
                return;
            }
#if 0
            DataSource<std::vector<double> >* dsvval = DataSource< std::vector<double> >::narrow(ds);
            if (dsvval) {
                Logger::log()  << dsvval->get() ;
                return;
            }
            DataSource< Double6D >* ds6d = DataSource<Double6D>::narrow(ds);
            if (ds6d) {
                Logger::log()  << ds6d->get() ;
                return;
            }
#endif
            DataSource<double>* dsd = DataSource<double>::narrow(ds);
            if (dsd) {
                Logger::log() << dsd->get() ;
                return;
            }
            DataSource<char>* dsc = DataSource<char>::narrow(ds);
            if (dsc) {
                Logger::log() <<'\''<< dsc->get()<<'\'' ;
                return;
            }

            DataSource<PropertyBag>* dspbag = DataSource<PropertyBag>::narrow(ds);
            if (dspbag) {
                PropertyBag bag( dspbag->get() );
                if (!recurse) {
                    int siz = bag.getProperties().size();
                    Logger::log()  << siz <<" Properties";
                } else {
                    if ( ! bag.empty() ) {
                        Logger::log()  <<Logger::nl;
                        for( PropertyBag::iterator it= bag.getProperties().begin(); it!=bag.getProperties().end(); ++it) {
                            Logger::log()  <<(*it)->getType()<<" "<< (*it)->getName();
                            DataSourceBase::shared_ptr propds = (*it)->getDataSource();
                            this->printResult( propds.get(), false );
                            Logger::log()  <<" ("<<(*it)->getDescription()<<')' << Logger::nl;
                        }
                    } else {
                        Logger::log()  <<"(empty PropertyBag)";
                    }
                }
                return;
            }

            // Leave void  as last since any DS is convertible to void !
            DataSource<void>* dsvd = DataSource<void>::narrow(ds);
            if (dsvd) {
                dsvd->get();
                Logger::log() << "(void)" ;
                return;
            }

            if (ds) {
                ds->evaluate();
                Logger::log() << "( result type '"+ds->getType()+"' not known to TaskBrowser )" ;
            }

        }