Kudu C++ client API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
callbacks.h
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 #ifndef KUDU_CLIENT_CALLBACKS_H
18 #define KUDU_CLIENT_CALLBACKS_H
19 
20 #ifdef KUDU_HEADERS_NO_STUBS
21 #include "kudu/gutil/macros.h"
22 #include "kudu/gutil/port.h"
23 #else
24 #include "kudu/client/stubs.h"
25 #endif
26 #include "kudu/util/kudu_export.h"
27 
28 namespace kudu {
29 
30 class Status;
31 
32 namespace client {
33 
34 
36 enum KuduLogSeverity {
37  SEVERITY_INFO,
38  SEVERITY_WARNING,
39  SEVERITY_ERROR,
40  SEVERITY_FATAL
41 };
42 
44 class KUDU_EXPORT KuduLoggingCallback {
45  public:
47  }
48 
49  virtual ~KuduLoggingCallback() {
50  }
51 
68  virtual void Run(KuduLogSeverity severity,
69  const char* filename,
70  int line_number,
71  const struct ::tm* time,
72  const char* message,
73  size_t message_len) = 0;
74 
75  private:
76  DISALLOW_COPY_AND_ASSIGN(KuduLoggingCallback);
77 };
78 
80 template <typename T>
81 class KUDU_EXPORT KuduLoggingMemberCallback : public KuduLoggingCallback {
82  public:
84  typedef void (T::*MemberType)(
85  KuduLogSeverity severity,
86  const char* filename,
87  int line_number,
88  const struct ::tm* time,
89  const char* message,
90  size_t message_len);
91 
98  KuduLoggingMemberCallback(T* object, MemberType member)
99  : object_(object),
100  member_(member) {
101  }
102 
104  virtual void Run(KuduLogSeverity severity,
105  const char* filename,
106  int line_number,
107  const struct ::tm* time,
108  const char* message,
109  size_t message_len) OVERRIDE {
110  (object_->*member_)(severity, filename, line_number, time,
111  message, message_len);
112  }
113 
114  private:
115  T* object_;
116  MemberType member_;
117 };
118 
121 template <typename T>
123  public:
125  typedef void (*FunctionType)(T arg,
126  KuduLogSeverity severity,
127  const char* filename,
128  int line_number,
129  const struct ::tm* time,
130  const char* message,
131  size_t message_len);
132 
139  KuduLoggingFunctionCallback(FunctionType function, T arg)
140  : function_(function),
141  arg_(arg) {
142  }
143 
145  virtual void Run(KuduLogSeverity severity,
146  const char* filename,
147  int line_number,
148  const struct ::tm* time,
149  const char* message,
150  size_t message_len) OVERRIDE {
151  function_(arg_, severity, filename, line_number, time,
152  message, message_len);
153  }
154 
155  private:
156  FunctionType function_;
157  T arg_;
158 };
159 
161 class KUDU_EXPORT KuduStatusCallback {
162  public:
164  }
165 
166  virtual ~KuduStatusCallback() {
167  }
168 
173  virtual void Run(const Status& s) = 0;
174 
175  private:
176  DISALLOW_COPY_AND_ASSIGN(KuduStatusCallback);
177 };
178 
180 template <typename T>
181 class KUDU_EXPORT KuduStatusMemberCallback : public KuduStatusCallback {
182  public:
184  typedef void (T::*MemberType)(const Status& s);
185 
192  KuduStatusMemberCallback(T* object, MemberType member)
193  : object_(object),
194  member_(member) {
195  }
196 
198  virtual void Run(const Status& s) OVERRIDE {
199  (object_->*member_)(s);
200  }
201 
202  private:
203  T* object_;
204  MemberType member_;
205 };
206 
209 template <typename T>
210 class KUDU_EXPORT KuduStatusFunctionCallback : public KuduStatusCallback {
211  public:
213  typedef void (*FunctionType)(T arg, const Status& s);
214 
222  KuduStatusFunctionCallback(FunctionType function, T arg)
223  : function_(function),
224  arg_(arg) {
225  }
226 
228  virtual void Run(const Status& s) OVERRIDE {
229  function_(arg_, s);
230  }
231 
232  private:
233  FunctionType function_;
234  T arg_;
235 };
236 
237 } // namespace client
238 } // namespace kudu
239 
240 #endif
The interface for all logging callbacks.
Definition: callbacks.h:44
A representation of an operation's outcome.
Definition: status.h:106
The logging callback that invokes a member function of an object.
Definition: callbacks.h:81
KuduStatusFunctionCallback(FunctionType function, T arg)
Definition: callbacks.h:222
KuduLoggingMemberCallback(T *object, MemberType member)
Definition: callbacks.h:98
The interface for all status callbacks.
Definition: callbacks.h:161
virtual void Run(KuduLogSeverity severity, const char *filename, int line_number, const struct::tm *time, const char *message, size_t message_len) OVERRIDE
Definition: callbacks.h:145
The status callback that invokes a member function of an object.
Definition: callbacks.h:181
KuduStatusMemberCallback(T *object, MemberType member)
Definition: callbacks.h:192
virtual void Run(const Status &s) OVERRIDE
Definition: callbacks.h:198
virtual void Run(KuduLogSeverity severity, const char *filename, int line_number, const struct::tm *time, const char *message, size_t message_len) OVERRIDE
Definition: callbacks.h:104
virtual void Run(const Status &s) OVERRIDE
Definition: callbacks.h:228
KuduLoggingFunctionCallback(FunctionType function, T arg)
Definition: callbacks.h:139
The status callback that invokes a function by pointer with a single argument.
Definition: callbacks.h:210
The logging callback that invokes a function by pointer with a single argument.
Definition: callbacks.h:122