Skip to content

Commit

Permalink
syncing with orocos-trunk version 6615, resolving bugs 332
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.mech.kuleuven.be/repos/orocos/trunk/rtt@6616 ce417995-dfc9-0310-95a0-acdaff106893
  • Loading branch information
rsmits committed Feb 19, 2007
1 parent 8468724 commit 94bcf09
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/CommandRepository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ namespace RTT
return false;
}
simplecommands[com->getName()] = com->getCommandImpl()->clone();
this->add(com->getName(), 0);
log(Debug) << "Added Command: '"<< com->getName() <<"'." <<endlog();
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/OperationFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ namespace RTT
int getArity( const std::string& name ) const
{
typename map_t::const_iterator i = data.find( name );
if ( i == data.end() ) return -1;
if ( i == data.end() || i->second == 0 ) return -1;
return i->second->arity();
}
/**
Expand All @@ -520,7 +520,7 @@ namespace RTT
ResultT produce( const std::string& name, const PropertyBag& args ) const
{
typename map_t::const_iterator i = data.find( name );
if ( i == data.end() ) ORO_THROW_OR_RETURN(name_not_found_exception(), ResultT());
if ( i == data.end() || i->second == 0) ORO_THROW_OR_RETURN(name_not_found_exception(), ResultT());
std::vector<DataSourceBase::shared_ptr> dsVect;
std::transform( args.begin(), args.end(),
std::back_inserter( dsVect ),
Expand All @@ -540,7 +540,7 @@ namespace RTT
const std::vector<DataSourceBase::shared_ptr>& args ) const
{
typename map_t::const_iterator i = data.find( name );
if ( i == data.end() ) ORO_THROW_OR_RETURN(name_not_found_exception(), ResultT());
if ( i == data.end() || i->second == 0) ORO_THROW_OR_RETURN(name_not_found_exception(), ResultT());
return i->second->produce( args );
}

Expand All @@ -554,7 +554,7 @@ namespace RTT
PropertyBag getArgumentSpec( const std::string& name ) const
{
typename map_t::const_iterator i = data.find( name );
if ( i == data.end() ) ORO_THROW_OR_RETURN(name_not_found_exception(), PropertyBag());
if ( i == data.end() || i->second == 0) ORO_THROW_OR_RETURN(name_not_found_exception(), PropertyBag());
return i->second->getArgumentSpec();
}

Expand All @@ -568,7 +568,7 @@ namespace RTT
Descriptions getArgumentList( const std::string& name ) const
{
typename map_t::const_iterator i = data.find( name );
if ( i == data.end() ) ORO_THROW_OR_RETURN(name_not_found_exception(), Descriptions());
if ( i == data.end() || i->second == 0) ORO_THROW_OR_RETURN(name_not_found_exception(), Descriptions());
return i->second->getArgumentList();
}

Expand All @@ -582,7 +582,7 @@ namespace RTT
std::string getResultType( const std::string& name ) const
{
typename map_t::const_iterator i = data.find( name );
if ( i == data.end() ) ORO_THROW_OR_RETURN(name_not_found_exception(), std::string());
if ( i == data.end() || i->second == 0) ORO_THROW_OR_RETURN(name_not_found_exception(), std::string());
return i->second->resultType();
}

Expand All @@ -596,7 +596,7 @@ namespace RTT
std::string getDescription( const std::string& name ) const
{
typename map_t::const_iterator i = data.find( name );
if ( i == data.end() ) ORO_THROW_OR_RETURN(name_not_found_exception(), std::string());
if ( i == data.end() || i->second == 0) ORO_THROW_OR_RETURN(name_not_found_exception(), std::string());
return i->second->description();
}

Expand Down
26 changes: 16 additions & 10 deletions src/Property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace RTT
*/
Property( const Property<T>& orig)
: PropertyBase(orig.getName(), orig.getDescription()),
_value( orig._value->clone() )
_value( orig._value ? orig._value->clone() : 0 )
{}

