2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_NOTIFY
|
|
|
|
#define OSG_NOTIFY 1
|
|
|
|
|
|
|
|
#include <osg/Export>
|
2009-05-18 20:04:07 +08:00
|
|
|
#include <osg/Referenced> // for NotifyHandler
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-03-03 21:27:21 +08:00
|
|
|
#include <ostream>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** 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
|
2009-05-18 20:04:07 +08:00
|
|
|
* variable OSGNOTIFYLEVEL or OSG_NOTIFY_LEVEL.
|
|
|
|
* See documentation on osg::notify() for further details.
|
2001-09-20 05:08:56 +08:00
|
|
|
*/
|
2001-01-11 00:32:10 +08:00
|
|
|
enum NotifySeverity {
|
|
|
|
ALWAYS=0,
|
|
|
|
FATAL=1,
|
|
|
|
WARN=2,
|
|
|
|
NOTICE=3,
|
|
|
|
INFO=4,
|
2001-09-20 05:08:56 +08:00
|
|
|
DEBUG_INFO=5,
|
|
|
|
DEBUG_FP=6
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** set the notify level, overriding the default or the value set by
|
2009-05-18 20:04:07 +08:00
|
|
|
* the environmental variable OSGNOTIFYLEVEL or OSG_NOTIFY_LEVEL.
|
2001-09-20 05:08:56 +08:00
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
extern OSG_EXPORT void setNotifyLevel(NotifySeverity severity);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** get the notify level. */
|
2005-04-12 01:14:17 +08:00
|
|
|
extern OSG_EXPORT NotifySeverity getNotifyLevel();
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-07-14 18:27:00 +08:00
|
|
|
/** is notification enabled, given the current setNotifyLevel() setting? */
|
|
|
|
extern OSG_EXPORT bool isNotifyEnabled(NotifySeverity severity);
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** initialize notify level. */
|
2005-04-12 01:14:17 +08:00
|
|
|
extern OSG_EXPORT bool initNotifyLevel();
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** 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
|
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
|
2001-09-20 05:08:56 +08:00
|
|
|
* all messages to be absorbed, which might be appropriate for final
|
|
|
|
* applications. Default NotifyLevel is NOTICE. Check the enum
|
2009-05-18 20:04:07 +08:00
|
|
|
* #NotifySeverity for full range of possibilities. To use the notify
|
2001-09-20 05:08:56 +08:00
|
|
|
* with your code simply use the notify function as a normal file
|
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
|
2001-09-20 05:08:56 +08:00
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
extern OSG_EXPORT std::ostream& notify(const NotifySeverity severity);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-12-15 05:49:04 +08:00
|
|
|
inline std::ostream& notify(void) { return notify(osg::INFO); }
|
|
|
|
|
2010-02-10 01:39:43 +08:00
|
|
|
#define NOTIFY(level) if (level>isNotifyEnabled(level)) osg::notify(level)
|
|
|
|
|
|
|
|
#if _DEBUG
|
|
|
|
#define DEBUG_NOTIFY(level) if (level>isNotifyEnabled(level)) osg::notify(level)
|
|
|
|
#else
|
|
|
|
// when using an optimized build use if (false) to tell the compiler to ignore the rest of the notify.
|
|
|
|
#define DEBUG_NOTIFY(level) if (false) osg::notify(level)
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|