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>
16 #include <Fw/Types/StringUtils.hpp>
18 #include <algorithm>
19 #include <cassert>
20 #include <cstdio>
21 #include <limits>
22 
23 namespace Fw {
25  FwSizeType lineNo,
26  FwSizeType numArgs,
27  FwAssertArgType arg1,
28  FwAssertArgType arg2,
29  FwAssertArgType arg3,
30  FwAssertArgType arg4,
31  FwAssertArgType arg5,
32  FwAssertArgType arg6,
33  CHAR* destBuffer,
34  FwSizeType buffSize);
35 
36 }
37 
38 namespace Svc {
39 
40 // ----------------------------------------------------------------------
41 // Construction, initialization, and destruction
42 // ----------------------------------------------------------------------
43 
46  // register component with adapter
47  this->m_adapter.regAssertReporter(this);
48  // register adapter
49  this->m_adapter.registerHook();
50  // Initialize the assert counter
51  this->m_assertCount = 0;
52 }
53 
55 
56 void AssertFatalAdapterComponentImpl::AssertFatalAdapter::reportAssert(FILE_NAME_ARG file,
57  FwSizeType lineNo,
58  FwSizeType numArgs,
59  FwAssertArgType arg1,
60  FwAssertArgType arg2,
61  FwAssertArgType arg3,
62  FwAssertArgType arg4,
63  FwAssertArgType arg5,
64  FwAssertArgType arg6) {
65  if (m_compPtr) {
66  m_compPtr->reportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6);
67  } else {
68  // Can't assert, what else can we do? Maybe somebody will see it.
69  Fw::Logger::log("Svc::AssertFatalAdapter not registered!\n");
70  assert(0);
71  }
72 }
73 
74 void AssertFatalAdapterComponentImpl::AssertFatalAdapter::regAssertReporter(AssertFatalAdapterComponentImpl* compPtr) {
75  this->m_compPtr = compPtr;
76 }
77 
79 
80 AssertFatalAdapterComponentImpl::AssertFatalAdapter::~AssertFatalAdapter() {}
81 
82 void AssertFatalAdapterComponentImpl::AssertFatalAdapter::doAssert() {
83  // do nothing since there will be a FATAL
84 }
85 
87  FwSizeType lineNo,
88  FwSizeType numArgs,
89  FwAssertArgType arg1,
90  FwAssertArgType arg2,
91  FwAssertArgType arg3,
92  FwAssertArgType arg4,
93  FwAssertArgType arg5,
94  FwAssertArgType arg6) {
95  // Get file arg for events
96 #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
97  Fw::LogStringArg fileArg;
98  fileArg.format("0x%08" PRIX32, file);
99 #else
100  const FwSizeType outputSize = std::min(static_cast<FwSizeType>(AssertFatalAdapterEventFileSize),
101  static_cast<FwSizeType>(FW_LOG_STRING_MAX_SIZE));
102  // File name argument is derived from a compiler string literal. Per the C++ standard, string literals are
103  // guaranteed to be null-terminated and whose maximum length is from U16_MAX to available system memory size. Thus,
104  // we choose a bound of the lowest allowed maximum literal length.
105  const CHAR* start = Fw::StringUtils::string_last_n(file, outputSize, std::numeric_limits<U16>::max());
106 
107  Fw::LogStringArg fileArg(start);
108 #endif
109 
111  Fw::defaultReportAssert(file, static_cast<U32>(lineNo), numArgs, arg1, arg2, arg3, arg4, arg5, arg6, msg,
112  sizeof(msg));
113  Fw::Logger::log("%s\n", msg);
114 
115  // Increment active assert counter
116  this->m_assertCount++;
117 
118  // Handle the case where the ports aren't connected yet or we've surpassed the maximum cascading FW_ASSERT failures
119  if (not this->isConnected_Log_OutputPort(0) || this->m_assertCount > FW_ASSERT_COUNT_MAX) {
120  assert(0);
121  return;
122  }
123 
124  switch (numArgs) {
125  case 0:
126  this->log_FATAL_AF_ASSERT_0(fileArg, static_cast<U32>(lineNo));
127  break;
128  case 1:
129  this->log_FATAL_AF_ASSERT_1(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1));
130  break;
131  case 2:
132  this->log_FATAL_AF_ASSERT_2(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
133  static_cast<U32>(arg2));
134  break;
135  case 3:
136  this->log_FATAL_AF_ASSERT_3(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
137  static_cast<U32>(arg2), static_cast<U32>(arg3));
138  break;
139  case 4:
140  this->log_FATAL_AF_ASSERT_4(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
141  static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4));
142  break;
143  case 5:
144  this->log_FATAL_AF_ASSERT_5(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
145  static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4),
146  static_cast<U32>(arg5));
147  break;
148  case 6:
149  this->log_FATAL_AF_ASSERT_6(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1),
150  static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4),
151  static_cast<U32>(arg5), static_cast<U32>(arg6));
152  break;
153  default:
154  this->log_FATAL_AF_UNEXPECTED_ASSERT(fileArg, static_cast<U32>(lineNo), static_cast<U32>(numArgs));
155  break;
156  }
157  // Assert processing complete, decrement active assert counter
158  this->m_assertCount--;
159 }
160 } // 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
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:23
const char * string_last_n(const char *source, const FwSizeType n, const FwSizeType buffer_size)
get a pointer to the last N characters of a string
Definition: StringUtils.cpp:24
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
bool isConnected_Log_OutputPort(FwIndexType portNum) 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:39
#define FW_ASSERT_TEXT_SIZE
Size of string used to store assert description // NO_CODESONAR LANG.PREPROC.MACROSTART/END.
static U32 min(const U32 a, const U32 b)
Definition: Checksum.cpp:16
RateGroupDivider component implementation.
Implementation of malloc based allocator.
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
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