libdatastr/lib/libdatastr.c
2000-07-28 15:30:55 +00:00

3072 lines
110 KiB
C

/* Utilisation des API sans vérification des arguments */
#define ND_MODE 1
#define SM_MODE 1
#include <libdatastr.h>
VER_INFO_EXPORT (libdatastr,"$Revision: 1.1 $", "$Name: $",__FILE__,"$Author: smas $")
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* FONCTIONS PUBLIQUES */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* FONCTIONS OPTIMISATION MAXIMALE (DS_MODE = 2) */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Ouverture d'une instance de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Instance : numéro de l'instance de la librairie */
/* (I) Context : nom du contexte */
/* (I) Debug_Mode : mode d'affichage des messages d'erreur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Open_I ( int Instance, const char * Context, DST_Flags Debug_Mode )
{
DST_Status rc;
int SM_Debug = SMD_DEBUG_NONE;
/* Définition du mode debug */
if (Debug_Mode & DSD_DEBUG)
{
DS_stderr = stderr;
SM_Debug = SMD_DEBUG;
}
else if (Debug_Mode & DSD_DEBUG_ALL)
{
DS_stderr = stderr;
SM_Debug = SMD_DEBUG_ALL;
}
/* Ouverture de la librairie LIBSHMEM */
rc = SM_Library_Open (Instance, Context, SMD_OPEN | SM_Debug);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Library_Open : unable to open the LIBSHMEM library");
DS_Error_Print ();
return rc;
}
/*
Lors de la première ouverture de la librairie LIBDATASTR,
on crée une structure locale permettant de référencer
les data structures ouvertes.
*/
if (DS_Open_Counter == 0)
{
rc = ND_DataStruct_Open (&OpenedDS_List, NDD_DS_TREE | NDD_MN_AUTO_EQU, NULL, NULL, NULL, TRUE);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Library_Open : unable to create the opened data structure list");
DS_Error_Print ();
SM_Library_Close (SMD_CLOSE);
return rc;
}
else strcpy (OpenedDS_List->Manager, "DS_OpenedDS_List_Manager");
}
DS_Open_Counter++;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Fermeture de l'instance de la librairie */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Close_I ( void )
{
DST_Status rc;
/*
A la dernière fermeture de la librairie LIBDATASTR, on détruit
la structure locale qui référence les data structures ouvertes.
*/
if (DS_Open_Counter == 1)
{
rc = ND_DataStruct_Close (OpenedDS_List);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Library_Close : unable to close the opened data structure list");
DS_Error_Print ();
if (DS_ERROR(rc)) return rc;
}
}
/* Fermeture de la librairie LIBSHMEM */
rc = SM_Library_Close (SMD_CLOSE);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Library_Close : unable to close the LIBSHMEM library");
DS_Error_Print ();
if (DS_ERROR(rc)) return rc;
}
DS_Open_Counter--;
return rc;
}
/*------------------------------------------------------------------------------*/
/* Définition de la sortie standard des messages d'erreur de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Out : flux de sortie des messages d'erreur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Stderr_Set_I ( FILE * Out )
{
DS_stderr = Out;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Création / ouverture d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) DS_Name : nom de la structure */
/* (O) Root : adresse du pointeur sur la racine de la structure */
/* (I) Type : type de la structure de données */
/* (I) Manager_FileName : nom du fichier qui définit les fonctions manager */
/* (I) Segment_Size : taille ds segments du heap sous-jacent */
/* (I) Open_Mode : mode d'ouverture de la structure */
/* (I) Own_Values : indique si la structure possède ses valeurs */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root,\
NDT_DataStruct_Type Type, const char * Manager_FileName, \
size_t Segment_Size, DST_Flags Open_Mode, int Own_Values )
{
DST_Status rc;
SMT_Heap * Heap;
SMT_DSH * DSH;
int Locked, Mode;
DST_RootDesc * RootDesc, Tmp_RootDesc;
DST_DataStruct * Opened_DataStruct;
char * Prefixed_Name = DS_Name_Prefix (DS_Name);
union semun Sem_Ctl;
*Root = NULL;
/* On définit ce qu'on va faire en fonction du mode d'ouverture demandé et de ce qui existe déjà ou non */
if (SM_Heap_Exist (Prefixed_Name) == SMS_YES)
{
if (DSD_MSK_OPEN (Open_Mode)) Mode = 2;
else if (DSD_MSK_NEW (Open_Mode)) Mode = 1;
else
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the data structure already exists and (Flags & DSD_OPEN & DSD_NEW) is false");
DS_Error_Print ();
return DSS_ERRAPI;
}
}
else if (DSD_MSK_CREATE (Open_Mode)) Mode = 3;
else
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the data structure \"%s\" does no exist and (Flags & DSD_CREATE) is false", DS_Name);
DS_Error_Print ();
return DSS_ERRAPI;
}
switch (Mode)
{
case 1:
/*--------------- Création d'une nouvelle data structure dans un heap existant ---------------*/
/* Ouverture du heap en écriture */
rc = SM_Heap_Open (Prefixed_Name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to open the data structure heap \"%s\" for writing", Prefixed_Name);
DS_Error_Print ();
return rc;
}
/* Création de la node structure */
Tmp_RootDesc.Heap_Name = Prefixed_Name;
rc = ND_DataStruct_Open (Root, Type, "DS_DataStruct_Alloc", "DS_DataStruct_Free", &Tmp_RootDesc, Own_Values);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to create a new node structure in the existing heap \"%s\"", Heap->Name);
DS_Error_Print ();
if (Locked == TRUE) SM_Heap_Unlock (Heap);
*Root = NULL;
return rc;
}
/* Allocation de mémoire pour la description de la nouvelle data structure */
rc = DS_DataStruct_Alloc (sizeof (DST_RootDesc) + strlen (Prefixed_Name) + strlen (Manager_FileName) + 2, (void **)(&RootDesc), &Tmp_RootDesc);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to allocate memory for the new data structure description");
DS_Error_Print ();
DS_DataStruct_Free (*Root, &Tmp_RootDesc);
if (Locked == TRUE) SM_Heap_Unlock (Heap);
*Root = NULL;
return rc;
}
RootDesc->Heap_Name = (char *)((size_t)RootDesc + sizeof (DST_RootDesc) );
strcpy (RootDesc->Heap_Name, Prefixed_Name);
RootDesc->Manager_FileName = (char *)((size_t)RootDesc + sizeof (DST_RootDesc) + strlen (Prefixed_Name) + 1);
strcpy (RootDesc->Manager_FileName, Manager_FileName);
/* On indique que la structure n'est pas propriétaire de son heap */
RootDesc->Heap_Owner = FALSE;
/* On indique que la structure est valide */
RootDesc->Valid = TRUE;
/* On rattache la desription de la data structure à la racine */
(*Root)->User = RootDesc;
/* Pour une telle data structure, on ne crée pas de sémaphore d'ouverture */
/* Déverrouillage du heap */
if (Locked == TRUE)
{
rc = SM_Heap_Unlock (Heap);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to unlock the data structure heap \"%s\"", Prefixed_Name);
DS_Error_Print ();
return rc;
}
}
return DSS_OK;
break;
case 2:
/*--------------- Ouverture d'une data structure existante --------------------*/
/* Si la structure a déjà été ouverte, on ne recommence pas */
rc = DS_DataStruct_IsOpen (DS_Name, Root);
if (rc == DSS_YES) return DSS_OK;
else if (DS_ERROR(rc)) return rc;
/* Accès au heap sous-jacent en lecture */
rc = SM_Heap_Open (Prefixed_Name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to open the data structure heap \"%s\" for reading", Prefixed_Name);
DS_Error_Print ();
return rc;
}
DSH = Heap->MHH->DSR->Head->Value;
/* La racine de la structure se trouve dans le premier chunk du premier segment du heap */
*Root = ( NDT_Root *)((size_t)(DSH->Start) + sizeof (NDT_Node) + sizeof (SMT_Chunk));
/* Chargement des fonctions manager de la structure */
RootDesc = (*Root)->User;
if (!RootDesc)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : data structure \"%s\" has no description defined", DS_Name);
DS_Error_Print ();
if (Locked == TRUE) SM_Heap_Unlock (Heap);
*Root = NULL;
return DSS_ERRAPI;
}
if (!RootDesc->Manager_FileName || !dlopen (( const char *)(RootDesc->Manager_FileName), RTLD_LAZY | RTLD_GLOBAL))
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to load the manager file %s of data structure \"%s\" (%s)", RootDesc->Manager_FileName == NULL ? "undefined" : (char *)(RootDesc->Manager_FileName), DS_Name, dlerror ());
DS_Error_Print ();
if (Locked == TRUE) SM_Heap_Unlock (Heap);
*Root = NULL;
return DSS_ERRDLL;
}
break;
case 3:
/*--------------- Création d'une nouvelle structure de données dans un nouveau heap -------------------*/
if (!Manager_FileName)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the manager file name (.so) is undefined");
DS_Error_Print ();
return DSS_ERRAPI;
}
/* Création d'un nouveau heap */
rc = SM_Heap_Open (Prefixed_Name, &Heap, Segment_Size, SMD_CREATE | SMD_WRITE, &Locked);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to create a heap for the data structure \"%s\"", DS_Name);
DS_Error_Print ();
return rc;
}
/* Création de la structure de données dans le heap */
Tmp_RootDesc.Heap_Name = Prefixed_Name;
rc = ND_DataStruct_Open (Root, Type, "DS_DataStruct_Alloc", "DS_DataStruct_Free", &Tmp_RootDesc, Own_Values);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to create the node structure");
DS_Error_Print ();
SM_Heap_End (Prefixed_Name);
*Root = NULL;
return rc;
}
/* Allocation de mémoire pour la description de la structure */
rc = DS_DataStruct_Alloc (sizeof (DST_RootDesc) + strlen (Prefixed_Name) + strlen (Manager_FileName) + 2, (void **)(&RootDesc), &Tmp_RootDesc);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to allocate memory for the data structure description");
DS_Error_Print ();
SM_Heap_End (Prefixed_Name);
*Root = NULL;
return rc;
}
RootDesc->Heap_Name = (char *)((size_t)RootDesc + sizeof (DST_RootDesc) );
strcpy (RootDesc->Heap_Name, Prefixed_Name);
RootDesc->Manager_FileName = (char *)((size_t)RootDesc + sizeof (DST_RootDesc) + strlen (Prefixed_Name) + 1);
strcpy (RootDesc->Manager_FileName, Manager_FileName);
/* On indique que la structure est propriétaire du heap */
RootDesc->Heap_Owner = TRUE;
/* On indique que la structure est valide */
RootDesc->Valid = TRUE;
/* On rattache la desription de la data structure à la racine */
(*Root)->User = RootDesc;
/* On crée un sémaphore pour compter le nombre de processus qui ouvrent la structure */
rc = DS_Semaphore_Create (*Root);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to create a semaphore for the data structure \"%s\"", DS_Name);
DS_Error_Print ();
SM_Heap_End (Prefixed_Name);
*Root = NULL;
return rc;
}
break;
default:
break;
}
/* On incrémente le sémaphore qui compte le nombre de processus qui ouvrent la structure */
rc = DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Open, 1);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to incremente the semaphore of data structure \"%s\"", DS_Name);
DS_Error_Print ();
if (Locked == TRUE) SM_Heap_Unlock (Heap);
if (Mode == 3)
{
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End (Prefixed_Name);
}
else DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Close, 1);
*Root = NULL;
return rc;
}
/* On ajoute la data structure à la liste des structures ouvertes par le processus courant */
Opened_DataStruct = (DST_DataStruct *)malloc (sizeof (DST_DataStruct));
Opened_DataStruct->Name = strdup (DS_Name);
Opened_DataStruct->Root = *Root;
rc = ND_Value_Add (OpenedDS_List, Opened_DataStruct);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to add structure \"%s\" to the opened structure list", DS_Name);
DS_Error_Print ();
if (Locked == TRUE) SM_Heap_Unlock (Heap);
if (Mode == 3)
{
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End (Prefixed_Name);
}
else DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Close, 1);
*Root = NULL;
return rc;
}
/* Déverrouillage du heap */
if (Locked == TRUE)
{
rc = SM_Heap_Unlock (Heap);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to unlock the data structure heap \"%s\"", Prefixed_Name);
DS_Error_Print ();
ND_Value_Remove (OpenedDS_List, Opened_DataStruct, (void **)&Opened_DataStruct);
ND_Value_Free (OpenedDS_List, Opened_DataStruct);
if (Mode == 3)
{
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End (Prefixed_Name);
}
else DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Close, 1);
*Root = NULL;
return rc;
}
}
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Verrouillage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Lock_Mode : type de verrou à poser sur la structure */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Lock_I ( NDT_Root * Root, DST_Flags Lock_Mode, int * Locked )
{
DST_Status rc;
SMT_Heap * Heap;
char * Heap_Name = ((DST_RootDesc *)(Root->User))->Heap_Name;
/* Réouverture du heap sous-jacent (rafraîchissement des segments) + verrouillage */
rc = SM_Heap_Open (Heap_Name, &Heap, 0, SMD_OPEN | Lock_Mode, Locked);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Lock : unable to reopen the data structure heap \"%s\" for %s",
Heap_Name, DSD_MSK_READ (Lock_Mode) ? "reading" : "writing");
DS_Error_Print ();
return rc;
}
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Déverrouillage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Unlock_I ( NDT_Root * Root )
{
DST_Status rc;
SMT_Heap * Heap;
char * Heap_Name = ((DST_RootDesc *)(Root->User))->Heap_Name;
rc = SM_Heap_IsOpen (Heap_Name, &Heap);
if (rc != SMS_YES)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Unlock : the data structure heap \"%s\" is not open", Heap_Name);
DS_Error_Print ();
return rc;
}
rc = SM_Heap_Unlock (Heap);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Unlock : unable to unlock the data structure heap \"%s\"", Heap_Name);
DS_Error_Print ();
return rc;
}
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Fermeture d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Close_I ( NDT_Root * Root, DST_Flags Close_Mode )
{
DST_Status rc;
SMT_Heap * Heap;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
char Heap_Name [256], * DS_Name;
DST_DataStruct To_Remove, * Opened_DataStruct;
union semun Sem_Ctl;
strcpy (Heap_Name, RootDesc->Heap_Name);
DS_Name = strstr (Heap_Name, DS_PREFIX);
if (DS_Name) DS_Name += strlen (DS_PREFIX) + 1;
else DS_Name = Heap_Name;
if (Close_Mode == DSD_DESTROY) /* Destruction de la data structure */
{
/* La data structure est-elle propriétaire du heap sous-jacent ? */
if (RootDesc->Heap_Owner == TRUE)
{
/* On vérifie qu'aucun autre processus n'a ouvert la data structure */
rc = DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Destroy, 2);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to destroy the data structure \"%s\" because it is opened by another process", DS_Name);
DS_Error_Print ();
return rc;
}
/* On supprime la structure proprement (toutes les valeurs sont supprimées les unes après les autres) */
rc = ND_DataStruct_Close (Root);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to close the node structure of \"%s\" data structure", DS_Name);
DS_Error_Print ();
return rc;
}
/* Suppression du sémaphore */
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl);
/* On supprime maintenant le heap */
rc = SM_Heap_End (Heap_Name);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to remove heap \"%s\"", Heap_Name);
DS_Error_Print ();
return rc;
}
}
else
{
/*
Dans le cas où la data structure n'est pas propriétaire du heap sous-jacent,
on ne peut pas garantir qu'aucun autre processus ne l'a ouverte.
On la supprime donc sans contrôle.
*/
rc = ND_DataStruct_Close (Root);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to close the node structure of \"%s\" data structure", DS_Name);
DS_Error_Print ();
return rc;
}
return DS_DataStruct_Free (RootDesc, (void *)RootDesc);
}
}
else /* Fermeture simple de la data structure */
{
/* On décrémente le sémaphore qui compte le nombre de processus ayant ouvert la data structure */
rc = DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Close, 1);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to decremente the semaphore of data structure \"%s\"", DS_Name);
DS_Error_Print ();
return rc;
}
/* Fermeture simple du heap */
rc = SM_Heap_IsOpen (Heap_Name, &Heap);
if (rc == SMS_YES)
{
rc = SM_Heap_Close (Heap);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to close heap \"%s\"", Heap_Name);
DS_Error_Print ();
return rc;
}
}
}
/* Suppression de la data structure de la liste des structures ouvertes */
To_Remove.Name = DS_Name;
rc = ND_Value_Remove (OpenedDS_List, &To_Remove, (void **)&Opened_DataStruct);
if (rc == NDS_OK) ND_Value_Free (OpenedDS_List, Opened_DataStruct);
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Affiche les informations d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root: pointeur sur la racine de la structure de données */
/* (I) Out : flux de sortie de l'affichage */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Info_Print_I ( NDT_Root * Root, FILE * Out )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Info_Print : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* Affichage des informations sur la structure */
rc = ND_DataStruct_Info_Print (Root, Out);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Info_Print : unable to print info about the data structure");
DS_Error_Print ();
return rc;
}
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Réorganisation d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à réorganiser */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Reorg_I ( NDT_Root * Root )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Reorg : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* On rend la structure invalide, le temps de sa réorganisation */
RootDesc->Valid = FALSE;
/* Réorganisation de la node structure */
rc = ND_DataStruct_Reorg (Root);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Reorg : unable to reorganize the node structure ");
DS_Error_Print ();
RootDesc->Valid = TRUE;
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
return rc;
}
/* On rend la structure à nouveau valide */
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Parcours de tous les noeuds d'une structure de données et exécution d'une */
/* commande sur chacun d'eux */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à parcourir */
/* (I) Command : commande à exécuter sur chaque noeud traversé */
/* (I) Data : pointeur de données utilisateur */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Traverse_I ( NDT_Root * Root, NDT_Command Command, void * Data )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Traverse : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* On rend éventuellement la structure invalide le temps de sa traversée */
switch ((int)Command)
{
case NDD_CMD_PRINT_VALUE:
break;
default:
RootDesc->Valid = FALSE;
break;
}
/* Traversée de la node structure */
rc = ND_DataStruct_Traverse (Root, Command, Data);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Traverse : unable to traverse the node structure ");
DS_Error_Print ();
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
return rc;
}
/* On rend la structure valide */
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Conversion d'une structure de données d'un type en un autre */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Target_Type : type de structure cible */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Convert_I ( NDT_Root * Root, NDT_DataStruct_Type Target_Type )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Convert : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* On rend la structure invalide le temps de sa conversion */
RootDesc->Valid = FALSE;
/* Conversion de la node structure */
rc = ND_DataStruct_Convert (Root, Target_Type);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Convert : unable to convert the node structure");
DS_Error_Print ();
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
return rc;
}
/* On rend la structure à nouveau valide */
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Affichage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à afficher */
/* (I) Out : flux de sortie */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Print_I ( NDT_Root * Root, FILE * Out )
{
return DS_DataStruct_Traverse_I (Root, NDD_CMD_PRINT_VALUE, Out);
}
/*------------------------------------------------------------------------------*/
/* Fonction de vérification / réparation d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (O) Nb_Detected : pointeur sur le nombre d'erreurs détectées */
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrigées */
/* (I) Out : flux de sortie du rapport */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Check_I ( NDT_Root * Root, int * Nb_Detected, int * Nb_Corrected, FILE * Out )
{
DST_Status rc;
SMT_Heap * Heap;
int Locked;
char * Heap_Name;
DST_Flags Previous_Lock;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
Heap_Name = RootDesc->Heap_Name;
/* On sauvegarde l'état de verrouillage précédent */
rc = SM_Heap_IsOpen (Heap_Name, &Heap);
if (rc != SMS_YES)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Check : the data structure heap \"%s\" is not open", Heap_Name);
DS_Error_Print ();
return rc;
}
Previous_Lock = Heap->Lock_Mode;
/* Verrouillage de la data structure en écriture */
rc = DS_DataStruct_Lock_I (Root, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error ND_DataStruct_Check : unable to lock the data structure for writing");
DS_Error_Print ();
return rc;
}
/* Vérification du heap sous-jacent à la data structure */
rc = SM_Heap_Check (Heap, Nb_Detected, Nb_Corrected, Out);
if (rc != SMS_OK)
{
if (Previous_Lock == SMD_UNDEF) DS_DataStruct_Unlock_I (Root);
else DS_DataStruct_Lock_I (Root, Previous_Lock, &Locked);
return rc;
}
else
{
/* Vérification de la structure de noeuds */
fprintf (Out, "Checking the node structure ...\n");
rc = ND_DataStruct_Check (Root, Nb_Detected, Nb_Corrected, Out);
}
/* On valide ou invalide la structure selon le résultat */
if (*Nb_Corrected == *Nb_Detected) RootDesc->Valid = TRUE;
else RootDesc->Valid = FALSE;
/* Retour au mode de verrouillage précédent */
if (Previous_Lock == SMD_UNDEF) DS_DataStruct_Unlock_I (Root);
else DS_DataStruct_Lock_I (Root, Previous_Lock, &Locked);
/* Affichage du résultat de la procédure de vérification */
if (*Nb_Detected)
{
fprintf (Out, "%d/%d error(s) corrected in the data structure\n", *Nb_Corrected, *Nb_Detected);
if (*Nb_Corrected < *Nb_Detected) return DSS_KO;
}
else fprintf (Out, "No error detected in the data structure\n");
return rc;
}
/*------------------------------------------------------------------------------*/
/* Affiche la structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Out : flux de sortie */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Dump_I ( NDT_Root * Root, FILE * Out )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Dump : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* Affichage de la node structure */
rc = ND_DataStruct_Dump (Root, Out);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Dump : unable to dump the node structure");
DS_Error_Print ();
return rc;
}
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Récupération du premier noeud d'une structure */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine dont on cherche le premier noeud */
/* (O) Node : pointeur sur le noeud à récupérer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_First_Get_I ( NDT_Root * Root, NDT_Node ** Node )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_First_Get : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* Récupération du premier noeud */
rc = ND_Node_First_Get (Root, Node);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Récupération du dernier noeud d'une structure */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine dont on cherche le dernier noeud */
/* (O) Node : pointeur sur le noeud à récupérer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Last_Get_I ( NDT_Root * Root, NDT_Node ** Node )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Last_Get : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* Récupération du dernier noeud */
rc = ND_Node_Last_Get (Root, Node);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Récupération du noeud suivant */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le suivant */
/* (O) Next_Node : pointeur sur le noeud suivant */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Next_Get_I ( NDT_Node * Node, NDT_Node ** Next_Node )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Node->Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Node->Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Next_Get : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* Récupération du noeud suivant */
rc = ND_Node_Next_Get (Node, Next_Node);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Récupération du noeud précédant */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le précédant */
/* (O) Prev_Node : pointeur sur le noeud précédant */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Previous_Get_I ( NDT_Node * Node, NDT_Node ** Prev_Node )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Node->Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Node->Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Previous_Get : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* Récupération du noeud précédent */
rc = ND_Node_Previous_Get (Node, Prev_Node);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Ajout d'un noeud à une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Node : pointeur sur le noeud à ajouter */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Add_I ( NDT_Root * Root, NDT_Node * Node )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Add : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* On rend la structure invalide le temps de l'ajout */
RootDesc->Valid = FALSE;
/* Ajout du noeud */
rc = ND_Node_Add (Root, Node);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Add : unable to add a node to the data structure");
DS_Error_Print ();
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
return rc;
}
/* On rend la structure à nouveau valide */
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Suppression d'un noeud dans une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud à supprimer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Remove_I ( NDT_Node * Node )
{
DST_Status rc;
NDT_Root * Root;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Node->Root->User);
Root = Node->Root;
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Remove : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* On rend la structure invalide le temps de la suppression du noeud */
RootDesc->Valid = FALSE;
/* Suppression dans la node structure */
rc = ND_Node_Remove (Node);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Remove : unable to remove a node from the structure");
DS_Error_Print ();
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
return rc;
}
/* On rend la structure à nouveau valide */
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Recherche un noeud dans un arbre et retourne le pointeur sur le noeud */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de l'abre */
/* (O) Node : adresse du pointeur sur le noeud à récuperer */
/* (I) Value : pointeur sur la valeur à rechercher */
/* (I) Data : pointeur de données */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Find_I ( NDT_Root * Root, NDT_Node ** Node, void * Value, void * Data )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
*Node = NULL;
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Find : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* Recherche dans la node structure */
rc = ND_Node_Find (Root, Node, Value, Data);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Allocation d'une valeur d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (O) Value : adresse d'un pointeur sur la valeur à allouer */
/* (I) ... : arguments relatifs à l'allocation de la valeur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Alloc_I ( NDT_Root * Root, void ** Value, ... )
{
DST_Status rc;
va_list Args;
/* Récupération des arguments pour l'allocation de la valeur */
va_start (Args, Value);
/* Appel du manager */
rc = ND_Manager_Exec (Root->Manager, NDD_CMD_MAKE_VALUE, Root, Value, Args);
va_end (Args);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Ajout d'une valeur à une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Value : pointeur sur la valeur à ajouter à la structure de données */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Add_I ( NDT_Root * Root, void * Value )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Value_Add : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* On rend la structure invalide le temps de l'ajout */
RootDesc->Valid = FALSE;
/* Ajout de la valeur */
rc = ND_Value_Add (Root, Value);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Value_Add : unable to add a value to the data structure");
DS_Error_Print ();
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
return rc;
}
/* On rend la structure à nouveau valide */
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Suppression du premier noeud correspondant à une valeur donnée */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Reference_Value : pointeur sur la valeur de référence */
/* (I) Removed_Value : adresse d'un pointeur sur la valeur supprimée */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Remove_I ( NDT_Root * Root, void * Reference_Value, void ** Removed_Value )
{
DST_Status rc;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On vérifie la structure */
Nb_Detected = Nb_Corrected = 0;
rc = DS_DataStruct_Check_L (Root, &Nb_Detected, &Nb_Corrected, DS_stderr);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Value_Remove : unable to check the data structure");
DS_Error_Print ();
return rc;
}
}
/* On rend la structure invalide le temps de la suppression de valeur */
RootDesc->Valid = FALSE;
/* Suppression du noeud correspondant à la valeur de référence */
rc = ND_Value_Remove (Root, Reference_Value, Removed_Value);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Value_Remove : unable to remove a value from the data structure");
DS_Error_Print ();
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
return rc;
}
/* On rend la structure à nouveau valide */
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Désallocation d'une valeur d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Value : pointeur sur la valeur à désallouer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Free_I ( NDT_Root * Root, void * Value )
{
return ND_Value_Free (Root, Value);
}
/*------------------------------------------------------------------------------*/
/* Allocation de mémoire pour une structure de données : */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Size : taille mémoire à allouer */
/* (O) Ptr : adresse du pointeur sur la zone de données allouée */
/*------------------------------------------------------------------------------*/
DST_Status DS_Alloc_I ( NDT_Root * Root, size_t Size, void ** Ptr )
{
return DS_DataStruct_Alloc (Size, Ptr, Root->User);
}
/*------------------------------------------------------------------------------*/
/* Désallocation d'une ressource pour une structure de données : */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Ptr : pointeur sur la zone à désallouer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Free_I ( NDT_Root * Root, void * Ptr )
{
return DS_DataStruct_Free (Ptr, Root->User);
}
/*------------------------------------------------------------------------------*/
/* FONCTIONS OPTIMISATION MOYENNE (DS_MODE = 1) */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Ouverture d'une instance de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Instance : numéro de l'instance de la librairie */
/* (I) Context : nom du contexte */
/* (I) Debug_Mode : mode d'affichage des messages d'erreur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Open_L ( int Instance, const char * Context, DST_Flags Debug_Mode )
{
return DS_Library_Open_I (Instance, Context, Debug_Mode);
}
/*------------------------------------------------------------------------------*/
/* Fermeture de l'instance de la librairie */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Close_L ( void )
{
return DS_Library_Close_I ();
}
/*------------------------------------------------------------------------------*/
/* Définition de la sortie standard des messages d'erreur de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Out : flux de sortie des messages d'erreur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Stderr_Set_L ( FILE * Out )
{
return DS_Library_Stderr_Set_I (Out);
}
/*------------------------------------------------------------------------------*/
/* Création / ouverture d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) DS_Name : nom de la structure */
/* (O) Root : adresse du pointeur sur la racine de la structure */
/* (I) Type : type de la structure de données */
/* (I) Manager_FileName : nom du fichier qui définit les fonctions manager */
/* (I) Segment_Size : taille ds segments du heap sous-jacent */
/* (I) Open_Mode : mode d'ouverture de la structure */
/* (I) Own_Values : indique si la structure possède ses valeurs */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Open_L ( const char * DS_Name, NDT_Root ** Root,\
NDT_DataStruct_Type Type, const char * Manager_FileName, \
size_t Segment_Size, DST_Flags Open_Mode, int Own_Values )
{
return DS_DataStruct_Open_I (DS_Name, Root, Type, Manager_FileName, Segment_Size, Open_Mode, Own_Values);
}
/*------------------------------------------------------------------------------*/
/* Verrouillage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Lock_Mode : type de verrou à poser sur la structure */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Lock_L ( NDT_Root * Root, DST_Flags Lock_Mode, int * Locked )
{
return DS_DataStruct_Lock_I (Root, Lock_Mode, Locked);
}
/*------------------------------------------------------------------------------*/
/* Déverrouillage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Unlock_L ( NDT_Root * Root )
{
return DS_DataStruct_Unlock_I (Root);
}
/*------------------------------------------------------------------------------*/
/* Fermeture d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Close_L ( NDT_Root * Root, DST_Flags Close_Mode )
{
return DS_DataStruct_Close_I (Root, Close_Mode);
}
/*------------------------------------------------------------------------------*/
/* Affiche les informations d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root: pointeur sur la racine de la structure de données */
/* (I) Out : flux de sortie de l'affichage */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Info_Print_L ( NDT_Root * Root, FILE * Out )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
rc = DS_DataStruct_Lock_I (Root, SMD_READ, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Info_Print : unable to lock the data structure for reading");
DS_Error_Print ();
return rc;
}
rc = DS_DataStruct_Info_Print_I (Root, Out);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Réorganisation d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à réorganiser */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Reorg_L ( NDT_Root * Root )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en écriture */
rc = DS_DataStruct_Lock_I (Root, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Reorg : unable to lock the data structure for writing");
DS_Error_Print ();
return rc;
}
rc = DS_DataStruct_Reorg_I (Root);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Parcours de tous les noeuds d'une structure de données et exécution d'une */
/* commande sur chacun d'eux */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à parcourir */
/* (I) Command : commande à exécuter sur chaque noeud traversé */
/* (I) Data : pointeur de données utilisateur */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Traverse_L ( NDT_Root * Root, NDT_Command Command, void * Data )
{
DST_Status rc;
SMT_Flags Lock_Mode;
int Locked;
/* Définition du mode de verrouillage de la data structure selon le type de commande */
switch ((int)Command)
{
case NDD_CMD_PRINT_VALUE:
Lock_Mode = SMD_READ;
break;
case NDD_CMD_DELETE_VALUE:
default:
Lock_Mode = SMD_WRITE;
break;
}
/* Verrouillage de la data structure */
rc = DS_DataStruct_Lock_I (Root, Lock_Mode, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Traverse : unable to lock the data structure for %s",
Lock_Mode == SMD_WRITE ? "writing" : "reading");
DS_Error_Print ();
return rc;
}
rc = DS_DataStruct_Traverse_I (Root, Command, Data);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Conversion d'une structure de données d'un type en un autre */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Target_Type : type de structure cible */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Convert_L ( NDT_Root * Root, NDT_DataStruct_Type Target_Type )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en écriture */
rc = DS_DataStruct_Lock_I (Root, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Convert : unable to lock the data structure for writing");
DS_Error_Print ();
return rc;
}
rc = DS_DataStruct_Convert_I (Root, Target_Type);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Affichage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à afficher */
/* (I) Out : flux de sortie */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Print_L ( NDT_Root * Root, FILE * Out )
{
return DS_DataStruct_Traverse_L (Root, NDD_CMD_PRINT_VALUE, Out);
}
/*------------------------------------------------------------------------------*/
/* Fonction de vérification / réparation d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (O) Nb_Detected : pointeur sur le nombre d'erreurs détectées */
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrigées */
/* (I) Out : flux de sortie du rapport */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Check_L ( NDT_Root * Root, int * Nb_Detected, int * Nb_Corrected, FILE * Out )
{
return DS_DataStruct_Check_I (Root, Nb_Detected, Nb_Corrected, Out);
}
/*------------------------------------------------------------------------------*/
/* Affiche la structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Out : flux de sortie */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Dump_L ( NDT_Root * Root, FILE * Out )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
rc = DS_DataStruct_Lock_I (Root, SMD_READ, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Dump : unable to lock the data structure for reading");
DS_Error_Print ();
return rc;
}
rc = DS_DataStruct_Dump_I (Root, Out);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Récupération du premier noeud d'une structure */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine dont on cherche le premier noeud */
/* (O) Node : pointeur sur le noeud à récupérer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_First_Get_L ( NDT_Root * Root, NDT_Node ** Node )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
rc = DS_DataStruct_Lock_I (Root, SMD_READ, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_First_Get : unable to lock the data structure for reading");
DS_Error_Print ();
return rc;
}
rc = DS_Node_First_Get_I (Root, Node);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Récupération du dernier noeud d'une structure */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine dont on cherche le dernier noeud */
/* (O) Node : pointeur sur le noeud à récupérer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Last_Get_L ( NDT_Root * Root, NDT_Node ** Node )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
rc = DS_DataStruct_Lock_I (Root, SMD_READ, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Last_Get : unable to lock the data structure for reading");
DS_Error_Print ();
return rc;
}
rc = DS_Node_Last_Get_I (Root, Node);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Récupération du noeud suivant */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le suivant */
/* (O) Next_Node : pointeur sur le noeud suivant */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Next_Get_L ( NDT_Node * Node, NDT_Node ** Next_Node )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
rc = DS_DataStruct_Lock_I (Node->Root, SMD_READ, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Next_Get : unable to lock the data structure for reading");
DS_Error_Print ();
return rc;
}
rc = DS_Node_Next_Get_I (Node, Next_Node);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Node->Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Récupération du noeud précédant */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le précédant */
/* (O) Prev_Node : pointeur sur le noeud précédant */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Previous_Get_L ( NDT_Node * Node, NDT_Node ** Prev_Node )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
rc = DS_DataStruct_Lock_I (Node->Root, SMD_READ, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Previous_Get : unable to lock the data structure for reading");
DS_Error_Print ();
return rc;
}
rc = DS_Node_Previous_Get_I (Node, Prev_Node);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Node->Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Ajout d'un noeud à une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Node : pointeur sur le noeud à ajouter */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Add_L ( NDT_Root * Root, NDT_Node * Node )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en écriture */
rc = DS_DataStruct_Lock_I (Root, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Add : unable to lock the data structure for writing");
DS_Error_Print ();
return rc;
}
rc = DS_Node_Add_I (Root, Node);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Suppression d'un noeud dans une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud à supprimer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Remove_L ( NDT_Node * Node )
{
DST_Status rc;
int Locked;
NDT_Root * Root = Node->Root;
/* Verrouillage de la data structure en écriture */
rc = DS_DataStruct_Lock_I (Root, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Remove : unable to lock the data structure for writing");
DS_Error_Print ();
return rc;
}
rc = DS_Node_Remove_I (Node);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Recherche un noeud dans un arbre et retourne le pointeur sur le noeud */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de l'abre */
/* (O) Node : adresse du pointeur sur le noeud à récuperer */
/* (I) Value : pointeur sur la valeur à rechercher */
/* (I) Data : pointeur de données */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Find_L ( NDT_Root * Root, NDT_Node ** Node, void * Value, void * Data )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
rc = DS_DataStruct_Lock_I (Root, SMD_READ, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Node_Find : unable to lock the data structure for reading");
DS_Error_Print ();
return rc;
}
rc = DS_Node_Find_I (Root, Node, Value, Data);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Allocation d'une valeur d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (O) Value : adresse d'un pointeur sur la valeur à allouer */
/* (I) ... : arguments relatifs à l'allocation de la valeur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Alloc_L ( NDT_Root * Root, void ** Value, ... )
{
DST_Status rc;
va_list Args;
/* Récupération des arguments pour l'allocation de la valeur */
va_start (Args, Value);
/* Appel du manager */
rc = ND_Manager_Exec (Root->Manager, NDD_CMD_MAKE_VALUE, Root, Value, Args);
va_end (Args);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Ajout d'une valeur à une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Value : pointeur sur la valeur à ajouter à la structure de données */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Add_L ( NDT_Root * Root, void * Value )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en écriture */
rc = DS_DataStruct_Lock_I (Root, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Value_Add : unable to lock the data structure for writing");
DS_Error_Print ();
return rc;
}
/* Ajout de la valeur */
rc = DS_Value_Add_I (Root, Value);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Suppression du premier noeud correspondant à une valeur donnée */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Reference_Value : pointeur sur la valeur de référence */
/* (I) Removed_Value : adresse d'un pointeur sur la valeur supprimée */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Remove_L ( NDT_Root * Root, void * Reference_Value, void ** Removed_Value )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en écriture */
rc = DS_DataStruct_Lock_I (Root, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_Value_Remove : unable to lock the data structure for writing");
DS_Error_Print ();
return rc;
}
rc = DS_Value_Remove_I (Root, Reference_Value, Removed_Value);
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Désallocation d'une valeur d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Value : pointeur sur la valeur à désallouer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Free_L ( NDT_Root * Root, void * Value )
{
return ND_Value_Free (Root, Value);
}
/*------------------------------------------------------------------------------*/
/* Allocation de mémoire pour une structure de données : */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Size : taille mémoire à allouer */
/* (O) Ptr : adresse du pointeur sur la zone de données allouée */
/*------------------------------------------------------------------------------*/
DST_Status DS_Alloc_L ( NDT_Root * Root, size_t Size, void ** Ptr )
{
return DS_DataStruct_Alloc (Size, Ptr, Root->User);
}
/*------------------------------------------------------------------------------*/
/* Désallocation d'une ressource pour une structure de données : */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Ptr : pointeur sur la zone à désallouer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Free_L ( NDT_Root * Root, void * Ptr )
{
return DS_DataStruct_Free (Ptr, Root->User);
}
/*------------------------------------------------------------------------------*/
/* FONCTIONS SECURISEES (DS_MODE = 0) */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Ouverture d'une instance de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Instance : numéro de l'instance de la librairie */
/* (I) Context : nom du contexte */
/* (I) Debug_Mode : mode d'affichage des messages d'erreur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Open_CL ( int Instance, const char * Context, DST_Flags Debug_Mode )
{
return DS_Library_Open_I (Instance, Context, Debug_Mode );
}
/*------------------------------------------------------------------------------*/
/* Fermeture de l'instance de la librairie */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Close_CL ( void )
{
return DS_Library_Close_I ();
}
/*------------------------------------------------------------------------------*/
/* Définition de la sortie standard des messages d'erreur de la librairie */
/*------------------------------------------------------------------------------*/
/* (I) Out : flux de sortie des messages d'erreur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Library_Stderr_Set_CL ( FILE * Out )
{
return DS_Library_Stderr_Set_I (Out);
}
/*------------------------------------------------------------------------------*/
/* Création / ouverture d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) DS_Name : nom de la structure */
/* (O) Root : adresse du pointeur sur la racine de la structure */
/* (I) Type : type de la structure de données */
/* (I) Manager_FileName : nom du fichier qui définit les fonctions manager */
/* (I) Segment_Size : taille ds segments du heap sous-jacent */
/* (I) Open_Mode : mode d'ouverture de la structure */
/* (I) Own_Values : indique si la structure possède ses valeurs */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Open_CL ( const char * DS_Name, NDT_Root ** Root,\
NDT_DataStruct_Type Type, const char * Manager_FileName, \
size_t Segment_Size, DST_Flags Open_Mode, int Own_Values )
{
if (!DS_Name)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the data structure name is undefined");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the root address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (Open_Mode & (DSD_CREATE | DSD_NEW) && !Manager_FileName)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the manager file name must be defined in creation mode");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Open_I (DS_Name, Root, Type, Manager_FileName, Segment_Size, Open_Mode, Own_Values);
}
/*------------------------------------------------------------------------------*/
/* Verrouillage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Lock_Mode : type de verrou à poser sur la structure */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Lock_CL ( NDT_Root * Root, DST_Flags Lock_Mode, int * Locked )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Lock : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Locked)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Lock : the lock indicator address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Lock_I (Root, Lock_Mode, Locked);
}
/*------------------------------------------------------------------------------*/
/* Déverrouillage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Unlock_CL ( NDT_Root * Root )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Unlock : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Unlock_I (Root);
}
/*------------------------------------------------------------------------------*/
/* Fermeture d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Close_CL ( NDT_Root * Root, DST_Flags Close_Mode )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Close_I (Root, Close_Mode);
}
/*------------------------------------------------------------------------------*/
/* Affiche les informations d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root: pointeur sur la racine de la structure de données */
/* (I) Out : flux de sortie de l'affichage */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Info_Print_CL ( NDT_Root * Root, FILE * Out )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Info_Print : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Out)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Info_Print : the out stream is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Info_Print_L (Root, Out);
}
/*------------------------------------------------------------------------------*/
/* Réorganisation d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à réorganiser */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Reorg_CL ( NDT_Root * Root )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Reorg : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Reorg_L (Root);
}
/*------------------------------------------------------------------------------*/
/* Parcours de tous les noeuds d'une structure de données et exécution d'une */
/* commande sur chacun d'eux */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à parcourir */
/* (I) Command : commande à exécuter sur chaque noeud traversé */
/* (I) Data : pointeur de données utilisateur */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Traverse_CL ( NDT_Root * Root, NDT_Command Command, void * Data )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Traverse : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Traverse_L (Root, Command, Data);
}
/*------------------------------------------------------------------------------*/
/* Conversion d'une structure de données d'un type en un autre */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Target_Type : type de structure cible */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Convert_CL ( NDT_Root * Root, NDT_DataStruct_Type Target_Type )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Convert : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Convert_L (Root, Target_Type);
}
/*------------------------------------------------------------------------------*/
/* Affichage d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à afficher */
/* (I) Out : flux de sortie */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Print_CL ( NDT_Root * Root, FILE * Out )
{
return DS_DataStruct_Traverse_CL (Root, NDD_CMD_PRINT_VALUE, Out);
}
/*------------------------------------------------------------------------------*/
/* Fonction de vérification / réparation d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (O) Nb_Detected : pointeur sur le nombre d'erreurs détectées */
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrigées */
/* (I) Out : flux de sortie du rapport */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Check_CL ( NDT_Root * Root, int * Nb_Detected, int * Nb_Corrected, FILE * Out )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Nb_Detected || !Nb_Corrected)
{
sprintf (DS_Error_Msg, "Error : one of the error number address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Out)
{
sprintf (DS_Error_Msg, "Error : the out stream is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Check_I (Root, Nb_Detected, Nb_Corrected, Out);
}
/*------------------------------------------------------------------------------*/
/* Affiche la structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Out : flux de sortie */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Dump_CL ( NDT_Root * Root, FILE * Out )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Dump : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Out)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Dump : the out stream is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_DataStruct_Dump_L (Root, Out);
}
/*------------------------------------------------------------------------------*/
/* Récupération du premier noeud d'une structure */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine dont on cherche le premier noeud */
/* (O) First_Node : adresse d'un pointeur sur le premier noeud à récupérer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_First_Get_CL ( NDT_Root * Root, NDT_Node ** First_Node )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Node_First_Get : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!First_Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_First_Get : the first node address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Node_First_Get_L (Root, First_Node);
}
/*------------------------------------------------------------------------------*/
/* Récupération du dernier noeud d'une structure */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la data structure */
/* (O) Last_Node : adresse d'un pointeur sur le dernier noeud */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Last_Get_CL ( NDT_Root * Root, NDT_Node ** Last_Node )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Node_Last_Get : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Last_Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_Last_Get : the last node address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Node_Last_Get_L (Root, Last_Node);
}
/*------------------------------------------------------------------------------*/
/* Récupération du noeud suivant */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le suivant */
/* (O) Next_Node : pointeur sur le noeud suivant */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Next_Get_CL ( NDT_Node * Node, NDT_Node ** Next_Node )
{
if (!Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_Next_Get : the node is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Next_Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_Next_Get : the next node address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Node_Next_Get_L (Node, Next_Node);
}
/*------------------------------------------------------------------------------*/
/* Récupération du noeud précédant */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le précédant */
/* (O) Prev_Node : pointeur sur le noeud précédant */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Previous_Get_CL ( NDT_Node * Node, NDT_Node ** Prev_Node )
{
if (!Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_Previous_Get : the node is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Prev_Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_Previous_Get : the previous node address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Node_Previous_Get_L (Node, Prev_Node);
}
/*------------------------------------------------------------------------------*/
/* Ajout d'un noeud à une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Node : pointeur sur le noeud à ajouter */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Add_CL ( NDT_Root * Root, NDT_Node * Node )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Node_Add : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_Add : the node is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Node_Add_L (Root, Node);
}
/*------------------------------------------------------------------------------*/
/* Suppression d'un noeud dans une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud à supprimer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Remove_CL ( NDT_Node * Node )
{
if (!Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_Remove : the node is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Node_Remove_L (Node);
}
/*------------------------------------------------------------------------------*/
/* Recherche un noeud dans un arbre et retourne le pointeur sur le noeud */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de l'abre */
/* (O) Node : adresse du pointeur sur le noeud à récuperer */
/* (I) Value : pointeur sur la valeur à rechercher */
/* (I) Data : pointeur de données */
/*------------------------------------------------------------------------------*/
DST_Status DS_Node_Find_CL ( NDT_Root * Root, NDT_Node ** Node, void * Value, void * Data )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Node_Find : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Node)
{
sprintf (DS_Error_Msg, "Error DS_Node_Find : the node address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Value)
{
sprintf (DS_Error_Msg, "Error DS_Node_Find : the value is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Node_Find_L (Root, Node, Value, Data);
}
/*------------------------------------------------------------------------------*/
/* Allocation d'une valeur d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (O) Value : adresse d'un pointeur sur la valeur à allouer */
/* (I) ... : arguments relatifs à l'allocation de la valeur */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Alloc_CL ( NDT_Root * Root, void ** Value, ... )
{
DST_Status rc;
va_list Args;
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Value_Alloc : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Value)
{
sprintf (DS_Error_Msg, "Error DS_Value_Alloc : the value address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
/* Récupération des arguments pour l'allocation de la valeur */
va_start (Args, Value);
/* Appel du manager */
rc = ND_Manager_Exec (Root->Manager, NDD_CMD_MAKE_VALUE, Root, Value, Args);
va_end (Args);
return rc;
}
/*------------------------------------------------------------------------------*/
/* Ajout d'une valeur à une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Value : pointeur sur la valeur à ajouter à la structure de données */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Add_CL ( NDT_Root * Root, void * Value )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Value_Add : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Value)
{
sprintf (DS_Error_Msg, "Error DS_Value_Add : the value is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Value_Add_L (Root, Value);
}
/*------------------------------------------------------------------------------*/
/* Suppression du premier noeud correspondant à une valeur donnée */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Reference_Value : pointeur sur la valeur de référence */
/* (I) Removed_Value : adresse d'un pointeur sur la valeur supprimée */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Remove_CL ( NDT_Root * Root, void * Reference_Value, void ** Removed_Value )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Value_Remove : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Reference_Value)
{
sprintf (DS_Error_Msg, "Error DS_Value_Remove : the reference value is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Removed_Value)
{
sprintf (DS_Error_Msg, "Error DS_Value_Remove : the removed value adress is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Value_Remove_L (Root, Reference_Value, Removed_Value);
}
/*------------------------------------------------------------------------------*/
/* Désallocation d'une valeur d'une structure de données */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Value : pointeur sur la valeur à désallouer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Value_Free_CL ( NDT_Root * Root, void * Value )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Value_Free : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Value)
{
sprintf (DS_Error_Msg, "Error DS_Value_Free : the value is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Value_Free_L (Root, Value);
}
/*------------------------------------------------------------------------------*/
/* Allocation de mémoire pour une structure de données : */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Size : taille mémoire à allouer */
/* (O) Ptr : adresse du pointeur sur la zone de données allouée */
/*------------------------------------------------------------------------------*/
DST_Status DS_Alloc_CL ( NDT_Root * Root, size_t Size, void ** Ptr )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Alloc : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (Size <= 0)
{
sprintf (DS_Error_Msg, "Error DS_Alloc : the allocation size must be > 0");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Ptr)
{
sprintf (DS_Error_Msg, "Error DS_Alloc : the data pointer address is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Alloc_L (Root, Size, Ptr);
}
/*------------------------------------------------------------------------------*/
/* Désallocation d'une ressource pour une structure de données : */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Ptr : pointeur sur la zone à désallouer */
/*------------------------------------------------------------------------------*/
DST_Status DS_Free_CL ( NDT_Root * Root, void * Ptr )
{
if (!Root)
{
sprintf (DS_Error_Msg, "Error DS_Free : the structure root is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
if (!Ptr)
{
sprintf (DS_Error_Msg, "Error DS_Free : the data pointer is null");
DS_Error_Print ();
return DSS_ERRAPI;
}
return DS_Free_L (Root, Ptr);
}
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* FONCTIONS PRIVEES */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Teste si une data structure a déjà été ouverte par le processus courant : */
/*------------------------------------------------------------------------------*/
/* (I) DS_Name : nom de la data structure */
/* (O) Root : adresse du pointeur sur la racine de la structure */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_IsOpen ( const char * DS_Name, NDT_Root ** Root )
{
DST_Status rc;
DST_DataStruct To_Find;
NDT_Node * Node;
To_Find.Name = DS_Name;
rc = ND_Node_Find (OpenedDS_List, &Node, &To_Find, NULL);
if (DS_ERROR(rc)) return rc;
if (rc != NDS_OK) return DSS_NO;
*Root = ((DST_DataStruct *)(Node->Value))->Root;
return DSS_YES;
}
/*------------------------------------------------------------------------------*/
/* Fonction d'allocation attachée à une structure de données : */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Alloc ( size_t Size, void ** Ptr, void * Data )
{
DST_Status rc;
SMT_Heap * Heap;
int Locked;
DST_RootDesc * RootDesc = (DST_RootDesc *)Data;
char * Heap_Name = RootDesc->Heap_Name;
rc = SM_Heap_IsOpen (Heap_Name, &Heap);
if (rc != SMS_YES)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Alloc : the data structure heap \"%s\" is not open", Heap_Name);
DS_Error_Print ();
return rc;
}
/* Verrouillage du heap en écriture */
rc = SM_Heap_Lock (Heap, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Alloc : unable to lock the data structure heap \"%s\" for writing", Heap_Name);
DS_Error_Print ();
return rc;
}
/* Allocation du chunk */
rc = SM_Chunk_Alloc (Heap, Size, Ptr);
if (rc != SMS_OK)
{
if (Locked == TRUE) SM_Heap_Unlock (Heap);
return rc;
}
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) SM_Heap_Unlock (Heap);
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Fonction de désallocation attachée à une structure de données : */
/*------------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Free ( void * Ptr, void * Data )
{
DST_Status rc;
SMT_Heap * Heap;
int Locked;
DST_RootDesc * RootDesc = (DST_RootDesc *)Data;
char * Heap_Name = RootDesc->Heap_Name;
rc = SM_Heap_IsOpen (Heap_Name, &Heap);
if (rc != SMS_YES)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Free : the data structure heap \"%s\" is not open", Heap_Name);
DS_Error_Print ();
return rc;
}
/* Verrouillage de la data structure en écriture */
rc = SM_Heap_Lock (Heap, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Free : unable to lock the data structure heap \"%s\" for writing", Heap_Name);
DS_Error_Print ();
return rc;
}
/* Désallocation du chunk */
rc = SM_Chunk_Free (Heap, Ptr);
if (rc != SMS_OK)
{
if (Locked == TRUE) SM_Heap_Unlock (Heap);
return rc;
}
/* Déverrouillage de la data structure si besoin */
if (Locked == TRUE) SM_Heap_Unlock (Heap);
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Routine d'affichage d'un message d'erreur */
/*------------------------------------------------------------------------------*/
void DS_Error_Print ( void )
{
if (DS_stderr) fprintf (DS_stderr, "%s\n", DS_Error_Msg);
}
/*------------------------------------------------------------------------------*/
/* Pour préfixer les noms de heap avec l'identifiant de la librairie */
/*------------------------------------------------------------------------------*/
static char * DS_Name_Prefix ( const char * Name )
{
static char Prefixed [256];
sprintf (Prefixed, "%s/%s", DS_PREFIX, Name);
return Prefixed;
}
/*------------------------------------------------------------------------------*/
/* Création d'un sémaphore pour gérer l'ouverture d'une data structure */
/*------------------------------------------------------------------------------*/
DST_Status DS_Semaphore_Create ( NDT_Root * Root )
{
union semun Sem_Ctl;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* Création du sémaphore */
RootDesc->OpenSemID = semget (IPC_PRIVATE, 1, 0777|IPC_CREAT|IPC_EXCL);
if (RootDesc->OpenSemID == -1)
{
switch (errno)
{
case ENOMEM:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Create : the amount of memory is not sufficient to create a new semaphore");
break;
case ENOSPC:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Create : the number of semaphores exceeds the system-imposed limit");
break;
default:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Create : unknown error (%d) while creating a semaphore", errno);
break;
}
DS_Error_Print ();
return DSS_ERRSEM;
}
/* Initialisation du sémaphore à 0 */
Sem_Ctl.val = 0;
if (semctl (RootDesc->OpenSemID, 0, SETVAL, Sem_Ctl))
{
sprintf (DS_Error_Msg, "Error DS_Semaphore_Create : unable to initialize the value of the semaphore %x", RootDesc->OpenSemID);
DS_Error_Print ();
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl);
return DSS_ERRSEM;
}
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Opération sur un sémaphore */
/*------------------------------------------------------------------------------*/
DST_Status DS_Semaphore_Operate (int SemID, struct sembuf * Operations, unsigned int Nb_Oper)
{
if (semop (SemID, Operations, Nb_Oper) == -1)
{
switch (errno)
{
case EAGAIN:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : the operation would result in suspension of the calling process but the operations have been defined in no wait mode");
break;
case EACCES:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : current process is not allowed to operate on semaphore %x", SemID);
break;
case EIDRM:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : semaphore %x does not exist", SemID);
break;
case EINTR:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : a signal was received while operating on semaphore %x", SemID);
return DSS_ERRSIG;
case EINVAL:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : the semaphore key %x is incorrect or the number of operations which can be done in UNDO mode exceeds the system-imposed limit", SemID);
break;
case ENOSPC:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : the maximum number of process which can operate on semaphore in UNDO mode has been reached");
break;
case ERANGE:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate: the value of semaphore %x has reached the system-imposed limit", SemID);
break;
default:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : unknown error %d while operating on semaphore %x", errno, SemID);
break;
}
DS_Error_Print ();
return DSS_ERRSEM;
}
return DSS_OK;
}
/*------------------------------------------------------------------------------*/
/* Fonction manager de la liste des DS ouvertes */
/*------------------------------------------------------------------------------*/
NDT_Status DS_OpenedDS_List_Manager ( va_list Args )
{
NDT_Command Command = (NDT_Command) va_arg (Args, NDT_Command);
if (Command == NDD_CMD_COMP_VALUE)
{
DST_DataStruct * DataStruct1 = (DST_DataStruct *) va_arg (Args, void *);
DST_DataStruct * DataStruct2 = (DST_DataStruct *) va_arg (Args, void *);
long comp;
va_end (Args);
comp = strcmp (DataStruct1->Name, DataStruct2->Name);
if (comp < 0) return NDS_LOWER;
if (comp > 0) return NDS_GREATER;
return NDS_EQUAL;
}
if (Command == NDD_CMD_DELETE_VALUE)
{
NDT_Root * Root = va_arg (Args, NDT_Root *);
DST_DataStruct * DataStruct = (DST_DataStruct *) va_arg (Args, void *);
free (DataStruct->Name);
free (DataStruct);
}
return NDS_OK;
}