00001 // 00002 // tools.hh : Other utility functions 00003 // authors : Fabio Silva 00004 // 00005 // Copyright (C) 2000-2002 by the University of Southern California 00006 // $Id: tools.hh,v 1.13 2005/09/13 04:53:50 tomh Exp $ 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License, 00010 // version 2, as published by the Free Software Foundation. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License along 00018 // with this program; if not, write to the Free Software Foundation, Inc., 00019 // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00020 // 00021 // Linking this file statically or dynamically with other modules is making 00022 // a combined work based on this file. Thus, the terms and conditions of 00023 // the GNU General Public License cover the whole combination. 00024 // 00025 // In addition, as a special exception, the copyright holders of this file 00026 // give you permission to combine this file with free software programs or 00027 // libraries that are released under the GNU LGPL and with code included in 00028 // the standard release of ns-2 under the Apache 2.0 license or under 00029 // otherwise-compatible licenses with advertising requirements (or modified 00030 // versions of such code, with unchanged license). You may copy and 00031 // distribute such a system following the terms of the GNU GPL for this 00032 // file and the licenses of the other code concerned, provided that you 00033 // include the source code of that other code when and as the GNU GPL 00034 // requires distribution of source code. 00035 // 00036 // Note that people who make modified versions of this file are not 00037 // obligated to grant this special exception for their modified versions; 00038 // it is their choice whether to do so. The GNU General Public License 00039 // gives permission to release a modified version without this exception; 00040 // this exception also makes it possible to release a modified version 00041 // which carries forward this exception. 00042 // 00043 00044 // 00045 // This file contains OS abstractions to make it easy to use diffusion 00046 // in different environments (i.e. in simulations, where time is 00047 // virtualized, and in embeddedd apps where error logging happens in 00048 // some non-trivial way). 00049 // 00050 // This file defines the various debug levels and a global debug level 00051 // variable (global_debug_level) that can be set according to how much 00052 // debug information one would like to get when using DiffPrint (see 00053 // below for further details). 00054 00055 #ifndef _TOOLS_HH_ 00056 #define _TOOLS_HH_ 00057 00058 #ifdef HAVE_CONFIG_H 00059 #include "config.h" 00060 #endif // HAVE_CONFIG_H 00061 00062 #include <stdio.h> 00063 #include <stdarg.h> 00064 #include <stdlib.h> 00065 #include <sys/time.h> 00066 #include <unistd.h> 00067 00068 // Defines the various debug levels 00069 #define DEBUG_NEVER 11 00070 #define DEBUG_LOTS_DETAILS 10 00071 #define DEBUG_MORE_DETAILS 8 00072 #define DEBUG_DETAILS 6 00073 #define DEBUG_SOME_DETAILS 4 00074 #define DEBUG_NO_DETAILS 3 00075 #define DEBUG_IMPORTANT 2 00076 #define DEBUG_ALWAYS 1 00077 00078 // Defines the default debug level 00079 #ifdef NS_DIFFUSION 00080 #define DEBUG_DEFAULT 0 00081 #else 00082 #define DEBUG_DEFAULT 1 00083 #endif // NS_DIFFUSION 00084 00085 extern int global_debug_level; 00086 00087 // SetSeed sets the random number generator's seed with the timeval 00088 // structure given in tv (which is not changed) 00089 void SetSeed(struct timeval *tv); 00090 00091 // GetTime returns a timeval structure with the current system time 00092 void GetTime(struct timeval *tv); 00093 00094 // GetRand returns a random number between 0 and RAND_MAX 00095 int GetRand(); 00096 00097 // DiffPrint can be used to print messages. In addition to take the 00098 // message to be printed (using the variable argument list format, 00099 // just like fprintf), DiffPrint also requires a debug level for this 00100 // particular message. This is is compared to the global debug level 00101 // and if it is below the current global debug level, the message is 00102 // sent to the logging device (usually set to stderr). 00103 void DiffPrint(int msg_debug_level, const char *fmt, ...); 00104 00105 // Same as DiffPrint but will print the current system time before 00106 // printing the message 00107 void DiffPrintWithTime(int msg_debug_level, const char *fmt, ...); 00108 #endif // !_TOOLS_HH_