/* ***********************IMPORTANT *********************************************
 *  Copyright (C) 2004-2007 Thierry Lagarde <tlagarde@users.sourceforge.net>
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License.
 *
 *
 *                      ********************
 *
 *
 *  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 Library General Public License for more details.
 *
 *
 *                      ********************
 *
 *
 * You are highly encouraged to send your changes to <tlagarde@users.sourceforge.net>
 * for possible incorporation into the main distribution.
 * By sending these changes to <tlagarde@users.sourceforge.net>,
 * it is assumed that you are offering <tlagarde@users.sourceforge.net>
 * the unlimited, non-exclusive right to reuse, modify, and relicense the code.
 *
 *
 *                      ********************
 *
 *  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.
 **************************************************************************************/
#ifndef         __DEBUG
#define         __DEBUG

#include "Semaphore.h"
#include "Liste_Equipement.h"
#include "Com/Initialisation_Com.h"
#include "Thread.h"
#include "Log.h"

enum enum_Niveau_Debug {
	D_SEG_FAULT = 0,
	D_ERRO ,
	D_WARN_USER,
	D_WARN,
	D_INFO_USER,
	D_INFO
};

int       Debug;

void      debug_printf (int Niveau_Debug, const char *file, const char *Fonction, int line, char *fmt, ...);
void      Initialisation_Debug (void);

#define ERROR_if(expr)	G_STMT_START{			\
     if (expr)									\
       {										\
		debug_printf(D_ERRO			\
		,__FILE__,__PRETTY_FUNCTION__,__LINE__  \
		,"`%s' failed. \nSocket ouvert[%d]  Thread[%d][%d]\n Nb equipement (%d)",#expr,  Nb_Socket_Ouverte, Info_Demarrage.Nb_Thread_Max, Info_Demarrage.Nb_Thread_Max - Valeur_Semaphore (&Semaphore_Thread_Scan),g_list_length (GList_Equipement));  				\
       };							}G_STMT_END
	   
#define return_WARNING_if(expr,val)	G_STMT_START{	\
     if (expr)										\
       {											\
		debug_printf(D_WARN				\
		,__FILE__,__PRETTY_FUNCTION__,__LINE__		\
		,"`%s' failed.",#expr);  					\
	 	return val;									\
       };									}G_STMT_END

#endif
