Skip to content

Master introduce v1cmd syntax #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ed84012
operations: add const qualifier in collect family of functions
Oct 27, 2014
f7d50e8
scripting: add support for .cmd() semantics in scripting
Oct 24, 2014
fe20289
Fixed the .cmd() syntax to also work in state machine scripts.
Oct 29, 2014
e9cb1e6
Introduce .cmd() and .send() syntax for exported script functions
Nov 4, 2014
ed73d78
scripting: fixed segfault in CmdFunction::reset() if the engine is al…
meyerj Nov 5, 2014
faf49ed
scripting: fix .send() bug when using a SendHandle for exported scrip…
Nov 7, 2014
514bde5
scripting: fixed the operation.call() syntax
meyerj Nov 12, 2014
edff4c6
scripting: fix .cmd() in while loops or state programs
psoetens May 1, 2015
d444550
scripting: fixed SendHandleAlias copying bug during state machine ins…
meyerj Feb 3, 2016
f82fa9a
Revert "scripting: fix .cmd() in while loops or state programs"
meyerj Feb 10, 2016
361fe29
scripting: Fixed collecting from a SendHandle returned from sending a…
meyerj Feb 12, 2016
89958a6
tests: add a test case to program_test for send and collect of script…
meyerj Oct 20, 2017
fdd9272
tests: fixed execution thread spec in fixture for the state_test
meyerj Oct 20, 2017
8a28d1f
scripting: fixed memory leak during destruction of CallFunction and C…
meyerj Jun 7, 2016
ff7a6a5
Merge remote-tracking branch 'origin/master' into master-introduce-v1…
meyerj Apr 16, 2019
15b2e3c
Add license header to rtt/scripting/CmdFunction.hpp
meyerj May 6, 2019
f217855
Merge remote-tracking branch 'origin/master' into master-introduce-v1…
meyerj May 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rtt/SendHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace RTT
/**
* Collect this operator if the method has no arguments.
*/
SendStatus collect()
SendStatus collect() const
{
if (this->impl)
return this->impl->collect();
Expand Down
21 changes: 11 additions & 10 deletions rtt/internal/AssignCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,33 @@ namespace RTT
{
public:
typedef typename AssignableDataSource<T>::shared_ptr LHSSource;
typedef typename DataSource<S>::const_ptr RHSSource;
typedef typename DataSource<S>::shared_ptr RHSSource;
private:
LHSSource lhs;
RHSSource rhs;
bool news;
public:
/**
* Assign \a r (rvalue) to \a l (lvalue);
*/
AssignCommand( LHSSource l, RHSSource r )
: lhs( l ), rhs( r ), news(false)
: lhs( l ), rhs( r )
{
}

void readArguments() {
news = rhs->evaluate();
}

bool execute()
{
if (news) {
lhs->set( rhs->rvalue() );
news=false;
return true;
}
return false;
// we ignore evaluate, which return value is legacy
// we always assign the current state of rhs
rhs->evaluate();
lhs->set( rhs->rvalue() );
return true;
}

void reset() {
rhs->reset();
}

virtual base::ActionInterface* clone() const
Expand Down
28 changes: 14 additions & 14 deletions rtt/internal/CollectSignature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ namespace RTT
CollectSignature(ToCollect implementation) : cimpl(implementation) {}
~CollectSignature() {}

SendStatus collect()
SendStatus collect() const
{
if (this->cimpl)
return this->cimpl->collect();
return SendFailure;
}

SendStatus collectIfDone()
SendStatus collectIfDone() const
{
if (this->cimpl)
return this->cimpl->collectIfDone();
Expand All @@ -154,14 +154,14 @@ namespace RTT
/**
* Collect this operator if the method has one argument.
*/
SendStatus collect(arg1_type a1)
SendStatus collect(arg1_type a1) const
{
if (cimpl)
return cimpl->collect( a1 );
return SendFailure;
}

SendStatus collectIfDone(arg1_type a1)
SendStatus collectIfDone(arg1_type a1) const
{
if (cimpl)
return cimpl->collectIfDone( a1 );
Expand All @@ -184,14 +184,14 @@ namespace RTT
/**
* Collect this operator if the method has two arguments.
*/
SendStatus collect(arg1_type t1, arg2_type t2)
SendStatus collect(arg1_type t1, arg2_type t2) const
{
if (cimpl)
return cimpl->collect(t1, t2);
return SendFailure;
}

SendStatus collectIfDone(arg1_type t1, arg2_type t2)
SendStatus collectIfDone(arg1_type t1, arg2_type t2) const
{
if (cimpl)
return cimpl->collectIfDone(t1, t2);
Expand All @@ -215,14 +215,14 @@ namespace RTT
/**
* Collect this operator if the method has three arguments.
*/
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3)
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3) const
{
if (cimpl)
return cimpl->collect(t1, t2, t3);
return SendFailure;
}

SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3)
SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3) const
{
if (cimpl)
return cimpl->collectIfDone(t1, t2, t3);
Expand All @@ -247,14 +247,14 @@ namespace RTT
/**
* Collect this operator if the method has four arguments.
*/
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4)
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4) const
{
if (cimpl)
return cimpl->collect(t1, t2, t3, t4);
return SendFailure;
}

SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4)
SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4) const
{
if (cimpl)
return cimpl->collectIfDone(t1, t2, t3, t4);
Expand All @@ -280,14 +280,14 @@ namespace RTT
/**
* Collect this operator if the method has four arguments.
*/
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5)
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5) const
{
if (cimpl)
return cimpl->collect(t1, t2, t3, t4, t5);
return SendFailure;
}

SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5)
SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5) const
{
if (cimpl)
return cimpl->collectIfDone(t1, t2, t3, t4, t5);
Expand All @@ -314,14 +314,14 @@ namespace RTT
/**
* Collect this operator if the method has four arguments.
*/
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6)
SendStatus collect(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6) const
{
if (cimpl)
return cimpl->collect(t1, t2, t3, t4, t5, t6);
return SendFailure;
}

SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6)
SendStatus collectIfDone(arg1_type t1, arg2_type t2, arg3_type t3, arg4_type t4, arg5_type t5, arg6_type t6) const
{
if (cimpl)
return cimpl->collectIfDone(t1, t2, t3, t4, t5, t6);
Expand Down
8 changes: 2 additions & 6 deletions rtt/internal/DataSources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ namespace RTT
// call alias->get() with alias->evaluate().
action->readArguments();
bool r = action->execute();
action->reset();
// alias may only be evaluated after action was executed.
alias->evaluate();
return r;
Expand All @@ -530,7 +529,6 @@ namespace RTT
{
action->readArguments();
action->execute();
action->reset();
return alias->get();
}

Expand All @@ -544,7 +542,7 @@ namespace RTT
return alias->rvalue();
}

virtual void reset() { alias->reset(); }
virtual void reset() { action->reset(); alias->reset(); }

virtual ActionAliasDataSource<T>* clone() const {
return new ActionAliasDataSource(action, alias.get());
Expand Down Expand Up @@ -580,7 +578,6 @@ namespace RTT
// call alias->get() with alias->evaluate().
action->readArguments();
bool r = action->execute();
action->reset();
// alias may only be evaluated after action was executed.
alias->evaluate();
return r;
Expand All @@ -590,7 +587,6 @@ namespace RTT
{
action->readArguments();
action->execute();
action->reset();
return alias->get();
}

Expand All @@ -613,7 +609,7 @@ namespace RTT
return alias->rvalue();
}

virtual void reset() { alias->reset(); }
virtual void reset() { action->reset(); alias->reset(); }

