/* ***********************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.
 **************************************************************************************/
#include "Equipement_Historique.h"
#include "Debug.h"
#include "Objet.h"
#include "Macro.h"


struct Struct_Historique *Ajouter_Historique (struct Struct_Equipement *Equipement, gchar * Chaine, gint Niveau_Historique)
{
	struct Struct_Historique *Historique = NULL;
	gchar    *Chaine_Historique = NULL, Date[30];

	ERROR_if (Equipement == NULL);
	ERROR_if (Chaine == NULL);
	MALLOC (Historique, sizeof (struct Struct_Historique));
	time (&Historique->Date);
	Historique->Niveau_Historique = Niveau_Historique;
	Historique->Historique = g_strdup (Chaine);
	G_LIST_APPEND (Equipement->GList_Historique, Historique);

	if (Equipement == Equipement_Selectionner) {
		ctime_r (&Historique->Date, Date);
		Date[strlen (Date) - 1] = '\0';
		Chaine_Historique = g_strdup_printf ("%s - %s", Date, Historique->Historique);
		switch (Historique->Niveau_Historique) {
		    case HISTORIQUE_INFO:
			    Ajouter_Nouvelle_Objet (INFO_HISTORIQUE_INFO, Chaine_Historique, NULL, NULL, PERE_RACINE, NULL, PERE_RACINE,PERE_RACINE, PERE_RACINE, PERE_RACINE, ID_Reseau_En_Cours, LISTE_INFO_HISTORIQUE);
			    break;
		    case HISTORIQUE_WARNING:
			    Ajouter_Nouvelle_Objet (INFO_HISTORIQUE_WARNING, Chaine_Historique, NULL, NULL, PERE_RACINE, NULL, PERE_RACINE,PERE_RACINE, PERE_RACINE, PERE_RACINE, ID_Reseau_En_Cours, LISTE_INFO_HISTORIQUE);
			    break;
		    case HISTORIQUE_ALERTE:
			    Ajouter_Nouvelle_Objet (INFO_HISTORIQUE_ALERTE, Chaine_Historique, NULL, NULL, PERE_RACINE, NULL, PERE_RACINE,PERE_RACINE, PERE_RACINE, PERE_RACINE, ID_Reseau_En_Cours, LISTE_INFO_HISTORIQUE);
			    break;
		    default:
			    debug_printf (INTERFACE, D_ERRO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Type Historique Inconnu");
		}
		MYFREE (Chaine_Historique);
	}
	return Historique;
}
