trying to fuse header / inc

This commit is contained in:
2021-07-19 16:25:51 +02:00
parent 7849b8e391
commit d47906e833
767 changed files with 117 additions and 135 deletions

View File

@ -0,0 +1,5 @@
target_sources(${LIB_FSFW_NAME}
PRIVATE
ObjectManager.cpp
SystemObject.cpp
)

View File

@ -0,0 +1,145 @@
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1
#include <iomanip>
#endif
#include <cstdlib>
ObjectManager* ObjectManager::objManagerInstance = nullptr;
ObjectManager* ObjectManager::instance() {
if(objManagerInstance == nullptr) {
objManagerInstance = new ObjectManager();
}
return objManagerInstance;
}
void ObjectManager::setObjectFactoryFunction(produce_function_t objFactoryFunc, void *factoryArgs) {
this->objectFactoryFunction = objFactoryFunc;
this->factoryArgs = factoryArgs;
}
ObjectManager::ObjectManager() {}
ObjectManager::~ObjectManager() {
for (auto const& iter : objectList) {
delete iter.second;
}
}
ReturnValue_t ObjectManager::insert( object_id_t id, SystemObjectIF* object) {
auto returnPair = objectList.emplace(id, object);
if (returnPair.second) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
// sif::debug << "ObjectManager::insert: Object " << std::hex
// << (int)id << std::dec << " inserted." << std::endl;
#endif
return this->RETURN_OK;
} else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectManager::insert: Object ID " << std::hex <<
static_cast<uint32_t>(id) << std::dec << " is already in use!" << std::endl;
sif::error << "Terminating program" << std::endl;
#else
sif::printError("ObjectManager::insert: Object ID 0x%08x is already in use!\n",
static_cast<unsigned int>(id));
sif::printError("Terminating program");
#endif
//This is very severe and difficult to handle in other places.
std::exit(INSERTION_FAILED);
}
}
ReturnValue_t ObjectManager::remove( object_id_t id ) {
if ( this->getSystemObject(id) != NULL ) {
this->objectList.erase( id );
#if FSFW_CPP_OSTREAM_ENABLED == 1
//sif::debug << "ObjectManager::removeObject: Object " << std::hex
// << (int)id << std::dec << " removed." << std::endl;
#endif
return RETURN_OK;
} else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectManager::removeObject: Requested object "
<< std::hex << (int)id << std::dec << " not found." << std::endl;
#endif
return NOT_FOUND;
}
}
SystemObjectIF* ObjectManager::getSystemObject( object_id_t id ) {
auto listIter = this->objectList.find( id );
if (listIter == this->objectList.end() ) {
return nullptr;
} else {
return listIter->second;
}
}
void ObjectManager::initialize() {
if(objectFactoryFunction == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectManager::initialize: Passed produceObjects "
"functions is nullptr!" << std::endl;
#else
sif::printError("ObjectManager::initialize: Passed produceObjects functions is nullptr!\n");
#endif
return;
}
objectFactoryFunction(factoryArgs);
ReturnValue_t result = RETURN_FAILED;
uint32_t errorCount = 0;
for (auto const& it : objectList) {
result = it.second->initialize();
if ( result != RETURN_OK ) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
object_id_t var = it.first;
sif::error << "ObjectManager::initialize: Object 0x" << std::hex <<
std::setw(8) << std::setfill('0')<< var << " failed to "
"initialize with code 0x" << result << std::dec <<
std::setfill(' ') << std::endl;
#endif
errorCount++;
}
}
if (errorCount > 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
<< " failed initializations." << std::endl;
#endif
}
//Init was successful. Now check successful interconnections.
errorCount = 0;
for (auto const& it : objectList) {
result = it.second->checkObjectConnections();
if ( result != RETURN_OK ) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectManager::ObjectManager: Object 0x" << std::hex <<
(int) it.first << " connection check failed with code 0x" << result <<
std::dec << std::endl;
#endif
errorCount++;
}
}
if (errorCount > 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
<< " failed connection checks." << std::endl;
#endif
}
}
void ObjectManager::printList() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "ObjectManager: Object List contains:" << std::endl;
for (auto const& it : objectList) {
sif::debug << std::hex << it.first << " | " << it.second << std::endl;
}
#endif
}

