From: Erik Hofman Date: Wed, 20 Jul 2016 13:01:30 +0000 (+0200) Subject: Add support for SG_POPUP messages which show a dialog at startup X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=95dcf51e9b9fac055ee3c9fe0ac91b9a8f1fffa6;p=simgear.git Add support for SG_POPUP messages which show a dialog at startup --- diff --git a/simgear/debug/debug_types.h b/simgear/debug/debug_types.h index ea666c86..ed5ee894 100644 --- a/simgear/debug/debug_types.h +++ b/simgear/debug/debug_types.h @@ -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; diff --git a/simgear/debug/logstream.cxx b/simgear/debug/logstream.cxx index 70f1fc42..453ad067 100644 --- a/simgear/debug/logstream.cxx +++ b/simgear/debug/logstream.cxx @@ -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 { diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index d4855756..4e2771b9 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -29,6 +29,7 @@ #include #include +#include // 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 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__)