00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MULTIPLEXSTREAMBUF_H
00020 #define MULTIPLEXSTREAMBUF_H
00021
00022 #include <pandabase.h>
00023
00024 #ifdef OLD_HAVE_IPC
00025 #include <ipc_mutex.h>
00026 #endif
00027
00028 #include "pvector.h"
00029 #include <stdio.h>
00030
00031
00032
00033
00034
00035
00036
00037 class EXPCL_PANDAEXPRESS MultiplexStreamBuf : public streambuf {
00038 public:
00039 MultiplexStreamBuf();
00040 virtual ~MultiplexStreamBuf();
00041
00042 enum BufferType {
00043 BT_none,
00044 BT_line,
00045 };
00046
00047 enum OutputType {
00048 OT_ostream,
00049 OT_stdio,
00050 OT_system_debug,
00051 };
00052
00053 void add_output(BufferType buffer_type, OutputType output_type,
00054 ostream *out = (ostream *)NULL,
00055 FILE *fout = (FILE *)NULL,
00056 bool owns_obj = false);
00057
00058 void flush();
00059
00060 protected:
00061 virtual int overflow(int c);
00062 virtual int sync();
00063
00064 private:
00065 void write_chars(const char *start, int length, bool flush);
00066
00067
00068 class Output {
00069 public:
00070 void close();
00071 void write_string(const string &str);
00072
00073 BufferType _buffer_type;
00074 OutputType _output_type;
00075 ostream *_out;
00076 FILE *_fout;
00077 bool _owns_obj;
00078 };
00079
00080 typedef pvector<Output> Outputs;
00081 Outputs _outputs;
00082
00083 string _line_buffer;
00084
00085 #ifdef OLD_HAVE_IPC
00086 mutex _lock;
00087 #endif
00088 };
00089
00090 #include "multiplexStreamBuf.I"
00091
00092 #endif