View File

@ -0,0 +1,78 @@
#ifndef FSFW_OBJECTMANAGER_OBJECTMANAGER_H_
#define FSFW_OBJECTMANAGER_OBJECTMANAGER_H_
#include "ObjectManagerIF.h"
#include "SystemObjectIF.h"
#include <map>
/**
* @brief This class implements a global object manager.
* @details This manager handles a list of available objects with system-wide
* relevance, such as device handlers, and TM/TC services. Objects can
* be inserted, removed and retrieved from the list. In addition, the
* class holds a so-called factory, that creates and inserts new
* objects if they are not already in the list. This feature automates
* most of the system initialization.
* As the system is static after initialization, no new objects are
* created or inserted into the list after startup.
* @ingroup system_objects
* @author Bastian Baetz
*/
class ObjectManager : public ObjectManagerIF {
public:
using produce_function_t = void (*) (void* args);
/**
* Returns the single instance of TaskFactory.
* The implementation of #instance is found in its subclasses.
* Thus, we choose link-time variability of the instance.
*/
static ObjectManager* instance();
void setObjectFactoryFunction(produce_function_t prodFunc, void* args);
template <typename T> T* get( object_id_t id );
/**
* @brief In the class's destructor, all objects in the list are deleted.
*/
virtual ~ObjectManager();
ReturnValue_t insert(object_id_t id, SystemObjectIF* object) override;
ReturnValue_t remove(object_id_t id) override;
void initialize() override;
void printList() override;
protected:
SystemObjectIF* getSystemObject(object_id_t id) override;
/**
* @brief This attribute is initialized with the factory function
* that creates new objects.
* @details The function is called if an object was requested with
* getSystemObject, but not found in objectList.
* @param The id of the object to be created.
* @return Returns a pointer to the newly created object or NULL.
*/
produce_function_t objectFactoryFunction = nullptr;
void* factoryArgs = nullptr;
private:
ObjectManager();
/**
* @brief This is the map of all initialized objects in the manager.
* @details Objects in the List must inherit the SystemObjectIF.
*/
std::map<object_id_t, SystemObjectIF*> objectList;
static ObjectManager* objManagerInstance;
};
// Documentation can be found in the class method declaration above
template <typename T>
T* ObjectManager::get( object_id_t id ) {
SystemObjectIF* temp = this->getSystemObject(id);
return dynamic_cast<T*>(temp);
}
#endif /* FSFW_OBJECTMANAGER_OBJECTMANAGER_H_ */

View File

@ -0,0 +1,68 @@
#ifndef FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
#define FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
#include "frameworkObjects.h"
#include "SystemObjectIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../serviceinterface/ServiceInterface.h"
/**
* @brief This class provides an interface to the global object manager.
* @details
* This manager handles a list of available objects with system-wide relevance, such as device
* handlers, and TM/TC services. They can be inserted, removed and retrieved from the list.
* On getting the object, the call checks if the object implements the requested interface.
* This interface does not specify a getter function because templates can't be used in interfaces.
* @author Bastian Baetz
* @ingroup system_objects
*/
class ObjectManagerIF : public HasReturnvaluesIF {
public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::OBJECT_MANAGER_IF;
static constexpr ReturnValue_t INSERTION_FAILED = MAKE_RETURN_CODE( 1 );
static constexpr ReturnValue_t NOT_FOUND = MAKE_RETURN_CODE( 2 );
//!< Can be used if the initialization of a SystemObject failed.
static constexpr ReturnValue_t CHILD_INIT_FAILED = MAKE_RETURN_CODE( 3 );
static constexpr ReturnValue_t INTERNAL_ERR_REPORTER_UNINIT = MAKE_RETURN_CODE( 4 );
protected:
/**
* @brief This method is used to hide the template-based get call from
* a specific implementation.
* @details So, an implementation only has to implement this call.
* @param id The object id of the requested object.
* @return The method returns a pointer to an object implementing (at
* least) the SystemObjectIF, or NULL.
*/
virtual SystemObjectIF* getSystemObject( object_id_t id ) = 0;
public:
/**
* @brief This is the empty virtual destructor as requested by C++ interfaces.
*/
virtual ~ObjectManagerIF( void ) {};
/**
* @brief With this call, new objects are inserted to the list.
* @details The implementation shall return an error code in case the
* object can't be added (e.g. the id is already in use).
* @param id The new id to be added to the list.
* @param object A pointer to the object to be added.
* @return @li INSERTION_FAILED in case the object could not be inserted.
* @li RETURN_OK in case the object was successfully inserted
*/
virtual ReturnValue_t insert( object_id_t id, SystemObjectIF* object ) = 0;
/**
* @brief With this call, an object is removed from the list.
* @param id The object id of the object to be removed.
* @return @li NOT_FOUND in case the object was not found
* @li RETURN_OK in case the object was successfully removed
*/
virtual ReturnValue_t remove( object_id_t id ) = 0;
virtual void initialize() = 0;
/**
* @brief This is a debug function, that prints the current content of the
* object list.
*/
virtual void printList() = 0;
};
#endif /* OBJECTMANAGERIF_H_ */

