F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
AssertFatalAdapterComponentImpl.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title AssertFatalAdapterImpl.cpp
3 // \author tcanham
4 // \brief cpp file for AssertFatalAdapter component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 
15 #include <FpConfig.hpp>
16 #include <Fw/Types/Assert.hpp>
17 #include <Fw/Logger/Logger.hpp>
18 #include <cassert>
19 #include <cstdio>
20 
21 namespace Fw {
23  (
24  FILE_NAME_ARG file,
25  NATIVE_UINT_TYPE lineNo,
26  NATIVE_UINT_TYPE numArgs,
27  FwAssertArgType arg1,
28  FwAssertArgType arg2,
29  FwAssertArgType arg3,
30  FwAssertArgType arg4,
31  FwAssertArgType arg5,
32  FwAssertArgType arg6,
33  CHAR* destBuffer,
34  NATIVE_INT_TYPE buffSize
35  );
36 
37 }
38 
39 namespace Svc {
40 
41  // ----------------------------------------------------------------------
42  // Construction, initialization, and destruction
43  // ----------------------------------------------------------------------
44 
47  const char *const compName
49  {
50  // register component with adapter
51  this->m_adapter.regAssertReporter(this);
52  // register adapter
53  this->m_adapter.registerHook();
54 
55  }
56 
59  {
60 
61  }
62 
63  void AssertFatalAdapterComponentImpl::AssertFatalAdapter::reportAssert(
64  FILE_NAME_ARG file,
65  NATIVE_UINT_TYPE lineNo,
66  NATIVE_UINT_TYPE numArgs,
67  FwAssertArgType arg1,
68  FwAssertArgType arg2,
69  FwAssertArgType arg3,
70  FwAssertArgType arg4,
71  FwAssertArgType arg5,
72  FwAssertArgType arg6
73  ) {
74 
75  if (m_compPtr) {
76  m_compPtr->reportAssert(file,lineNo,numArgs,
77  arg1,arg2,arg3,arg4,arg5,arg6);
78  } else {
79  // Can't assert, what else can we do? Maybe somebody will see it.
80  Fw::Logger::log("Svc::AssertFatalAdapter not registered!\n");
81  assert(0);
82  }
83  }
84 
85  void AssertFatalAdapterComponentImpl::AssertFatalAdapter::regAssertReporter(AssertFatalAdapterComponentImpl* compPtr) {
86  this->m_compPtr = compPtr;
87  }
88 
90  }
91 
92  AssertFatalAdapterComponentImpl::AssertFatalAdapter::~AssertFatalAdapter() {
93  }
94 
95  void AssertFatalAdapterComponentImpl::AssertFatalAdapter::doAssert() {
96  // do nothing since there will be a FATAL
97  }
98 
100  FILE_NAME_ARG file,
101  NATIVE_UINT_TYPE lineNo,
102  NATIVE_UINT_TYPE numArgs,
103  FwAssertArgType arg1,
104  FwAssertArgType arg2,
105  FwAssertArgType arg3,
106  FwAssertArgType arg4,
107  FwAssertArgType arg5,
108  FwAssertArgType arg6
109  ) {
110 
111 
112 #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
113  Fw::LogStringArg fileArg;
114  fileArg.format("0x%08" PRIX32,file);
115 #else
116  Fw::LogStringArg fileArg(file);
117 #endif
118 
120  Fw::defaultReportAssert(file,lineNo,numArgs,arg1,arg2,arg3,arg4,arg5,arg6,msg,sizeof(msg));
121  Fw::Logger::log("%s\n", msg);
122 
123  // Handle the case where the ports aren't connected yet
124  if (not this->isConnected_Log_OutputPort(0)) {
125  assert(0);
126  return;
127  }
128 
129  switch (numArgs) {
130  case 0:
131  this->log_FATAL_AF_ASSERT_0(
132  fileArg,
133  lineNo);
134  break;
135  case 1:
136  this->log_FATAL_AF_ASSERT_1(
137  fileArg,
138  lineNo,
139  static_cast<U32>(arg1));
140  break;
141  case 2:
142  this->log_FATAL_AF_ASSERT_2(
143  fileArg,
144  lineNo,
145  static_cast<U32>(arg1),
146  static_cast<U32>(arg2));
147  break;
148  case 3:
149  this->log_FATAL_AF_ASSERT_3(
150  fileArg,
151  lineNo,
152  static_cast<U32>(arg1),
153  static_cast<U32>(arg2),
154  static_cast<U32>(arg3));
155  break;
156  case 4:
157  this->log_FATAL_AF_ASSERT_4(
158  fileArg,
159  lineNo,
160  static_cast<U32>(arg1),
161  static_cast<U32>(arg2),
162  static_cast<U32>(arg3),
163  static_cast<U32>(arg4));
164  break;
165  case 5:
166  this->log_FATAL_AF_ASSERT_5(
167  fileArg,
168  lineNo,
169  static_cast<U32>(arg1),
170  static_cast<U32>(arg2),
171  static_cast<U32>(arg3),
172  static_cast<U32>(arg4),
173  static_cast<U32>(arg5));
174  break;
175  case 6:
176  this->log_FATAL_AF_ASSERT_6(
177  fileArg,
178  lineNo,
179  static_cast<U32>(arg1),
180  static_cast<U32>(arg2),
181  static_cast<U32>(arg3),
182  static_cast<U32>(arg4),
183  static_cast<U32>(arg5),
184  static_cast<U32>(arg6));
185  break;
186  default:
187  this->log_FATAL_AF_UNEXPECTED_ASSERT(fileArg,lineNo,numArgs);
188  break;
189  }
190 
191  }
192 } // end namespace Svc
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
void log_FATAL_AF_UNEXPECTED_ASSERT(const Fw::StringBase &file, U32 line, U32 numArgs) const
void log_FATAL_AF_ASSERT_1(const Fw::StringBase &file, U32 line, U32 arg1) const
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:39
void log_FATAL_AF_ASSERT_3(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2, U32 arg3) const
void reportAssert(FILE_NAME_ARG file, NATIVE_UINT_TYPE lineNo, NATIVE_UINT_TYPE numArgs, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwAssertArgType arg4, FwAssertArgType arg5, FwAssertArgType arg6)
Report the assert as a FATAL.
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
char CHAR
Definition: BasicTypes.h:32
void log_FATAL_AF_ASSERT_2(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2) const
#define FW_ASSERT_TEXT_SIZE
Size of string used to store assert description.
Definition: FpConfig.hpp:19
void log_FATAL_AF_ASSERT_5(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2, U32 arg3, U32 arg4, U32 arg5) const
#define FILE_NAME_ARG
Definition: Assert.hpp:16
void log_FATAL_AF_ASSERT_4(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2, U32 arg3, U32 arg4) const
void log_FATAL_AF_ASSERT_0(const Fw::StringBase &file, U32 line) const
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:55
C++-compatible configuration header for fprime configuration.
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
Definition: StringBase.hpp:42
AssertFatalAdapterComponentImpl AssertFatalAdapter
Auto-generated base for AssertFatalAdapter component.
void defaultReportAssert(FILE_NAME_ARG file, NATIVE_UINT_TYPE lineNo, NATIVE_UINT_TYPE numArgs, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwAssertArgType arg4, FwAssertArgType arg5, FwAssertArgType arg6, CHAR *destBuffer, NATIVE_INT_TYPE buffSize)
Definition: Assert.cpp:22
void log_FATAL_AF_ASSERT_6(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2, U32 arg3, U32 arg4, U32 arg5, U32 arg6) const