blob: a84f811f1f44c0e0b07afc1b43288dc80dec3b79 [file] [log] [blame]
Mathias Agopian7922fa22009-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
Martijn Coenene01f4f22016-05-12 12:33:28 +020020#include <hwbinder/Static.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070021
Martijn Coenen4080edc2016-05-04 14:17:02 +020022#include <hwbinder/BufferedTextOutput.h>
23#include <hwbinder/IPCThreadState.h>
Mathias Agopian7922fa22009-05-18 15:08:03 -070024#include <utils/Log.h>
25
26namespace android {
Martijn Coenenf75a23d2016-08-01 11:55:17 +020027namespace hardware {
Mathias Agopian7922fa22009-05-18 15:08:03 -070028
Mathias Agopian4ea13dc2013-05-06 20:20:50 -070029// ------------ Text output streams
30
31Vector<int32_t> gTextBuffers;
32
33class LogTextOutput : public BufferedTextOutput
34{
35public:
36 LogTextOutput() : BufferedTextOutput(MULTITHREADED) { }
37 virtual ~LogTextOutput() { };
38
39protected:
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
49class FdTextOutput : public BufferedTextOutput
50{
51public:
Chih-Hung Hsieh1f555e92016-04-25 15:41:05 -070052 explicit FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { }
Mathias Agopian4ea13dc2013-05-06 20:20:50 -070053 virtual ~FdTextOutput() { };
54
55protected:
56 virtual status_t writeLines(const struct iovec& vec, size_t N)
57 {
58 writev(mFD, &vec, N);
59 return NO_ERROR;
60 }
61
62private:
63 int mFD;
64};
65
66static LogTextOutput gLogTextOutput;
67static FdTextOutput gStdoutTextOutput(STDOUT_FILENO);
68static FdTextOutput gStderrTextOutput(STDERR_FILENO);
69
70TextOutput& alog(gLogTextOutput);
71TextOutput& aout(gStdoutTextOutput);
72TextOutput& aerr(gStderrTextOutput);
73
Mathias Agopian7922fa22009-05-18 15:08:03 -070074// ------------ ProcessState.cpp
75
Yabin Cui0695b992018-06-05 15:36:42 -070076Mutex& gProcessMutex = *new Mutex;
Mathias Agopian7922fa22009-05-18 15:08:03 -070077sp<ProcessState> gProcess;
78
Steven Moreland7c2fb2f2017-03-12 21:04:31 -070079class LibHwbinderIPCtStatics
Mathias Agopian7922fa22009-05-18 15:08:03 -070080{
81public:
Steven Moreland7c2fb2f2017-03-12 21:04:31 -070082 LibHwbinderIPCtStatics()
Mathias Agopian7922fa22009-05-18 15:08:03 -070083 {
84 }
85
Steven Moreland7c2fb2f2017-03-12 21:04:31 -070086 ~LibHwbinderIPCtStatics()
Mathias Agopian7922fa22009-05-18 15:08:03 -070087 {
88 IPCThreadState::shutdown();
89 }
90};
91
Steven Moreland7c2fb2f2017-03-12 21:04:31 -070092static LibHwbinderIPCtStatics gIPCStatics;
Mathias Agopian7922fa22009-05-18 15:08:03 -070093
Martijn Coenenf75a23d2016-08-01 11:55:17 +020094} // namespace hardware
Mathias Agopian7922fa22009-05-18 15:08:03 -070095} // namespace android