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