blob: 26c9a563aeda0a9bb24dbc88d042a5ce7b266b5b [file] [log] [blame]
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +02001/*
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
cyy8fdb7582019-02-05 02:57:21 +080023#include <thrift/thrift_export.h>
24
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +020025namespace apache {
26namespace thrift {
27
28class TOutput {
29public:
James E. King III278528c2019-01-11 12:17:44 -050030 TOutput();
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +020031
32 inline void setOutputFunction(void (*function)(const char*)) { f_ = function; }
33
34 inline void operator()(const char* message) { f_(message); }
35
36 // It is important to have a const char* overload here instead of
37 // just the string version, otherwise errno could be corrupted
38 // if there is some problem allocating memory when constructing
39 // the string.
40 void perror(const char* message, int errno_copy);
41 inline void perror(const std::string& message, int errno_copy) {
42 perror(message.c_str(), errno_copy);
43 }
44
45 void printf(const char* message, ...);
46
47 static void errorTimeWrapper(const char* msg);
48
49 /** Just like strerror_r but returns a C++ string object. */
50 static std::string strerror_s(int errno_copy);
51
52private:
53 void (*f_)(const char*);
54};
55
cyy8fdb7582019-02-05 02:57:21 +080056THRIFT_EXPORT extern TOutput GlobalOutput;
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +020057}
58} // namespace apache::thrift
59
60#endif //_THRIFT_OUTPUT_H_