* 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 *msgSpaceOpen(msgSpaceId spaceId);
int msgSpaceDelete(msgSpaceId spaceId);
int msgSp2nzgId(msgSpaceId dest, const msgSpaceId src);
/* nzg_state.c */

View file

@ -1,5 +1,7 @@
#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
@ -14,11 +16,14 @@ msgSpace * msgSpaceCreate(
int poolNb,
msgPool * queueNbCar ){
msgSpaceId nzgId;
//msgSpaceList mSList;
/* msgSpaceList mSList; */
int mSFd; // shm file descriptor
int i;
static int mSIdNum=-1;
msgSpace * mSAddr;
fprintf(stderr,"Creating msgSpace with id : %s\n",spaceId);
mSIdNum++;
mSAddr=NULL;
@ -27,7 +32,9 @@ msgSpace * msgSpaceCreate(
/** on créee le nouvel element **/
printf("PAGESIZE : %d\n",(int)PAGESIZE);
msgSp2nzgId(nzgId,spaceId);
if (msgSpaceIdIntern(nzgId,spaceId) < 0){
return NULL;
}
printf("Id interne : %s\n",nzgId);
mSFd=shm_open(
nzgId,
@ -41,7 +48,7 @@ msgSpace * msgSpaceCreate(
return NULL;
}
//on redimentionne l'element
/* on redimentionne l'element */
if (ftruncate(mSFd, sizeof(* mSAddr)) == -1){
fprintf( stderr, "msgSpace resizing failed: %s\n",
strerror( errno ) );
@ -63,6 +70,14 @@ msgSpace * msgSpaceCreate(
/* on ferme le descripteur du fichier */
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 crée queueNb files de messages */
@ -89,7 +104,9 @@ msgSpace * msgSpaceCreate(
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmId;
msgSpaceId nzgId;
if (msgSp2nzgId(nzgId,spaceId));
if (msgSpaceIdIntern(nzgId,spaceId) < 0){
return NULL;
}
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
@ -98,9 +115,10 @@ msgSpace * msgSpaceOpen(msgSpaceId spaceId){
}
int msgSpaceDelete(msgSpaceId spaceId){
fprintf(stderr,"Deleting msgSpace with id : %s\n",spaceId);
//int shmId;
msgSpaceId nzgId;
if (msgSp2nzgId(nzgId,spaceId) == -1){
if (msgSpaceIdIntern(nzgId,spaceId) == -1){
//TODO: message d'erreur
return -1;
}
@ -112,7 +130,7 @@ int msgSpaceDelete(msgSpaceId spaceId){
return 0;
}
int msgSp2nzgId(msgSpaceId dest,const msgSpaceId src ){
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src ){
if (strlen(src)>MSGSPACE_ID_LEN){
return -1;
}
@ -124,3 +142,16 @@ int msgSp2nzgId(msgSpaceId dest,const msgSpaceId src ){
#endif
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;
}