Static.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <hwbinder/Static.h>
  19. #include <hwbinder/BufferedTextOutput.h>
  20. #include <hwbinder/IPCThreadState.h>
  21. #include <utils/Log.h>
  22. namespace android {
  23. namespace hardware {
  24. // ------------ Text output streams
  25. Vector<int32_t> gTextBuffers;
  26. class LogTextOutput : public BufferedTextOutput
  27. {
  28. public:
  29. LogTextOutput() : BufferedTextOutput(MULTITHREADED) { }
  30. virtual ~LogTextOutput() { };
  31. protected:
  32. virtual status_t writeLines(const struct iovec& vec, size_t N)
  33. {
  34. //android_writevLog(&vec, N); <-- this is now a no-op
  35. if (N != 1) ALOGI("WARNING: writeLines N=%zu\n", N);
  36. ALOGI("%.*s", (int)vec.iov_len, (const char*) vec.iov_base);
  37. return NO_ERROR;
  38. }
  39. };
  40. class FdTextOutput : public BufferedTextOutput
  41. {
  42. public:
  43. explicit FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { }
  44. virtual ~FdTextOutput() { };
  45. protected:
  46. virtual status_t writeLines(const struct iovec& vec, size_t N)
  47. {
  48. writev(mFD, &vec, N);
  49. return NO_ERROR;
  50. }
  51. private:
  52. int mFD;
  53. };
  54. static LogTextOutput gLogTextOutput;
  55. static FdTextOutput gStdoutTextOutput(STDOUT_FILENO);
  56. static FdTextOutput gStderrTextOutput(STDERR_FILENO);
  57. TextOutput& alog(gLogTextOutput);
  58. TextOutput& aout(gStdoutTextOutput);
  59. TextOutput& aerr(gStderrTextOutput);
  60. // ------------ ProcessState.cpp
  61. Mutex& gProcessMutex = *new Mutex;
  62. sp<ProcessState> gProcess;
  63. } // namespace hardware
  64. } // namespace android