2020-08-13 20:53:35 +02:00
|
|
|
#include "HasActionsIF.h"
|
|
|
|
#include "SimpleActionHelper.h"
|
2020-10-29 13:27:41 +01:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
SimpleActionHelper::SimpleActionHelper(HasActionsIF* setOwner,
|
2021-01-28 11:50:33 +01:00
|
|
|
MessageQueueIF* useThisQueue) :
|
|
|
|
ActionHelper(setOwner, useThisQueue), isExecuting(false) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleActionHelper::~SimpleActionHelper() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleActionHelper::step(ReturnValue_t result) {
|
2021-01-28 11:50:33 +01:00
|
|
|
// STEP_OFFESET is subtracted to compensate for adding offset in base
|
|
|
|
// method, which is not necessary here.
|
|
|
|
ActionHelper::step(stepCount - STEP_OFFSET, lastCommander, lastAction,
|
|
|
|
result);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
resetHelper();
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleActionHelper::finish(ReturnValue_t result) {
|
2021-01-28 11:50:33 +01:00
|
|
|
ActionHelper::finish(lastCommander, lastAction, result);
|
|
|
|
resetHelper();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t SimpleActionHelper::reportData(SerializeIF* data) {
|
2021-01-28 11:50:33 +01:00
|
|
|
return ActionHelper::reportData(lastCommander, lastAction, data);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleActionHelper::resetHelper() {
|
2021-01-28 11:50:33 +01:00
|
|
|
stepCount = 0;
|
|
|
|
isExecuting = false;
|
|
|
|
lastAction = 0;
|
|
|
|
lastCommander = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
|
2021-01-28 11:50:33 +01:00
|
|
|
ActionId_t actionId, store_address_t dataAddress) {
|
|
|
|
CommandMessage reply;
|
|
|
|
if (isExecuting) {
|
|
|
|
ipcStore->deleteData(dataAddress);
|
|
|
|
ActionMessage::setStepReply(&reply, actionId, 0,
|
|
|
|
HasActionsIF::IS_BUSY);
|
|
|
|
queueToUse->sendMessage(commandedBy, &reply);
|
|
|
|
}
|
|
|
|
const uint8_t* dataPtr = NULL;
|
|
|
|
size_t size = 0;
|
|
|
|
ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
|
|
|
queueToUse->sendMessage(commandedBy, &reply);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastCommander = commandedBy;
|
|
|
|
lastAction = actionId;
|
|
|
|
result = owner->executeAction(actionId, commandedBy, dataPtr, size);
|
|
|
|
ipcStore->deleteData(dataAddress);
|
|
|
|
switch (result) {
|
|
|
|
case HasReturnvaluesIF::RETURN_OK:
|
|
|
|
isExecuting = true;
|
|
|
|
stepCount++;
|
|
|
|
break;
|
|
|
|
case HasActionsIF::EXECUTION_FINISHED:
|
|
|
|
ActionMessage::setCompletionReply(&reply, actionId,
|
|
|
|
HasReturnvaluesIF::RETURN_OK);
|
|
|
|
queueToUse->sendMessage(commandedBy, &reply);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
|
|
|
queueToUse->sendMessage(commandedBy, &reply);
|
|
|
|
break;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
}
|