F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
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::logMsg("Entry: %d Ptr: %p Str: %s\n", static_cast<POINTER_CAST>(obj),
32  reinterpret_cast<POINTER_CAST>(this->m_objPtrArray[obj]), reinterpret_cast<POINTER_CAST>(objDump));
33 #else
34  Fw::Logger::logMsg("Entry: %d Ptr: %p Name: %s\n",static_cast<POINTER_CAST>(obj),
35  reinterpret_cast<POINTER_CAST>(this->m_objPtrArray[obj]),
36  reinterpret_cast<POINTER_CAST>(this->m_objPtrArray[obj]->getObjName()));
37 #endif // FW_OBJECT_TO_STRING
38 #else
39  Fw::Logger::logMsg("Entry: %d Ptr: %p Str:\n", obj, reinterpret_cast<POINTER_CAST>(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::logMsg("Entry: %d Ptr: %p Str: %s\n", static_cast<POINTER_CAST>(obj),
52  reinterpret_cast<POINTER_CAST>(this->m_objPtrArray[obj]), reinterpret_cast<POINTER_CAST>(objDump));
53 #else
54  Fw::Logger::logMsg("Entry: %d Ptr: %p Name: %s\n",static_cast<POINTER_CAST>(obj),
55  reinterpret_cast<POINTER_CAST>(this->m_objPtrArray[obj]),
56  reinterpret_cast<POINTER_CAST>(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
PlatformPointerCastType POINTER_CAST
Definition: BasicTypes.h:53
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
#define FW_OBJ_SIMPLE_REG_BUFF_SIZE
Size of object registry dump string.
Definition: FpConfig.h:245
#define FW_OBJ_SIMPLE_REG_ENTRIES
Number of objects stored in simple object registry.
Definition: FpConfig.h:240
C++-compatible configuration header for fprime configuration.
Class declaration for a simple object registry.
static void logMsg(const char *fmt, POINTER_CAST a0=0, POINTER_CAST a1=0, POINTER_CAST a2=0, POINTER_CAST a3=0, POINTER_CAST a4=0, POINTER_CAST a5=0, POINTER_CAST a6=0, POINTER_CAST a7=0, POINTER_CAST a8=0, POINTER_CAST a9=0)
Definition: Logger.cpp:18