l3.libnazgul/test/test_msgSpaceState.c

101 lines
2.3 KiB
C
Raw Normal View History

2020-03-03 21:17:08 +00:00
#ifdef _NZG_HPUX
#include <sys/wait.h>
#else
#include <wait.h>
#endif
#include "libnazgul.h"
void usage(char * myname){
printf("Usage: %s [--all | msgSpaceId1 msgSpaceId2 ... ]\n",myname);
}
int about(char * spaceId){
msgPoolDataTabSemId ressourceSemId;
sem_t * ressourceSemFd;
int i;
msgPoolData * poolDataTab;
msgSpace * space;
int ressourceSemVal;
if (strlen(spaceId)> MSGSPACE_ID_LEN){
//verif de la longueur
fprintf(stderr,"Too long ident : %s\n",spaceId);
goto ERROR;
} else {
int err;
msgSpaceListLock();
err=msgSpaceListFindId(spaceId);
msgSpaceListUnlock();
if (err < 1){
if (err==0){
// le msgSpace existe
space=msgSpaceOpen(spaceId);
// on lit les informations sur le msgSpace
// les pool
for (i=0;i<space->poolNb;i++){
msgPoolSemIdIntern(ressourceSemId,space->externId,i);
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
if (ressourceSemFd == SEM_FAILED){
NZG_ERROR("sem_open",ressourceSemId);
goto ERROR;
}
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
NZG_ERROR("sem_getvalue",ressourceSemId);
goto ERROR;
}
msgPoolDataTabLock(space);
poolDataTab= msgPoolDataTabOpen(space);
// donner le nombre de buffer disponibles
printf("- %d/%d free buffers in pool #%d\n",
ressourceSemVal,
poolDataTab[i].bufferNb,
i);
msgPoolDataTabClose(space,poolDataTab);
msgPoolDataTabUnlock(space);
if(sem_close(ressourceSemFd) <0){
NZG_ERROR("sem_getvalue",ressourceSemId);
goto ERROR;
}
// pour chaque buffer, dire s'il est libre ou pas
// et le processus/addresse associ<63>
}
msgSpaceClose(space);
} else {
// zut, il y a soit une erreur
NZG_ERROR("spaceListFindId : error ",spaceId);
}
} else {
// on quitte : l'element n'existe
fprintf(stderr,"Ident %s does not exist.\n",spaceId);
}
}
return 0;
ERROR:
return -1;
}
int main(int argc,char **argv){
printf("Args %d\n",argc);
if (argc<2){
usage(argv[0]);
}else {
if (argc==2){
if (strcmp("--all",argv[1])==0){
// listing
printf("[ Listing of msgSpaces ]\n");
} else {
// only one msgSpaceId
printf("[ About %s ]\n",argv[1]);
about(argv[1]);
}
} else {
int i;
for (i=1;i<argc;i++){
printf("[ About %s ]\n",argv[i]);
about(argv[i]);
}
}
}
return 0;
}