Diagnostics.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef __DIAGNOSTICS_H_
19 #define __DIAGNOSTICS_H_
20 
21 #include <chrono>
22 #include <deque>
23 
33 class ErrorcodeReport // Errorcode from library
34 {
35 public:
36  bool Code_Exists; // true when errorcode returned
37  int ErrorCode; // code number
38  std::string Errorcode_Namespace; // namespace of the code (for lookup)
39 
41  ErrorcodeReport() : Code_Exists(false), ErrorCode(0), Errorcode_Namespace(""){};
42 };
43 
52 {
53 public:
54  short Level; // 0 = OK, 1 = WARN, 2=ERROR
55  std::string Message; // Description of the error
56  std::string Recommendation; // Possible solutions for the user
57  ErrorcodeReport Errorcode_Report; // Errorcode that is returned from a function
58 
59  std::chrono::time_point<std::chrono::system_clock> Time; // time when status is reported
60 
62  DiagnosticStatus() : Level(0), Message(""), Recommendation(""), Time(std::chrono::system_clock::now()){};
63 };
64 
73 {
74  /*TODO: - select format for errorlookups (.h, .txt, yaml)
75  * - implement report status
76  * - implement read methodes
77  * - implement QueLength methodes
78  */
79 public:
82  {
83  m_StatusQueLength = 5; // 5 is default value
84 
85  // initialize member variabeles
86  m_StatusList = new std::deque<DiagnosticStatus>[m_StatusQueLength];
87 
88  // initialize default ok return value (default 0)
89  m_Default_Ok_Value = 0;
90 
91  // TODO: read in errorcode lists
92  }
93 
96  {
97  delete m_StatusList;
98  };
99 
100  /*******************************************|
101  | Useage interface |
102  |*******************************************/
103 
105 
109  void ReportStatus(short Level, std::string Message)
110  {
111  DiagnosticStatus NewStatus;
112 
113  NewStatus.Level = Level;
114  NewStatus.Time = std::chrono::system_clock::now();
115  NewStatus.Message = Message;
116 
117  m_StatusList->push_front(NewStatus);
118  m_StatusList->pop_back();
119  }
120 
124  void ReportStatus(short Level, std::string Message, std::string Recommendation)
125  {
126  DiagnosticStatus NewStatus;
127 
128  NewStatus.Level = Level;
129  NewStatus.Time = std::chrono::system_clock::now();
130  NewStatus.Message = Message;
131  NewStatus.Message = Recommendation;
132 
133  m_StatusList->push_front(NewStatus);
134  m_StatusList->pop_back();
135  }
136 
140  void ReportStatus(short Level, int Errorcode, std::string Errorcode_Namespace, std::string Recommendation)
141  {
142  DiagnosticStatus NewStatus;
143 
144  NewStatus.Level = Level;
145  NewStatus.Time = std::chrono::system_clock::now();
146 
147  // TODO: generate message from errorcode
148 
149  NewStatus.Message = Recommendation;
150 
151  m_StatusList->push_front(NewStatus);
152  m_StatusList->pop_back();
153  }
154 
158  void ReportStatus(int Errorcode, std::string Errorcode_Namespace)
159  {
160  DiagnosticStatus NewStatus;
161 
162  // TODO: get message from errorcodelist
163 
164  NewStatus.Time = std::chrono::system_clock::now();
165 
166  m_StatusList->push_front(NewStatus);
167  m_StatusList->pop_back();
168  }
169 
171 
177  void ReadActualStatus(short* Level, std::string* Message, std::string* Recommendation)
178  {
179  DiagnosticStatus ActualStatus = m_StatusList->at(0);
180 
181  // resize strings for the size of the upcoming message
182  Message->clear();
183  Recommendation->clear();
184 
185  // write output
186  Level = (short*)ActualStatus.Level;
187  Message->append(ActualStatus.Message);
188  Recommendation->append(ActualStatus.Recommendation);
189  }
190 
195  {
196  DiagnosticStatus ActualStatus = m_StatusList->at(0);
197  return ActualStatus.Level;
198  }
199 
204  {
205  DiagnosticStatus ActualStatus = m_StatusList->at(0);
206  return ActualStatus.Message;
207  }
208 
213  {
214  DiagnosticStatus ActualStatus = m_StatusList->at(0);
215  return ActualStatus.Recommendation;
216  }
217 
218  /*******************************************|
219  | Configurations |
220  |*******************************************/
221 
223 
228  {
229  return m_StatusQueLength;
230  }
231 
235  void SetMaxStatusQueLength(int StatusQueLength)
236  {
237  m_StatusQueLength = StatusQueLength;
238  }
239 
244  {
245  return m_StatusQueLength;
246  }
247 
249 
254  {
255  return m_Default_Ok_Value = 0;
256  }
257 
261  void SetDefaultOKValue(int Default_Ok_Value)
262  {
263  m_Default_Ok_Value = Default_Ok_Value;
264  }
265 
266 private:
267  std::deque<DiagnosticStatus>* m_StatusList; // List that holds the last status messages in a deque
268 
269  int m_StatusQueLength; // maximal length of status que
270  int m_Default_Ok_Value; // is used for check if return value needs to
271  // be reported
272 };
273 
274 #endif
ErrorcodeReport Errorcode_Report
Definition: Diagnostics.h:57
std::string ReadActualStatusRecommendation()
Retuns the actual status recommendation.
Definition: Diagnostics.h:212
int ReadActualStatusLevel()
Retuns the actual status level.
Definition: Diagnostics.h:194
ErrorcodeReport (helper-)class for status reporting of common libraries.
Definition: Diagnostics.h:33
std::string Errorcode_Namespace
Definition: Diagnostics.h:38
void ReportStatus(int Errorcode, std::string Errorcode_Namespace)
automatic report of status by errorcode. Can be used for return values of library functions...
Definition: Diagnostics.h:158
std::string Recommendation
Definition: Diagnostics.h:56
int m_Default_Ok_Value
Definition: Diagnostics.h:270
DiagnosticStatus()
Constructor.
Definition: Diagnostics.h:62
void ReadActualStatus(short *Level, std::string *Message, std::string *Recommendation)
Read the status.
Definition: Diagnostics.h:177
int GetDefaultOKValue()
Default ok value read/write.
Definition: Diagnostics.h:253
std::string Message
Definition: Diagnostics.h:55
void ReportStatus(short Level, std::string Message)
Report a Status.
Definition: Diagnostics.h:109
int m_StatusQueLength
Definition: Diagnostics.h:269
int GetMaxStatusQueLength()
Gets the maximal length of status history that can be read.
Definition: Diagnostics.h:243
std::deque< DiagnosticStatus > * m_StatusList
Definition: Diagnostics.h:267
Diagnosics()
Constructor.
Definition: Diagnostics.h:81
DiagnosticStatus (helper-)class for status reporting of common libraries.
Definition: Diagnostics.h:51
void SetDefaultOKValue(int Default_Ok_Value)
sets a new default ok value
Definition: Diagnostics.h:261
~Diagnosics()
Destructor.
Definition: Diagnostics.h:95
Diagnostics class for status reporting of common libraries.
Definition: Diagnostics.h:72
std::string ReadActualStatusMessage()
Retuns the actual status message.
Definition: Diagnostics.h:203
std::chrono::time_point< std::chrono::system_clock > Time
Definition: Diagnostics.h:59
ErrorcodeReport()
Constructor.
Definition: Diagnostics.h:41
Level
void ReportStatus(short Level, std::string Message, std::string Recommendation)
for simple status report by hand with problem solution
Definition: Diagnostics.h:124
void ReportStatus(short Level, int Errorcode, std::string Errorcode_Namespace, std::string Recommendation)
report with manually set level for a errorcode and additional comments
Definition: Diagnostics.h:140
int GetActualStatusQueLength()
status que length
Definition: Diagnostics.h:227
void SetMaxStatusQueLength(int StatusQueLength)
Sets the maximal length of status history that can be read. Default is 5 elements.
Definition: Diagnostics.h:235


schunk_powercube_chain
Author(s): Florian Weisshardt
autogenerated on Mon Nov 25 2019 03:48:21