1 /** \file BufferedLogCallback.hxx
2 * Buffer certain log messages permanently for later retrieval and display
5 // Copyright (C) 2013 James Turner zakalawe@mac.com
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef SG_DEBUG_BUFFEREDLOGCALLBACK_HXX
24 #define SG_DEBUG_BUFFEREDLOGCALLBACK_HXX
27 #include <memory> // for std::auto_ptr
29 #include <simgear/debug/logstream.hxx>
34 class BufferedLogCallback : public LogCallback
37 BufferedLogCallback(sgDebugClass c, sgDebugPriority p);
38 virtual ~BufferedLogCallback();
40 /// truncate messages longer than a certain length. This is to work-around
41 /// for broken PUI behaviour, it can be removed once PUI is gone.
42 void truncateAt(unsigned int);
44 virtual void operator()(sgDebugClass c, sgDebugPriority p,
45 const char* file, int line, const std::string& aMessage);
48 * read the stamp value associated with the log buffer. This is
49 * incremented whenever the log contents change, so can be used
50 * to poll for changes.
52 unsigned int stamp() const;
55 * copying a (large) vector of std::string would be very expensive.
56 * once logged, this call retains storage of the underlying string data,
57 * so when copying, it's sufficient to pass around the strings as raw
58 * char arrays. This means we're only copying a vector of pointers,
59 * which is very efficient.
61 typedef std::vector<unsigned char*> vector_cstring;
64 * copy the buffered log data into the provided output list
65 * (which will be cleared first). This method is safe to call from
68 * returns the stamp value of the copied data
70 unsigned int threadsafeCopy(vector_cstring& aOutput);
72 class BufferedLogCallbackPrivate;
73 std::auto_ptr<BufferedLogCallbackPrivate> d;
77 } // of namespace simgear
79 #endif // of SG_DEBUG_BUFFEREDLOGCALLBACK_HXX