1 /* 2 * Copyright (C) 2006 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 #ifndef ANDROID_HARDWARE_BUFFEREDTEXTOUTPUT_H 18 #define ANDROID_HARDWARE_BUFFEREDTEXTOUTPUT_H 19 20 #include <hwbinder/TextOutput.h> 21 #include <utils/threads.h> 22 #include <sys/uio.h> 23 24 // --------------------------------------------------------------------------- 25 namespace android { 26 namespace hardware { 27 28 class BufferedTextOutput : public TextOutput 29 { 30 public: 31 //** Flags for constructor */ 32 enum { 33 MULTITHREADED = 0x0001 34 }; 35 36 BufferedTextOutput(uint32_t flags = 0); 37 virtual ~BufferedTextOutput(); 38 39 virtual status_t print(const char* txt, size_t len); 40 virtual void moveIndent(int delta); 41 42 virtual void pushBundle(); 43 virtual void popBundle(); 44 45 protected: 46 virtual status_t writeLines(const struct iovec& vec, size_t N) = 0; 47 48 private: 49 struct BufferState; 50 struct ThreadState; 51 52 static ThreadState*getThreadState(); 53 static void threadDestructor(void *st); 54 55 BufferState*getBuffer() const; 56 57 uint32_t mFlags; 58 const int32_t mSeq; 59 const int32_t mIndex; 60 61 Mutex mLock; 62 BufferState* mGlobalState; 63 }; 64 65 // --------------------------------------------------------------------------- 66 }; // namespace hardware 67 }; // namespace android 68 69 #endif // ANDROID_HARDWARE_BUFFEREDTEXTOUTPUT_H 70