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;
logstream::~logstream()
{
+ popup_msgs.clear();
global_privateLogstream->stop();
delete global_privateLogstream;
}
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
{
#include <simgear/debug/debug_types.h>
#include <sstream>
+#include <vector>
// forward decls
class SGPath;
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.
private:
// constructor
logstream();
+
+ std::vector<std::string> popup_msgs;
};
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__)