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