/*----------------------------------------------------------------------------*/ /* libdatastr.h */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* 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 */ /* . */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* Includes */ /*----------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include //#include #include #include /*----------------------------------------------------------------------------*/ /* Definitions */ /*----------------------------------------------------------------------------*/ #define LGD_MODULE_NAME "ds" extern char * strdup ( const char * ); /* Compteur d'ouverture de la librairie */ unsigned int DS_Open_Counter = 0; /* Tous les heaps créés via la librairie LIBDATASTR seront préfixés par le nom suivant */ #define DS_PREFIX "DATASTR" /* Flux de sortie des messages d'erreur */ FILE * DS_stderr; /* Pour gérer les ouvertures, fermetures ou destructions d'une data structure, on opère sur un sémaphore (OpenSemID) rattaché à la description de la structure qui comptabilise les processus ayant ouvert la data structure. */ struct sembuf DS_SemOp_Open [1] = { {0, 1, SEM_UNDO|IPC_NOWAIT} }; struct sembuf DS_SemOp_Close [1] = { {0, -1, SEM_UNDO|IPC_NOWAIT} }; struct sembuf DS_SemOp_Destroy [2] = { {0, -1, SEM_UNDO|IPC_NOWAIT}, {0, 0, SEM_UNDO|IPC_NOWAIT} }; typedef union semun { int val; struct semid_ds * buf; unsigned short int * array; } semun; /* Liste des data structure ouvertes par le processus courant */ NDT_Root *OpenedDS_List; typedef struct DST_DataStruct { char *Name; NDT_Root *Root_Ptr; } DST_DataStruct; /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* Fonctions privées de la librairie */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* Création d'un sémaphore pour gérer l'ouverture d'une data structure */ /*----------------------------------------------------------------------------*/ DST_Status DS_Semaphore_Create( NDT_Root *); /*----------------------------------------------------------------------------*/ /* Opération sur un sémaphore */ /*----------------------------------------------------------------------------*/ DST_Status DS_Semaphore_Operate (int, struct sembuf *, unsigned int); /*----------------------------------------------------------------------------*/ /* Fonction d'allocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ DST_Status DS_DataStruct_Alloc ( void **Ptr, size_t Size, void *Data ); /*----------------------------------------------------------------------------*/ /* Fonction de désallocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ DST_Status DS_DataStruct_Free ( void *Ptr, void *Data ); /*----------------------------------------------------------------------------*/ /* Routine d'affichage d'un message d'erreur */ /*----------------------------------------------------------------------------*/ void DS_Error_Print ( void ); /*----------------------------------------------------------------------------*/ /* Pour préfixer les noms de heap avec l'identifiant de la librairie */ /*----------------------------------------------------------------------------*/ DST_Status DS_Name_Prefix( char *Prefixed, const char *Unprefixed); /*----------------------------------------------------------------------------*/ /* Teste si une data structure a déjà été ouverte par le processus courant */ /*----------------------------------------------------------------------------*/ DST_Status DS_DataStruct_IsOpen( NDT_Root **Root_Ptr_Ptr, char *DS_Name); /*----------------------------------------------------------------------------*/ /* Fonction manager de la liste des DS ouvertes */ /*----------------------------------------------------------------------------*/ NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr);