diff --git a/ipc/CommandMessage.cpp b/ipc/CommandMessage.cpp index 392906880..64d4d41cc 100644 --- a/ipc/CommandMessage.cpp +++ b/ipc/CommandMessage.cpp @@ -66,10 +66,6 @@ size_t CommandMessage::getMinimumMessageSize() const { return MINIMUM_COMMAND_MESSAGE_SIZE; } -size_t CommandMessage::getMaximumMessageSize() const { - return MessageQueueMessage::MAX_MESSAGE_SIZE; -} - bool CommandMessage::isClearedCommandMessage() { return getCommand() == CMD_NONE; } diff --git a/ipc/CommandMessage.h b/ipc/CommandMessage.h index 72f393573..a09494c6c 100644 --- a/ipc/CommandMessage.h +++ b/ipc/CommandMessage.h @@ -24,11 +24,11 @@ class CommandMessage: public CommandMessageBase { public: /** * This is the size of a message as it is seen by the MessageQueue. + * It can hold the CommandMessage header plus 2 4-byte parameters. * 14 of the 24 available MessageQueueMessage bytes are used. */ static const size_t MINIMUM_COMMAND_MESSAGE_SIZE = - MessageQueueMessage::HEADER_SIZE + sizeof(Command_t) + - 2 * sizeof(uint32_t); + CommandMessageIF::HEADER_SIZE + 2 * sizeof(uint32_t); /** * Default Constructor, does not initialize anything. @@ -55,8 +55,6 @@ public: /** MessageQueueMessageIF functions used for minimum size check. */ size_t getMinimumMessageSize() const override; - /** MessageQueueMessageIF functions used for maximum size check. */ - size_t getMaximumMessageSize() const override; /** * Get the first parameter of the message diff --git a/ipc/CommandMessageBase.cpp b/ipc/CommandMessageBase.cpp index 7085ab88d..80f9d3786 100644 --- a/ipc/CommandMessageBase.cpp +++ b/ipc/CommandMessageBase.cpp @@ -55,10 +55,18 @@ size_t CommandMessageBase::getMessageSize() const { return internalMessage->getMessageSize(); } +size_t CommandMessageBase::getMaximumMessageSize() const { + return internalMessage->getMaximumMessageSize(); +} + MessageQueueMessageIF* CommandMessageBase::getInternalMessage() const { return internalMessage; } +size_t CommandMessageBase::getMinimumMessageSize() const { + return MINIMUM_COMMAND_MESSAGE_BASE_SIZE; +} + void CommandMessageBase::setReplyRejected(ReturnValue_t reason, Command_t initialCommand) { std::memcpy(getData(), &reason, sizeof(reason)); diff --git a/ipc/CommandMessageBase.h b/ipc/CommandMessageBase.h index d2f24c7e6..b237b68f3 100644 --- a/ipc/CommandMessageBase.h +++ b/ipc/CommandMessageBase.h @@ -15,13 +15,21 @@ * size checks: * * 1. getMinimumMessageSize() - * 2. getMaximumMessageSize() * + * The maximum message size generally depends on the buffer size of the passed + * internal message. * Don't forget to set the message size of the passed message in the concrete * commandmessage implementation! */ class CommandMessageBase: public CommandMessageIF { public: + //! This minimum size is derived from the interface requirement to be able + //! to set a rejected reply, which contains a returnvalue and the initial + //! command. + static constexpr size_t MINIMUM_COMMAND_MESSAGE_BASE_SIZE = + CommandMessageIF::HEADER_SIZE + sizeof(ReturnValue_t) + + sizeof(Command_t); + CommandMessageBase(MessageQueueMessageIF* message); /** @@ -58,6 +66,12 @@ public: virtual void setMessageSize(size_t messageSize) override; virtual size_t getMessageSize() const override; + //! This depends on the maximum message size of the passed internal message. + virtual size_t getMaximumMessageSize() const override; + + //! Return the constant minimum message size. + virtual size_t getMinimumMessageSize() const override; + /** * A command message can be rejected and needs to offer a function * to set a rejected reply