blob: 7a77f6de54152d014f508302a60e9b279255047b [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) { }
36 virtual ~LogTextOutput() { };
37
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) { }
Mathias Agopian002e1e52013-05-06 20:20:50 -070052 virtual ~FdTextOutput() { };
53
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
67static LogTextOutput gLogTextOutput;
68static FdTextOutput gStdoutTextOutput(STDOUT_FILENO);
69static FdTextOutput gStderrTextOutput(STDERR_FILENO);
70
71TextOutput& alog(gLogTextOutput);
72TextOutput& aout(gStdoutTextOutput);
73TextOutput& aerr(gStderrTextOutput);
74
Mathias Agopian208059f2009-05-18 15:08:03 -070075// ------------ ProcessState.cpp
76
Yabin Cuic39caf32018-06-05 14:34:36 -070077Mutex& gProcessMutex = *new Mutex;
Mathias Agopian208059f2009-05-18 15:08:03 -070078sp<ProcessState> gProcess;
79
Mathias Agopian208059f2009-05-18 15:08:03 -070080} // namespace android