driver
src
tcp
errorhandler.cpp
Go to the documentation of this file.
1
5
#include <stdio.h>
// for printf() and fprintf()
6
#include <stdlib.h>
// for atoi() and exit()
7
// #include <string.h> // for memset()
8
//#include <backward/iostream.h> // fuer cout()
9
#include "pthread.h"
10
#include "
sick_scan/tcp/errorhandler.hpp
"
11
#ifndef _MSC_VER
12
#include "
sick_scan/tcp/Time.hpp
"
13
#endif
14
// Print mutex to print thread-safe
15
pthread_mutex_t
m_printMutex
= PTHREAD_MUTEX_INITIALIZER;
16
20
void
doNothing
()
21
{
22
}
23
24
28
void
dieWithError
(std::string errorMessage)
29
{
30
// Mutex setzen
31
pthread_mutex_lock(&
m_printMutex
);
32
33
// Nachricht schreiben
34
printError
(errorMessage.c_str());
35
36
// Mutex wieder freigeben
37
pthread_mutex_unlock(&
m_printMutex
);
38
39
// Programm abbrechen
40
exit(1);
41
}
42
46
void
infoMessage
(std::string message,
bool
print)
47
{
48
if
(
print
==
true
)
49
{
50
#ifndef _MSC_VER
51
Time
t =
Time::now
();
52
#endif
53
// Mutex setzen
54
pthread_mutex_lock(&
m_printMutex
);
55
56
// Nachricht schreiben
57
#ifndef _MSC_VER
58
printf(
"%s "
, t.
toString
().c_str());
59
#endif
60
printf (
"Info: %s\n"
, message.c_str());
61
fflush(0);
62
63
// Mutex wieder freigeben
64
pthread_mutex_unlock(&
m_printMutex
);
65
}
66
}
67
68
69
70
//
71
// Warnungs-Text auf die Ausgabe schreiben.
72
//
73
void
printWarning
(std::string message)
74
{
75
#ifndef _MSC_VER
76
Time
t =
Time::now
();
77
#endif
78
// Mutex setzen
79
pthread_mutex_lock(&
m_printMutex
);
80
81
#ifndef _MSC_VER
82
printf (
"%s "
, t.
toString
().c_str());
83
#endif
84
printf (
"Warning: %s\n"
, message.c_str());
85
fflush(0);
86
87
// Mutex wieder freigeben
88
pthread_mutex_unlock(&
m_printMutex
);
89
}
90
91
//
92
// Fehler-Text auf die Ausgabe schreiben.
93
//
94
void
printError
(std::string message)
95
{
96
#ifndef _MSC_VER
97
Time
t =
Time::now
();
98
#endif
99
100
// Mutex setzen
101
pthread_mutex_lock(&
m_printMutex
);
102
103
#ifndef _MSC_VER
104
printf(
"%s "
, t.
toString
().c_str());
105
#endif
106
printf (
"ERROR: %s\n"
, message.c_str());
107
fflush(0);
108
109
// Mutex wieder freigeben
110
pthread_mutex_unlock(&
m_printMutex
);
111
}
Time::now
static Time now()
Definition:
Time.cpp:168
errorhandler.hpp
doNothing
void doNothing()
Definition:
errorhandler.cpp:20
infoMessage
void infoMessage(std::string message, bool print)
Definition:
errorhandler.cpp:46
Time::toString
std::string toString() const
Definition:
Time.cpp:40
dieWithError
void dieWithError(std::string errorMessage)
Definition:
errorhandler.cpp:28
printWarning
void printWarning(std::string message)
Definition:
errorhandler.cpp:73
m_printMutex
pthread_mutex_t m_printMutex
Definition:
errorhandler.cpp:15
printError
void printError(std::string message)
Definition:
errorhandler.cpp:94
Time.hpp
Time
Definition:
Time.hpp:44
print
ROSCONSOLE_DECL void print(FilterBase *filter, void *logger, Level level, const char *file, int line, const char *function, const char *fmt,...) ROSCONSOLE_PRINTF_ATTRIBUTE(7
sick_scan
Author(s): Michael Lehning
, Jochen Sprickerhof
, Martin Günther
autogenerated on Thu Sep 8 2022 02:30:19