]> git.mxchange.org Git - simgear.git/blob - simgear/debug/BufferedLogCallback.hxx
Merge branch 'next' of git.mxchange.org:/var/cache/git/repos/simgear into next
[simgear.git] / simgear / debug / BufferedLogCallback.hxx
1 /** \file BufferedLogCallback.hxx
2  * Buffer certain log messages permanently for later retrieval and display
3  */
4
5 // Copyright (C) 2013  James Turner  zakalawe@mac.com
6 //
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.
11 //
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.
16 //
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.
20 //
21      
22      
23 #ifndef SG_DEBUG_BUFFEREDLOGCALLBACK_HXX
24 #define SG_DEBUG_BUFFEREDLOGCALLBACK_HXX
25
26 #include <vector>
27 #include <memory> // for std::auto_ptr
28
29 #include <simgear/debug/logstream.hxx>
30
31 namespace simgear
32 {
33
34 class BufferedLogCallback : public LogCallback
35 {
36 public:
37     BufferedLogCallback(sgDebugClass c, sgDebugPriority p);
38     virtual ~BufferedLogCallback();
39     
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);
43     
44     virtual void operator()(sgDebugClass c, sgDebugPriority p, 
45         const char* file, int line, const std::string& aMessage);
46     
47     /**
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.
51      */
52     unsigned int stamp() const;
53     
54     /**
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.
60     */
61     typedef std::vector<unsigned char*> vector_cstring;
62      
63     /**
64      * copy the buffered log data into the provided output list
65      * (which will be cleared first). This method is safe to call from
66      * any thread.
67      *
68      * returns the stamp value of the copied data
69      */
70     unsigned int threadsafeCopy(vector_cstring& aOutput);
71 private:
72     class BufferedLogCallbackPrivate;
73     std::auto_ptr<BufferedLogCallbackPrivate> d;
74 };
75      
76
77 } // of namespace simgear
78
79 #endif // of SG_DEBUG_BUFFEREDLOGCALLBACK_HXX