root/OpenSceneGraph/trunk/include/osg/Notify @ 11047

Revision 11047, 5.0 kB (checked in by robert, 5 years ago)

Fixed typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_NOTIFY_H
15#define OSG_NOTIFY_H 1
16
17#include <osg/Export>
18#include <osg/Referenced> // for NotifyHandler
19
20#include <ostream>
21
22namespace osg {
23
24/** Range of notify levels from DEBUG_FP through to FATAL, ALWAYS
25  * is reserved for forcing the absorption of all messages.  The
26  * keywords are also used verbatim when specified by the environmental
27  * variable OSGNOTIFYLEVEL or OSG_NOTIFY_LEVEL.
28  * See documentation on osg::notify() for further details.
29  */
30enum NotifySeverity {
31    ALWAYS=0,
32    FATAL=1,
33    WARN=2,
34    NOTICE=3,
35    INFO=4,
36    DEBUG_INFO=5,
37    DEBUG_FP=6
38};
39
40/** set the notify level, overriding the default or the value set by
41  * the environmental variable OSGNOTIFYLEVEL or OSG_NOTIFY_LEVEL.
42  */
43extern OSG_EXPORT void setNotifyLevel(NotifySeverity severity);
44
45/** get the notify level. */
46extern OSG_EXPORT NotifySeverity getNotifyLevel();
47
48/** is notification enabled, given the current setNotifyLevel() setting? */
49extern OSG_EXPORT bool isNotifyEnabled(NotifySeverity severity);
50
51/** initialize notify level. */
52extern OSG_EXPORT bool initNotifyLevel();
53
54/** notify messaging function for providing fatal through to verbose
55  * debugging messages.  Level of messages sent to the console can
56  * be controlled by setting the NotifyLevel either within your
57  * application or via the an environmental variable i.e.
58  * - setenv OSGNOTIFYLEVEL DEBUG (for tsh)
59  * - export OSGNOTIFYLEVEL=DEBUG (for bourne shell)
60  * - set OSGNOTIFYLEVEL=DEBUG (for Windows)
61  *
62  * All tell the osg to redirect all debugging and more important messages
63  * to the notification stream (useful for debugging) setting ALWAYS will force
64  * all messages to be absorbed, which might be appropriate for final
65  * applications.  Default NotifyLevel is NOTICE.  Check the enum
66  * #NotifySeverity for full range of possibilities.  To use the notify
67  * with your code simply use the notify function as a normal file
68  * stream (like std::cout) i.e
69  * @code
70  * osg::notify(osg::DEBUG) << "Hello Bugs!" << std::endl;
71  * @endcode
72  * @see setNotifyLevel, setNotifyHandler
73  */
74extern OSG_EXPORT std::ostream& notify(const NotifySeverity severity);
75
76inline std::ostream& notify(void) { return notify(osg::INFO); }
77
78#define OSG_NOTIFY(level) if (isNotifyEnabled(level)) osg::notify(level)
79
80#if _DEBUG
81    #define OSG_DEBUG_NOTIFY(level) if (isNotifyEnabled(level)) osg::notify(level)
82#else
83    // when using an optimized build use if (false) to tell the compiler to ignore the rest of the notify.
84    #define OSG_DEBUG_NOTIFY(level) if (false) osg::notify(level)
85#endif
86
87/** Handler processing output of notification stream. It acts as a sink to
88  * notification messages. It is called when notification stream needs to be
89  * synchronized (i.e. after osg::notify() << std::endl).
90  * StandardNotifyHandler is used by default, it writes notifications to stderr
91  * (severity <= WARN) or stdout (severity > WARN).
92  * Notifications can be redirected to other sinks such as GUI widgets or
93  * windows debugger (WinDebugNotifyHandler) with custom handlers.
94  * Use setNotifyHandler to set custom handler.
95  * Note that osg notification API is not thread safe although notification
96  * handler is called from many threads. When incorporating handlers into GUI
97  * widgets you must take care of thread safety on your own.
98  * @see setNotifyHandler
99  */
100class OSG_EXPORT NotifyHandler : public osg::Referenced
101{
102public:
103    virtual void notify(osg::NotifySeverity severity, const char *message) = 0;
104};
105
106/** Set notification handler, by default StandardNotifyHandler is used.
107  * @see NotifyHandler
108  */
109extern OSG_EXPORT void setNotifyHandler(NotifyHandler *handler);
110
111/** Get currrent notification handler. */
112extern OSG_EXPORT NotifyHandler *getNotifyHandler();
113
114/** Redirects notification stream to stderr (severity <= WARN) or stdout (severity > WARN).
115  * The fputs() function is used to write messages to standard files. Note that
116  * std::out and std::cerr streams are not used.
117  * @see setNotifyHandler
118  */
119class OSG_EXPORT StandardNotifyHandler : public NotifyHandler
120{
121public:
122    void notify(osg::NotifySeverity severity, const char *message);
123};
124
125#if defined(WIN32) && !defined(__CYGWIN__)
126
127/** Redirects notification stream to windows debugger with use of
128  * OuputDebugString functions.
129  * @see setNotifyHandler
130  */
131class OSG_EXPORT WinDebugNotifyHandler : public NotifyHandler
132{
133public:
134    void notify(osg::NotifySeverity severity, const char *message);
135};
136
137#endif
138
139}
140
141#endif
Note: See TracBrowser for help on using the browser.