F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleObjRegistry.cpp
Go to the documentation of this file.
1 #include <Fw/Logger/Logger.hpp>
3 #include <FpConfig.hpp>
4 #include <Fw/Types/Assert.hpp>
5 #include <cstdio>
6 #include <cstring>
7 
8 #if FW_OBJECT_REGISTRATION == 1
9 
10 namespace Fw {
11 
12  SimpleObjRegistry::SimpleObjRegistry() {
13  ObjBase::setObjRegistry(this);
14  this->m_numEntries = 0;
15  // Initialize pointer array
16  for (NATIVE_INT_TYPE entry = 0; entry < FW_OBJ_SIMPLE_REG_ENTRIES; entry++) {
17  this->m_objPtrArray[entry] = nullptr;
18  }
19  }
20 
21  SimpleObjRegistry::~SimpleObjRegistry() {
22  ObjBase::setObjRegistry(nullptr);
23  }
24 
25  void SimpleObjRegistry::dump() {
26  for (NATIVE_INT_TYPE obj = 0; obj < this->m_numEntries; obj++) {
27 #if FW_OBJECT_NAMES == 1
28 #if FW_OBJECT_TO_STRING == 1
29  char objDump[FW_OBJ_SIMPLE_REG_BUFF_SIZE];
30  this->m_objPtrArray[obj]->toString(objDump,sizeof(objDump));
31  Fw::Logger::log("Entry: %d Ptr: %p Str: %s\n", obj,
32  this->m_objPtrArray[obj], objDump);
33 #else
34  Fw::Logger::log("Entry: %d Ptr: %p Name: %s\n", obj,
35  this->m_objPtrArray[obj],
36  this->m_objPtrArray[obj]->getObjName());
37 #endif // FW_OBJECT_TO_STRING
38 #else
39  Fw::Logger::log("Entry: %d Ptr: %p\n", obj, this->m_objPtrArray[obj]);
40 #endif
41  }
42  }
43 
44 #if FW_OBJECT_NAMES == 1
45  void SimpleObjRegistry::dump(const char* objName) {
46  for (NATIVE_INT_TYPE obj = 0; obj < this->m_numEntries; obj++) {
47  char objDump[FW_OBJ_SIMPLE_REG_BUFF_SIZE];
48  if (strncmp(objName,this->m_objPtrArray[obj]->getObjName(),sizeof(objDump)) == 0) {
49 #if FW_OBJECT_TO_STRING == 1
50  this->m_objPtrArray[obj]->toString(objDump,sizeof(objDump));
51  Fw::Logger::log("Entry: %d Ptr: %p Str: %s\n", obj,
52  this->m_objPtrArray[obj], objDump);
53 #else
54  Fw::Logger::log("Entry: %d Ptr: %p Name: %s\n",obj,
55  this->m_objPtrArray[obj],
56  this->m_objPtrArray[obj]->getObjName());
57 #endif
58  }
59  }
60  }
61 #endif
62  void SimpleObjRegistry::regObject(ObjBase* obj) {
63  FW_ASSERT(this->m_numEntries < FW_OBJ_SIMPLE_REG_ENTRIES);
64  this->m_objPtrArray[this->m_numEntries++] = obj;
65 
66  }
67 
68  void SimpleObjRegistry::clear() {
69  this->m_numEntries = 0;
70  }
71 
72 }
73 
74 #endif
75 
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
#define FW_OBJ_SIMPLE_REG_BUFF_SIZE
Size of object registry dump string.
Definition: FpConfig.h:259
#define FW_OBJ_SIMPLE_REG_ENTRIES
Number of objects stored in simple object registry.
Definition: FpConfig.h:254
C++-compatible configuration header for fprime configuration.
Class declaration for a simple object registry.
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21