From 829be0f08298c8aea79eccfff9403a2c23e381c8 Mon Sep 17 00:00:00 2001
From: "Robin.Mueller" <robin.mueller.m@gmail.com>
Date: Mon, 12 Oct 2020 16:58:04 +0200
Subject: [PATCH] doc correction, action helper new helper function

---
 action/ActionHelper.cpp | 56 +++++++++++++++++++++++++++++++++++------
 action/ActionHelper.h   | 15 +++++++++--
 action/HasActionsIF.h   |  7 +++---
 3 files changed, 65 insertions(+), 13 deletions(-)

diff --git a/action/ActionHelper.cpp b/action/ActionHelper.cpp
index ab986c6c..8122885b 100644
--- a/action/ActionHelper.cpp
+++ b/action/ActionHelper.cpp
@@ -89,22 +89,28 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
 	if (result != HasReturnvaluesIF::RETURN_OK) {
 		return result;
 	}
-	result = data->serialize(&dataPtr, &size, maxSize, SerializeIF::Endianness::BIG);
+	result = data->serialize(&dataPtr, &size, maxSize,
+	        SerializeIF::Endianness::BIG);
 	if (result != HasReturnvaluesIF::RETURN_OK) {
 		ipcStore->deleteData(storeAddress);
 		return result;
 	}
-	//We don't need to report the objectId, as we receive REQUESTED data before the completion success message.
-	//True aperiodic replies need to be reported with another dedicated message.
+	// We don't need to report the objectId, as we receive REQUESTED data
+	// before the completion success message.
+	// True aperiodic replies need to be reported with
+	// another dedicated message.
 	ActionMessage::setDataReply(&reply, replyId, storeAddress);
 
-	//TODO Service Implementation sucks at the moment
-	if (hideSender){
+	// TODO: Service Implementation sucks at the moment
+	// TODO: why does it suck and why would someone need to hide the sender?
+	if (hideSender) {
 		result = MessageQueueSenderIF::sendMessage(reportTo, &reply);
-	} else {
+	}
+	else {
 		result = queueToUse->sendMessage(reportTo, &reply);
 	}
-	if ( result != HasReturnvaluesIF::RETURN_OK){
+
+	if (result != HasReturnvaluesIF::RETURN_OK){
 		ipcStore->deleteData(storeAddress);
 	}
 	return result;
@@ -112,3 +118,39 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
 
 void ActionHelper::resetHelper() {
 }
+
+ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
+        ActionId_t replyId, const uint8_t *data, size_t dataSize,
+        bool hideSender) {
+    CommandMessage reply;
+    store_address_t storeAddress;
+    ReturnValue_t result = ipcStore->addData(&storeAddress, data, dataSize);
+    if (result != HasReturnvaluesIF::RETURN_OK) {
+        return result;
+    }
+
+    if (result != HasReturnvaluesIF::RETURN_OK) {
+        ipcStore->deleteData(storeAddress);
+        return result;
+    }
+
+    // We don't need to report the objectId, as we receive REQUESTED data
+    // before the completion success message.
+    // True aperiodic replies need to be reported with
+    // another dedicated message.
+    ActionMessage::setDataReply(&reply, replyId, storeAddress);
+
+    // TODO: Service Implementation sucks at the moment
+    // TODO: why does it suck and why would someone need to hide the sender?
+    if (hideSender) {
+        result = MessageQueueSenderIF::sendMessage(reportTo, &reply);
+    }
+    else {
+        result = queueToUse->sendMessage(reportTo, &reply);
+    }
+
+    if (result != HasReturnvaluesIF::RETURN_OK){
+        ipcStore->deleteData(storeAddress);
+    }
+    return result;
+}
diff --git a/action/ActionHelper.h b/action/ActionHelper.h
index a20f286a..17ca3ebd 100644
--- a/action/ActionHelper.h
+++ b/action/ActionHelper.h
@@ -69,8 +69,8 @@ public:
 	void finish(MessageQueueId_t reportTo, ActionId_t commandId,
 	        ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
 	/**
-	 * Function to be called by the owner if an action does report data
-	 *
+	 * Function to be called by the owner if an action does report data.
+	 * Takes a SerializeIF* pointer and serializes it into the IPC store.
 	 * @param reportTo  MessageQueueId_t to report the action completion
 	 *                  message to
 	 * @param replyId ID of the executed command
@@ -79,6 +79,17 @@ public:
 	 */
 	ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId,
 	        SerializeIF* data, bool hideSender = false);
+    /**
+     * Function to be called by the owner if an action does report data.
+     * Takes the raw data and writes it into the IPC store.
+     * @param reportTo  MessageQueueId_t to report the action completion
+     *                  message to
+     * @param replyId ID of the executed command
+     * @param data Pointer to the data
+     * @return Returns RETURN_OK if successful, otherwise failure code
+     */
+    ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId,
+            const uint8_t* data, size_t dataSize, bool hideSender = false);
 	/**
 	 * Function to setup the MessageQueueIF* of the helper. Can be used to
 	 * set the MessageQueueIF* if message queue is unavailable at construction
diff --git a/action/HasActionsIF.h b/action/HasActionsIF.h
index 886d0837..a26ed588 100644
--- a/action/HasActionsIF.h
+++ b/action/HasActionsIF.h
@@ -47,10 +47,9 @@ public:
 	virtual MessageQueueId_t getCommandQueue() const = 0;
 	/**
 	 * Execute or initialize the execution of a certain function.
-	 * Returning #EXECUTION_FINISHED or a failure code, nothing else needs to
-	 * be done. When needing more steps, return RETURN_OK and issue steps and
-	 * completion manually.
-	 * One "step failed" or completion report must be issued!
+	 * When used in conjunction with the ActionHelper class, returning
+	 * a return code which is not equal to RETURN_OK will trigger a step reply
+	 * with step 0.
 	 */
 	virtual ReturnValue_t executeAction(ActionId_t actionId,
 			MessageQueueId_t commandedBy, const uint8_t* data, size_t size) = 0;