MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_reporting.h
1 /* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef RPL_REPORTING_H
17 #define RPL_REPORTING_H
18 
19 #include "my_sys.h" /* loglevel */
20 
24 #define MAX_SLAVE_ERRMSG 1024
25 
26 // todo: consider to remove rpl_reporting.cc,h from building embedded
27 #if !defined(EMBEDDED_LIBRARY)
28 class THD;
29 #endif
30 
39 {
40 public:
48  Slave_reporting_capability(char const *thread_name);
49 
60  virtual void report(loglevel level, int err_code, const char *msg, ...) const
61  ATTRIBUTE_FORMAT(printf, 4, 5);
62  void va_report(loglevel level, int err_code, const char *prefix_msg,
63  const char *msg, va_list v_args) const;
64 
69  void clear_error() {
71  m_last_error.clear();
73  }
74 
75 #if !defined(EMBEDDED_LIBRARY)
76 
79  int has_temporary_error(THD *thd, uint error_arg= 0, bool* silent= 0) const;
80 #endif // EMBEDDED_LIBRARY
81 
85  class Error {
86  friend class Slave_reporting_capability;
87  public:
88  Error()
89  {
90  clear();
91  }
92 
93  void clear()
94  {
95  number= 0;
96  message[0]= '\0';
97  timestamp[0]= '\0';
98 
99  }
100 
101  void update_timestamp()
102  {
103  time_t skr;
104  struct tm tm_tmp;
105  struct tm *start;
106 
107  skr= my_time(0);
108  localtime_r(&skr, &tm_tmp);
109  start=&tm_tmp;
110 
111  sprintf(timestamp, "%02d%02d%02d %02d:%02d:%02d",
112  start->tm_year % 100,
113  start->tm_mon+1,
114  start->tm_mday,
115  start->tm_hour,
116  start->tm_min,
117  start->tm_sec);
118  timestamp[15]= '\0';
119  }
120 
122  uint32 number;
124  char message[MAX_SLAVE_ERRMSG];
126  char timestamp[16];
127  };
128 
129  Error const& last_error() const { return m_last_error; }
130  bool is_error() const { return last_error().number != 0; }
131 
132  virtual ~Slave_reporting_capability()= 0;
133 
134 protected:
135 
136  virtual void do_report(loglevel level, int err_code,
137  const char *msg, va_list v_args) const
138  {
139  va_report(level, err_code, NULL, msg, v_args);
140  }
141 
142 private:
146  mutable Error m_last_error;
147 
148  char const *const m_thread_name;
149 
150  // not implemented
153 };
154 
155 #endif // RPL_REPORTING_H
156