00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef KUDU_CLIENT_CALLBACKS_H
00018 #define KUDU_CLIENT_CALLBACKS_H
00019
00020 #ifdef KUDU_HEADERS_NO_STUBS
00021 #include "kudu/gutil/macros.h"
00022 #include "kudu/gutil/port.h"
00023 #else
00024 #include "kudu/client/stubs.h"
00025 #endif
00026 #include "kudu/util/kudu_export.h"
00027
00028 namespace kudu {
00029
00030 class Status;
00031
00032 namespace client {
00033
00034
00036 enum KuduLogSeverity {
00037 SEVERITY_INFO,
00038 SEVERITY_WARNING,
00039 SEVERITY_ERROR,
00040 SEVERITY_FATAL
00041 };
00042
00044 class KUDU_EXPORT KuduLoggingCallback {
00045 public:
00046 KuduLoggingCallback() {
00047 }
00048
00049 virtual ~KuduLoggingCallback() {
00050 }
00051
00068 virtual void Run(KuduLogSeverity severity,
00069 const char* filename,
00070 int line_number,
00071 const struct ::tm* time,
00072 const char* message,
00073 size_t message_len) = 0;
00074
00075 private:
00076 DISALLOW_COPY_AND_ASSIGN(KuduLoggingCallback);
00077 };
00078
00080 template <typename T>
00081 class KUDU_EXPORT KuduLoggingMemberCallback : public KuduLoggingCallback {
00082 public:
00084 typedef void (T::*MemberType)(
00085 KuduLogSeverity severity,
00086 const char* filename,
00087 int line_number,
00088 const struct ::tm* time,
00089 const char* message,
00090 size_t message_len);
00091
00098 KuduLoggingMemberCallback(T* object, MemberType member)
00099 : object_(object),
00100 member_(member) {
00101 }
00102
00104 virtual void Run(KuduLogSeverity severity,
00105 const char* filename,
00106 int line_number,
00107 const struct ::tm* time,
00108 const char* message,
00109 size_t message_len) OVERRIDE {
00110 (object_->*member_)(severity, filename, line_number, time,
00111 message, message_len);
00112 }
00113
00114 private:
00115 T* object_;
00116 MemberType member_;
00117 };
00118
00121 template <typename T>
00122 class KUDU_EXPORT KuduLoggingFunctionCallback : public KuduLoggingCallback {
00123 public:
00125 typedef void (*FunctionType)(T arg,
00126 KuduLogSeverity severity,
00127 const char* filename,
00128 int line_number,
00129 const struct ::tm* time,
00130 const char* message,
00131 size_t message_len);
00132
00139 KuduLoggingFunctionCallback(FunctionType function, T arg)
00140 : function_(function),
00141 arg_(arg) {
00142 }
00143
00145 virtual void Run(KuduLogSeverity severity,
00146 const char* filename,
00147 int line_number,
00148 const struct ::tm* time,
00149 const char* message,
00150 size_t message_len) OVERRIDE {
00151 function_(arg_, severity, filename, line_number, time,
00152 message, message_len);
00153 }
00154
00155 private:
00156 FunctionType function_;
00157 T arg_;
00158 };
00159
00161 class KUDU_EXPORT KuduStatusCallback {
00162 public:
00163 KuduStatusCallback() {
00164 }
00165
00166 virtual ~KuduStatusCallback() {
00167 }
00168
00173 virtual void Run(const Status& s) = 0;
00174
00175 private:
00176 DISALLOW_COPY_AND_ASSIGN(KuduStatusCallback);
00177 };
00178
00180 template <typename T>
00181 class KUDU_EXPORT KuduStatusMemberCallback : public KuduStatusCallback {
00182 public:
00184 typedef void (T::*MemberType)(const Status& s);
00185
00192 KuduStatusMemberCallback(T* object, MemberType member)
00193 : object_(object),
00194 member_(member) {
00195 }
00196
00198 virtual void Run(const Status& s) OVERRIDE {
00199 (object_->*member_)(s);
00200 }
00201
00202 private:
00203 T* object_;
00204 MemberType member_;
00205 };
00206
00209 template <typename T>
00210 class KUDU_EXPORT KuduStatusFunctionCallback : public KuduStatusCallback {
00211 public:
00213 typedef void (*FunctionType)(T arg, const Status& s);
00214
00222 KuduStatusFunctionCallback(FunctionType function, T arg)
00223 : function_(function),
00224 arg_(arg) {
00225 }
00226
00228 virtual void Run(const Status& s) OVERRIDE {
00229 function_(arg_, s);
00230 }
00231
00232 private:
00233 FunctionType function_;
00234 T arg_;
00235 };
00236
00237 }
00238 }
00239
00240 #endif