virtual ActionAliasAssignableDataSource<T>* clone() const {
return new ActionAliasAssignableDataSource(action, alias.get());
Expand Down
52 changes: 47 additions & 5 deletions rtt/internal/FusedFunctorDataSource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,24 +333,27 @@ namespace RTT
*/
template<typename Signature>
struct FusedMSendDataSource
: public DataSource<SendHandle<Signature> >
: public AssignableDataSource<SendHandle<Signature> >
{
typedef SendHandle<Signature> result_type;
typedef result_type value_t;
typedef typename DataSource<value_t>::const_reference_t const_reference_t;
typedef typename AssignableDataSource<value_t>::param_t param_t;
typedef typename AssignableDataSource<value_t>::const_reference_t const_reference_t;
typedef typename AssignableDataSource<value_t>::reference_t reference_t;
typedef create_sequence<
typename boost::function_types::parameter_types<Signature>::type> SequenceFactory;
typedef typename SequenceFactory::type DataSourceSequence;
typename base::OperationCallerBase<Signature>::shared_ptr ff;
DataSourceSequence args;
mutable SendHandle<Signature> sh; // mutable because of get() const
mutable bool isqueued;
public:
typedef boost::intrusive_ptr<FusedMSendDataSource<Signature> >
shared_ptr;

FusedMSendDataSource(typename base::OperationCallerBase<Signature>::shared_ptr g,
const DataSourceSequence& s = DataSourceSequence() ) :
ff(g), args(s)
ff(g), args(s), sh(), isqueued(false)
{
}

Expand All @@ -359,6 +362,14 @@ namespace RTT
args = a1;
}

virtual void set( param_t t ) {
sh = t;
}

reference_t set() {
return sh;
}

value_t value() const
{
return sh;
Expand All @@ -371,21 +382,38 @@ namespace RTT

value_t get() const
{
if (isqueued)
return sh;
// put the member's object as first since SequenceFactory does not know about the OperationCallerBase type.
sh = bf::invoke(&base::OperationCallerBase<Signature>::send, bf::cons<base::OperationCallerBase<Signature>*, typename SequenceFactory::data_type>(ff.get(), SequenceFactory::data(args)));
if ( sh.ready() ) // only queued if sh contains a collectable operation
isqueued = true;
return sh;
}

void reset() {
isqueued = false;
}

virtual FusedMSendDataSource<Signature>* clone() const
{
return new FusedMSendDataSource<Signature> (ff, args);
}

virtual FusedMSendDataSource<Signature>* copy(
std::map<
const base::DataSourceBase*,
base::DataSourceBase*>& alreadyCloned) const
{
return new FusedMSendDataSource<Signature> (ff, SequenceFactory::copy(args, alreadyCloned));
// we need copy semantics because FusedMCollectDataSource tracks us.
if ( alreadyCloned[this] != 0 ) {
assert( dynamic_cast<FusedMSendDataSource<Signature>*>( alreadyCloned[this] ) == static_cast<FusedMSendDataSource<Signature>*>( alreadyCloned[this] ) );
return static_cast<FusedMSendDataSource<Signature>*>( alreadyCloned[this] );
}
// Other pieces in the code rely on insertion in the map :
alreadyCloned[this] = new FusedMSendDataSource<Signature>(ff, SequenceFactory::copy(args, alreadyCloned));
// return copy
return static_cast<FusedMSendDataSource<Signature>*>( alreadyCloned[this] );
}
};

Expand Down Expand Up @@ -452,18 +480,32 @@ namespace RTT
{
return new FusedMCollectDataSource<Signature> ( args, isblocking);
}

virtual FusedMCollectDataSource<Signature>* copy(
std::map<
const base::DataSourceBase*,
base::DataSourceBase*>& alreadyCloned) const
{
return new FusedMCollectDataSource<Signature> ( SequenceFactory::copy(args, alreadyCloned), isblocking);
// we need copy semantics because CmdCollectCondition tracks us.
// WARNING: This is a tricky precedent... should all DataSources with state + multiple living references then implement this ? Should we assert on this ?
if ( alreadyCloned[this] != 0 ) {
assert ( dynamic_cast<FusedMCollectDataSource<Signature>*>( alreadyCloned[this] ) == static_cast<FusedMCollectDataSource<Signature>*>( alreadyCloned[this] ) );
return static_cast<FusedMCollectDataSource<Signature>*>( alreadyCloned[this] );
}
// Other pieces in the code rely on insertion in the map :
alreadyCloned[this] = new FusedMCollectDataSource<Signature>(SequenceFactory::copy(args, alreadyCloned), isblocking);
// return copy
return static_cast<FusedMCollectDataSource<Signature>*>( alreadyCloned[this] );
}
};

/**
* A Function object that reacts to a Signal by writing the arguments in
* data sources and calling an action object.
*
* Implementation note: this class does not require copy/clone semantics because
* it is re-created for each SM instantiation, so it already gets the copy/cloned
* Data Sources in its constructor.
*/
template<typename Signature>
struct FusedMSignal : public base::DisposableInterface
Expand Down
Loading