-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathErrorHandler.cpp
More file actions
121 lines (102 loc) · 2.98 KB
/
ErrorHandler.cpp
File metadata and controls
121 lines (102 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// Created by florianfrank on 29.12.20.
//
#if 0
#include <memory.h>
#include <cstdio>
#include <cerrno>
#if __WIN32__
#include <string.h>
#endif
#include "ErrorHandler.h"
#include "ErrorCodeDefines.h"
char errMsgBuff[512];
const char* PIL_ErrorCodeToString(PIL_ERROR_CODE errorCode)
{
switch (errorCode)
{
case PIL_NO_ERROR:
return "Success";
case PIL_INVALID_ARGUMENTS:
return "Invalid arguments";
case PIL_TIMEOUT:
return "Socket timeout";
case PIL_ERRNO:
{
sprintf(errMsgBuff, "Errno %d (%s)", errno, strerror(errno));
return errMsgBuff;
}
case PIL_INTERFACE_CLOSED:
return "Socket is closed";
case PIL_INVALID_BAUDRATE:
return "Baudrate not supported";
case PIL_INSUFFICIENT_RESOURCES:
return "Insufficient resources";
case PIL_DEADLOCK_DETECTED:
return "Deadlock detected";
case PIL_THREAD_NOT_JOINABLE:
return "Thread not joinable";
case PIL_THREAD_NOT_FOUND:
return "Thread not found";
case PIL_ONLY_PARTIALLY_READ_WRITTEN:
return "File only partially written";
case PIL_NO_SUCH_FILE:
return "No such file or directory";
case PIL_XML_PARSING_ERROR:
return "Error while parsing XML file";
default:
return "Unknown error";
}
return "Unknown error";
}
bool PIL_ReturnErrorMessage(char *errorStr, PIL_ErrorHandle *socketStruct)
{
if(!errorStr)
return false;
if(!socketStruct)
{
strcpy(errorStr, "socketStruct == NULL");
return false;
}
const char *errCodeStr = PIL_ErrorCodeToString(socketStruct->m_ErrorCode);
if(socketStruct->m_ErrorCode == PIL_ERRNO)
{
sprintf(errorStr, "%s: %s", errCodeStr, strerror(socketStruct->m_ErrnoCode));
return true;
}
if(strcmp(socketStruct->m_ErrorMessage, "") != 0)
{
sprintf(errorStr, "%s: %s", errCodeStr, socketStruct->m_ErrorMessage);
return true;
}
strcpy(errorStr, errCodeStr);
return true;
}
bool PIL_SetLastError(PIL_ErrorHandle *errStruct, PIL_ERROR_CODE errorCode)
{
errStruct->m_ErrorCode = errorCode;
if(errorCode == PIL_ERRNO)
{
errStruct->m_ErrnoCode = errno;
}
strcpy(errStruct->m_ErrorMessage, "");
if(errorCode == PIL_NO_ERROR)
return true;
return false;
}
const char* PIL_ReturnErrorMessage(PIL_ErrorHandle *errorHandle)
{
PIL_ReturnErrorMessage(errMsgBuff, errorHandle);
return errMsgBuff;
}
bool PIL_SetLastErrorMsg(PIL_ErrorHandle *errStruct, PIL_ERROR_CODE errorCode, const char* errorMessage)
{
if(!errStruct)
return false;
if(strlen(errorMessage) > MAX_ERROR_MSG_LEN)
return false;
strcpy(errStruct->m_ErrorMessage, errorMessage);
errStruct->m_ErrorCode = errorCode;
return true;
}
#endif