2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2010-02-10 20:44:59 +08:00
|
|
|
#ifndef OSG_NOTIFY_H
|
|
|
|
#define OSG_NOTIFY_H 1
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#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
|
|
|
|
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
|
|
|
|
2010-02-12 19:45:00 +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
|
|
|
|
|
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
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2012-03-22 01:36:20 +08:00
|
|
|
* stream (like std::cout) i.e
|
2009-05-18 20:04:07 +08:00
|
|
|
* @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-15 19:36:05 +08:00
|
|
|
#define OSG_NOTIFY(level) if (osg::isNotifyEnabled(level)) osg::notify(level)
|
2010-06-01 17:23:21 +08:00
|
|
|
#define OSG_ALWAYS OSG_NOTIFY(osg::ALWAYS)
|
2010-04-29 04:33:40 +08:00
|
|
|
#define OSG_FATAL OSG_NOTIFY(osg::FATAL)
|
2010-02-12 19:45:00 +08:00
|
|
|
#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)
|
2010-05-29 01:17:34 +08:00
|
|
|
#define OSG_DEBUG_FP OSG_NOTIFY(osg::DEBUG_FP)
|
2010-02-10 01:39:43 +08:00
|
|
|
|
2012-03-22 01:36:20 +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
|
2009-05-18 20:04:07 +08:00
|
|
|
* synchronized (i.e. after osg::notify() << std::endl).
|
2012-03-22 01:36:20 +08:00
|
|
|
* StandardNotifyHandler is used by default, it writes notifications to stderr
|
2009-05-18 20:04:07 +08:00
|
|
|
* (severity <= WARN) or stdout (severity > WARN).
|
2012-03-22 01:36:20 +08:00
|
|
|
* Notifications can be redirected to other sinks such as GUI widgets or
|
2009-05-18 20:04:07 +08:00
|
|
|
* windows debugger (WinDebugNotifyHandler) with custom handlers.
|
|
|
|
* Use setNotifyHandler to set custom handler.
|
2012-03-22 01:36:20 +08:00
|
|
|
* Note that osg notification API is not thread safe although notification
|
2009-05-18 20:04:07 +08:00
|
|
|
* 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);
|
|
|
|
};
|
|
|
|
|
2020-07-18 00:01:05 +08:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2009-05-18 20:04:07 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Redirects notification stream to windows debugger with use of
|
2009-05-18 20:04:07 +08:00
|
|
|
* 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
|