Merge remote-tracking branch 'upstream/master' into mueller_StoreAccessor
This commit is contained in:
commit
c8b92a8828
@ -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"<<
|
@ -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_ */
|
@ -1,38 +1,40 @@
|
|||||||
#include <framework/objectmanager/ObjectManager.h>
|
#include <framework/objectmanager/ObjectManager.h>
|
||||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
|
#include <iomanip>
|
||||||
#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 +46,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,6 @@ T* ObjectManagerIF::get( object_id_t id ) {
|
|||||||
if(objectManager == nullptr) {
|
if(objectManager == nullptr) {
|
||||||
sif::error << "ObjectManagerIF: Global object manager has not "
|
sif::error << "ObjectManagerIF: Global object manager has not "
|
||||||
"been initialized yet!" << std::endl;
|
"been initialized yet!" << std::endl;
|
||||||
std::exit(1);
|
|
||||||
}
|
}
|
||||||
SystemObjectIF* temp = this->getSystemObject(id);
|
SystemObjectIF* temp = this->getSystemObject(id);
|
||||||
return dynamic_cast<T*>(temp);
|
return dynamic_cast<T*>(temp);
|
||||||
|
Loading…
Reference in New Issue
Block a user