libptpmgmt  1.3
libptpmgmt library that provides the functionality of linuxptp pmc
err.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-3.0-or-later
2  SPDX-FileCopyrightText: Copyright © 2021 Erez Geva <ErezGeva2@gmail.com> */
3 
14 #ifndef __PTPMGMT_ERR_H
15 #define __PTPMGMT_ERR_H
16 
17 #include "name.h"
18 
19 #ifdef __cplusplus
20 __PTPMGMT_NAMESPACE_BEGIN
21 
28 class Error
29 {
30  private:
31  int m_errno;
32  int m_line;
33  std::string m_file;
34  std::string m_msg;
35  std::string m_func;
36  std::string m_fmsg;
37  std::string m_emsg;
38  void doClear();
39  Error() : m_line(0) {}
40  void doError(bool use_errno, const char *file, int line, const char *func,
41  const std::string &msg);
42  const std::string &fetch();
43  static Error &getCur();
44  public:
45 
46  #ifndef SWIG
48  static void perror(const char *file, int line, const char *func,
49  const std::string &msg)
50  { getCur().doError(true, file, line, func, msg); }
51  static void error(const char *file, int line, const char *func,
52  const std::string &msg)
53  { getCur().doError(false, file, line, func, msg); }
54  static std::string doFormat(const char *format, ...);
55  static void clear() { getCur().m_line = 0; }
57  #endif /* SWIG */
58 
63  static bool isError() { return getCur().m_line > 0; }
68  static const std::string &getError() { return getCur().fetch(); }
73  static const std::string &getFile() { return getCur().m_file; }
78  static int getFileLine() { return getCur().m_line; }
83  static const std::string &getFunc() { return getCur().m_func; }
88  static int getErrno() { return getCur().m_errno; }
94  static const std::string &getMsg() { return getCur().m_msg; }
100  static const std::string &getErrnoMsg();
101 };
102 
103 __PTPMGMT_NAMESPACE_END
104 #else /* __cplusplus */
105 #include "c/err.h"
106 #endif /* __cplusplus */
107 
108 #endif /* __PTPMGMT_ERR_H */
Get Last Error happend in library, C API.
Keep last error.
Definition: err.h:29
static const std::string & getError()
Definition: err.h:68
static const std::string & getErrnoMsg()
static const std::string & getMsg()
Definition: err.h:94
static bool isError()
Definition: err.h:63
static int getFileLine()
Definition: err.h:78
static const std::string & getFunc()
Definition: err.h:83
static int getErrno()
Definition: err.h:88
static const std::string & getFile()
Definition: err.h:73
Define name space.