Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 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 | |
cyy | 8fdb758 | 2019-02-05 02:57:21 +0800 | [diff] [blame] | 23 | #include <thrift/thrift_export.h> |
| 24 | |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 25 | namespace apache { |
| 26 | namespace thrift { |
| 27 | |
| 28 | class TOutput { |
| 29 | public: |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 30 | TOutput(); |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 31 | |
| 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 | |
| 52 | private: |
| 53 | void (*f_)(const char*); |
| 54 | }; |
| 55 | |
cyy | 8fdb758 | 2019-02-05 02:57:21 +0800 | [diff] [blame] | 56 | THRIFT_EXPORT extern TOutput GlobalOutput; |
Konrad Grochowski | 24ea0bf | 2015-05-07 14:59:29 +0200 | [diff] [blame] | 57 | } |
| 58 | } // namespace apache::thrift |
| 59 | |
| 60 | #endif //_THRIFT_OUTPUT_H_ |