F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
21namespace 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
39namespace Svc {
40
41 // ----------------------------------------------------------------------
42 // Construction, initialization, and destruction
43 // ----------------------------------------------------------------------
44
45 AssertFatalAdapterComponentImpl ::
46 AssertFatalAdapterComponentImpl(
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
57 AssertFatalAdapterComponentImpl ::
58 ~AssertFatalAdapterComponentImpl()
59 {
60
61 }
62
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,
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
89 AssertFatalAdapterComponentImpl::AssertFatalAdapter::AssertFatalAdapter() : m_compPtr(nullptr) {
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 // fprintf(stderr... allocates large buffers on stack as stderr is unbuffered by the OS
122 // and this can conflict with the traditionally smaller stack sizes.
123 printf("%s\n", msg);
124
125 // Handle the case where the ports aren't connected yet
126 if (not this->isConnected_Log_OutputPort(0)) {
127 assert(0);
128 return;
129 }
130
131 switch (numArgs) {
132 case 0:
134 fileArg,
135 lineNo);
136 break;
137 case 1:
139 fileArg,
140 lineNo,
141 static_cast<U32>(arg1));
142 break;
143 case 2:
145 fileArg,
146 lineNo,
147 static_cast<U32>(arg1),
148 static_cast<U32>(arg2));
149 break;
150 case 3:
152 fileArg,
153 lineNo,
154 static_cast<U32>(arg1),
155 static_cast<U32>(arg2),
156 static_cast<U32>(arg3));
157 break;
158 case 4:
160 fileArg,
161 lineNo,
162 static_cast<U32>(arg1),
163 static_cast<U32>(arg2),
164 static_cast<U32>(arg3),
165 static_cast<U32>(arg4));
166 break;
167 case 5:
169 fileArg,
170 lineNo,
171 static_cast<U32>(arg1),
172 static_cast<U32>(arg2),
173 static_cast<U32>(arg3),
174 static_cast<U32>(arg4),
175 static_cast<U32>(arg5));
176 break;
177 case 6:
179 fileArg,
180 lineNo,
181 static_cast<U32>(arg1),
182 static_cast<U32>(arg2),
183 static_cast<U32>(arg3),
184 static_cast<U32>(arg4),
185 static_cast<U32>(arg5),
186 static_cast<U32>(arg6));
187 break;
188 default:
189 this->log_FATAL_AF_UNEXPECTED_ASSERT(fileArg,lineNo,numArgs);
190 break;
191 }
192
193 }
194} // end namespace Svc
#define FILE_NAME_ARG
Definition Assert.hpp:16
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:55
char CHAR
Definition BasicTypes.h:32
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:56
PlatformAssertArgType FwAssertArgType
Definition FpConfig.h:39
C++-compatible configuration header for fprime configuration.
#define FW_ASSERT_TEXT_SIZE
Size of string used to store assert description.
Definition FpConfig.hpp:19
static void log(const char *format,...)
log a formated string with supplied arguments
Definition Logger.cpp:21
void format(const CHAR *formatString,...)
write formatted string to buffer
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
Auto-generated base for AssertFatalAdapter component.
void log_FATAL_AF_ASSERT_3(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2, U32 arg3) const
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
void log_FATAL_AF_ASSERT_2(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2) const
void log_FATAL_AF_ASSERT_1(const Fw::StringBase &file, U32 line, U32 arg1) const
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 log_FATAL_AF_ASSERT_5(const Fw::StringBase &file, U32 line, U32 arg1, U32 arg2, U32 arg3, U32 arg4, U32 arg5) const
void log_FATAL_AF_UNEXPECTED_ASSERT(const Fw::StringBase &file, U32 line, U32 numArgs) 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.
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:18