143 lines
6.1 KiB
C
143 lines
6.1 KiB
C
/*----------------------------------------------------------------------------*/
|
||
/* 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 */
|
||
/* <https://www.gnu.org/licenses/>. */
|
||
/*----------------------------------------------------------------------------*/
|
||
|
||
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/* Includes */
|
||
/*----------------------------------------------------------------------------*/
|
||
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include <dlfcn.h>
|
||
#include <stdarg.h>
|
||
#include <errno.h>
|
||
#include <sys/types.h>
|
||
#include <sys/sem.h>
|
||
#include <sys/ipc.h>
|
||
|
||
//#include <ver.h>
|
||
|
||
#include <node.h>
|
||
#include <datastr.h>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/* 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<63><72>s via la librairie LIBDATASTR seront pr<70>fix<69>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<6F>re sur un s<>maphore (OpenSemID) rattach<63> <20> 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 {
|
||
NDT_Root * Root;
|
||
char * Name;
|
||
} DST_DataStruct;
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/*----------------------------------------------------------------------------*/
|
||
/* Fonctions priv<69>es de la librairie */
|
||
/*----------------------------------------------------------------------------*/
|
||
/*----------------------------------------------------------------------------*/
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/* Cr<43>ation d'un s<>maphore pour g<>rer l'ouverture d'une data structure */
|
||
/*----------------------------------------------------------------------------*/
|
||
DST_Status DS_Semaphore_Create (NDT_Root * Root);
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/* Op<4F>ration sur un s<>maphore */
|
||
/*----------------------------------------------------------------------------*/
|
||
DST_Status DS_Semaphore_Operate (int, struct sembuf *, unsigned int);
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/* Fonction d'allocation attach<63>e <20> une structure de donn<6E>es : */
|
||
/*----------------------------------------------------------------------------*/
|
||
DST_Status DS_DataStruct_Alloc ( size_t Size, void ** Ptr, void * Data );
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/* Fonction de d<>sallocation attach<63>e <20> une structure de donn<6E>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<70>fixer les noms de heap avec l'identifiant de la librairie */
|
||
/*----------------------------------------------------------------------------*/
|
||
static char * DS_Name_Prefix (const char * Name);
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/* Teste si une data structure a d<>j<EFBFBD> <20>t<EFBFBD> ouverte par le processus courant */
|
||
/*----------------------------------------------------------------------------*/
|
||
DST_Status DS_DataStruct_IsOpen (const char * DS_Name, NDT_Root ** Root);
|
||
|
||
/*----------------------------------------------------------------------------*/
|
||
/* Fonction manager de la liste des DS ouvertes */
|
||
/*----------------------------------------------------------------------------*/
|
||
NDT_Status DS_OpenedDS_List_Manager (va_list Args);
|