libptpmgmt  1.4
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 = 0;
32  int m_line = 0;
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  void doError(bool use_errno, const char *file, int line, const char *func,
40  const std::string &msg);
41  const std::string &fetch();
42  static Error &getCur();
43  public:
44 
45  #ifndef SWIG
47  static void perror(const char *file, int line, const char *func,
48  const std::string &msg)
49  { getCur().doError(true, file, line, func, msg); }
50  static void error(const char *file, int line, const char *func,
51  const std::string &msg)
52  { getCur().doError(false, file, line, func, msg); }
53  static std::string doFormat(const char *format, ...);
54  static void clear() { getCur().m_line = 0; }
56  #endif /* SWIG */
57 
62  static bool isError() { return getCur().m_line > 0; }
67  static const std::string &getError() { return getCur().fetch(); }
72  static const std::string &getFile() { return getCur().m_file; }
77  static int getFileLine() { return getCur().m_line; }
82  static const std::string &getFunc() { return getCur().m_func; }
87  static int getErrno() { return getCur().m_errno; }
93  static const std::string &getMsg() { return getCur().m_msg; }
99  static const std::string &getErrnoMsg();
100 };
101 
102 __PTPMGMT_NAMESPACE_END
103 #else /* __cplusplus */
104 #include "c/err.h"
105 #endif /* __cplusplus */
106 
107 #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:67
static const std::string & getErrnoMsg()
static const std::string & getMsg()
Definition: err.h:93
static bool isError()
Definition: err.h:62
static int getFileLine()
Definition: err.h:77
static const std::string & getFunc()
Definition: err.h:82
static int getErrno()
Definition: err.h:87
static const std::string & getFile()
Definition: err.h:72
Define name space.