]> git.mxchange.org Git - simgear.git/commitdiff
Add support for SG_POPUP messages which show a dialog at startup
authorErik Hofman <erik@ehofman.com>
Wed, 20 Jul 2016 13:01:30 +0000 (15:01 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 13 Aug 2016 08:21:16 +0000 (10:21 +0200)
simgear/debug/debug_types.h
simgear/debug/logstream.cxx
simgear/debug/logstream.hxx

index ea666c869828c5a0bf49be5b341f541514372a56..ed5ee89472333233fd4bb4594c9938ac55dd4b11 100644 (file)
@@ -48,7 +48,8 @@ typedef enum {
     SG_DEBUG,          // Less frequent debug type messages
     SG_INFO,           // Informatory messages
     SG_WARN,           // Possible impending problem
-    SG_ALERT           // Very possible impending problem
+    SG_ALERT,          // Very possible impending problem
+    SG_POPUP           // Severe enough to alert using a pop-up window
     // SG_EXIT,        // Problem (no core)
     // SG_ABORT        // Abandon ship (core)
 } sgDebugPriority;
index 70f1fc42092bcf24b924339579ec992c6c5d34c8..453ad0670000770d2dadc508312d360aef50d534 100644 (file)
@@ -365,6 +365,7 @@ logstream::logstream()
 
 logstream::~logstream()
 {
+    popup_msgs.clear();
     global_privateLogstream->stop();
     delete global_privateLogstream;
 }
@@ -394,6 +395,30 @@ logstream::log( sgDebugClass c, sgDebugPriority p,
     global_privateLogstream->log(c, p, fileName, line, msg);
 }
 
+void
+logstream::popup( const std::string& msg)
+{
+    popup_msgs.push_back(msg);
+}
+
+std::string
+logstream::get_popup()
+{
+    std::string rv = "";
+    if (!popup_msgs.empty())
+    {
+        rv = popup_msgs.front();
+        popup_msgs.erase(popup_msgs.begin());
+    }
+    return rv;
+}
+
+bool
+logstream::has_popup()
+{
+    return (popup_msgs.size() > 0) ? true : false;
+}
+
 bool
 logstream::would_log( sgDebugClass c, sgDebugPriority p ) const
 {
index d48557565214556de75d60ead4fd4028204b4464..4e2771b9989857923be633eaf92019f3234a0a05 100644 (file)
@@ -29,6 +29,7 @@
 #include <simgear/debug/debug_types.h>
 
 #include <sstream>
+#include <vector>
  
 // forward decls
 class SGPath;
@@ -98,6 +99,23 @@ public:
     void log( sgDebugClass c, sgDebugPriority p,
             const char* fileName, int line, const std::string& msg);
 
+    /**
+     * support for the SG_POPUP logging class
+     * set the content of the popup message
+     */
+    void popup( const std::string& msg);
+
+    /**
+     * retrieve the contents of the popup message and clear it's internal
+     * content. The return value may be an empty string.
+     */
+    std::string get_popup();
+
+    /**
+     * return true if a new popup message is available. false otherwise.
+     */
+    bool has_popup();
+
    /**
     * \relates logstream
     * Return the one and only logstream instance.
@@ -119,6 +137,8 @@ public:
 private:
     // constructor
     logstream();
+
+    std::vector<std::string> popup_msgs;
 };
 
 logstream& sglog();
@@ -131,16 +151,16 @@ logstream& sglog();
  * @param P priority
  * @param M message
  */
+# define SG_LOGX(C,P,M) \
+    do { if(sglog().would_log(C,P)) {                         \
+        std::ostringstream os; os << M;                  \
+        sglog().log(C, P, __FILE__, __LINE__, os.str()); \
+        if (P == SG_POPUP) sglog().popup(os.str());      \
+    } } while(0)
 #ifdef FG_NDEBUG
-# define SG_LOG(C,P,M)
+# define SG_LOG(C,P,M) do { if(P == SG_POPUP) SG_LOGX(C,P,M) } while(0)
 #else
-# define SG_LOG(C,P,M) do {                     \
-       if(sglog().would_log(C,P)) {                      \
-        std::ostringstream os;                             \
-        os << M;                                       \
-        sglog().log(C, P, __FILE__, __LINE__, os.str()); \
-    } \
-} while(0)
+# define SG_LOG(C,P,M) SG_LOGX(C,P,M)
 #endif
 
 #define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)