My Project
rpl_reporting.h
00001 /* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #ifndef RPL_REPORTING_H
00017 #define RPL_REPORTING_H
00018 
00019 #include "my_sys.h"                             /* loglevel */
00020 
00024 #define MAX_SLAVE_ERRMSG      1024
00025 
00026 // todo: consider to remove rpl_reporting.cc,h from building embedded
00027 #if !defined(EMBEDDED_LIBRARY)
00028 class THD;
00029 #endif
00030 
00038 class Slave_reporting_capability
00039 {
00040 public:
00042   mutable mysql_mutex_t err_lock;
00048   Slave_reporting_capability(char const *thread_name);
00049 
00060   virtual void report(loglevel level, int err_code, const char *msg, ...) const
00061     ATTRIBUTE_FORMAT(printf, 4, 5);
00062   void va_report(loglevel level, int err_code, const char *prefix_msg,
00063                  const char *msg, va_list v_args) const;
00064 
00069   void clear_error() {
00070     mysql_mutex_lock(&err_lock);
00071     m_last_error.clear();
00072     mysql_mutex_unlock(&err_lock);
00073   }
00074 
00075 #if !defined(EMBEDDED_LIBRARY)
00076 
00079   int has_temporary_error(THD *thd, uint error_arg= 0, bool* silent= 0) const;
00080 #endif // EMBEDDED_LIBRARY
00081   
00085   class Error {
00086     friend class Slave_reporting_capability;
00087   public:
00088     Error()
00089     {
00090       clear();
00091     }
00092 
00093     void clear()
00094     {
00095       number= 0;
00096       message[0]= '\0';
00097       timestamp[0]= '\0';
00098 
00099     }
00100 
00101     void update_timestamp()
00102     {
00103       time_t skr;
00104       struct tm tm_tmp;
00105       struct tm *start;
00106 
00107       skr= my_time(0);
00108       localtime_r(&skr, &tm_tmp);
00109       start=&tm_tmp;
00110 
00111       sprintf(timestamp, "%02d%02d%02d %02d:%02d:%02d",
00112               start->tm_year % 100,
00113               start->tm_mon+1,
00114               start->tm_mday,
00115               start->tm_hour,
00116               start->tm_min,
00117               start->tm_sec);
00118       timestamp[15]= '\0';
00119     }
00120 
00122     uint32 number;
00124     char message[MAX_SLAVE_ERRMSG];
00126     char timestamp[16];
00127   };
00128 
00129   Error const& last_error() const { return m_last_error; }
00130   bool is_error() const { return last_error().number != 0; }
00131 
00132   virtual ~Slave_reporting_capability()= 0;
00133 
00134 protected:
00135 
00136   virtual void do_report(loglevel level, int err_code,
00137                  const char *msg, va_list v_args) const
00138   {
00139     va_report(level, err_code, NULL, msg, v_args);
00140   }
00141 
00142 private:
00146   mutable Error m_last_error;
00147 
00148   char const *const m_thread_name;
00149 
00150   // not implemented
00151   Slave_reporting_capability(const Slave_reporting_capability& rhs);
00152   Slave_reporting_capability& operator=(const Slave_reporting_capability& rhs);
00153 };
00154 
00155 #endif // RPL_REPORTING_H
00156 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines