* modifié les fonctions de nommage

This commit is contained in:
glenux 2004-02-19 19:52:11 +00:00
parent e09c683a08
commit 3b24ed7282
2 changed files with 37 additions and 7 deletions

View file

@ -10,7 +10,6 @@ int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest, msgSpacePoolId src, int num);
msgSpace *msgSpaceCreate(msgSpaceId spaceId, int queueNb, int poolNb, msgPool *queueNbCar); msgSpace *msgSpaceCreate(msgSpaceId spaceId, int queueNb, int poolNb, msgPool *queueNbCar);
msgSpace *msgSpaceOpen(msgSpaceId spaceId); msgSpace *msgSpaceOpen(msgSpaceId spaceId);
int msgSpaceDelete(msgSpaceId spaceId); int msgSpaceDelete(msgSpaceId spaceId);
int msgSp2nzgId(msgSpaceId dest, const msgSpaceId src);
/* nzg_state.c */ /* nzg_state.c */

View file

@ -1,5 +1,7 @@
#include "libnazgul.h" #include "libnazgul.h"
/* prototypes des fonctions annexes à ne pas exporter */
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
/* /*
* spaceId : identifiant externe de l'espace de msg * spaceId : identifiant externe de l'espace de msg
@ -14,11 +16,14 @@ msgSpace * msgSpaceCreate(
int poolNb, int poolNb,
msgPool * queueNbCar ){ msgPool * queueNbCar ){
msgSpaceId nzgId; msgSpaceId nzgId;
//msgSpaceList mSList; /* msgSpaceList mSList; */
int mSFd; // shm file descriptor int mSFd; // shm file descriptor
int i; int i;
static int mSIdNum=-1; static int mSIdNum=-1;
msgSpace * mSAddr; msgSpace * mSAddr;
fprintf(stderr,"Creating msgSpace with id : %s\n",spaceId);
mSIdNum++; mSIdNum++;
mSAddr=NULL; mSAddr=NULL;
@ -27,7 +32,9 @@ msgSpace * msgSpaceCreate(
/** on créee le nouvel element **/ /** on créee le nouvel element **/
printf("PAGESIZE : %d\n",(int)PAGESIZE); printf("PAGESIZE : %d\n",(int)PAGESIZE);
msgSp2nzgId(nzgId,spaceId); if (msgSpaceIdIntern(nzgId,spaceId) < 0){
return NULL;
}
printf("Id interne : %s\n",nzgId); printf("Id interne : %s\n",nzgId);
mSFd=shm_open( mSFd=shm_open(
nzgId, nzgId,
@ -41,7 +48,7 @@ msgSpace * msgSpaceCreate(
return NULL; return NULL;
} }
//on redimentionne l'element /* on redimentionne l'element */
if (ftruncate(mSFd, sizeof(* mSAddr)) == -1){ if (ftruncate(mSFd, sizeof(* mSAddr)) == -1){
fprintf( stderr, "msgSpace resizing failed: %s\n", fprintf( stderr, "msgSpace resizing failed: %s\n",
strerror( errno ) ); strerror( errno ) );
@ -63,6 +70,14 @@ msgSpace * msgSpaceCreate(
/* on ferme le descripteur du fichier */ /* on ferme le descripteur du fichier */
close(mSFd); close(mSFd);
/* on remplit la structure */
strncpy(mSAddr->id,nzgId,MSGSPACE_ID_LEN);
mSAddr->poolNb=poolNb;
mSAddr->queueNb=queueNb;
mSAddr->pid=getpid();
/* TODO: creation du poolData */
/* TODO: on ajoute spaceId a la liste des msgSpace connus */ /* TODO: on ajoute spaceId a la liste des msgSpace connus */
/* TODO: on crée queueNb files de messages */ /* TODO: on crée queueNb files de messages */
@ -89,7 +104,9 @@ msgSpace * msgSpaceCreate(
msgSpace * msgSpaceOpen(msgSpaceId spaceId){ msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmId; int shmId;
msgSpaceId nzgId; msgSpaceId nzgId;
if (msgSp2nzgId(nzgId,spaceId)); if (msgSpaceIdIntern(nzgId,spaceId) < 0){
return NULL;
}
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){ if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open"); perror("shm_open");
return NULL; return NULL;
@ -98,9 +115,10 @@ msgSpace * msgSpaceOpen(msgSpaceId spaceId){
} }
int msgSpaceDelete(msgSpaceId spaceId){ int msgSpaceDelete(msgSpaceId spaceId){
fprintf(stderr,"Deleting msgSpace with id : %s\n",spaceId);
//int shmId; //int shmId;
msgSpaceId nzgId; msgSpaceId nzgId;
if (msgSp2nzgId(nzgId,spaceId) == -1){ if (msgSpaceIdIntern(nzgId,spaceId) == -1){
//TODO: message d'erreur //TODO: message d'erreur
return -1; return -1;
} }
@ -112,7 +130,7 @@ int msgSpaceDelete(msgSpaceId spaceId){
return 0; return 0;
} }
int msgSp2nzgId(msgSpaceId dest,const msgSpaceId src ){ int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src ){
if (strlen(src)>MSGSPACE_ID_LEN){ if (strlen(src)>MSGSPACE_ID_LEN){
return -1; return -1;
} }
@ -124,3 +142,16 @@ int msgSp2nzgId(msgSpaceId dest,const msgSpaceId src ){
#endif #endif
return 0; return 0;
} }
int msgSpacePoolDataIdIntern(msgSpaceId dest,const msgSpaceId src ){
if (strlen(src)>MSGSPACE_ID_LEN){
return -1;
}
/* sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId); */
#ifdef _NZG_REALFILEID
sprintf(dest,"/tmp/nzgSpacePoolData%s",(char *)src);
#else
sprintf(dest,"/nzgSpacePoolData%s",(char *)src);
#endif
return 0;
}