From d5eca5fa6fcfab0ffa96fcf0d82f46559cbb60c2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 5 Dec 2000 02:54:48 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/egg/eggTexture.h | 2 +- panda/src/express/multiplexStream.I | 20 ++++++++++-- panda/src/express/multiplexStream.h | 3 ++ panda/src/express/multiplexStreamBuf.I | 5 +-- panda/src/express/multiplexStreamBuf.cxx | 40 ++++++++++++++++++++++++ panda/src/express/multiplexStreamBuf.h | 9 ++++-- panda/src/framework/framework.cxx | 18 +++++++++++ 7 files changed, 89 insertions(+), 8 deletions(-) diff --git a/panda/src/egg/eggTexture.h b/panda/src/egg/eggTexture.h index 412e50b776..990072bd15 100644 --- a/panda/src/egg/eggTexture.h +++ b/panda/src/egg/eggTexture.h @@ -187,7 +187,7 @@ public: }; INLINE ostream &operator << (ostream &out, const EggTexture &n) { - return out << (Filename &)n; + return out << n.get_filename(); } ostream EXPCL_PANDAEGG &operator << (ostream &out, EggTexture::Format format); diff --git a/panda/src/express/multiplexStream.I b/panda/src/express/multiplexStream.I index 72de480a77..0986a50507 100644 --- a/panda/src/express/multiplexStream.I +++ b/panda/src/express/multiplexStream.I @@ -24,7 +24,21 @@ INLINE void MultiplexStream:: add_ostream(ostream *out, bool delete_later) { _msb.add_output(MultiplexStreamBuf::BT_none, MultiplexStreamBuf::OT_ostream, - out, delete_later); + out, NULL, delete_later); +} + +//////////////////////////////////////////////////////////////////// +// Function: MultiplexStream::add_stdio_file +// Access: Public +// Description: Adds the given file, previously opened using the C +// stdio library, to the multiplex output. +//////////////////////////////////////////////////////////////////// +INLINE bool MultiplexStream:: +add_stdio_file(FILE *fout, bool close_when_done) { + _msb.add_output(MultiplexStreamBuf::BT_line, + MultiplexStreamBuf::OT_ostream, + NULL, fout, close_when_done); + return true; } //////////////////////////////////////////////////////////////////// @@ -36,7 +50,7 @@ INLINE void MultiplexStream:: add_standard_output() { _msb.add_output(MultiplexStreamBuf::BT_none, MultiplexStreamBuf::OT_ostream, - &cout, false); + &cout, NULL, false); } //////////////////////////////////////////////////////////////////// @@ -58,7 +72,7 @@ add_file(Filename file) { _msb.add_output(MultiplexStreamBuf::BT_line, MultiplexStreamBuf::OT_ostream, - out, true); + out, NULL, true); return true; } diff --git a/panda/src/express/multiplexStream.h b/panda/src/express/multiplexStream.h index 5f2c21a6be..e355f47693 100644 --- a/panda/src/express/multiplexStream.h +++ b/panda/src/express/multiplexStream.h @@ -12,6 +12,8 @@ #include +#include + //////////////////////////////////////////////////////////////////// // Class : MultiplexStream // Description : This is a special ostream that forwards the data that @@ -26,6 +28,7 @@ PUBLISHED: INLINE MultiplexStream(); INLINE void add_ostream(ostream *out, bool delete_later = false); + INLINE bool add_stdio_file(FILE *file, bool close_when_done); INLINE void add_standard_output(); INLINE bool add_file(Filename file); INLINE void add_system_debug(); diff --git a/panda/src/express/multiplexStreamBuf.I b/panda/src/express/multiplexStreamBuf.I index 7fa8fdceac..65f3466d55 100644 --- a/panda/src/express/multiplexStreamBuf.I +++ b/panda/src/express/multiplexStreamBuf.I @@ -14,12 +14,13 @@ INLINE void MultiplexStreamBuf:: add_output(MultiplexStreamBuf::BufferType buffer_type, MultiplexStreamBuf::OutputType output_type, - ostream *out, bool owns_ostream) { + ostream *out, FILE *fout, bool owns_obj) { Output o; o._buffer_type = buffer_type; o._output_type = output_type; o._out = out; - o._owns_ostream = owns_ostream; + o._fout = fout; + o._owns_obj = owns_obj; _outputs.push_back(o); } diff --git a/panda/src/express/multiplexStreamBuf.cxx b/panda/src/express/multiplexStreamBuf.cxx index 7fa9556087..b7f54b68d1 100644 --- a/panda/src/express/multiplexStreamBuf.cxx +++ b/panda/src/express/multiplexStreamBuf.cxx @@ -21,6 +21,32 @@ typedef int streamsize; #endif +//////////////////////////////////////////////////////////////////// +// Function: MultiplexStreamBuf::Output::close +// Access: Public +// Description: Closes or deletes the relevant pointers, if _owns_obj +// is true. +//////////////////////////////////////////////////////////////////// +void MultiplexStreamBuf::Output:: +close() { + if (_owns_obj) { + switch (_output_type) { + case OT_ostream: + assert(_out != (ostream *)NULL); + delete _out; + break; + + case OT_stdio: + assert(_fout != (FILE *)NULL); + fclose(_fout); + break; + + default: + break; + } + } +} + //////////////////////////////////////////////////////////////////// // Function: MultiplexStreamBuf::Output::write_string // Access: Public @@ -32,6 +58,13 @@ write_string(const string &str) { case OT_ostream: assert(_out != (ostream *)NULL); _out->write(str.data(), str.length()); + _out->flush(); + break; + + case OT_stdio: + assert(_fout != (FILE *)NULL); + fwrite(str.data(), str.length(), 1, _fout); + fflush(_fout); break; case OT_system_debug: @@ -65,6 +98,13 @@ MultiplexStreamBuf() { MultiplexStreamBuf:: ~MultiplexStreamBuf() { sync(); + + // Make sure all of our owned pointers are freed. + Outputs::iterator oi; + for (oi = _outputs.begin(); oi != _outputs.end(); ++oi) { + Output &out = (*oi); + out.close(); + } } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/express/multiplexStreamBuf.h b/panda/src/express/multiplexStreamBuf.h index 5b97a17461..d67e14119a 100644 --- a/panda/src/express/multiplexStreamBuf.h +++ b/panda/src/express/multiplexStreamBuf.h @@ -9,6 +9,7 @@ #include #include +#include //////////////////////////////////////////////////////////////////// // Class : MultiplexStreamBuf @@ -28,12 +29,14 @@ public: enum OutputType { OT_ostream, + OT_stdio, OT_system_debug, }; INLINE void add_output(BufferType buffer_type, OutputType output_type, ostream *out = (ostream *)NULL, - bool owns_ostream = false); + FILE *fout = (FILE *)NULL, + bool owns_obj = false); INLINE void flush(); @@ -47,12 +50,14 @@ private: class Output { public: + void close(); void write_string(const string &str); BufferType _buffer_type; OutputType _output_type; ostream *_out; - bool _owns_ostream; + FILE *_fout; + bool _owns_obj; }; typedef vector Outputs; diff --git a/panda/src/framework/framework.cxx b/panda/src/framework/framework.cxx index f73a06b0b0..984f25f447 100644 --- a/panda/src/framework/framework.cxx +++ b/panda/src/framework/framework.cxx @@ -85,6 +85,7 @@ #include #include #include +#include #ifdef USE_IPC #include @@ -875,6 +876,23 @@ void event_x(CPT_Event) { int framework_main(int argc, char *argv[]) { pystub(); + // The first thing we should do is to set up a multiplexing Notify. + MultiplexStream *mstream = new MultiplexStream; + Notify::ptr()->set_ostream_ptr(mstream, true); + mstream->add_standard_output(); + mstream->add_system_debug(); + + string framework_notify_output = framework.GetString("framework-notify-output", ""); + if (!framework_notify_output.empty()) { + if (!mstream->add_file(framework_notify_output)) { + framework_cat.error() + << "Unable to open " << framework_notify_output << " for output.\n"; + } else { + framework_cat.info() + << "Sending Notify output to " << framework_notify_output << "\n"; + } + } + GeomNorms::init_type(); #ifndef DEBUG