blob: 93f7e4f0c4769aca7a1ec995b20ae284b6ced8f7 [file] [log] [blame]
The Android Open Source Projectcbb10112009-03-03 19:31:44 -08001/*
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/utils/Static.h>
21
22#include <utils/BufferedTextOutput.h>
23#include <utils/IPCThreadState.h>
24#include <utils/Log.h>
25
26namespace android {
27
28class LibUtilsFirstStatics
29{
30public:
31 LibUtilsFirstStatics()
32 {
33 initialize_string8();
34 initialize_string16();
35 }
36
37 ~LibUtilsFirstStatics()
38 {
39 terminate_string16();
40 terminate_string8();
41 }
42};
43
44static LibUtilsFirstStatics gFirstStatics;
45int gDarwinCantLoadAllObjects = 1;
46
47// ------------ Text output streams
48
49Vector<int32_t> gTextBuffers;
50
51class LogTextOutput : public BufferedTextOutput
52{
53public:
54 LogTextOutput() : BufferedTextOutput(MULTITHREADED) { }
55 virtual ~LogTextOutput() { };
56
57protected:
58 virtual status_t writeLines(const struct iovec& vec, size_t N)
59 {
60 android_writevLog(&vec, N);
61 return NO_ERROR;
62 }
63};
64
65class FdTextOutput : public BufferedTextOutput
66{
67public:
68 FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { }
69 virtual ~FdTextOutput() { };
70
71protected:
72 virtual status_t writeLines(const struct iovec& vec, size_t N)
73 {
74 writev(mFD, &vec, N);
75 return NO_ERROR;
76 }
77
78private:
79 int mFD;
80};
81
82static LogTextOutput gLogTextOutput;
83static FdTextOutput gStdoutTextOutput(STDOUT_FILENO);
84static FdTextOutput gStderrTextOutput(STDERR_FILENO);
85
86TextOutput& alog(gLogTextOutput);
87TextOutput& aout(gStdoutTextOutput);
88TextOutput& aerr(gStderrTextOutput);
89
90#ifndef LIBUTILS_NATIVE
91
92// ------------ ProcessState.cpp
93
94Mutex gProcessMutex;
95sp<ProcessState> gProcess;
96
97class LibUtilsIPCtStatics
98{
99public:
100 LibUtilsIPCtStatics()
101 {
102 }
103
104 ~LibUtilsIPCtStatics()
105 {
106 IPCThreadState::shutdown();
107 }
108};
109
110static LibUtilsIPCtStatics gIPCStatics;
111
112// ------------ ServiceManager.cpp
113
114Mutex gDefaultServiceManagerLock;
115sp<IServiceManager> gDefaultServiceManager;
116sp<IPermissionController> gPermissionController;
117
118#endif
119
120} // namespace android