1
0
forked from fsfw/fsfw

renormalized line endings

This commit is contained in:
2020-08-28 18:33:29 +02:00
parent 9abd796e6f
commit 1b9c8446b7
381 changed files with 38723 additions and 38723 deletions

View File

@ -1,107 +1,107 @@
#include "../objectmanager/ObjectManager.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <iomanip>
#include <cstdlib>
ObjectManager::ObjectManager( void (*setProducer)() ):
produceObjects(setProducer) {
//There's nothing special to do in the constructor.
}
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) {
// sif::debug << "ObjectManager::insert: Object " << std::hex
// << (int)id << std::dec << " inserted." << std::endl;
return this->RETURN_OK;
} else {
sif::error << "ObjectManager::insert: Object id " << std::hex
<< (int)id << std::dec << " is already in use!" << std::endl;
sif::error << "Terminating program." << std::endl;
//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 );
//sif::debug << "ObjectManager::removeObject: Object " << std::hex
// << (int)id << std::dec << " removed." << std::endl;
return RETURN_OK;
} else {
sif::error << "ObjectManager::removeObject: Requested object "
<< std::hex << (int)id << std::dec << " not found." << std::endl;
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;
}
}
ObjectManager::ObjectManager() : produceObjects(nullptr) {
}
void ObjectManager::initialize() {
if(produceObjects == nullptr) {
sif::error << "ObjectManager::initialize: Passed produceObjects "
"functions is nullptr!" << std::endl;
return;
}
this->produceObjects();
ReturnValue_t result = RETURN_FAILED;
uint32_t errorCount = 0;
for (auto const& it : objectList) {
result = it.second->initialize();
if ( result != RETURN_OK ) {
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;
errorCount++;
}
}
if (errorCount > 0) {
sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
<< " failed initializations." << std::endl;
}
//Init was successful. Now check successful interconnections.
errorCount = 0;
for (auto const& it : objectList) {
result = it.second->checkObjectConnections();
if ( result != RETURN_OK ) {
sif::error << "ObjectManager::ObjectManager: Object " << std::hex <<
(int) it.first << " connection check failed with code 0x"
<< result << std::dec << std::endl;
errorCount++;
}
}
if (errorCount > 0) {
sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
<< " failed connection checks." << std::endl;
}
}
void ObjectManager::printList() {
sif::debug << "ObjectManager: Object List contains:" << std::endl;
for (auto const& it : objectList) {
sif::debug << std::hex << it.first << " | " << it.second << std::endl;
}
}
#include "../objectmanager/ObjectManager.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <iomanip>
#include <cstdlib>
ObjectManager::ObjectManager( void (*setProducer)() ):
produceObjects(setProducer) {
//There's nothing special to do in the constructor.
}
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) {
// sif::debug << "ObjectManager::insert: Object " << std::hex
// << (int)id << std::dec << " inserted." << std::endl;
return this->RETURN_OK;
} else {
sif::error << "ObjectManager::insert: Object id " << std::hex
<< (int)id << std::dec << " is already in use!" << std::endl;
sif::error << "Terminating program." << std::endl;
//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 );
//sif::debug << "ObjectManager::removeObject: Object " << std::hex
// << (int)id << std::dec << " removed." << std::endl;
return RETURN_OK;
} else {
sif::error << "ObjectManager::removeObject: Requested object "
<< std::hex << (int)id << std::dec << " not found." << std::endl;
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;
}
}
ObjectManager::ObjectManager() : produceObjects(nullptr) {
}
void ObjectManager::initialize() {
if(produceObjects == nullptr) {
sif::error << "ObjectManager::initialize: Passed produceObjects "
"functions is nullptr!" << std::endl;
return;
}
this->produceObjects();
ReturnValue_t result = RETURN_FAILED;
uint32_t errorCount = 0;
for (auto const& it : objectList) {
result = it.second->initialize();
if ( result != RETURN_OK ) {
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;
errorCount++;
}
}
if (errorCount > 0) {
sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
<< " failed initializations." << std::endl;
}
//Init was successful. Now check successful interconnections.
errorCount = 0;
for (auto const& it : objectList) {
result = it.second->checkObjectConnections();
if ( result != RETURN_OK ) {
sif::error << "ObjectManager::ObjectManager: Object " << std::hex <<
(int) it.first << " connection check failed with code 0x"
<< result << std::dec << std::endl;
errorCount++;
}
}
if (errorCount > 0) {
sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
<< " failed connection checks." << std::endl;
}
}
void ObjectManager::printList() {
sif::debug << "ObjectManager: Object List contains:" << std::endl;
for (auto const& it : objectList) {
sif::debug << std::hex << it.first << " | " << it.second << std::endl;
}
}

View File

