Mathias Agopian | 7922fa2 | 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 | |
Martijn Coenen | e01f4f2 | 2016-05-12 12:33:28 +0200 | [diff] [blame] | 20 | #include <hwbinder/Static.h> |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 21 | |
Martijn Coenen | 4080edc | 2016-05-04 14:17:02 +0200 | [diff] [blame] | 22 | #include <hwbinder/BufferedTextOutput.h> |
| 23 | #include <hwbinder/IPCThreadState.h> |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 24 | #include <utils/Log.h> |
| 25 | |
| 26 | namespace android { |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 27 | namespace hardware { |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 28 | |
Mathias Agopian | 4ea13dc | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 29 | // ------------ Text output streams |
| 30 | |
| 31 | Vector<int32_t> gTextBuffers; |
| 32 | |
| 33 | class LogTextOutput : public BufferedTextOutput |
| 34 | { |
| 35 | public: |
| 36 | LogTextOutput() : BufferedTextOutput(MULTITHREADED) { } |
| 37 | virtual ~LogTextOutput() { }; |
| 38 | |
| 39 | protected: |
| 40 | virtual status_t writeLines(const struct iovec& vec, size_t N) |
| 41 | { |
| 42 | //android_writevLog(&vec, N); <-- this is now a no-op |
| 43 | if (N != 1) ALOGI("WARNING: writeLines N=%zu\n", N); |
| 44 | ALOGI("%.*s", (int)vec.iov_len, (const char*) vec.iov_base); |
| 45 | return NO_ERROR; |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | class FdTextOutput : public BufferedTextOutput |
| 50 | { |
| 51 | public: |
Chih-Hung Hsieh | 1f555e9 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 52 | explicit FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { } |
Mathias Agopian | 4ea13dc | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 53 | virtual ~FdTextOutput() { }; |
| 54 | |
| 55 | protected: |
| 56 | virtual status_t writeLines(const struct iovec& vec, size_t N) |
| 57 | { |
| 58 | writev(mFD, &vec, N); |
| 59 | return NO_ERROR; |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | int mFD; |
| 64 | }; |
| 65 | |
| 66 | static LogTextOutput gLogTextOutput; |
| 67 | static FdTextOutput gStdoutTextOutput(STDOUT_FILENO); |
| 68 | static FdTextOutput gStderrTextOutput(STDERR_FILENO); |
| 69 | |
| 70 | TextOutput& alog(gLogTextOutput); |
| 71 | TextOutput& aout(gStdoutTextOutput); |
| 72 | TextOutput& aerr(gStderrTextOutput); |
| 73 | |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 74 | // ------------ ProcessState.cpp |
| 75 | |
| 76 | Mutex gProcessMutex; |
| 77 | sp<ProcessState> gProcess; |
| 78 | |
Steven Moreland | 7c2fb2f | 2017-03-12 21:04:31 -0700 | [diff] [blame] | 79 | class LibHwbinderIPCtStatics |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 80 | { |
| 81 | public: |
Steven Moreland | 7c2fb2f | 2017-03-12 21:04:31 -0700 | [diff] [blame] | 82 | LibHwbinderIPCtStatics() |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 83 | { |
| 84 | } |
| 85 | |
Steven Moreland | 7c2fb2f | 2017-03-12 21:04:31 -0700 | [diff] [blame] | 86 | ~LibHwbinderIPCtStatics() |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 87 | { |
| 88 | IPCThreadState::shutdown(); |
| 89 | } |
| 90 | }; |
| 91 | |
Steven Moreland | 7c2fb2f | 2017-03-12 21:04:31 -0700 | [diff] [blame] | 92 | static LibHwbinderIPCtStatics gIPCStatics; |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 93 | |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 94 | } // namespace hardware |
Mathias Agopian | 7922fa2 | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 95 | } // namespace android |