libdatastr/lib/libdatastr.c

3200 lines
111 KiB
C
Raw Normal View History

/*----------------------------------------------------------------------------*/
/* libdatastr.c */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* This file is part of LibDataStr. */
/* */
/* LibDataStr is free software: you can redistribute it and/or modify it */
/* under the terms of the GNU Lesser General Public License as published */
/* by the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* LibDataStr is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public */
/* License along with LibDataStr. If not, see */
/* <https://www.gnu.org/licenses/>. */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Includes */
/*----------------------------------------------------------------------------*/
#define _LIBDATASTR_C_
2000-07-28 17:30:55 +02:00
/* 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<75>ro de l'instance de la librairie */
/* (I) Context : nom du contexte */
/* (I) Debug_Mode : mode d'affichage des messages d'erreur */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
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<EFBFBD>re ouverture de la librairie LIBDATASTR,
on cr<EFBFBD>e une structure locale permettant de r<EFBFBD>f<EFBFBD>rencer
les data structures ouvertes.
*/
2000-07-28 17:30:55 +02:00
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 */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
DST_Status DS_Library_Close_I ( void )
{
DST_Status rc;
/*
A la derni<EFBFBD>re fermeture de la librairie LIBDATASTR, on d<EFBFBD>truit
la structure locale qui r<EFBFBD>f<EFBFBD>rence les data structures ouvertes.
*/
2000-07-28 17:30:55 +02:00
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 */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
DST_Status DS_Library_Stderr_Set_I ( FILE * Out )
{
DS_stderr = Out;
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Cr<43>ation / ouverture d'une structure de donn<6E>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<6E>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<73>de ses valeurs */
/*----------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
2000-07-28 17:30:55 +02:00
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<6E> et de ce qui existe d<>j<EFBFBD> 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<43>ation d'une nouvelle data structure dans un heap existant -------------*/
2000-07-28 17:30:55 +02:00
/* Ouverture du heap en <20>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<43>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<72>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 <20> la racine */
(*Root)->User = RootDesc;
/* Pour une telle data structure, on ne cr<63>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 ------------------*/
2000-07-28 17:30:55 +02:00
/* Si la structure a d<>j<EFBFBD> <20>t<EFBFBD> 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<63>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<43>ation d'une nouvelle structure de donn<6E>es dans un nouveau heap -----------------*/
2000-07-28 17:30:55 +02:00
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<43>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<43>ation de la structure de donn<6E>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<72>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 <20> la racine */
(*Root)->User = RootDesc;
/* On cr<63>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<63>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 <20> 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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Lock_Mode : type de verrou <20> poser sur la structure */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<72>chissement des segments) + verrouillage */
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/* {
2000-07-28 17:30:55 +02:00
/* La data structure est-elle propri<72>taire du heap sous-jacent ? */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Heap_Owner == TRUE)
{
/* On v<>rifie qu'aucun autre processus n'a ouvert la data structure */
/*
2000-07-28 17:30:55 +02:00
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<69>es les unes apr<70>s les autres) */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl);
/* On supprime maintenant le heap */
/*
2000-07-28 17:30:55 +02:00
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<EFBFBD> la data structure n'est pas propri<EFBFBD>taire du heap sous-jacent,
on ne peut pas garantir qu'aucun autre processus ne l'a ouverte.
On la supprime donc sans contr<EFBFBD>le.
*/
/*
2000-07-28 17:30:55 +02:00
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 */
/* {
2000-07-28 17:30:55 +02:00
/* On d<>cr<63>mente le s<>maphore qui compte le nombre de processus ayant ouvert la data structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root: pointeur sur la racine de la structure de donn<6E>es */
/* (I) Out : flux de sortie de l'affichage */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> r<>organiser */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = FALSE;
/* R<>organisation de la node structure */
/*
2000-07-28 17:30:55 +02:00
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 <20> nouveau valide */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Parcours de tous les noeuds d'une structure de donn<6E>es et ex<65>cution d'une */
/* commande sur chacun d'eux */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> parcourir*/
/* (I) Command : commande <20> ex<65>cuter sur chaque noeud travers<72> */
/* (I) Data : pointeur de donn<6E>es utilisateur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 <20>ventuellement la structure invalide le temps de sa travers<72>e */
/*
2000-07-28 17:30:55 +02:00
switch ((int)Command)
{
case NDD_CMD_PRINT_VALUE:
break;
default:
RootDesc->Valid = FALSE;
break;
}
/* Travers<72>e de la node structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Conversion d'une structure de donn<6E>es d'un type en un autre */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Target_Type : type de structure cible */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = FALSE;
/* Conversion de la node structure */
/*
2000-07-28 17:30:55 +02:00
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 <20> nouveau valide */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Affichage d'une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> afficher */
/* (I) Out : flux de sortie */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (O) Nb_Detected : pointeur sur le nombre d'erreurs d<>tect<63>es */
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrig<69>es */
/* (I) Out : flux de sortie du rapport */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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'<27>tat de verrouillage pr<70>c<EFBFBD>dent */
/*
2000-07-28 17:30:55 +02:00
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 <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 <20> la data structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (*Nb_Corrected == *Nb_Detected) RootDesc->Valid = TRUE;
else RootDesc->Valid = FALSE;
/* Retour au mode de verrouillage pr<70>c<EFBFBD>dent */
/*
2000-07-28 17:30:55 +02:00
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<6F>dure de v<>rification */
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Out : flux de sortie */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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<75>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 <20> r<>cup<75>rer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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<75>ration du premier noeud */
/*
2000-07-28 17:30:55 +02:00
rc = ND_Node_First_Get (Root, Node);
return rc;
}
/*----------------------------------------------------------------------------*/
/* R<>cup<75>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 <20> r<>cup<75>rer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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<75>ration du dernier noeud */
/*
2000-07-28 17:30:55 +02:00
rc = ND_Node_Last_Get (Root, Node);
return rc;
}
/*----------------------------------------------------------------------------*/
/* R<>cup<75>ration du noeud suivant */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le suivant */
/* (O) Next_Node : pointeur sur le noeud suivant */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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<75>ration du noeud suivant */
/*
2000-07-28 17:30:55 +02:00
rc = ND_Node_Next_Get (Node, Next_Node);
return rc;
}
/*----------------------------------------------------------------------------*/
/* R<>cup<75>ration du noeud pr<70>c<EFBFBD>dant */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le pr<70>c<EFBFBD>dant */
/* (O) Prev_Node : pointeur sur le noeud pr<70>c<EFBFBD>dant */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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<75>ration du noeud pr<70>c<EFBFBD>dent */
/*
2000-07-28 17:30:55 +02:00
rc = ND_Node_Previous_Get (Node, Prev_Node);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Ajout d'un noeud <20> une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Node : pointeur sur le noeud <20> ajouter */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = FALSE;
/* Ajout du noeud */
/*
2000-07-28 17:30:55 +02:00
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 <20> nouveau valide */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Suppression d'un noeud dans une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud <20> supprimer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = FALSE;
/* Suppression dans la node structure */
/*
2000-07-28 17:30:55 +02:00
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 <20> nouveau valide */
/*
2000-07-28 17:30:55 +02:00
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 <20> r<>cuperer */
/* (I) Value : pointeur sur la valeur <20> rechercher */
/* (I) Data : pointeur de donn<6E>es */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
rc = ND_Node_Find (Root, Node, Value, Data);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Allocation d'une valeur d'une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (O) Value : adresse d'un pointeur sur la valeur <20> allouer */
/* (I) ... : arguments relatifs <20> l'allocation de la valeur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Value_Alloc_I ( NDT_Root * Root, void ** Value, ... )
{
DST_Status rc;
va_list Args;
/* R<>cup<75>ration des arguments pour l'allocation de la valeur */
/*
2000-07-28 17:30:55 +02:00
va_start (Args, Value);
/* Appel du manager */
/*
2000-07-28 17:30:55 +02:00
rc = ND_Manager_Exec (Root->Manager, NDD_CMD_MAKE_VALUE, Root, Value, Args);
va_end (Args);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Ajout d'une valeur <20> une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Value : pointeur sur la valeur <20> ajouter <20> la structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = FALSE;
/* Ajout de la valeur */
/*
2000-07-28 17:30:55 +02:00
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 <20> nouveau valide */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Suppression du premier noeud correspondant <20> une valeur donn<6E>e */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Reference_Value : pointeur sur la valeur de r<>f<EFBFBD>rence */
/* (I) Removed_Value : adresse d'un pointeur sur la valeur supprim<69>e */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (RootDesc->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
/* On v<>rifie la structure */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = FALSE;
/* Suppression du noeud correspondant <20> la valeur de r<>f<EFBFBD>rence */
/*
2000-07-28 17:30:55 +02:00
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 <20> nouveau valide */
/*
2000-07-28 17:30:55 +02:00
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* D<>sallocation d'une valeur d'une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Value : pointeur sur la valeur <20> d<>sallouer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es : */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Size : taille m<>moire <20> allouer */
/* (O) Ptr : adresse du pointeur sur la zone de donn<6E>es allou<6F>e */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es : */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Ptr : pointeur sur la zone <20> d<>sallouer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Free_I ( NDT_Root * Root, void * Ptr )
{
return DS_DataStruct_Free (Ptr, Root->User);
}
/*----------------------------------------------------------------------------*/
/* FONCTIONS OPTIMISATION MOYENNE (DS_MODE = 1) */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/*----------------------------------------------------------------------------*/
/* Ouverture d'une instance de la librairie */
/*----------------------------------------------------------------------------*/
/* (I) Instance : num<75>ro de l'instance de la librairie */
/* (I) Context : nom du contexte */
/* (I) Debug_Mode : mode d'affichage des messages d'erreur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Library_Stderr_Set_L ( FILE * Out )
{
return DS_Library_Stderr_Set_I (Out);
}
/*----------------------------------------------------------------------------*/
/* Cr<43>ation / ouverture d'une structure de donn<6E>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<6E>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<73>de ses valeurs */
/*----------------------------------------------------------------------------*/
/*
DST_Status DS_DataStruct_Open_L ( const char * DS_Name, NDT_Root ** Root, \
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Lock_Mode : type de verrou <20> poser sur la structure */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_DataStruct_Unlock_L ( NDT_Root * Root )
{
return DS_DataStruct_Unlock_I (Root);
}
/*----------------------------------------------------------------------------*/
/* Fermeture d'une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root: pointeur sur la racine de la structure de donn<6E>es */
/* (I) Out : flux de sortie de l'affichage */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_DataStruct_Info_Print_L ( NDT_Root * Root, FILE * Out )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* R<>organisation d'une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> r<>organiser */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_DataStruct_Reorg_L ( NDT_Root * Root )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Parcours de tous les noeuds d'une structure de donn<6E>es et ex<65>cution d'une */
/* commande sur chacun d'eux */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> parcourir*/
/* (I) Command : commande <20> ex<65>cuter sur chaque noeud travers<72> */
/* (I) Data : pointeur de donn<6E>es utilisateur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Conversion d'une structure de donn<6E>es d'un type en un autre */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Target_Type : type de structure cible */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Affichage d'une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> afficher */
/* (I) Out : flux de sortie */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (O) Nb_Detected : pointeur sur le nombre d'erreurs d<>tect<63>es */
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrig<69>es */
/* (I) Out : flux de sortie du rapport */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Out : flux de sortie */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_DataStruct_Dump_L ( NDT_Root * Root, FILE * Out )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en lecture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* R<>cup<75>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 <20> r<>cup<75>rer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* R<>cup<75>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 <20> r<>cup<75>rer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* R<>cup<75>ration du noeud suivant */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le suivant */
/* (O) Next_Node : pointeur sur le noeud suivant */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Node->Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* R<>cup<75>ration du noeud pr<70>c<EFBFBD>dant */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le pr<70>c<EFBFBD>dant */
/* (O) Prev_Node : pointeur sur le noeud pr<70>c<EFBFBD>dant */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Node->Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Ajout d'un noeud <20> une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Node : pointeur sur le noeud <20> ajouter */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Node_Add_L ( NDT_Root * Root, NDT_Node * Node )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Suppression d'un noeud dans une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud <20> supprimer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 <20> r<>cuperer */
/* (I) Value : pointeur sur la valeur <20> rechercher */
/* (I) Data : pointeur de donn<6E>es */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Allocation d'une valeur d'une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (O) Value : adresse d'un pointeur sur la valeur <20> allouer */
/* (I) ... : arguments relatifs <20> l'allocation de la valeur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Value_Alloc_L ( NDT_Root * Root, void ** Value, ... )
{
DST_Status rc;
va_list Args;
/* R<>cup<75>ration des arguments pour l'allocation de la valeur */
/*
2000-07-28 17:30:55 +02:00
va_start (Args, Value);
/* Appel du manager */
/*
2000-07-28 17:30:55 +02:00
rc = ND_Manager_Exec (Root->Manager, NDD_CMD_MAKE_VALUE, Root, Value, Args);
va_end (Args);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Ajout d'une valeur <20> une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Value : pointeur sur la valeur <20> ajouter <20> la structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Value_Add_L ( NDT_Root * Root, void * Value )
{
DST_Status rc;
int Locked;
/* Verrouillage de la data structure en <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
rc = DS_Value_Add_I (Root, Value);
/* D<>verrouillage de la data structure si besoin */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Suppression du premier noeud correspondant <20> une valeur donn<6E>e */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Reference_Value : pointeur sur la valeur de r<>f<EFBFBD>rence */
/* (I) Removed_Value : adresse d'un pointeur sur la valeur supprim<69>e */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* D<>sallocation d'une valeur d'une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Value : pointeur sur la valeur <20> d<>sallouer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es : */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Size : taille m<>moire <20> allouer */
/* (O) Ptr : adresse du pointeur sur la zone de donn<6E>es allou<6F>e */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es : */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Ptr : pointeur sur la zone <20> d<>sallouer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Free_L ( NDT_Root * Root, void * Ptr )
{
return DS_DataStruct_Free (Ptr, Root->User);
}
/*----------------------------------------------------------------------------*/
/* FONCTIONS SECURISEES (DS_MODE = 0) */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/*----------------------------------------------------------------------------*/
/* Ouverture d'une instance de la librairie */
/*----------------------------------------------------------------------------*/
/* (I) Instance : num<75>ro de l'instance de la librairie */
/* (I) Context : nom du contexte */
/* (I) Debug_Mode : mode d'affichage des messages d'erreur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Library_Stderr_Set_CL ( FILE * Out )
{
return DS_Library_Stderr_Set_I (Out);
}
/*----------------------------------------------------------------------------*/
/* Cr<43>ation / ouverture d'une structure de donn<6E>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<6E>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<73>de ses valeurs */
/*----------------------------------------------------------------------------*/
/*
DST_Status DS_DataStruct_Open_CL ( const char * DS_Name, NDT_Root ** Root, \
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Lock_Mode : type de verrou <20> poser sur la structure */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root: pointeur sur la racine de la structure de donn<6E>es */
/* (I) Out : flux de sortie de l'affichage */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> r<>organiser */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es et ex<65>cution d'une */
/* commande sur chacun d'eux */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> parcourir*/
/* (I) Command : commande <20> ex<65>cuter sur chaque noeud travers<72> */
/* (I) Data : pointeur de donn<6E>es utilisateur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es d'un type en un autre */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Target_Type : type de structure cible */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es <20> afficher */
/* (I) Out : flux de sortie */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (O) Nb_Detected : pointeur sur le nombre d'erreurs d<>tect<63>es */
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrig<69>es */
/* (I) Out : flux de sortie du rapport */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Out : flux de sortie */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<75>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 <20> r<>cup<75>rer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<75>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 */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<75>ration du noeud suivant */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le suivant */
/* (O) Next_Node : pointeur sur le noeud suivant */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<75>ration du noeud pr<70>c<EFBFBD>dant */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud dont on cherche le pr<70>c<EFBFBD>dant */
/* (O) Prev_Node : pointeur sur le noeud pr<70>c<EFBFBD>dant */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 <20> une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Node : pointeur sur le noeud <20> ajouter */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud <20> supprimer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 <20> r<>cuperer */
/* (I) Value : pointeur sur la valeur <20> rechercher */
/* (I) Data : pointeur de donn<6E>es */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (O) Value : adresse d'un pointeur sur la valeur <20> allouer */
/* (I) ... : arguments relatifs <20> l'allocation de la valeur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<75>ration des arguments pour l'allocation de la valeur */
/*
2000-07-28 17:30:55 +02:00
va_start (Args, Value);
/* Appel du manager */
/*
2000-07-28 17:30:55 +02:00
rc = ND_Manager_Exec (Root->Manager, NDD_CMD_MAKE_VALUE, Root, Value, Args);
va_end (Args);
return rc;
}
/*----------------------------------------------------------------------------*/
/* Ajout d'une valeur <20> une structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Value : pointeur sur la valeur <20> ajouter <20> la structure de donn<6E>es */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 <20> une valeur donn<6E>e */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Reference_Value : pointeur sur la valeur de r<>f<EFBFBD>rence */
/* (I) Removed_Value : adresse d'un pointeur sur la valeur supprim<69>e */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Value : pointeur sur la valeur <20> d<>sallouer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es : */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Size : taille m<>moire <20> allouer */
/* (O) Ptr : adresse du pointeur sur la zone de donn<6E>es allou<6F>e */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<6E>es : */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de donn<6E>es */
/* (I) Ptr : pointeur sur la zone <20> d<>sallouer */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
2000-07-28 17:30:55 +02:00
/*----------------------------------------------------------------------------*/
/* Teste si une data structure a d<>j<EFBFBD> <20>t<EFBFBD> ouverte par le processus courant : */
/*----------------------------------------------------------------------------*/
/* (I) DS_Name : nom de la data structure */
/* (O) Root : adresse du pointeur sur la racine de la structure */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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<63>e <20> une structure de donn<6E>es : */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) SM_Heap_Unlock (Heap);
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Fonction de d<>sallocation attach<63>e <20> une structure de donn<6E>es : */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 <20>criture */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
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 */
/*
2000-07-28 17:30:55 +02:00
if (Locked == TRUE) SM_Heap_Unlock (Heap);
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Routine d'affichage d'un message d'erreur */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
void DS_Error_Print ( void )
{
if (DS_stderr) fprintf (DS_stderr, "%s\n", DS_Error_Msg);
}
/*----------------------------------------------------------------------------*/
/* Pour pr<70>fixer les noms de heap avec l'identifiant de la librairie */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
static char * DS_Name_Prefix ( const char * Name )
{
static char Prefixed [256];
sprintf (Prefixed, "%s/%s", DS_PREFIX, Name);
return Prefixed;
}
/*----------------------------------------------------------------------------*/
/* Cr<43>ation d'un s<>maphore pour g<>rer l'ouverture d'une data structure */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
DST_Status DS_Semaphore_Create ( NDT_Root * Root )
{
union semun Sem_Ctl;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* Cr<43>ation du s<>maphore */
/*
2000-07-28 17:30:55 +02:00
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 <20> 0 */
/*
2000-07-28 17:30:55 +02:00
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<4F>ration sur un s<>maphore */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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 */
/*----------------------------------------------------------------------------*/
/*
2000-07-28 17:30:55 +02:00
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;
}