Merge remote-tracking branch 'upstream/master' into mueller_ServiceStreamEnhancement

This commit is contained in:
Robin Müller 2020-06-10 16:40:48 +02:00
commit dd8543fedd
4 changed files with 80 additions and 74 deletions

View File

@ -1,25 +1,25 @@
#include <framework/globalfunctions/printer.h> #include <framework/globalfunctions/arrayprinter.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <bitset> #include <bitset>
void printer::print(const uint8_t *data, size_t size, OutputType type, void arrayprinter::print(const uint8_t *data, size_t size, OutputType type,
bool printInfo, size_t maxCharPerLine) { bool printInfo, size_t maxCharPerLine) {
if(printInfo) { if(printInfo) {
sif::info << "Printing data with size " << size << ": "; sif::info << "Printing data with size " << size << ": ";
} }
sif::info << "["; sif::info << "[";
if(type == OutputType::HEX) { if(type == OutputType::HEX) {
printer::printHex(data, size, maxCharPerLine); arrayprinter::printHex(data, size, maxCharPerLine);
} }
else if (type == OutputType::DEC) { else if (type == OutputType::DEC) {
printer::printDec(data, size, maxCharPerLine); arrayprinter::printDec(data, size, maxCharPerLine);
} }
else if(type == OutputType::BIN) { else if(type == OutputType::BIN) {
printer::printBin(data, size); arrayprinter::printBin(data, size);
} }
} }
void printer::printHex(const uint8_t *data, size_t size, void arrayprinter::printHex(const uint8_t *data, size_t size,
size_t maxCharPerLine) { size_t maxCharPerLine) {
sif::info << std::hex; sif::info << std::hex;
for(size_t i = 0; i < size; i++) { for(size_t i = 0; i < size; i++) {
@ -36,7 +36,7 @@ void printer::printHex(const uint8_t *data, size_t size,
sif::info << "]" << std::endl; sif::info << "]" << std::endl;
} }
void printer::printDec(const uint8_t *data, size_t size, void arrayprinter::printDec(const uint8_t *data, size_t size,
size_t maxCharPerLine) { size_t maxCharPerLine) {
sif::info << std::dec; sif::info << std::dec;
for(size_t i = 0; i < size; i++) { for(size_t i = 0; i < size; i++) {
@ -51,7 +51,7 @@ void printer::printDec(const uint8_t *data, size_t size,
sif::info << "]" << std::endl; sif::info << "]" << std::endl;
} }
void printer::printBin(const uint8_t *data, size_t size) { void arrayprinter::printBin(const uint8_t *data, size_t size) {
sif::info << "\n" << std::flush; sif::info << "\n" << std::flush;
for(size_t i = 0; i < size; i++) { for(size_t i = 0; i < size; i++) {
sif::info << "Byte " << i + 1 << ": 0b"<< sif::info << "Byte " << i + 1 << ": 0b"<<

View File

@ -1,16 +1,15 @@
#ifndef FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ #ifndef FRAMEWORK_GLOBALFUNCTIONS_ARRAYPRINTER_H_
#define FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ #define FRAMEWORK_GLOBALFUNCTIONS_ARRAYPRINTER_H_
#include <cstdint> #include <cstdint>
#include <cstddef> #include <cstddef>
namespace printer {
enum class OutputType { enum class OutputType {
DEC, DEC,
HEX, HEX,
BIN BIN
}; };
namespace arrayprinter {
void print(const uint8_t* data, size_t size, OutputType type = OutputType::HEX, void print(const uint8_t* data, size_t size, OutputType type = OutputType::HEX,
bool printInfo = true, size_t maxCharPerLine = 12); bool printInfo = true, size_t maxCharPerLine = 12);
void printHex(const uint8_t* data, size_t size, size_t maxCharPerLine = 12); void printHex(const uint8_t* data, size_t size, size_t maxCharPerLine = 12);
@ -18,4 +17,4 @@ void printDec(const uint8_t* data, size_t size, size_t maxCharPerLine = 12);
void printBin(const uint8_t* data, size_t size); void printBin(const uint8_t* data, size_t size);
} }
#endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */ #endif /* FRAMEWORK_GLOBALFUNCTIONS_ARRAYPRINTER_H_ */

View File

@ -2,37 +2,38 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <cstdlib> #include <cstdlib>
ObjectManager::ObjectManager( void (*setProducer)() ) : produceObjects(setProducer) { ObjectManager::ObjectManager( void (*setProducer)() ):
produceObjects(setProducer) {
//There's nothing special to do in the constructor. //There's nothing special to do in the constructor.
} }
ObjectManager::~ObjectManager() { ObjectManager::~ObjectManager() {
std::map<object_id_t, SystemObjectIF*>::iterator it; for (auto const& iter : objectList) {
for (it = this->objectList.begin(); it != this->objectList.end(); it++) { delete iter.second;
delete it->second;
} }
} }
ReturnValue_t ObjectManager::insert( object_id_t id, SystemObjectIF* object) { ReturnValue_t ObjectManager::insert( object_id_t id, SystemObjectIF* object) {
bool insert_return = this->objectList.insert( std::pair< object_id_t, SystemObjectIF* >( id, object ) ).second; auto returnPair = objectList.emplace(id, object);
if (insert_return == true) { if (returnPair.second) {
// sif::debug << "ObjectManager::insert: Object " << std::hex // sif::debug << "ObjectManager::insert: Object " << std::hex
// << (int)id << std::dec << " inserted." << std::endl; // << (int)id << std::dec << " inserted." << std::endl;
return this->RETURN_OK; return this->RETURN_OK;
} else { } else {
sif::error << "ObjectManager::insert: Object id " << std::hex sif::error << "ObjectManager::insert: Object id " << std::hex
<< (int)id << std::dec << " is already in use!" << std::endl; << (int)id << std::dec << " is already in use!" << std::endl;
exit(0); //This is very severe and difficult to handle in other places. sif::error << "Terminating program." << std::endl;
return this->INSERTION_FAILED; //This is very severe and difficult to handle in other places.
std::exit(INSERTION_FAILED);
} }
} }
ReturnValue_t ObjectManager::remove( object_id_t id ) { ReturnValue_t ObjectManager::remove( object_id_t id ) {
if ( this->getSystemObject(id) != NULL ) { if ( this->getSystemObject(id) != NULL ) {
this->objectList.erase( id ); this->objectList.erase( id );
sif::debug << "ObjectManager::removeObject: Object " << std::hex //sif::debug << "ObjectManager::removeObject: Object " << std::hex
<< (int)id << std::dec << " removed." << std::endl; // << (int)id << std::dec << " removed." << std::endl;
return RETURN_OK; return RETURN_OK;
} else { } else {
sif::error << "ObjectManager::removeObject: Requested object " sif::error << "ObjectManager::removeObject: Requested object "
@ -44,61 +45,63 @@ ReturnValue_t ObjectManager::remove( object_id_t id ) {
SystemObjectIF* ObjectManager::getSystemObject( object_id_t id ) { SystemObjectIF* ObjectManager::getSystemObject( object_id_t id ) {
std::map<object_id_t, SystemObjectIF*>::iterator it = this->objectList.find( id ); auto listIter = this->objectList.find( id );
if (it == this->objectList.end() ) { if (listIter == this->objectList.end() ) {
//Changed for testing different method. return nullptr;
// SystemObjectIF* object = this->produceObjects( id );
// return object;
return NULL;
} else { } else {
return it->second; return listIter->second;
} }
} }
ObjectManager::ObjectManager( ) : produceObjects(NULL) { ObjectManager::ObjectManager() : produceObjects(nullptr) {
} }
void ObjectManager::initialize() { void ObjectManager::initialize() {
if(produceObjects == nullptr) {
sif::error << "ObjectManager::initialize: Passed produceObjects "
"functions is nullptr!" << std::endl;
return;
}
this->produceObjects(); this->produceObjects();
ReturnValue_t return_value = RETURN_FAILED; ReturnValue_t result = RETURN_FAILED;
uint32_t error_count = 0; uint32_t errorCount = 0;
for (std::map<object_id_t, SystemObjectIF*>::iterator it = this->objectList.begin(); it != objectList.end(); it++ ) { for (auto const& it : objectList) {
return_value = it->second->initialize(); result = it.second->initialize();
if ( return_value != RETURN_OK ) { if ( result != RETURN_OK ) {
object_id_t var = it->first; object_id_t var = it.first;
sif::error << "Object " << std::hex << (int) var sif::error << "ObjectManager::initialize: Object 0x" << std::hex <<
<< " failed to initialize with code 0x" << return_value std::setw(8) << std::setfill('0')<< var << " failed to "
<< std::dec << std::endl; "initialize with code 0x" << result << std::dec <<
error_count++; std::setfill(' ') << std::endl;
errorCount++;
} }
} }
if (error_count > 0) { if (errorCount > 0) {
sif::error << "ObjectManager::ObjectManager: Counted " << error_count sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
<< " failed initializations." << std::endl; << " failed initializations." << std::endl;
} }
//Init was successful. Now check successful interconnections. //Init was successful. Now check successful interconnections.
error_count = 0; errorCount = 0;
for (std::map<object_id_t, SystemObjectIF*>::iterator it = this->objectList.begin(); it != objectList.end(); it++ ) { for (auto const& it : objectList) {
return_value = it->second->checkObjectConnections(); result = it.second->checkObjectConnections();
if ( return_value != RETURN_OK ) { if ( result != RETURN_OK ) {
sif::error << "Object " << std::hex << (int) it->first sif::error << "ObjectManager::ObjectManager: Object " << std::hex <<
<< " connection check failed with code 0x" << return_value (int) it.first << " connection check failed with code 0x"
<< std::dec << std::endl; << result << std::dec << std::endl;
error_count++; errorCount++;
} }
} }
if (error_count > 0) { if (errorCount > 0) {
sif::error << "ObjectManager::ObjectManager: Counted " << error_count sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
<< " failed connection checks." << std::endl; << " failed connection checks." << std::endl;
} }
} }
void ObjectManager::printList() { void ObjectManager::printList() {
std::map<object_id_t, SystemObjectIF*>::iterator it; std::map<object_id_t, SystemObjectIF*>::iterator it;
sif::debug << "ObjectManager: Object List contains:" << std::endl; sif::debug << "ObjectManager: Object List contains:" << std::endl;
for (it = this->objectList.begin(); it != this->objectList.end(); it++) { for (auto const& it : objectList) {
sif::debug << std::hex << it->first << " | " << it->second << std::endl; sif::debug << std::hex << it.first << " | " << it.second << std::endl;
} }
} }

View File

@ -1,16 +1,10 @@
/** #ifndef FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
* @file ObjectManagerIF.h #define FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
* @brief This file contains the implementation of the ObjectManagerIF interface
* @date 19.09.2012
* @author Bastian Baetz
*/
#ifndef OBJECTMANAGERIF_H_
#define OBJECTMANAGERIF_H_
#include <framework/objectmanager/frameworkObjects.h> #include <framework/objectmanager/frameworkObjects.h>
#include <framework/objectmanager/SystemObjectIF.h> #include <framework/objectmanager/SystemObjectIF.h>
#include <framework/returnvalues/HasReturnvaluesIF.h> #include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
/** /**
* @brief This class provides an interface to the global object manager. * @brief This class provides an interface to the global object manager.
@ -19,13 +13,17 @@
* inserted, removed and retrieved from the list. On getting the * inserted, removed and retrieved from the list. On getting the
* object, the call checks if the object implements the requested * object, the call checks if the object implements the requested
* interface. * interface.
* \ingroup system_objects * @author Bastian Baetz
* @ingroup system_objects
*/ */
class ObjectManagerIF : public HasReturnvaluesIF { class ObjectManagerIF : public HasReturnvaluesIF {
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::OBJECT_MANAGER_IF; static constexpr uint8_t INTERFACE_ID = CLASS_ID::OBJECT_MANAGER_IF;
static const ReturnValue_t INSERTION_FAILED = MAKE_RETURN_CODE( 1 ); static constexpr ReturnValue_t INSERTION_FAILED = MAKE_RETURN_CODE( 1 );
static const ReturnValue_t NOT_FOUND = MAKE_RETURN_CODE( 2 ); 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: protected:
/** /**
* @brief This method is used to hide the template-based get call from * @brief This method is used to hide the template-based get call from
@ -77,15 +75,21 @@ public:
virtual void printList() = 0; virtual void printList() = 0;
}; };
template <typename T>
T* ObjectManagerIF::get( object_id_t id ) {
SystemObjectIF* temp = this->getSystemObject(id);
return dynamic_cast<T*>(temp);
}
/** /**
* @brief This is the forward declaration of the global objectManager instance. * @brief This is the forward declaration of the global objectManager instance.
*/ */
extern ObjectManagerIF *objectManager; 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_ */ #endif /* OBJECTMANAGERIF_H_ */