Skip to content

Commit a6ced57

Browse files
psoetensPeter Soetens
authored and
Peter Soetens
committed
scripting: fix .cmd() in while loops or state programs
A wrapper did forcefully not forward the reset(). It seems this is no longer required, since removing that code makes .cmd() invocations work correctly again. Signed-off-by: Peter Soetens <[email protected]>
1 parent 9e6f701 commit a6ced57

File tree

3 files changed

+11
-55
lines changed

3 files changed

+11
-55
lines changed

rtt/scripting/CmdFunction.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ namespace RTT
6565
minit->readArguments();
6666
maccept = minit->execute() && mrunner->runFunction( _foo.get() );
6767
// we ignore the ret value of start(). It could have been auto-started during loading() of the function.
68-
if ( _foo->needsStart() ) // _foo might be auto-started in runFunction()
68+
if ( _foo->needsStart() ) { // _foo might be auto-started in runFunction()
6969
_foo->start();
70+
}
7071
if ( ! maccept ) {
7172
return ss = SendFailure;
7273
}
@@ -100,6 +101,7 @@ namespace RTT
100101
mrunner->removeFunction( _foo.get() );
101102
maccept = false;
102103
isqueued = false;
104+
ss = SendNotReady;
103105
}
104106

105107
CmdFunction* clone() const

rtt/scripting/FunctionFactory.cpp

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -62,49 +62,6 @@
6262
namespace RTT {
6363
using namespace detail;
6464

65-
class CmdFunctionWrapper
66-
: public DataSource<SendStatus>
67-
{
68-
DataSource<SendStatus>::shared_ptr alias;
69-
public:
70-
typedef boost::intrusive_ptr<CmdFunctionWrapper> shared_ptr;
71-
72-
CmdFunctionWrapper(DataSource<SendStatus>* ds)
73-
: alias(ds)
74-
{}
75-
76-
~CmdFunctionWrapper() { }
77-
78-
bool evaluate() const {
79-
return alias->evaluate();
80-
}
81-
82-
DataSource<SendStatus>::result_t get() const
83-
{
84-
return alias->get();
85-
}
86-
87-
DataSource<SendStatus>::result_t value() const
88-
{
89-
return alias->value();
90-
}
91-
92-
DataSource<SendStatus>::const_reference_t rvalue() const
93-
{
94-
return alias->rvalue();
95-
}
96-
97-
virtual void reset() { /* nop, don't reset ! */ }
98-
99-
virtual CmdFunctionWrapper* clone() const {
100-
return new CmdFunctionWrapper(alias.get());
101-
}
102-
virtual CmdFunctionWrapper* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const {
103-
return new CmdFunctionWrapper(alias->copy(alreadyCloned) );
104-
}
105-
};
106-
107-
10865
FunctionFactory::FunctionFactory(ProgramInterfacePtr pi, ExecutionEngine* procs)
10966
: func(pi), proc(procs) {}
11067

@@ -245,12 +202,7 @@ namespace RTT {
245202

246203
if (args.size() >= 1) {
247204
if ( dynamic_cast<CmdFunction* > (args[0].get()) != 0 ) {
248-
// The CmdFunction : wrap it and return it
249-
// wrapping is necessary because we don't want to propagate reset()
250-
return new CmdFunctionWrapper( dynamic_cast<CmdFunction*>(args[0].get()) );
251-
} else if ( dynamic_cast<CmdFunctionWrapper* > (args[0].get()) != 0 ) {
252-
// Return argument.
253-
return args[0];
205+
return dynamic_cast<CmdFunction*>(args[0].get());
254206
} else {
255207
log(Error) <<"FunctionFactory: Please define your SendHandle with 'var SendHandle' for script functions." <<endlog();
256208
return 0;

tests/program_test.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,16 +527,18 @@ BOOST_AUTO_TEST_CASE(testProgramCmdFoo)
527527
+ "do test.assert( tvar_i == -1 ) \n"
528528
+ "do test.assert( tvar_i == tconst_i ) \n"
529529
+ "set tvar_i = +2\n" // 10
530-
+ "do test.assert( tvar_i == +2 )\n"
531-
+ "do foo.cmd(tvar_i)\n"
532-
+ "do test.assert( tvar_i == +4 )\n"
533-
+ "tss = foo.cmd(tvar_i)\n"
530+
+ "while (tvar_i != +6) {\n"
531+
+ " tss = foo.cmd(tvar_i)\n"
532+
+ " do test.assert( tss == SendSuccess )\n"
533+
+ "}\n"
534534
+ "do test.assert( tvar_i == +6 )\n"
535+
+ "tss = foo.cmd(tvar_i)\n"
536+
+ "do test.assert( tvar_i == +8 )\n"
535537
+ "do test.assert( tss == SendSuccess )\n"
536538
+ "}";
537539
this->doProgram( prog, tc );
538540
Attribute<int> i = tc->provides()->getAttribute("tvar_i");
539-
BOOST_REQUIRE_EQUAL( 6, i.get() );
541+
BOOST_REQUIRE_EQUAL( 8, i.get() );
540542
this->finishProgram( tc, "x");
541543
}
542544

0 commit comments

Comments
 (0)