Home | History | Annotate | Download | only in binder
      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/binder/Static.h>
     21 
     22 #include <binder/BufferedTextOutput.h>
     23 #include <binder/IPCThreadState.h>
     24 #include <utils/Log.h>
     25 
     26 namespace android {
     27 
     28 // ------------ Text output streams
     29 
     30 Vector<int32_t> gTextBuffers;
     31 
     32 class LogTextOutput : public BufferedTextOutput
     33 {
     34 public:
     35     LogTextOutput() : BufferedTextOutput(MULTITHREADED) { }
     36     virtual ~LogTextOutput() { };
     37 
     38 protected:
     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 
     48 class FdTextOutput : public BufferedTextOutput
     49 {
     50 public:
     51     explicit FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { }
     52     virtual ~FdTextOutput() { };
     53 
     54 protected:
     55     virtual status_t writeLines(const struct iovec& vec, size_t N)
     56     {
     57         writev(mFD, &vec, N);
     58         return NO_ERROR;
     59     }
     60 
     61 private:
     62     int mFD;
     63 };
     64 
     65 static LogTextOutput gLogTextOutput;
     66 static FdTextOutput gStdoutTextOutput(STDOUT_FILENO);
     67 static FdTextOutput gStderrTextOutput(STDERR_FILENO);
     68 
     69 TextOutput& alog(gLogTextOutput);
     70 TextOutput& aout(gStdoutTextOutput);
     71 TextOutput& aerr(gStderrTextOutput);
     72 
     73 // ------------ ProcessState.cpp
     74 
     75 Mutex& gProcessMutex = *new Mutex;
     76 sp<ProcessState> gProcess;
     77 
     78 class LibBinderIPCtStatics
     79 {
     80 public:
     81     LibBinderIPCtStatics()
     82     {
     83     }
     84 
     85     ~LibBinderIPCtStatics()
     86     {
     87         IPCThreadState::shutdown();
     88     }
     89 };
     90 
     91 static LibBinderIPCtStatics gIPCStatics;
     92 
     93 // ------------ IServiceManager.cpp
     94 
     95 Mutex gDefaultServiceManagerLock;
     96 sp<IServiceManager> gDefaultServiceManager;
     97 #ifndef __ANDROID_VNDK__
     98 sp<IPermissionController> gPermissionController;
     99 #endif
    100 bool gSystemBootCompleted = false;
    101 
    102 }   // namespace android
    103