optimized command messages a bit

This commit is contained in:
Robin Müller 2020-06-14 17:59:14 +02:00
parent 8c03f6a823
commit 9f69191f23
4 changed files with 25 additions and 9 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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));

View File

@ -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