Skip to content

Commit

Permalink
SlaveActivity
Browse files Browse the repository at this point in the history
Fixed bug in which case operations within Task's were not called anymore
if the task is not running, and a slave of another one.
  • Loading branch information
goldhoorn committed Jun 16, 2014
1 parent 661a32a commit ed1d5f3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
11 changes: 11 additions & 0 deletions rtt/ExecutionEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ namespace RTT
msg_cond.broadcast(); // required for waitForMessages() (3rd party thread)
}

void ExecutionEngine::takeoverMessages( ExecutionEngine *remote )
{
DisposableInterface* com(0);
{
while ( remote->mqueue->dequeue( com ) ) {
assert( com );
mqueue->enqueue( com );
}
}
}

bool ExecutionEngine::process( DisposableInterface* c )
{
if ( c && this->getActivity() ) {
Expand Down
7 changes: 7 additions & 0 deletions rtt/ExecutionEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ namespace RTT
* Set the 'owner' task in the exception state.
*/
void setExceptionTask();

/**
* this function is mentioned for activietes that are not running by her own
* but need to push messages to this execution engine, like SlaveActivity
*/
void takeoverMessages(ExecutionEngine *remote);

protected:
/**
* Call this if you wish to block on a message arriving in the Execution Engine.
Expand Down
4 changes: 4 additions & 0 deletions rtt/base/ActivityInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ bool ActivityInterface::run(RunnableInterface* _r)
return true;
}

RunnableInterface* ActivityInterface::getRunner()
{
return runner;
}

6 changes: 6 additions & 0 deletions rtt/base/ActivityInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ namespace RTT
* run this activity. Will not be null.
*/
virtual os::ThreadInterface* thread() = 0;

/**
* Returns the current RunnableInterface for this
*/
virtual RunnableInterface* getRunner();

};

}}
Expand Down
15 changes: 14 additions & 1 deletion rtt/extras/SlaveActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "SlaveActivity.hpp"
#include "../os/MainThread.hpp"
#include "Logger.hpp"
#include <rtt/ExecutionEngine.hpp>

namespace RTT {
using namespace extras;
Expand Down Expand Up @@ -178,8 +179,20 @@ namespace RTT {

bool SlaveActivity::trigger()
{
if (mmaster)
ExecutionEngine *master = dynamic_cast<ExecutionEngine*>( mmaster->getRunner() );
ExecutionEngine * r= dynamic_cast<ExecutionEngine*>( runner );
if(!master || !r){
Logger::log() << Logger::Fatal << " SlaveActivity: cannot push messages to another engine, current engine is unsupported." << Logger::endl;
return false;
}else{
master->takeoverMessages( r );
}

if(mmaster)
{
return mmaster->trigger();
}

return false;
}

Expand Down

0 comments on commit ed1d5f3

Please sign in to comment.