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 #include <Fw/FPrimeBasicTypes.hpp>
14 #include <Fw/Logger/Logger.hpp>
15 #include <Fw/Types/Assert.hpp>
17 #include <cassert>
18 #include <cstdio>
19 
20 namespace Fw {
22  FwSizeType lineNo,
23  FwSizeType numArgs,
24  FwAssertArgType arg1,
25  FwAssertArgType arg2,
26  FwAssertArgType arg3,
27  FwAssertArgType arg4,
28  FwAssertArgType arg5,
29  FwAssertArgType arg6,
30  CHAR* destBuffer,
31  FwSizeType buffSize);
32 
33 }
34 
35 namespace Svc {
36 
37 // ----------------------------------------------------------------------
38 // Construction, initialization, and destruction
39 // ----------------------------------------------------------------------
40 
43  // register component with adapter
44  this->m_adapter.regAssertReporter(this);
45  // register adapter
46  this->m_adapter.registerHook();
47  // Initialize the assert counter
48  this->m_assertCount = 0;
49 }
50 
52 
53 void AssertFatalAdapterComponentImpl::AssertFatalAdapter::reportAssert(FILE_NAME_ARG file,
54  FwSizeType lineNo,
55  FwSizeType numArgs,
56  FwAssertArgType arg1,
57  FwAssertArgType arg2,
58  FwAssertArgType arg3,
59  FwAssertArgType arg4,
60  FwAssertArgType arg5,
61  FwAssertArgType arg6) {
62  if (m_compPtr) {
63  m_compPtr->reportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6);
64  } else {
65  // Can't assert, what else can we do? Maybe somebody will see it.
66  Fw::Logger::log("Svc::AssertFatalAdapter not registered!\n");
67  assert(0);
68  }
69 }
70 
71 void AssertFatalAdapterComponentImpl::AssertFatalAdapter::regAssertReporter(AssertFatalAdapterComponentImpl* compPtr) {
72  this->m_compPtr = compPtr;
73 }
74 
76 
77 AssertFatalAdapterComponentImpl::AssertFatalAdapter::~AssertFatalAdapter() {}
78 
79 void AssertFatalAdapterComponentImpl::AssertFatalAdapter::doAssert() {
80  // do nothing since there will be a FATAL
81 }
82 
84  FwSizeType lineNo,
85  FwSizeType numArgs,
86  FwAssertArgType arg1,
87  FwAssertArgType arg2,
88  FwAssertArgType arg3,
89  FwAssertArgType arg4,
90  FwAssertArgType arg5,
91  FwAssertArgType arg6) {
92 #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
93  Fw::LogStringArg fileArg;
94  fileArg.format("0x%08" PRIX32, file);
95 #else
96  Fw::LogStringArg fileArg(file);
97 #endif
98 
100  Fw::defaultReportAssert(file, static_cast<U32>(lineNo), numArgs, arg1, arg2, arg3, arg4, arg5, arg6, msg,
101  sizeof(msg));
102  Fw::Logger::log("%s\n", msg);
103 
104  // Increment active assert counter
105  this->m_assertCount++;
106 
107  // Handle the case where the ports aren't connected yet or we've surpassed the maximum cascading FW_ASSERT failures
108  if (not this->isConnected_Log_OutputPort(0) || this->m_assertCount > FW_ASSERT_COUNT_MAX) {
109  assert(0);
110  return;
111  }
112 
113  switch (numArgs) {
114  case 0:
115  this->log_FATAL_AF_ASSERT_0(fileArg, static_cast<U32>(lineNo));
116  break;
117  case 1:
118  this->log_FATAL_AF_ASSERT_1(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1));
119  break;
120  case 2:
121  this->log_FATAL_AF_ASSERT_2(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
122  static_cast<U32>(arg2));
123  break;
124  case 3:
125  this->log_FATAL_AF_ASSERT_3(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
126  static_cast<U32>(arg2), static_cast<U32>(arg3));
127  break;
128  case 4:
129  this->log_FATAL_AF_ASSERT_4(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
130  static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4));
131  break;
132  case 5:
133  this->log_FATAL_AF_ASSERT_5(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
134  static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4),
135  static_cast<U32>(arg5));
136  break;
137  case 6:
138  this->log_FATAL_AF_ASSERT_6(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
139  static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4),
140  static_cast<U32>(arg5), static_cast<U32>(arg6));
141  break;
142  default:
143  this->log_FATAL_AF_UNEXPECTED_ASSERT(fileArg, static_cast<U32>(lineNo), static_cast<U32>(numArgs));
144  break;
145  }
146  // Assert processing complete, decrement active assert counter
147  this->m_assertCount--;
148 }
149 } // end namespace Svc
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
PlatformSizeType FwSizeType
void log_FATAL_AF_ASSERT_3(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2, U32 arg3) const
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
char CHAR
Definition: BasicTypes.h:59
#define FW_ASSERT_COUNT_MAX
Maximum number of cascading FW_ASSERT check failures before forcing a system assert.
Definition: FpConfig.h:330
void log_FATAL_AF_ASSERT_2(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2) const
void defaultReportAssert(FILE_NAME_ARG file, FwSizeType lineNo, FwSizeType numArgs, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwAssertArgType arg4, FwAssertArgType arg5, FwAssertArgType arg6, CHAR *destBuffer, FwSizeType buffSize)
Definition: Assert.cpp:22
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
void reportAssert(FILE_NAME_ARG file, FwSizeType lineNo, FwSizeType numArgs, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwAssertArgType arg4, FwAssertArgType arg5, FwAssertArgType arg6)
Report the assert as a FATAL.
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:55
#define FW_ASSERT_TEXT_SIZE
Size of string used to store assert description.
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
Definition: StringBase.hpp:42
RateGroupDivider component implementation.
AssertFatalAdapterComponentImpl AssertFatalAdapter
Auto-generated base for AssertFatalAdapter component.
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
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