1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _THRIFT_OUTPUT_H_
21#define _THRIFT_OUTPUT_H_ 1
22
23namespace apache {
24namespace thrift {
25
26class TOutput {
27public:
28 TOutput() : f_(&errorTimeWrapper) {}
29
30 inline void setOutputFunction(void (*function)(const char*)) { f_ = function; }
31
32 inline void operator()(const char* message) { f_(message); }
33
34 // It is important to have a const char* overload here instead of
35 // just the string version, otherwise errno could be corrupted
36 // if there is some problem allocating memory when constructing
37 // the string.
38 void perror(const char* message, int errno_copy);
39 inline void perror(const std::string& message, int errno_copy) {
40 perror(message.c_str(), errno_copy);
41 }
42
43 void printf(const char* message, ...);
44
45 static void errorTimeWrapper(const char* msg);
46
47 /** Just like strerror_r but returns a C++ string object. */
48 static std::string strerror_s(int errno_copy);
49
50private:
51 void (*f_)(const char*);
52};
53
54extern TOutput GlobalOutput;
55}
56} // namespace apache::thrift
57
58#endif //_THRIFT_OUTPUT_H_
59