blob: b870c342d7feeb19cb70cb1cc90d1fc9e77fc9eb [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
20#include <private/binder/Static.h>
21
Mathias Agopian002e1e52013-05-06 20:20:50 -070022#include <binder/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:
51 FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { }
52 virtual ~FdTextOutput() { };
53
54protected:
55 virtual status_t writeLines(const struct iovec& vec, size_t N)
56 {
57 writev(mFD, &vec, N);
58 return NO_ERROR;
59 }
60
61private:
62 int mFD;
63};
64
65static LogTextOutput gLogTextOutput;
66static FdTextOutput gStdoutTextOutput(STDOUT_FILENO);
67static FdTextOutput gStderrTextOutput(STDERR_FILENO);
68
69TextOutput& alog(gLogTextOutput);
70TextOutput& aout(gStdoutTextOutput);
71TextOutput& aerr(gStderrTextOutput);
72
Mathias Agopian208059f2009-05-18 15:08:03 -070073// ------------ ProcessState.cpp
74
75Mutex gProcessMutex;
76sp<ProcessState> gProcess;
77
Mathias Agopian002e1e52013-05-06 20:20:50 -070078class LibBinderIPCtStatics
Mathias Agopian208059f2009-05-18 15:08:03 -070079{
80public:
Mathias Agopian002e1e52013-05-06 20:20:50 -070081 LibBinderIPCtStatics()
Mathias Agopian208059f2009-05-18 15:08:03 -070082 {
83 }
84
Mathias Agopian002e1e52013-05-06 20:20:50 -070085 ~LibBinderIPCtStatics()
Mathias Agopian208059f2009-05-18 15:08:03 -070086 {
87 IPCThreadState::shutdown();
88 }
89};
90
Mathias Agopian002e1e52013-05-06 20:20:50 -070091static LibBinderIPCtStatics gIPCStatics;
Mathias Agopian208059f2009-05-18 15:08:03 -070092
Dianne Hackborn7e790af2014-11-11 12:22:53 -080093// ------------ Parcel.cpp
94
95Mutex gParcelGlobalAllocSizeLock;
96size_t gParcelGlobalAllocSize = 0;
97size_t gParcelGlobalAllocCount = 0;
98
99// ------------ IServiceManager.cpp
Mathias Agopian208059f2009-05-18 15:08:03 -0700100
101Mutex gDefaultServiceManagerLock;
102sp<IServiceManager> gDefaultServiceManager;
103sp<IPermissionController> gPermissionController;
104
105} // namespace android