/**
Expand All @@ -131,7 +131,7 @@ namespace RTT
* @see ready() to inspect if the creation succeeded.
*/
Property( PropertyBase* source)
: PropertyBase(source->getName(), source->getDescription()),
: PropertyBase(source ? source->getName() : "", source ? source->getDescription() : ""),
_value( source ? AssignableDataSource<DataSourceType>::narrow(source->getDataSource().get() ) : 0 )
{
}
Expand Down Expand Up @@ -167,14 +167,20 @@ namespace RTT
*/
Property<T>& operator=( PropertyBase* source )
{
this->setName( source->getName() );
this->setDescription( source->getDescription() );
typename AssignableDataSource<DataSourceType>::shared_ptr vptr
= AssignableDataSource<DataSourceType>::narrow(source->getDataSource().get() );
if (vptr)
_value = vptr;
else
_value = detail::BuildType<value_t>::Value() ;
if ( source ) {
this->setName( source->getName() );
this->setDescription( source->getDescription() );
typename AssignableDataSource<DataSourceType>::shared_ptr vptr
= AssignableDataSource<DataSourceType>::narrow(source->getDataSource().get() );
if (vptr)
_value = vptr;
else
_value = detail::BuildType<value_t>::Value() ;
} else {
this->setName( "" );
this->setDescription( "" );
_value = 0;
}
return *this;
}

Expand Down
42 changes: 22 additions & 20 deletions src/dlib/DLibCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ namespace RTT
{
protected:
int id;
ProtocolT* protocol;
public:
/**
* The defaults are reset by the constructor.
*/
DLibCommandImpl()
: id(0)
: id(0), protocol(0)
{
}

Expand All @@ -91,36 +92,36 @@ namespace RTT
* @return true if ready and succesfully sent.
*/
bool invoke() {
if (id)
return ProtocolT::sendCommand(id);
if (id && (this->protocol->getCommandStatus(id) & ( DispatchInterface::Ready | DispatchInterface::Done) ) )
return protocol->sendCommand(id);
return false;
}

template<class T1>
bool invoke( T1 a1 ) {
if (id)
return ProtocolT::sendCommand(id, a1);
if (id && (this->protocol->getCommandStatus(id) & ( DispatchInterface::Ready | DispatchInterface::Done) ) )
return protocol->sendCommand(id, a1);
return false;
}

template<class T1, class T2>
bool invoke( T1 a1, T2 a2 ) {
if (id)
return ProtocolT::sendCommand(id, a1, a2);
if (id && (this->protocol->getCommandStatus(id) & ( DispatchInterface::Ready | DispatchInterface::Done) ) )
return protocol->sendCommand(id, a1, a2);
return false;
}

template<class T1, class T2, class T3>
bool invoke( T1 a1, T2 a2, T3 a3 ) {
if (id)
return ProtocolT::sendCommand(id, a1, a2, a3);
if (id && (this->protocol->getCommandStatus(id) & ( DispatchInterface::Ready | DispatchInterface::Done) ) )
return protocol->sendCommand(id, a1, a2, a3);
return false;
}

template<class T1, class T2, class T3, class T4>
bool invoke( T1 a1, T2 a2, T3 a3, T4 a4 ) {
if (id)
return ProtocolT::sendCommand(id, a1, a2, a4);
if (id && (this->protocol->getCommandStatus(id) & ( DispatchInterface::Ready | DispatchInterface::Done) ) )
return protocol->sendCommand(id, a1, a2, a3, a4);
return false;
}
};
Expand All @@ -147,9 +148,10 @@ namespace RTT
* @param component The name of the target component.
* @param name The name of this command.
*/
DLibCommand(std::string component, std::string name)
DLibCommand(std::string component, std::string name, ProtocolT* _protocol)
{
this->id = ProtocolT::getCommandId(component,name);
this->protocol = _protocol;
this->id = this->protocol->getCommandId(component,name);
if (this->id == 0) {
log(Error) << "Could not find Component '"<<component <<"' or Command '"<<name<<"' in that component."<<endlog();
}
Expand All @@ -158,7 +160,7 @@ namespace RTT
virtual void readArguments() {}

virtual bool ready() const {
DispatchInterface::Status st = ProtocolT::getCommandStatus(this->id);
unsigned int st = this->protocol->getCommandStatus(this->id);
return st == DispatchInterface::Ready || st == DispatchInterface::Done;
}

Expand All @@ -171,27 +173,27 @@ namespace RTT
}

virtual bool done() const {
return ProtocolT::getCommandStatus(this->id) == DispatchInterface::Done;
return this->protocol->getCommandStatus(this->id) == DispatchInterface::Done;
}

virtual void reset() {
return ProtocolT::resetCommand(this->id);
return this->protocol->resetCommand(this->id);
}

