Diagnostics.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #ifndef __DIAGNOSTICS_H_
00019 #define __DIAGNOSTICS_H_
00020 
00021 #include <chrono>
00022 #include <deque>
00023 
00033 class ErrorcodeReport  // Errorcode from library
00034 {
00035 public:
00036   bool Code_Exists;                 // true when errorcode returned
00037   int ErrorCode;                    // code number
00038   std::string Errorcode_Namespace;  // namespace of the code (for lookup)
00039 
00041   ErrorcodeReport() : Code_Exists(false), ErrorCode(0), Errorcode_Namespace(""){};
00042 };
00043 
00051 class DiagnosticStatus
00052 {
00053 public:
00054   short Level;                       // 0 = OK, 1 = WARN, 2=ERROR
00055   std::string Message;               // Description of the error
00056   std::string Recommendation;        // Possible solutions for the user
00057   ErrorcodeReport Errorcode_Report;  // Errorcode that is returned from a function
00058 
00059   std::chrono::time_point<std::chrono::system_clock> Time;  // time when status is reported
00060 
00062   DiagnosticStatus() : Level(0), Message(""), Recommendation(""), Time(std::chrono::system_clock::now()){};
00063 };
00064 
00072 class Diagnosics
00073 {
00074   /*TODO:       - select format for errorlookups (.h, .txt, yaml)
00075    *            - implement report status
00076    *            - implement read methodes
00077    *            - implement QueLength methodes
00078    */
00079 public:
00081   Diagnosics()
00082   {
00083     m_StatusQueLength = 5;  // 5 is default value
00084 
00085     // initialize member variabeles
00086     m_StatusList = new std::deque<DiagnosticStatus>[m_StatusQueLength];
00087 
00088     // initialize default ok return value (default 0)
00089     m_Default_Ok_Value = 0;
00090 
00091     // TODO: read in errorcode lists
00092   }
00093 
00095   ~Diagnosics()
00096   {
00097     delete m_StatusList;
00098   };
00099 
00100   /*******************************************|
00101   |                     Useage interface                                |
00102   |*******************************************/
00103 
00105 
00109   void ReportStatus(short Level, std::string Message)
00110   {
00111     DiagnosticStatus NewStatus;
00112 
00113     NewStatus.Level = Level;
00114     NewStatus.Time = std::chrono::system_clock::now();
00115     NewStatus.Message = Message;
00116 
00117     m_StatusList->push_front(NewStatus);
00118     m_StatusList->pop_back();
00119   }
00120 
00124   void ReportStatus(short Level, std::string Message, std::string Recommendation)
00125   {
00126     DiagnosticStatus NewStatus;
00127 
00128     NewStatus.Level = Level;
00129     NewStatus.Time = std::chrono::system_clock::now();
00130     NewStatus.Message = Message;
00131     NewStatus.Message = Recommendation;
00132 
00133     m_StatusList->push_front(NewStatus);
00134     m_StatusList->pop_back();
00135   }
00136 
00140   void ReportStatus(short Level, int Errorcode, std::string Errorcode_Namespace, std::string Recommendation)
00141   {
00142     DiagnosticStatus NewStatus;
00143 
00144     NewStatus.Level = Level;
00145     NewStatus.Time = std::chrono::system_clock::now();
00146 
00147     // TODO: generate message from errorcode
00148 
00149     NewStatus.Message = Recommendation;
00150 
00151     m_StatusList->push_front(NewStatus);
00152     m_StatusList->pop_back();
00153   }
00154 
00158   void ReportStatus(int Errorcode, std::string Errorcode_Namespace)
00159   {
00160     DiagnosticStatus NewStatus;
00161 
00162     // TODO: get message from errorcodelist
00163 
00164     NewStatus.Time = std::chrono::system_clock::now();
00165 
00166     m_StatusList->push_front(NewStatus);
00167     m_StatusList->pop_back();
00168   }
00169 
00171 
00177   void ReadActualStatus(short* Level, std::string* Message, std::string* Recommendation)
00178   {
00179     DiagnosticStatus ActualStatus = m_StatusList->at(0);
00180 
00181     // resize strings for the size of the upcoming message
00182     Message->clear();
00183     Recommendation->clear();
00184 
00185     // write output
00186     Level = (short*)ActualStatus.Level;
00187     Message->append(ActualStatus.Message);
00188     Recommendation->append(ActualStatus.Recommendation);
00189   }
00190 
00194   int ReadActualStatusLevel()
00195   {
00196     DiagnosticStatus ActualStatus = m_StatusList->at(0);
00197     return ActualStatus.Level;
00198   }
00199 
00203   std::string ReadActualStatusMessage()
00204   {
00205     DiagnosticStatus ActualStatus = m_StatusList->at(0);
00206     return ActualStatus.Message;
00207   }
00208 
00212   std::string ReadActualStatusRecommendation()
00213   {
00214     DiagnosticStatus ActualStatus = m_StatusList->at(0);
00215     return ActualStatus.Recommendation;
00216   }
00217 
00218   /*******************************************|
00219   |                     Configurations                                  |
00220   |*******************************************/
00221 
00223 
00227   int GetActualStatusQueLength()
00228   {
00229     return m_StatusQueLength;
00230   }
00231 
00235   void SetMaxStatusQueLength(int StatusQueLength)
00236   {
00237     m_StatusQueLength = StatusQueLength;
00238   }
00239 
00243   int GetMaxStatusQueLength()
00244   {
00245     return m_StatusQueLength;
00246   }
00247 
00249 
00253   int GetDefaultOKValue()
00254   {
00255     return m_Default_Ok_Value = 0;
00256   }
00257 
00261   void SetDefaultOKValue(int Default_Ok_Value)
00262   {
00263     m_Default_Ok_Value = Default_Ok_Value;
00264   }
00265 
00266 private:
00267   std::deque<DiagnosticStatus>* m_StatusList;  // List that holds the last status messages in a deque
00268 
00269   int m_StatusQueLength;   // maximal length of status que
00270   int m_Default_Ok_Value;  // is used for check if return value needs to
00271                            // be reported
00272 };
00273 
00274 #endif


schunk_powercube_chain
Author(s): Florian Weisshardt
autogenerated on Sat Jun 8 2019 20:25:18