The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [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 | |
| 20 | #include <private/utils/Static.h> |
| 21 | |
| 22 | #include <utils/BufferedTextOutput.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <utils/Log.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | class LibUtilsFirstStatics |
| 28 | { |
| 29 | public: |
| 30 | LibUtilsFirstStatics() |
| 31 | { |
| 32 | initialize_string8(); |
| 33 | initialize_string16(); |
| 34 | } |
| 35 | |
| 36 | ~LibUtilsFirstStatics() |
| 37 | { |
| 38 | terminate_string16(); |
| 39 | terminate_string8(); |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | static LibUtilsFirstStatics gFirstStatics; |
| 44 | int gDarwinCantLoadAllObjects = 1; |
| 45 | |
| 46 | // ------------ Text output streams |
| 47 | |
| 48 | Vector<int32_t> gTextBuffers; |
| 49 | |
| 50 | class LogTextOutput : public BufferedTextOutput |
| 51 | { |
| 52 | public: |
| 53 | LogTextOutput() : BufferedTextOutput(MULTITHREADED) { } |
| 54 | virtual ~LogTextOutput() { }; |
| 55 | |
| 56 | protected: |
| 57 | virtual status_t writeLines(const struct iovec& vec, size_t N) |
| 58 | { |
| 59 | android_writevLog(&vec, N); |
| 60 | return NO_ERROR; |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | class FdTextOutput : public BufferedTextOutput |
| 65 | { |
| 66 | public: |
| 67 | FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { } |
| 68 | virtual ~FdTextOutput() { }; |
| 69 | |
| 70 | protected: |
| 71 | virtual status_t writeLines(const struct iovec& vec, size_t N) |
| 72 | { |
| 73 | writev(mFD, &vec, N); |
| 74 | return NO_ERROR; |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | int mFD; |
| 79 | }; |
| 80 | |
| 81 | static LogTextOutput gLogTextOutput; |
| 82 | static FdTextOutput gStdoutTextOutput(STDOUT_FILENO); |
| 83 | static FdTextOutput gStderrTextOutput(STDERR_FILENO); |
| 84 | |
| 85 | TextOutput& alog(gLogTextOutput); |
| 86 | TextOutput& aout(gStdoutTextOutput); |
| 87 | TextOutput& aerr(gStderrTextOutput); |
| 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | } // namespace android |