blob: bd0063060701e5ff0a42b92b38c31a430132feda [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
23namespace apache {
24namespace thrift {
25
26class TOutput {
27public:
James E. King III278528c2019-01-11 12:17:44 -050028 TOutput();
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +020029
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
Carel Combrink08352772025-11-03 12:15:06 +000050 /** Get a singleton instance of the global TOutput object used by
51 * the library internally. */
52 static TOutput& instance();
53
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +020054private:
55 void (*f_)(const char*);
56};
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +020057}
58} // namespace apache::thrift
59
60#endif //_THRIFT_OUTPUT_H_