| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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_BUFFEREDTEXTOUTPUT_H | 
|  | 18 | #define ANDROID_BUFFEREDTEXTOUTPUT_H | 
|  | 19 |  | 
| Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 20 | #include <binder/TextOutput.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/threads.h> | 
| Colin Cross | f5f8fa0 | 2013-07-23 14:52:34 -0700 | [diff] [blame] | 22 | #include <sys/uio.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 |  | 
|  | 24 | // --------------------------------------------------------------------------- | 
|  | 25 | namespace android { | 
|  | 26 |  | 
|  | 27 | class BufferedTextOutput : public TextOutput | 
|  | 28 | { | 
|  | 29 | public: | 
|  | 30 | //** Flags for constructor */ | 
|  | 31 | enum { | 
|  | 32 | MULTITHREADED = 0x0001 | 
|  | 33 | }; | 
|  | 34 |  | 
|  | 35 | BufferedTextOutput(uint32_t flags = 0); | 
|  | 36 | virtual             ~BufferedTextOutput(); | 
|  | 37 |  | 
|  | 38 | virtual status_t    print(const char* txt, size_t len); | 
|  | 39 | virtual void        moveIndent(int delta); | 
|  | 40 |  | 
|  | 41 | virtual void        pushBundle(); | 
|  | 42 | virtual void        popBundle(); | 
|  | 43 |  | 
|  | 44 | protected: | 
|  | 45 | virtual status_t    writeLines(const struct iovec& vec, size_t N) = 0; | 
|  | 46 |  | 
|  | 47 | private: | 
|  | 48 | struct BufferState; | 
|  | 49 | struct ThreadState; | 
|  | 50 |  | 
|  | 51 | static  ThreadState*getThreadState(); | 
|  | 52 | static  void        threadDestructor(void *st); | 
|  | 53 |  | 
|  | 54 | BufferState*getBuffer() const; | 
|  | 55 |  | 
|  | 56 | uint32_t            mFlags; | 
|  | 57 | const int32_t       mSeq; | 
|  | 58 | const int32_t       mIndex; | 
|  | 59 |  | 
|  | 60 | Mutex               mLock; | 
|  | 61 | BufferState*        mGlobalState; | 
|  | 62 | }; | 
|  | 63 |  | 
|  | 64 | // --------------------------------------------------------------------------- | 
|  | 65 | }; // namespace android | 
|  | 66 |  | 
|  | 67 | #endif // ANDROID_BUFFEREDTEXTOUTPUT_H |