virtual bool sent() const {
return ProtocolT::getCommandStatus(this->id) >= DispatchInterface::Sent;
return this->protocol->getCommandStatus(this->id) >= DispatchInterface::Sent;
}

virtual bool accepted() const {
return ProtocolT::getCommandStatus(this->id) >= DispatchInterface::Accepted;
return this->protocol->getCommandStatus(this->id) >= DispatchInterface::Accepted;
}

virtual bool executed() const {
return ProtocolT::getCommandStatus(this->id) >= DispatchInterface::Executed;
return this->protocol->getCommandStatus(this->id) >= DispatchInterface::Executed;
}

virtual bool valid() const {
return getCommandStatus(this->id) >= DispatchInterface::Valid;
return this->protocol->getCommandStatus(this->id) >= DispatchInterface::Valid;
}

virtual ConditionInterface* createCondition() const
Expand Down
17 changes: 17 additions & 0 deletions tests/property_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@ void PropertyTest::testInit()
Property<unsigned int> pui("PUI","", 0 );
Property<int> pi("PI","", 0 );
Property<bool> pb("PB","", false );

// Test null assignment
PropertyBase* pbase = 0;
Property<int> p2 = pbase;
CPPUNIT_ASSERT( !p2.ready() );
Property<int> p3;
CPPUNIT_ASSERT( !p3.ready() );

p3 = pbase;
CPPUNIT_ASSERT( !p3.ready() );

p2 = p3;
CPPUNIT_ASSERT( !p2.ready() );

p2 = pi;
CPPUNIT_ASSERT( p2.ready() );

CPPUNIT_ASSERT(true);
}

Expand Down
27 changes: 23 additions & 4 deletions tools/scripts/header_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,30 @@ echo " copyright : (C) "`date +%Y` $1 >> $3.tmp.header
echo " email : "$2 >> $3.tmp.header
echo " " >> $3.tmp.header
echo " ***************************************************************************" >> $3.tmp.header
echo " * This library is free software; you can redistribute it and/or *" >> $3.tmp.header
echo " * modify it under the terms of the GNU General Public *" >> $3.tmp.header
echo " * License as published by the Free Software Foundation; *" >> $3.tmp.header
echo " * version 2 of the License. *" >> $3.tmp.header
echo " * *" >> $3.tmp.header
echo " * This program is free software; you can redistribute it and/or modify *" >> $3.tmp.header
echo " * it under the terms of the GNU General Public License as published by *" >> $3.tmp.header
echo " * the Free Software Foundation; either version 2 of the License, or *" >> $3.tmp.header
echo " * (at your option) any later version. *" >> $3.tmp.header
echo " * As a special exception, you may use this file as part of a free *" >> $3.tmp.header
echo " * software library without restriction. Specifically, if other files *" >> $3.tmp.header
echo " * instantiate templates or use macros or inline functions from this *" >> $3.tmp.header
echo " * file, or you compile this file and link it with other files to *" >> $3.tmp.header
echo " * produce an executable, this file does not by itself cause the *" >> $3.tmp.header
echo " * resulting executable to be covered by the GNU General Public *" >> $3.tmp.header
echo " * License. This exception does not however invalidate any other *" >> $3.tmp.header
echo " * reasons why the executable file might be covered by the GNU General *" >> $3.tmp.header
echo " * Public License. *" >> $3.tmp.header
echo " * *" >> $3.tmp.header
echo " * This library is distributed in the hope that it will be useful, *" >> $3.tmp.header
echo " * but WITHOUT ANY WARRANTY; without even the implied warranty of *" >> $3.tmp.header
echo " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *" >> $3.tmp.header
echo " * Lesser General Public License for more details. *" >> $3.tmp.header
echo " * *" >> $3.tmp.header
echo " * You should have received a copy of the GNU General Public *" >> $3.tmp.header
echo " * License along with this library; if not, write to the Free Software *" >> $3.tmp.header
echo " * Foundation, Inc., 59 Temple Place, *" >> $3.tmp.header
echo " * Suite 330, Boston, MA 02111-1307 USA *" >> $3.tmp.header
echo " * *" >> $3.tmp.header
echo " ***************************************************************************/" >> $3.tmp.header
echo " " >> $3.tmp.header
Expand Down

0 comments on commit 94bcf09

Please sign in to comment.