diff --git a/container/ArrayList.h b/container/ArrayList.h index 6bd5c1d5a..19454777b 100644 --- a/container/ArrayList.h +++ b/container/ArrayList.h @@ -1,15 +1,15 @@ -#ifndef FSFW_CONTAINER_ARRAYLIST_H_ -#define FSFW_CONTAINER_ARRAYLIST_H_ +#ifndef ARRAYLIST_H_ +#define ARRAYLIST_H_ #include "../returnvalues/HasReturnvaluesIF.h" #include "../serialize/SerializeAdapter.h" #include "../serialize/SerializeIF.h" /** - * @brief A List that stores its values in an array. - * @details - * The underlying storage is an array that can be allocated by the class - * itself or supplied via ctor. + * A List that stores its values in an array. + * + * The backend is an array that can be allocated by the class itself or supplied via ctor. + * * * @ingroup container */ @@ -20,53 +20,6 @@ public: static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST; static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01); - /** - * This is the allocating constructor. - * It allocates an array of the specified size. - * @param maxSize - */ - ArrayList(count_t maxSize) : - size(0), maxSize_(maxSize), allocated(true) { - entries = new T[maxSize]; - } - - /** - * This is the non-allocating constructor - * - * It expects a pointer to an array of a certain size and initializes - * itself to it. - * - * @param storage the array to use as backend - * @param maxSize size of storage - * @param size size of data already present in storage - */ - ArrayList(T *storage, count_t maxSize, count_t size = 0) : - size(size), entries(storage), maxSize_(maxSize), allocated(false) { - } - - /** - * Copying is forbiden by declaring copy ctor and copy assignment deleted - * It is too ambigous in this case. - * (Allocate a new backend? Use the same? What to do in an modifying call?) - */ - ArrayList(const ArrayList& other) = delete; - const ArrayList& operator=(const ArrayList& other) = delete; - - /** - * Number of Elements stored in this List - */ - count_t size; - - - /** - * Destructor, if the allocating constructor was used, it deletes the array. - */ - virtual ~ArrayList() { - if (allocated) { - delete[] entries; - } - } - /** * An Iterator to go trough an ArrayList * @@ -78,7 +31,10 @@ public: /** * Empty ctor, points to NULL */ - Iterator(): value(0) {} + Iterator() : + value(0) { + + } /** * Initializes the Iterator to point to an element @@ -116,31 +72,70 @@ public: return tmp; } - T& operator*() { + T& operator*(){ return *value; } - const T& operator*() const { + const T& operator*() const{ return *value; } - T *operator->() { + T *operator->(){ return value; } - const T *operator->() const { + const T *operator->() const{ return value; } + + //SHOULDDO this should be implemented as non-member + bool operator==(const typename ArrayList::Iterator& other) const{ + return (value == other.value); + } + + //SHOULDDO this should be implemented as non-member + bool operator!=(const typename ArrayList::Iterator& other) const { + return !(*this == other); + } }; - friend bool operator==(const ArrayList::Iterator& lhs, - const ArrayList::Iterator& rhs) { - return (lhs.value == rhs.value); + /** + * Number of Elements stored in this List + */ + count_t size; + + /** + * This is the allocating constructor; + * + * It allocates an array of the specified size. + * + * @param maxSize + */ + ArrayList(count_t maxSize) : + size(0), maxSize_(maxSize), allocated(true) { + entries = new T[maxSize]; } - friend bool operator!=(const ArrayList::Iterator& lhs, - const ArrayList::Iterator& rhs) { - return not (lhs.value == rhs.value); + /** + * This is the non-allocating constructor + * + * It expects a pointer to an array of a certain size and initializes itself to it. + * + * @param storage the array to use as backend + * @param maxSize size of storage + * @param size size of data already present in storage + */ + ArrayList(T *storage, count_t maxSize, count_t size = 0) : + size(size), entries(storage), maxSize_(maxSize), allocated(false) { + } + + /** + * Destructor, if the allocating constructor was used, it deletes the array. + */ + virtual ~ArrayList() { + if (allocated) { + delete[] entries; + } } /** @@ -196,7 +191,7 @@ public: * * @return maximum number of elements */ - size_t maxSize() const { + uint32_t maxSize() const { return this->maxSize_; } @@ -231,7 +226,19 @@ public: count_t remaining() { return (maxSize_ - size); } - +private: + /** + * This is the copy constructor + * + * It is private, as copying is too ambigous in this case. (Allocate a new backend? Use the same? + * What to do in an modifying call?) + * + * @param other + */ + ArrayList(const ArrayList& other) : + size(other.size), entries(other.entries), maxSize_(other.maxSize_), allocated( + false) { + } protected: /** * pointer to the array in which the entries are stored @@ -240,14 +247,12 @@ protected: /** * remembering the maximum size */ - size_t maxSize_; + uint32_t maxSize_; /** * true if the array was allocated and needs to be deleted in the destructor. */ bool allocated; + }; - - - -#endif /* FSFW_CONTAINER_ARRAYLIST_H_ */ +#endif /* ARRAYLIST_H_ */ diff --git a/container/FixedMap.h b/container/FixedMap.h index 7a5220faa..d1cc31ff1 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -7,21 +7,14 @@ #include /** - * @brief Map implementation for maps with a pre-defined size. - * @details - * Can be initialized with desired maximum size. - * Iterator is used to access pair and iterate through map entries. - * Complexity O(n). * @warning Iterators return a non-const key_t in the pair. * @warning A User is not allowed to change the key, otherwise the map is corrupted. * @ingroup container */ template class FixedMap: public SerializeIF { - static_assert (std::is_trivially_copyable::value or - std::is_base_of::value, - "Types used in FixedMap must either be trivial copy-able or a " - "derived class from SerializeIF to be serialize-able"); + static_assert (std::is_trivially_copyable::value or std::is_base_of::value, + "Types used in FixedMap must either be trivial copy-able or a derived Class from SerializeIF to be serialize-able"); public: static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP; static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01); @@ -61,16 +54,6 @@ public: } }; - friend bool operator==(const typename FixedMap::Iterator& lhs, - const typename FixedMap::Iterator& rhs) { - return (lhs.value == rhs.value); - } - - friend bool operator!=(const typename FixedMap::Iterator& lhs, - const typename FixedMap::Iterator& rhs) { - return not (lhs.value == rhs.value); - } - Iterator begin() const { return Iterator(&theMap[0]); } @@ -153,24 +136,6 @@ public: return HasReturnvaluesIF::RETURN_OK; } - bool empty() { - if(_size == 0) { - return true; - } - else { - return false; - } - } - - bool full() { - if(_size >= theMap.maxSize()) { - return true; - } - else { - return false; - } - } - void clear() { _size = 0; } diff --git a/events/Event.h b/events/Event.h index e22c9db16..f8410f328 100644 --- a/events/Event.h +++ b/events/Event.h @@ -4,7 +4,7 @@ #include #include "fwSubsystemIdRanges.h" //could be move to more suitable location -#include +#include typedef uint16_t EventId_t; typedef uint8_t EventSeverity_t; diff --git a/osal/host/MessageQueue.cpp b/osal/host/MessageQueue.cpp index bced37139..550cfc33a 100644 --- a/osal/host/MessageQueue.cpp +++ b/osal/host/MessageQueue.cpp @@ -20,20 +20,20 @@ MessageQueue::~MessageQueue() { } ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo, - MessageQueueMessageIF* message, bool ignoreFault) { + MessageQueueMessage* message, bool ignoreFault) { return sendMessageFrom(sendTo, message, this->getId(), ignoreFault); } -ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessageIF* message) { +ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessage* message) { return sendToDefaultFrom(message, this->getId()); } -ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message, +ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault) { return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault); } -ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) { +ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) { if (this->lastPartner != 0) { return sendMessageFrom(this->lastPartner, message, this->getId()); } else { @@ -42,13 +42,13 @@ ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) { } ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo, - MessageQueueMessageIF* message, MessageQueueId_t sentFrom, + MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault) { return sendMessageFromMessageQueue(sendTo, message, sentFrom, ignoreFault); } -ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message, +ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message, MessageQueueId_t* receivedFrom) { ReturnValue_t status = this->receiveMessage(message); if(status == HasReturnvaluesIF::RETURN_OK) { @@ -57,7 +57,7 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message, return status; } -ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) { +ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) { if(messageQueue.empty()) { return MessageQueueIF::EMPTY; } @@ -104,7 +104,7 @@ bool MessageQueue::isDefaultDestinationSet() const { // static core function to send messages. ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, - MessageQueueMessageIF* message, MessageQueueId_t sentFrom, + MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault) { if(message->getMessageSize() > message->getMaximumMessageSize()) { // Actually, this should never happen or an error will be emitted diff --git a/osal/host/MessageQueue.h b/osal/host/MessageQueue.h index 97a9e4915..00345b591 100644 --- a/osal/host/MessageQueue.h +++ b/osal/host/MessageQueue.h @@ -77,7 +77,7 @@ public: * is not incremented if queue is full. */ ReturnValue_t sendMessage(MessageQueueId_t sendTo, - MessageQueueMessageIF* message, bool ignoreFault = false) override; + MessageQueueMessage* message, bool ignoreFault = false) override; /** * @brief This operation sends a message to the default destination. * @details As in the sendMessage method, this function uses the @@ -85,7 +85,7 @@ public: * queue id as "sentFrom" information. * @param message A pointer to a previously created message, which is sent. */ - ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override; + ReturnValue_t sendToDefault(MessageQueueMessage* message) override; /** * @brief This operation sends a message to the last communication partner. * @details This operation simplifies answering an incoming message by using @@ -93,7 +93,7 @@ public: * message received yet (i.e. lastPartner is zero), an error code is returned. * @param message A pointer to a previously created message, which is sent. */ - ReturnValue_t reply(MessageQueueMessageIF* message) override; + ReturnValue_t reply(MessageQueueMessage* message) override; /** * @brief With the sendMessage call, a queue message is sent to a @@ -113,7 +113,7 @@ public: * is not incremented if queue is full. */ virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, - MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE, + MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false) override; /** @@ -127,7 +127,7 @@ public: * sender's queue id into the message. This variable is set to zero by * default. */ - virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message, + virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false) override; @@ -140,7 +140,7 @@ public: * @param message A pointer to a message in which the received data is stored. * @param receivedFrom A pointer to a queue id in which the sender's id is stored. */ - ReturnValue_t receiveMessage(MessageQueueMessageIF* message, + ReturnValue_t receiveMessage(MessageQueueMessage* message, MessageQueueId_t *receivedFrom) override; /** @@ -153,7 +153,7 @@ public: * function returns immediately. * @param message A pointer to a message in which the received data is stored. */ - ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override; + ReturnValue_t receiveMessage(MessageQueueMessage* message) override; /** * Deletes all pending messages in the queue. * @param count The number of flushed messages. @@ -206,7 +206,7 @@ protected: * @param context Specify whether call is made from task or from an ISR. */ static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo, - MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE, + MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault=false); //static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); diff --git a/osal/host/QueueFactory.cpp b/osal/host/QueueFactory.cpp index da3fea55a..19ec7963d 100644 --- a/osal/host/QueueFactory.cpp +++ b/osal/host/QueueFactory.cpp @@ -1,4 +1,5 @@ #include "../../ipc/QueueFactory.h" +#include "../../ipc/MessageQueueSenderIF.h" #include "../../osal/host/MessageQueue.h" #include "../../serviceinterface/ServiceInterfaceStream.h" #include @@ -7,11 +8,10 @@ QueueFactory* QueueFactory::factoryInstance = nullptr; ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo, - MessageQueueMessageIF* message, MessageQueueId_t sentFrom, + MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault) { return MessageQueue::sendMessageFromMessageQueue(sendTo,message, sentFrom,ignoreFault); - return HasReturnvaluesIF::RETURN_OK; } QueueFactory* QueueFactory::instance() { diff --git a/timemanager/CCSDSTime.cpp b/timemanager/CCSDSTime.cpp index f99f8fbb4..e660dd2e6 100644 --- a/timemanager/CCSDSTime.cpp +++ b/timemanager/CCSDSTime.cpp @@ -1,4 +1,5 @@ #include "../timemanager/CCSDSTime.h" +#include #include #include #include @@ -158,7 +159,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* } // Newlib nano can't parse uint8, see SCNu8 documentation and https://sourceware.org/newlib/README // Suggestion: use uint16 all the time. This should work on all systems. -#ifdef NEWLIB_NANO_NO_C99_IO +#ifdef FSFW_NO_C99_IO uint16_t year; uint16_t month; uint16_t day;