Files
unison/src/core/debug.h

133 lines
3.7 KiB
C
Raw Normal View History

2007-02-06 20:40:38 +01:00
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef DEBUG_H
#define DEBUG_H
2007-02-13 10:23:47 +01:00
/**
* \defgroup debugging
* \brief Debugging functions and macros
*
* - DEBUG functionality: macros which allow developers to
* send information out on screen only in debugging builds.
* All debug messages are disabled by default. To enable
* selected debug messages, use the ns3::DebugComponentEnable
2007-02-13 18:20:24 +01:00
* function. Alternatively, you can use the NS_DEBUG
2007-02-13 10:23:47 +01:00
* environment variable to define a ';'-separated list of
2007-02-13 18:20:24 +01:00
* messages to enable. For example, NS_DEBUG=a;b;c;DAFD;GH
2007-02-13 10:23:47 +01:00
* would enable the components 'a', 'b', 'c', 'DAFD', and, 'GH'.
*/
2007-02-06 20:40:38 +01:00
namespace ns3 {
2007-02-13 10:23:47 +01:00
/**
* \param name a debug component name
* \ingroup debugging
*
* Enable the debugging output associated with that debug component.
* The debugging output can be later disabled with a call
* to ns3::DebugComponentDisable.
*/
2007-02-06 20:40:38 +01:00
void DebugComponentEnable (char const *name);
2007-02-13 10:23:47 +01:00
/**
* \param name a debug component name
* \ingroup debugging
*
* Disable the debugging output associated with that debug component.
* The debugging output can be later re-enabled with a call
* to ns3::DebugComponentEnable.
*/
2007-02-06 20:40:38 +01:00
void DebugComponentDisable (char const *name);
2007-02-13 10:23:47 +01:00
/**
* \ingroup debugging
* Print the list of debugging messages available.
*/
2007-02-06 20:40:38 +01:00
void DebugComponentPrintList (void);
class DebugComponent {
public:
2007-02-16 09:00:22 +01:00
DebugComponent (char const *name);
2007-02-06 20:40:38 +01:00
bool IsEnabled (void);
void Enable (void);
void Disable (void);
private:
bool m_isEnabled;
};
}; // namespace ns3
#ifdef NS3_DEBUG_ENABLE
2007-02-16 09:00:22 +01:00
#include <string>
#include <iostream>
2007-02-13 10:23:47 +01:00
/**
* \ingroup debugging
* \param name a string
*
* Define a Debug component with a specific name. This macro
* should be used at the top of every file in which you want
2007-02-13 18:20:24 +01:00
* to use the NS_DEBUG macro. This macro defines a new
2007-02-13 10:23:47 +01:00
* "debug component" which can be later selectively enabled
* or disabled with the ns3::DebugComponentEnable and
2007-02-13 18:20:24 +01:00
* ns3::DebugComponentDisable functions or with the NS_DEBUG
2007-02-13 10:23:47 +01:00
* environment variable.
*/
2007-02-13 18:20:24 +01:00
#define NS_DEBUG_COMPONENT_DEFINE(name) \
2007-02-07 08:49:54 +01:00
static ns3::DebugComponent g_debug = ns3::DebugComponent (name);
2007-02-06 20:40:38 +01:00
2007-02-13 10:23:47 +01:00
/**
* \ingroup debugging
* \param msg message to output
*
* Generate debugging output in the "debug component" of the
2007-02-13 18:20:24 +01:00
* current file. i.e., every call to NS_DEBUG from within
2007-02-13 10:23:47 +01:00
* a file implicitely generates out within the component
2007-02-13 18:20:24 +01:00
* defined with the NS_DEBUG_COMPONENT_DEFINE macro in the
2007-02-13 10:23:47 +01:00
* same file.
*/
2007-02-13 18:20:24 +01:00
#define NS_DEBUG(msg) \
2007-02-06 20:40:38 +01:00
if (g_debug.IsEnabled ()) \
{ \
2007-02-13 10:23:47 +01:00
std::cout << msg << std::endl; \
2007-02-06 20:40:38 +01:00
}
2007-02-13 09:45:32 +01:00
2007-02-16 09:26:56 +01:00
/**
* \ingroup debugging
* \param msg message to output
*
* Generate debugging output unconditionally in all
* debug builds.
*/
2007-02-16 09:42:53 +01:00
#define NS_DEBUG_UNCOND(msg) \
2007-02-16 09:26:56 +01:00
std::cout << msg << std::endl;
2007-02-06 20:40:38 +01:00
#else /* NS3_DEBUG_ENABLE */
2007-02-13 18:20:24 +01:00
#define NS_DEBUG_COMPONENT_DEFINE(name)
#define NS_DEBUG(x)
2007-02-16 09:26:56 +01:00
#define NS_DEBUG_UNCOND(msg)
2007-02-06 20:40:38 +01:00
#endif /* NS3_DEBUG_ENABLE */
#endif /* DEBUG_H */