errorhandler.cpp
Go to the documentation of this file.
00001 
00005 #include <stdio.h>      // for printf() and fprintf()
00006 #include <stdlib.h>     // for atoi() and exit()
00007 // #include <string.h>     // for memset()
00008 //#include <backward/iostream.h>        // fuer cout()
00009 
00010 #include "errorhandler.hpp"
00011 #include "Time.hpp"
00012 
00013 // Print mutex to print thread-safe
00014 pthread_mutex_t m_printMutex = PTHREAD_MUTEX_INITIALIZER;
00015 
00019 void doNothing()
00020 {
00021 }
00022 
00023 
00027 void dieWithError(std::string errorMessage)
00028 {
00029         // Mutex setzen
00030         pthread_mutex_lock(&m_printMutex);
00031         
00032         // Nachricht schreiben
00033     printError(errorMessage.c_str());
00034         
00035         // Mutex wieder freigeben
00036         pthread_mutex_unlock(&m_printMutex);
00037 
00038         // Programm abbrechen
00039     exit(1);
00040 }
00041 
00045 void infoMessage(std::string message, bool print)
00046 {
00047         if (print == true)
00048         {
00049                 Time t = Time::now();
00050         
00051                 // Mutex setzen
00052                 pthread_mutex_lock(&m_printMutex);
00053                 
00054                 // Nachricht schreiben
00055                 printf ("%s ", t.toString().c_str());
00056                 printf ("Info: %s\n", message.c_str());
00057                 fflush(0);
00058 
00059                 // Mutex wieder freigeben
00060                 pthread_mutex_unlock(&m_printMutex);
00061         }
00062 }
00063 
00064 
00065 
00066 //
00067 // Warnungs-Text auf die Ausgabe schreiben.
00068 //
00069 void printWarning(std::string message)
00070 {
00071         Time t = Time::now();
00072         
00073         // Mutex setzen
00074         pthread_mutex_lock(&m_printMutex);
00075                 
00076         printf ("%s ", t.toString().c_str());
00077         printf ("Warning: %s\n", message.c_str());
00078         fflush(0);
00079                 
00080         // Mutex wieder freigeben
00081         pthread_mutex_unlock(&m_printMutex);
00082 }
00083 
00084 //
00085 // Fehler-Text auf die Ausgabe schreiben.
00086 //
00087 void printError(std::string message)
00088 {
00089         Time t = Time::now();
00090         
00091         // Mutex setzen
00092         pthread_mutex_lock(&m_printMutex);
00093                 
00094         printf ("%s ", t.toString().c_str());
00095         printf ("ERROR: %s\n", message.c_str());
00096         fflush(0);
00097         
00098         // Mutex wieder freigeben
00099         pthread_mutex_unlock(&m_printMutex);
00100 }


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Wed Jun 14 2017 04:04:50