@ -1,67 +1,67 @@
/**
* @file ObjectManager.h
* @brief This file contains the implementation of the ObjectManager class
* @date 18.09.2012
* @author Bastian Baetz
*/
#ifndef OBJECTMANAGER_H_
#define OBJECTMANAGER_H_
#include "../objectmanager/ObjectManagerIF.h"
#include "../objectmanager/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
*/
class ObjectManager : public ObjectManagerIF {
private:
//comparison?
/**
* \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;
protected:
SystemObjectIF* getSystemObject( object_id_t id );
/**
* @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.
*/
void (*produceObjects)();
public:
/**
* @brief Apart from setting the producer function, nothing special
* happens in the constructor.
* @param setProducer A pointer to a factory function.
*/
ObjectManager( void (*produce)() );
ObjectManager();
/**
* @brief In the class's destructor, all objects in the list are deleted.
*/
//SHOULDDO: If, for some reason, deleting an ObjectManager instance is required, check if this works.
virtual ~ObjectManager( void );
ReturnValue_t insert( object_id_t id, SystemObjectIF* object );
ReturnValue_t remove( object_id_t id );
void initialize();
void printList();
};
#endif /* OBJECTMANAGER_H_ */
/**
* @file ObjectManager.h
* @brief This file contains the implementation of the ObjectManager class
* @date 18.09.2012
* @author Bastian Baetz
*/
#ifndef OBJECTMANAGER_H_
#define OBJECTMANAGER_H_
#include "../objectmanager/ObjectManagerIF.h"
#include "../objectmanager/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
*/
class ObjectManager : public ObjectManagerIF {
private:
//comparison?
/**
* \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;
protected:
SystemObjectIF* getSystemObject( object_id_t id );
/**
* @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.
*/
void (*produceObjects)();
public:
/**
* @brief Apart from setting the producer function, nothing special
* happens in the constructor.
* @param setProducer A pointer to a factory function.
*/
ObjectManager( void (*produce)() );
ObjectManager();
/**
* @brief In the class's destructor, all objects in the list are deleted.
*/
//SHOULDDO: If, for some reason, deleting an ObjectManager instance is required, check if this works.
virtual ~ObjectManager( void );
ReturnValue_t insert( object_id_t id, SystemObjectIF* object );
ReturnValue_t remove( object_id_t id );
void initialize();
void printList();
};
#endif /* OBJECTMANAGER_H_ */

View File

@ -1,95 +1,95 @@
#ifndef FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
#define FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
#include "../objectmanager/frameworkObjects.h"
#include "../objectmanager/SystemObjectIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../serviceinterface/ServiceInterfaceStream.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.
* @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 );
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 the get call, interfaces of an object can be retrieved in
* a type-safe manner.
* @details With the template-based call, the object list is searched with the
* getSystemObject method and afterwards it is checked, if the object
* implements the requested interface (with a dynamic_cast).
* @param id The object id of the requested object.
* @return The method returns a pointer to an object implementing the
* requested interface, or NULL.
*/
template <typename T> T* get( object_id_t id );
/**
* @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;
};
/**
* @brief This is the forward declaration of the global objectManager instance.
*/
extern ObjectManagerIF *objectManager;
/*Documentation can be found in the class method declaration above.*/
template <typename T>
T* ObjectManagerIF::get( object_id_t id ) {
if(objectManager == nullptr) {
sif::error << "ObjectManagerIF: Global object manager has not "
"been initialized yet!" << std::endl;
}
SystemObjectIF* temp = this->getSystemObject(id);
return dynamic_cast<T*>(temp);
}
#endif /* OBJECTMANAGERIF_H_ */
#ifndef FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
#define FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
#include "../objectmanager/frameworkObjects.h"
#include "../objectmanager/SystemObjectIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../serviceinterface/ServiceInterfaceStream.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.
* @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 );
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 the get call, interfaces of an object can be retrieved in
* a type-safe manner.
* @details With the template-based call, the object list is searched with the
* getSystemObject method and afterwards it is checked, if the object
* implements the requested interface (with a dynamic_cast).
* @param id The object id of the requested object.
* @return The method returns a pointer to an object implementing the
* requested interface, or NULL.
*/
template <typename T> T* get( object_id_t id );
/**
* @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;
};
/**
* @brief This is the forward declaration of the global objectManager instance.
*/
extern ObjectManagerIF *objectManager;
/*Documentation can be found in the class method declaration above.*/
template <typename T>
T* ObjectManagerIF::get( object_id_t id ) {
if(objectManager == nullptr) {
sif::error << "ObjectManagerIF: Global object manager has not "
"been initialized yet!" << std::endl;
}
SystemObjectIF* temp = this->getSystemObject(id);
return dynamic_cast<T*>(temp);
}
#endif /* OBJECTMANAGERIF_H_ */

View File

@ -1,37 +1,37 @@
#include "../events/EventManagerIF.h"
#include "../objectmanager/ObjectManager.h"
#include "../objectmanager/SystemObject.h"
SystemObject::SystemObject(object_id_t setObjectId, bool doRegister) :
objectId(setObjectId), registered(doRegister) {
if (registered) {
objectManager->insert(objectId, this);
}
}
SystemObject::~SystemObject() {
if (registered) {
objectManager->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);
}
#include "../events/EventManagerIF.h"
#include "../objectmanager/ObjectManager.h"
#include "../objectmanager/SystemObject.h"
SystemObject::SystemObject(object_id_t setObjectId, bool doRegister) :
objectId(setObjectId), registered(doRegister) {
if (registered) {
objectManager->insert(objectId, this);
}
}
SystemObject::~SystemObject() {
if (registered) {
objectManager->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

@ -1,62 +1,62 @@
#ifndef FRAMEWORK_OBJECTMANAGER_SYSTEMOBJECTIF_H_
#define FRAMEWORK_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 /* FRAMEWORK_OBJECTMANAGER_SYSTEMOBJECTIF_H_ */
#ifndef FRAMEWORK_OBJECTMANAGER_SYSTEMOBJECTIF_H_
#define FRAMEWORK_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 /* FRAMEWORK_OBJECTMANAGER_SYSTEMOBJECTIF_H_ */