View File

@ -0,0 +1,37 @@
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/events/EventManagerIF.h"
SystemObject::SystemObject(object_id_t setObjectId, bool doRegister) :
objectId(setObjectId), registered(doRegister) {
if (registered) {
ObjectManager::instance()->insert(objectId, this);
}
}
SystemObject::~SystemObject() {
if (registered) {
ObjectManager::instance()->remove(objectId);
}
}
object_id_t SystemObject::getObjectId() const {
return objectId;
}
void SystemObject::triggerEvent(Event event, uint32_t parameter1,
uint32_t parameter2) {
EventManagerIF::triggerEvent(objectId, event, parameter1, parameter2);
}
ReturnValue_t SystemObject::initialize() {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SystemObject::checkObjectConnections() {
return HasReturnvaluesIF::RETURN_OK;
}
void SystemObject::forwardEvent(Event event, uint32_t parameter1, uint32_t parameter2) const {
EventManagerIF::triggerEvent(objectId, event, parameter1, parameter2);
}

View File

@ -0,0 +1,58 @@
#ifndef FSFW_OBJECTMANAGER_SYSTEMOBJECT_H_
#define FSFW_OBJECTMANAGER_SYSTEMOBJECT_H_
#include "SystemObjectIF.h"
#include "fsfw/events/Event.h"
#include "fsfw/events/EventReportingProxyIF.h"
#include "fsfw/timemanager/Clock.h"
/**
* @brief This class automates insertion into the ObjectManager and
* management of the object id.
* @details This class is more a base class, which shall be inherited by any
* class that is announced to ObjectManager. It automatically includes
* itself (and therefore the inheriting class) in the object manager's
* list.
* @author Ulrich Mohr
* @ingroup system_objects
*/
class SystemObject: public SystemObjectIF {
private:
/**
* @brief This is the id the class instant got assigned.
*/
const object_id_t objectId;
const bool registered;
public:
/**
* Helper function to send Event Messages to the Event Manager
* @param event
* @param parameter1
* @param parameter2
*/
virtual void triggerEvent(Event event, uint32_t parameter1 = 0,
uint32_t parameter2 = 0);
/**
* @brief The class's constructor.
* @details In the constructor, the object id is set and the class is
* inserted in the object manager.
* @param setObjectId The id the object shall have.
* @param doRegister Determines if the object is registered in
* the global object manager.
*/
SystemObject(object_id_t setObjectId, bool doRegister = true);
/**
* @brief On destruction, the object removes itself from the list.
*/
virtual ~SystemObject();
object_id_t getObjectId() const override;
virtual ReturnValue_t initialize() override;
virtual ReturnValue_t checkObjectConnections();
virtual void forwardEvent(Event event, uint32_t parameter1 = 0,
uint32_t parameter2 = 0) const;
};
#endif /* FSFW_OBJECTMANAGER_SYSTEMOBJECT_H_ */

View File

@ -0,0 +1,62 @@
#ifndef FSFW_OBJECTMANAGER_SYSTEMOBJECTIF_H_
#define FSFW_OBJECTMANAGER_SYSTEMOBJECTIF_H_
#include "../events/EventReportingProxyIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include <cstdint>
/**
* @defgroup system_objects Software System Object Management
* The classes to create System Objects and classes to manage these are
* contained in this group. System Objects are software elements that can be
* controlled externally. They all have a unique object identifier.
*/
/**
* This is the typedef for object identifiers.
* @ingroup system_objects
*/
typedef uint32_t object_id_t;
/**
* This interface allows a class to be included in the object manager
* list.
* It does not provide any method definitions, still it is required to
* perform a type check with dynamic_cast.
* @author Bastian Baetz
* @ingroup system_objects
*/
class SystemObjectIF : public EventReportingProxyIF {
public:
/**
* This is a simple getter to return the object identifier.
* @return Returns the object id of this object.
*/
virtual object_id_t getObjectId() const = 0;
/**
* The empty virtual destructor as required for C++ interfaces.
*/
virtual ~SystemObjectIF() {}
/**
* @brief Initializes the object.
* There are initialization steps which can also be done in the constructor.
* However, there is no clean way to get a returnvalue from a constructor.
* Furthermore some components require other system object to be created
* which might not have been built yet.
* Therefore, a two-step initialization resolves this problem and prevents
* circular dependencies of not-fully initialized objects on start up.
* @return - @c RETURN_OK in case the initialization was successful
* - @c RETURN_FAILED otherwise
*/
virtual ReturnValue_t initialize() = 0;
/**
* @brief Checks if all object-object interconnections are satisfying
* for operation.
* Some objects need certain other objects (or a certain number), to be
* registered as children. These checks can be done in this method.
* @return - @c RETURN_OK in case the check was successful
* - @c any other code otherwise
*/
virtual ReturnValue_t checkObjectConnections() = 0;
};
#endif /* #ifndef FSFW_OBJECTMANAGER_SYSTEMOBJECTIF_H_ */

View File

@ -0,0 +1,40 @@
#ifndef FSFW_OBJECTMANAGER_FRAMEWORKOBJECTS_H_
#define FSFW_OBJECTMANAGER_FRAMEWORKOBJECTS_H_
#include "SystemObjectIF.h"
// The objects will be instantiated in the ID order
namespace objects {
enum framework_objects: object_id_t {
FSFW_OBJECTS_START = 0x53000000,
// Default verification reporter.
PUS_SERVICE_1_VERIFICATION = 0x53000001,
PUS_SERVICE_2_DEVICE_ACCESS = 0x53000002,
PUS_SERVICE_3_HOUSEKEEPING = 0x53000003,
PUS_SERVICE_5_EVENT_REPORTING = 0x53000005,
PUS_SERVICE_8_FUNCTION_MGMT = 0x53000008,
PUS_SERVICE_9_TIME_MGMT = 0x53000009,
PUS_SERVICE_17_TEST = 0x53000017,
PUS_SERVICE_20_PARAMETERS = 0x53000020,
PUS_SERVICE_200_MODE_MGMT = 0x53000200,
PUS_SERVICE_201_HEALTH = 0x53000201,
//Generic IDs for IPC, modes, health, events
HEALTH_TABLE = 0x53010000,
// MODE_STORE = 0x53010100,
EVENT_MANAGER = 0x53030000,
INTERNAL_ERROR_REPORTER = 0x53040000,
IPC_STORE = 0x534f0300,
//IDs for PUS Packet Communication
TC_STORE = 0x534f0100,
TM_STORE = 0x534f0200,
TIME_STAMPER = 0x53500010,
FSFW_OBJECTS_END = 0x53ffffff,
NO_OBJECT = 0xFFFFFFFF
};
}
#endif /* FSFW_OBJECTMANAGER_FRAMEWORKOBJECTS_H_ */