blob: 565f2e25f3600b54d33bd97bbaafdfeefaf64925 [file] [log] [blame]
Mathias Agopian208059f2009-05-18 15:08:03 -07001/*
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 Morelanda4853cd2019-07-12 15:44:37 -070020#include "Static.h"
Mathias Agopian208059f2009-05-18 15:08:03 -070021
Steven Moreland6c7d2142020-01-30 14:39:17 -080022#include "BufferedTextOutput.h"
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/IPCThreadState.h>
Mathias Agopian208059f2009-05-18 15:08:03 -070024#include <utils/Log.h>
25
26namespace android {
27
Mathias Agopian002e1e52013-05-06 20:20:50 -070028// ------------ Text output streams
29
30Vector<int32_t> gTextBuffers;
31
32class LogTextOutput : public BufferedTextOutput
33{
34public:
35 LogTextOutput() : BufferedTextOutput(MULTITHREADED) { }
Jooyung Hanc91e3cb2020-11-25 06:38:17 +090036 virtual ~LogTextOutput() { }
Mathias Agopian002e1e52013-05-06 20:20:50 -070037
38protected:
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
48class FdTextOutput : public BufferedTextOutput
49{
50public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070051 explicit FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { }
Jooyung Hanc91e3cb2020-11-25 06:38:17 +090052 virtual ~FdTextOutput() { }
Mathias Agopian002e1e52013-05-06 20:20:50 -070053
54protected:
55 virtual status_t writeLines(const struct iovec& vec, size_t N)
56 {
Steven Moreland28723ae2019-04-01 18:52:30 -070057 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 Agopian002e1e52013-05-06 20:20:50 -070060 return NO_ERROR;
61 }
62
63private:
64 int mFD;
65};
66
Steven Moreland7c0edeb2020-02-18 16:41:21 -080067TextOutput& alog(*new LogTextOutput());
68TextOutput& aout(*new FdTextOutput(STDOUT_FILENO));
69TextOutput& aerr(*new FdTextOutput(STDERR_FILENO));
Mathias Agopian002e1e52013-05-06 20:20:50 -070070
Mathias Agopian208059f2009-05-18 15:08:03 -070071} // namespace android