OpenSceneGraph/include/osg/Notify

144 lines
5.1 KiB
Plaintext
Raw Normal View History

2006-07-18 23:21:48 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_NOTIFY_H
#define OSG_NOTIFY_H 1
2001-01-11 00:32:10 +08:00
#include <osg/Export>
From Maciej Krol,"With advent of GUI applications in OSG there is a growing need to redirect notification messages to third party systems. For example windows applications do not have console output, it would be appropriate to redirect notifications to GUI widget or debug output. I have revamped notification system to fit this need. New notification stream is using NotifyHandler as a message sink. Handler is called whenever stream is synchronized (i.e. after <<std::endl). Standard streams std::cout and std::cerr are no longer used although by default StandardNotifyHandler is a message sink. Custom notification handler can be set with osg::setNotifyHandler(NotifyHandler *) function. Two implementations of NotifyHandler are currently available: - StandardNotifyHandler, calls fputs(message, stderr) for severity <= WARN and fputs(message, stdout) for severity > WARN - WinDebugNotifyHandler, windows users can redirect notifications to windows debug output, notifications can be viewed in output window of the debugger i.e. MSVC or DebugView (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) (see screenshot). I have seen on osg-users that some people do std::cerr.rdbuf(otherStream.rdbuf()) to redirect notifications. This trick will no longer work since osg::notify() returns internal osg::NotifyStream not std::cout or std::cerr. You can use osg::notify().rdbuf(otherStream.rdbuf()) to do this instead. Additionally I've made some minor fixes: - Minor imrovements to osg::notify documentation - NullStream could crash by deleting stream buffer other than default NullStreamBuffer in the destructor i.e. after osg::notify(osg::DEBUG_FP).rdbuf(otherStream.rdbuf())"
2009-05-18 20:04:07 +08:00
#include <osg/Referenced> // for NotifyHandler
2001-01-11 00:32:10 +08:00
#include <ostream>
2001-01-11 00:32:10 +08:00
namespace osg {
/** Range of notify levels from DEBUG_FP through to FATAL, ALWAYS
* is reserved for forcing the absorption of all messages. The
* keywords are also used verbatim when specified by the environmental
From Maciej Krol,"With advent of GUI applications in OSG there is a growing need to redirect notification messages to third party systems. For example windows applications do not have console output, it would be appropriate to redirect notifications to GUI widget or debug output. I have revamped notification system to fit this need. New notification stream is using NotifyHandler as a message sink. Handler is called whenever stream is synchronized (i.e. after <<std::endl). Standard streams std::cout and std::cerr are no longer used although by default StandardNotifyHandler is a message sink. Custom notification handler can be set with osg::setNotifyHandler(NotifyHandler *) function. Two implementations of NotifyHandler are currently available: - StandardNotifyHandler, calls fputs(message, stderr) for severity <= WARN and fputs(message, stdout) for severity > WARN - WinDebugNotifyHandler, windows users can redirect notifications to windows debug output, notifications can be viewed in output window of the debugger i.e. MSVC or DebugView (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) (see screenshot). I have seen on osg-users that some people do std::cerr.rdbuf(otherStream.rdbuf()) to redirect notifications. This trick will no longer work since osg::notify() returns internal osg::NotifyStream not std::cout or std::cerr. You can use osg::notify().rdbuf(otherStream.rdbuf()) to do this instead. Additionally I've made some minor fixes: - Minor imrovements to osg::notify documentation - NullStream could crash by deleting stream buffer other than default NullStreamBuffer in the destructor i.e. after osg::notify(osg::DEBUG_FP).rdbuf(otherStream.rdbuf())"
2009-05-18 20:04:07 +08:00
* variable OSGNOTIFYLEVEL or OSG_NOTIFY_LEVEL.
* See documentation on osg::notify() for further details.
*/
2001-01-11 00:32:10 +08:00
enum NotifySeverity {
ALWAYS=0,
FATAL=1,
WARN=2,
NOTICE=3,
INFO=4,
DEBUG_INFO=5,
DEBUG_FP=6
2001-01-11 00:32:10 +08:00
};
/** set the notify level, overriding the default or the value set by
From Maciej Krol,"With advent of GUI applications in OSG there is a growing need to redirect notification messages to third party systems. For example windows applications do not have console output, it would be appropriate to redirect notifications to GUI widget or debug output. I have revamped notification system to fit this need. New notification stream is using NotifyHandler as a message sink. Handler is called whenever stream is synchronized (i.e. after <<std::endl). Standard streams std::cout and std::cerr are no longer used although by default StandardNotifyHandler is a message sink. Custom notification handler can be set with osg::setNotifyHandler(NotifyHandler *) function. Two implementations of NotifyHandler are currently available: - StandardNotifyHandler, calls fputs(message, stderr) for severity <= WARN and fputs(message, stdout) for severity > WARN - WinDebugNotifyHandler, windows users can redirect notifications to windows debug output, notifications can be viewed in output window of the debugger i.e. MSVC or DebugView (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) (see screenshot). I have seen on osg-users that some people do std::cerr.rdbuf(otherStream.rdbuf()) to redirect notifications. This trick will no longer work since osg::notify() returns internal osg::NotifyStream not std::cout or std::cerr. You can use osg::notify().rdbuf(otherStream.rdbuf()) to do this instead. Additionally I've made some minor fixes: - Minor imrovements to osg::notify documentation - NullStream could crash by deleting stream buffer other than default NullStreamBuffer in the destructor i.e. after osg::notify(osg::DEBUG_FP).rdbuf(otherStream.rdbuf())"
2009-05-18 20:04:07 +08:00
* the environmental variable OSGNOTIFYLEVEL or OSG_NOTIFY_LEVEL.
*/
extern OSG_EXPORT void setNotifyLevel(NotifySeverity severity);
2001-01-11 00:32:10 +08:00
/** get the notify level. */
extern OSG_EXPORT NotifySeverity getNotifyLevel();
2001-01-11 00:32:10 +08:00
/** initialize notify level. */
extern OSG_EXPORT bool initNotifyLevel();
2001-01-11 00:32:10 +08:00
#ifdef OSG_NOTIFY_DISABLED
inline bool isNotifyEnabled(NotifySeverity) { return false; }
#else
/** is notification enabled, given the current setNotifyLevel() setting? */
extern OSG_EXPORT bool isNotifyEnabled(NotifySeverity severity);
#endif
/** notify messaging function for providing fatal through to verbose
* debugging messages. Level of messages sent to the console can
* be controlled by setting the NotifyLevel either within your
From Maciej Krol,"With advent of GUI applications in OSG there is a growing need to redirect notification messages to third party systems. For example windows applications do not have console output, it would be appropriate to redirect notifications to GUI widget or debug output. I have revamped notification system to fit this need. New notification stream is using NotifyHandler as a message sink. Handler is called whenever stream is synchronized (i.e. after <<std::endl). Standard streams std::cout and std::cerr are no longer used although by default StandardNotifyHandler is a message sink. Custom notification handler can be set with osg::setNotifyHandler(NotifyHandler *) function. Two implementations of NotifyHandler are currently available: - StandardNotifyHandler, calls fputs(message, stderr) for severity <= WARN and fputs(message, stdout) for severity > WARN - WinDebugNotifyHandler, windows users can redirect notifications to windows debug output, notifications can be viewed in output window of the debugger i.e. MSVC or DebugView (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) (see screenshot). I have seen on osg-users that some people do std::cerr.rdbuf(otherStream.rdbuf()) to redirect notifications. This trick will no longer work since osg::notify() returns internal osg::NotifyStream not std::cout or std::cerr. You can use osg::notify().rdbuf(otherStream.rdbuf()) to do this instead. Additionally I've made some minor fixes: - Minor imrovements to osg::notify documentation - NullStream could crash by deleting stream buffer other than default NullStreamBuffer in the destructor i.e. after osg::notify(osg::DEBUG_FP).rdbuf(otherStream.rdbuf())"
2009-05-18 20:04:07 +08:00
* application or via the an environmental variable i.e.
* - setenv OSGNOTIFYLEVEL DEBUG (for tsh)
* - export OSGNOTIFYLEVEL=DEBUG (for bourne shell)
* - set OSGNOTIFYLEVEL=DEBUG (for Windows)
*
* All tell the osg to redirect all debugging and more important messages
* to the notification stream (useful for debugging) setting ALWAYS will force
* all messages to be absorbed, which might be appropriate for final
* applications. Default NotifyLevel is NOTICE. Check the enum
From Maciej Krol,"With advent of GUI applications in OSG there is a growing need to redirect notification messages to third party systems. For example windows applications do not have console output, it would be appropriate to redirect notifications to GUI widget or debug output. I have revamped notification system to fit this need. New notification stream is using NotifyHandler as a message sink. Handler is called whenever stream is synchronized (i.e. after <<std::endl). Standard streams std::cout and std::cerr are no longer used although by default StandardNotifyHandler is a message sink. Custom notification handler can be set with osg::setNotifyHandler(NotifyHandler *) function. Two implementations of NotifyHandler are currently available: - StandardNotifyHandler, calls fputs(message, stderr) for severity <= WARN and fputs(message, stdout) for severity > WARN - WinDebugNotifyHandler, windows users can redirect notifications to windows debug output, notifications can be viewed in output window of the debugger i.e. MSVC or DebugView (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) (see screenshot). I have seen on osg-users that some people do std::cerr.rdbuf(otherStream.rdbuf()) to redirect notifications. This trick will no longer work since osg::notify() returns internal osg::NotifyStream not std::cout or std::cerr. You can use osg::notify().rdbuf(otherStream.rdbuf()) to do this instead. Additionally I've made some minor fixes: - Minor imrovements to osg::notify documentation - NullStream could crash by deleting stream buffer other than default NullStreamBuffer in the destructor i.e. after osg::notify(osg::DEBUG_FP).rdbuf(otherStream.rdbuf())"
2009-05-18 20:04:07 +08:00
* #NotifySeverity for full range of possibilities. To use the notify
* with your code simply use the notify function as a normal file
From Maciej Krol,"With advent of GUI applications in OSG there is a growing need to redirect notification messages to third party systems. For example windows applications do not have console output, it would be appropriate to redirect notifications to GUI widget or debug output. I have revamped notification system to fit this need. New notification stream is using NotifyHandler as a message sink. Handler is called whenever stream is synchronized (i.e. after <<std::endl). Standard streams std::cout and std::cerr are no longer used although by default StandardNotifyHandler is a message sink. Custom notification handler can be set with osg::setNotifyHandler(NotifyHandler *) function. Two implementations of NotifyHandler are currently available: - StandardNotifyHandler, calls fputs(message, stderr) for severity <= WARN and fputs(message, stdout) for severity > WARN - WinDebugNotifyHandler, windows users can redirect notifications to windows debug output, notifications can be viewed in output window of the debugger i.e. MSVC or DebugView (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) (see screenshot). I have seen on osg-users that some people do std::cerr.rdbuf(otherStream.rdbuf()) to redirect notifications. This trick will no longer work since osg::notify() returns internal osg::NotifyStream not std::cout or std::cerr. You can use osg::notify().rdbuf(otherStream.rdbuf()) to do this instead. Additionally I've made some minor fixes: - Minor imrovements to osg::notify documentation - NullStream could crash by deleting stream buffer other than default NullStreamBuffer in the destructor i.e. after osg::notify(osg::DEBUG_FP).rdbuf(otherStream.rdbuf())"
2009-05-18 20:04:07 +08:00
* stream (like std::cout) i.e
* @code
* osg::notify(osg::DEBUG) << "Hello Bugs!" << std::endl;
* @endcode
* @see setNotifyLevel, setNotifyHandler
*/
extern OSG_EXPORT std::ostream& notify(const NotifySeverity severity);
2001-01-11 00:32:10 +08:00
inline std::ostream& notify(void) { return notify(osg::INFO); }
2010-02-10 20:48:21 +08:00
#define OSG_NOTIFY(level) if (isNotifyEnabled(level)) osg::notify(level)
#define OSG_FATAL OSG_NOTIFY(osg::FALTAL)
#define OSG_WARN OSG_NOTIFY(osg::WARN)
#define OSG_NOTICE OSG_NOTIFY(osg::NOTICE)
#define OSG_INFO OSG_NOTIFY(osg::INFO)
#define OSG_DEBUG OSG_NOTIFY(osg::DEBUG_INFO)
From Maciej Krol,"With advent of GUI applications in OSG there is a growing need to redirect notification messages to third party systems. For example windows applications do not have console output, it would be appropriate to redirect notifications to GUI widget or debug output. I have revamped notification system to fit this need. New notification stream is using NotifyHandler as a message sink. Handler is called whenever stream is synchronized (i.e. after <<std::endl). Standard streams std::cout and std::cerr are no longer used although by default StandardNotifyHandler is a message sink. Custom notification handler can be set with osg::setNotifyHandler(NotifyHandler *) function. Two implementations of NotifyHandler are currently available: - StandardNotifyHandler, calls fputs(message, stderr) for severity <= WARN and fputs(message, stdout) for severity > WARN - WinDebugNotifyHandler, windows users can redirect notifications to windows debug output, notifications can be viewed in output window of the debugger i.e. MSVC or DebugView (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) (see screenshot). I have seen on osg-users that some people do std::cerr.rdbuf(otherStream.rdbuf()) to redirect notifications. This trick will no longer work since osg::notify() returns internal osg::NotifyStream not std::cout or std::cerr. You can use osg::notify().rdbuf(otherStream.rdbuf()) to do this instead. Additionally I've made some minor fixes: - Minor imrovements to osg::notify documentation - NullStream could crash by deleting stream buffer other than default NullStreamBuffer in the destructor i.e. after osg::notify(osg::DEBUG_FP).rdbuf(otherStream.rdbuf())"
2009-05-18 20:04:07 +08:00
/** Handler processing output of notification stream. It acts as a sink to
* notification messages. It is called when notification stream needs to be
* synchronized (i.e. after osg::notify() << std::endl).
* StandardNotifyHandler is used by default, it writes notifications to stderr
* (severity <= WARN) or stdout (severity > WARN).
* Notifications can be redirected to other sinks such as GUI widgets or
* windows debugger (WinDebugNotifyHandler) with custom handlers.
* Use setNotifyHandler to set custom handler.
* Note that osg notification API is not thread safe although notification
* handler is called from many threads. When incorporating handlers into GUI
* widgets you must take care of thread safety on your own.
* @see setNotifyHandler
*/
class OSG_EXPORT NotifyHandler : public osg::Referenced
{
public:
virtual void notify(osg::NotifySeverity severity, const char *message) = 0;
};
/** Set notification handler, by default StandardNotifyHandler is used.
* @see NotifyHandler
*/
extern OSG_EXPORT void setNotifyHandler(NotifyHandler *handler);
/** Get currrent notification handler. */
extern OSG_EXPORT NotifyHandler *getNotifyHandler();
/** Redirects notification stream to stderr (severity <= WARN) or stdout (severity > WARN).
* The fputs() function is used to write messages to standard files. Note that
* std::out and std::cerr streams are not used.
* @see setNotifyHandler
*/
class OSG_EXPORT StandardNotifyHandler : public NotifyHandler
{
public:
void notify(osg::NotifySeverity severity, const char *message);
};
#if defined(WIN32) && !defined(__CYGWIN__)
/** Redirects notification stream to windows debugger with use of
* OuputDebugString functions.
* @see setNotifyHandler
*/
class OSG_EXPORT WinDebugNotifyHandler : public NotifyHandler
{
public:
void notify(osg::NotifySeverity severity, const char *message);
};
#endif
}
2001-01-11 00:32:10 +08:00
#endif