Merge remote-tracking branch 'upstream/master' into mueller_ServiceStreamEnhancement
This commit is contained in:
commit
dd8543fedd
@ -1,25 +1,25 @@
|
||||
#include <framework/globalfunctions/printer.h>
|
||||
#include <framework/globalfunctions/arrayprinter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#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) {
|
||||
if(printInfo) {
|
||||
sif::info << "Printing data with size " << size << ": ";
|
||||
}
|
||||
sif::info << "[";
|
||||
if(type == OutputType::HEX) {
|
||||
printer::printHex(data, size, maxCharPerLine);
|
||||
arrayprinter::printHex(data, size, maxCharPerLine);
|
||||
}
|
||||
else if (type == OutputType::DEC) {
|
||||
printer::printDec(data, size, maxCharPerLine);
|
||||
arrayprinter::printDec(data, size, maxCharPerLine);
|
||||
}
|
||||
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) {
|
||||
sif::info << std::hex;
|
||||
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;
|
||||
}
|
||||
|
||||
void printer::printDec(const uint8_t *data, size_t size,
|
||||
void arrayprinter::printDec(const uint8_t *data, size_t size,
|
||||
size_t maxCharPerLine) {
|
||||
sif::info << std::dec;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
for(size_t i = 0; i < size; i++) {
|
||||
sif::info << "Byte " << i + 1 << ": 0b"<<
|
@ -1,16 +1,15 @@
|
||||
#ifndef FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_
|
||||
#define FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_
|
||||
#ifndef FRAMEWORK_GLOBALFUNCTIONS_ARRAYPRINTER_H_
|
||||
#define FRAMEWORK_GLOBALFUNCTIONS_ARRAYPRINTER_H_
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace printer {
|
||||
|
||||
enum class OutputType {
|
||||
DEC,
|
||||
HEX,
|
||||
BIN
|
||||
};
|
||||
|
||||
namespace arrayprinter {
|
||||
void print(const uint8_t* data, size_t size, OutputType type = OutputType::HEX,
|
||||
bool printInfo = true, 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);
|
||||
}
|
||||
|
||||
#endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */
|
||||
#endif /* FRAMEWORK_GLOBALFUNCTIONS_ARRAYPRINTER_H_ */
|
@ -2,37 +2,38 @@
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <cstdlib>
|
||||
|
||||
ObjectManager::ObjectManager( void (*setProducer)() ) : produceObjects(setProducer) {
|
||||
ObjectManager::ObjectManager( void (*setProducer)() ):
|
||||
produceObjects(setProducer) {
|
||||
//There's nothing special to do in the constructor.
|
||||
}
|
||||
|
||||
|
||||
ObjectManager::~ObjectManager() {
|
||||
std::map<object_id_t, SystemObjectIF*>::iterator it;
|
||||
for (it = this->objectList.begin(); it != this->objectList.end(); it++) {
|
||||
delete it->second;
|
||||
for (auto const& iter : objectList) {
|
||||
delete iter.second;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
if (insert_return == true) {
|
||||
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;
|
||||
exit(0); //This is very severe and difficult to handle in other places.
|
||||
return this->INSERTION_FAILED;
|
||||
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;
|
||||
//sif::debug << "ObjectManager::removeObject: Object " << std::hex
|
||||
// << (int)id << std::dec << " removed." << std::endl;
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
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 ) {
|
||||
std::map<object_id_t, SystemObjectIF*>::iterator it = this->objectList.find( id );
|
||||
if (it == this->objectList.end() ) {
|
||||
//Changed for testing different method.
|
||||
// SystemObjectIF* object = this->produceObjects( id );
|
||||
// return object;
|
||||
return NULL;
|
||||
auto listIter = this->objectList.find( id );
|
||||
if (listIter == this->objectList.end() ) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return it->second;
|
||||
return listIter->second;
|
||||
}
|
||||
}
|
||||
|
||||
ObjectManager::ObjectManager( ) : produceObjects(NULL) {
|
||||
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 return_value = RETURN_FAILED;
|
||||
uint32_t error_count = 0;
|
||||
for (std::map<object_id_t, SystemObjectIF*>::iterator it = this->objectList.begin(); it != objectList.end(); it++ ) {
|
||||
return_value = it->second->initialize();
|
||||
if ( return_value != RETURN_OK ) {
|
||||
object_id_t var = it->first;
|
||||
sif::error << "Object " << std::hex << (int) var
|
||||
<< " failed to initialize with code 0x" << return_value
|
||||
<< std::dec << std::endl;
|
||||
error_count++;
|
||||
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 (error_count > 0) {
|
||||
sif::error << "ObjectManager::ObjectManager: Counted " << error_count
|
||||
if (errorCount > 0) {
|
||||
sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
|
||||
<< " failed initializations." << std::endl;
|
||||
}
|
||||
//Init was successful. Now check successful interconnections.
|
||||
error_count = 0;
|
||||
for (std::map<object_id_t, SystemObjectIF*>::iterator it = this->objectList.begin(); it != objectList.end(); it++ ) {
|
||||
return_value = it->second->checkObjectConnections();
|
||||
if ( return_value != RETURN_OK ) {
|
||||
sif::error << "Object " << std::hex << (int) it->first
|
||||
<< " connection check failed with code 0x" << return_value
|
||||
<< std::dec << std::endl;
|
||||
error_count++;
|
||||
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 (error_count > 0) {
|
||||
sif::error << "ObjectManager::ObjectManager: Counted " << error_count
|
||||
if (errorCount > 0) {
|
||||
sif::error << "ObjectManager::ObjectManager: Counted " << errorCount
|
||||
<< " failed connection checks." << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ObjectManager::printList() {
|
||||
std::map<object_id_t, SystemObjectIF*>::iterator it;
|
||||
sif::debug << "ObjectManager: Object List contains:" << std::endl;
|
||||
for (it = this->objectList.begin(); it != this->objectList.end(); it++) {
|
||||
sif::debug << std::hex << it->first << " | " << it->second << std::endl;
|
||||
for (auto const& it : objectList) {
|
||||
sif::debug << std::hex << it.first << " | " << it.second << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,10 @@
|
||||
/**
|
||||
* @file 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_
|
||||
#ifndef FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
||||
#define FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
||||
|
||||
#include <framework/objectmanager/frameworkObjects.h>
|
||||
#include <framework/objectmanager/SystemObjectIF.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
/**
|
||||
* @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
|
||||
* object, the call checks if the object implements the requested
|
||||
* interface.
|
||||
* \ingroup system_objects
|
||||
* @author Bastian Baetz
|
||||
* @ingroup system_objects
|
||||
*/
|
||||
class ObjectManagerIF : public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::OBJECT_MANAGER_IF;
|
||||
static const ReturnValue_t INSERTION_FAILED = MAKE_RETURN_CODE( 1 );
|
||||
static const ReturnValue_t NOT_FOUND = MAKE_RETURN_CODE( 2 );
|
||||
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
|
||||
@ -77,15 +75,21 @@ public:
|
||||
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.
|
||||
*/
|
||||
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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user