Mathias Agopian | 208059f | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | // All static variables go here, to control initialization and |
| 18 | // destruction order in the library. |
| 19 | |
Steven Moreland | a4853cd | 2019-07-12 15:44:37 -0700 | [diff] [blame] | 20 | #include "Static.h" |
Mathias Agopian | 208059f | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 21 | |
Steven Moreland | 6c7d214 | 2020-01-30 14:39:17 -0800 | [diff] [blame] | 22 | #include "BufferedTextOutput.h" |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/IPCThreadState.h> |
Mathias Agopian | 208059f | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 24 | #include <utils/Log.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 28 | // ------------ Text output streams |
| 29 | |
| 30 | Vector<int32_t> gTextBuffers; |
| 31 | |
| 32 | class LogTextOutput : public BufferedTextOutput |
| 33 | { |
| 34 | public: |
| 35 | LogTextOutput() : BufferedTextOutput(MULTITHREADED) { } |
Jooyung Han | c91e3cb | 2020-11-25 06:38:17 +0900 | [diff] [blame] | 36 | virtual ~LogTextOutput() { } |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 37 | |
| 38 | protected: |
| 39 | virtual status_t writeLines(const struct iovec& vec, size_t N) |
| 40 | { |
| 41 | //android_writevLog(&vec, N); <-- this is now a no-op |
| 42 | if (N != 1) ALOGI("WARNING: writeLines N=%zu\n", N); |
| 43 | ALOGI("%.*s", (int)vec.iov_len, (const char*) vec.iov_base); |
| 44 | return NO_ERROR; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | class FdTextOutput : public BufferedTextOutput |
| 49 | { |
| 50 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 51 | explicit FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { } |
Jooyung Han | c91e3cb | 2020-11-25 06:38:17 +0900 | [diff] [blame] | 52 | virtual ~FdTextOutput() { } |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 53 | |
| 54 | protected: |
| 55 | virtual status_t writeLines(const struct iovec& vec, size_t N) |
| 56 | { |
Steven Moreland | 28723ae | 2019-04-01 18:52:30 -0700 | [diff] [blame] | 57 | ssize_t ret = writev(mFD, &vec, N); |
| 58 | if (ret == -1) return -errno; |
| 59 | if (static_cast<size_t>(ret) != N) return UNKNOWN_ERROR; |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 60 | return NO_ERROR; |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | int mFD; |
| 65 | }; |
| 66 | |
Steven Moreland | 7c0edeb | 2020-02-18 16:41:21 -0800 | [diff] [blame] | 67 | TextOutput& alog(*new LogTextOutput()); |
| 68 | TextOutput& aout(*new FdTextOutput(STDOUT_FILENO)); |
| 69 | TextOutput& aerr(*new FdTextOutput(STDERR_FILENO)); |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 70 | |
Mathias Agopian | 208059f | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 71 | } // namespace android |