Static.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // All static variables go here, to control initialization and
  17. // destruction order in the library.
  18. #include <private/binder/Static.h>
  19. #include <binder/BufferedTextOutput.h>
  20. #include <binder/IPCThreadState.h>
  21. #include <utils/Log.h>
  22. namespace android {
  23. // ------------ Text output streams
  24. Vector<int32_t> gTextBuffers;
  25. class LogTextOutput : public BufferedTextOutput
  26. {
  27. public:
  28. LogTextOutput() : BufferedTextOutput(MULTITHREADED) { }
  29. virtual ~LogTextOutput() { };
  30. protected:
  31. virtual status_t writeLines(const struct iovec& vec, size_t N)
  32. {
  33. //android_writevLog(&vec, N); <-- this is now a no-op
  34. if (N != 1) ALOGI("WARNING: writeLines N=%zu\n", N);
  35. ALOGI("%.*s", (int)vec.iov_len, (const char*) vec.iov_base);
  36. return NO_ERROR;
  37. }
  38. };
  39. class FdTextOutput : public BufferedTextOutput
  40. {
  41. public:
  42. FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { }
  43. virtual ~FdTextOutput() { };
  44. protected:
  45. virtual status_t writeLines(const struct iovec& vec, size_t N)
  46. {
  47. writev(mFD, &vec, N);
  48. return NO_ERROR;
  49. }
  50. private:
  51. int mFD;
  52. };
  53. static LogTextOutput gLogTextOutput;
  54. static FdTextOutput gStdoutTextOutput(STDOUT_FILENO);
  55. static FdTextOutput gStderrTextOutput(STDERR_FILENO);
  56. TextOutput& alog(gLogTextOutput);
  57. TextOutput& aout(gStdoutTextOutput);
  58. TextOutput& aerr(gStderrTextOutput);
  59. // ------------ ProcessState.cpp
  60. Mutex gProcessMutex;
  61. sp<ProcessState> gProcess;
  62. class LibBinderIPCtStatics
  63. {
  64. public:
  65. LibBinderIPCtStatics()
  66. {
  67. }
  68. ~LibBinderIPCtStatics()
  69. {
  70. IPCThreadState::shutdown();
  71. }
  72. };
  73. static LibBinderIPCtStatics gIPCStatics;
  74. // ------------ IServiceManager.cpp
  75. Mutex gDefaultServiceManagerLock;
  76. sp<IServiceManager> gDefaultServiceManager;
  77. sp<IPermissionController> gPermissionController;
  78. } // namespace android