2004-02-19 10:27:59 +00:00
|
|
|
|
#include "libnazgul.h"
|
2004-02-19 10:39:55 +00:00
|
|
|
|
|
2004-02-16 21:25:11 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* spaceId : identifiant externe de l'espace de msg
|
|
|
|
|
* queueNb : nombre de files de messages
|
|
|
|
|
* poolNb : nombre de pool de buffers
|
|
|
|
|
* queueNbCar : tableau de caracteristiques des different pool
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
msgSpace * msgSpaceCreate(
|
2004-02-17 22:49:44 +00:00
|
|
|
|
msgSpaceId spaceId,
|
|
|
|
|
int queueNb,
|
|
|
|
|
int poolNb,
|
|
|
|
|
msgPool * queueNbCar ){
|
|
|
|
|
msgSpaceId nzgId;
|
2004-02-19 10:24:42 +00:00
|
|
|
|
msgSpaceList mSList;
|
2004-02-19 10:39:55 +00:00
|
|
|
|
int mSFd; // shm file descriptor
|
2004-02-19 10:24:42 +00:00
|
|
|
|
static int mSIdNum=-1;
|
2004-02-19 10:39:55 +00:00
|
|
|
|
msgSpace * mSAddr;
|
2004-02-19 09:57:25 +00:00
|
|
|
|
|
2004-02-19 10:24:42 +00:00
|
|
|
|
mSIdNum++;
|
2004-02-19 10:39:55 +00:00
|
|
|
|
mSAddr=NULL;
|
2004-02-19 09:57:25 +00:00
|
|
|
|
/** recuperation de la liste des msgSpace **/
|
|
|
|
|
/* (creation si elle n'existe pas */
|
|
|
|
|
|
|
|
|
|
/** on cr<63>ee le nouvel element **/
|
2004-02-17 16:38:08 +00:00
|
|
|
|
printf("PAGESIZE : %d\n",(int)PAGESIZE);
|
2004-02-17 22:49:44 +00:00
|
|
|
|
nzgId=msgSp2nzgId(spaceId);
|
2004-02-19 10:39:55 +00:00
|
|
|
|
mSFd=shm_open(
|
2004-02-19 09:57:25 +00:00
|
|
|
|
nzgId,
|
2004-02-19 10:39:55 +00:00
|
|
|
|
O_RDWR|O_CREAT|O_EXCL|O_TRUNC,
|
2004-02-19 09:57:25 +00:00
|
|
|
|
MSGSPACE_DEFAULT_MODE
|
|
|
|
|
);
|
2004-02-19 10:39:55 +00:00
|
|
|
|
if (mSFd == -1 ) {
|
|
|
|
|
fprintf( stderr, "msgSpace creation failed: %s\n",
|
|
|
|
|
strerror( errno ) );
|
2004-02-17 16:38:08 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2004-02-16 21:25:11 +00:00
|
|
|
|
|
2004-02-19 10:39:55 +00:00
|
|
|
|
//on redimentionne l'element
|
|
|
|
|
if (ftruncate(mSFd, sizeof(PAGESIZE)) == -1){
|
|
|
|
|
fprintf( stderr, "msgSpace resizing failed: %s\n",
|
|
|
|
|
strerror( errno ) );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Map the memory object */
|
|
|
|
|
mSAddr = mmap( 0, sizeof( *mSAddr ),
|
|
|
|
|
PROT_READ | PROT_WRITE,
|
|
|
|
|
MAP_SHARED, mSFd, 0 );
|
|
|
|
|
if( mSAddr == MAP_FAILED ) {
|
|
|
|
|
fprintf( stderr, "mmap failed: %s\n",
|
|
|
|
|
strerror( errno ) );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2004-02-16 21:25:11 +00:00
|
|
|
|
|
2004-02-19 10:39:55 +00:00
|
|
|
|
printf( "Map addr is 0x%08x\n", mSAddr );
|
2004-02-17 22:49:44 +00:00
|
|
|
|
/* on ajoute spaceId a la liste des msgSpace connus */
|
|
|
|
|
|
|
|
|
|
/* on cr<63>e queueNb files de messages */
|
|
|
|
|
|
|
|
|
|
/* on cr<63>er poolNb pool de buffers */
|
|
|
|
|
|
|
|
|
|
/* on attache tout ce beau monde au spaceId */
|
2004-02-16 21:25:11 +00:00
|
|
|
|
|
2004-02-17 22:49:44 +00:00
|
|
|
|
/* on renvoie un pointeur sur le bon spaceId */
|
2004-02-19 10:39:55 +00:00
|
|
|
|
return mSAddr;
|
2004-02-16 21:25:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-19 09:57:25 +00:00
|
|
|
|
/*
|
|
|
|
|
* spaceId : blabla
|
|
|
|
|
*/
|
|
|
|
|
|
2004-02-17 16:38:08 +00:00
|
|
|
|
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
|
|
|
|
|
int shmId;
|
2004-02-17 19:32:44 +00:00
|
|
|
|
char * nzgId=msgSp2nzgId(spaceId);
|
2004-02-17 16:38:08 +00:00
|
|
|
|
if ((shmId=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
|
|
|
|
|
perror("shm_open");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2004-02-17 15:44:20 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void msgSpaceDelete(msgSpaceId spaceId){
|
2004-02-17 21:53:14 +00:00
|
|
|
|
//int shmId;
|
2004-02-17 19:42:25 +00:00
|
|
|
|
msgSpaceId nzgId=msgSp2nzgId(spaceId);
|
|
|
|
|
int er;
|
|
|
|
|
if ((er=shm_unlink(nzgId))<0){
|
|
|
|
|
perror("shm_unlink");
|
|
|
|
|
};
|
2004-02-17 15:44:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-02-17 19:32:44 +00:00
|
|
|
|
msgSpaceId msgSp2nzgId(msgSpaceId spaceId){
|
|
|
|
|
char * resNzgId;
|
|
|
|
|
int slen;
|
|
|
|
|
slen=strlen(spaceId);
|
2004-02-19 09:57:25 +00:00
|
|
|
|
resNzgId = (char *)malloc(sizeof(char)*(slen+11));
|
|
|
|
|
sprintf(resNzgId,"/tmp/.nzg-%s",(char *)spaceId);
|
2004-02-17 19:32:44 +00:00
|
|
|
|
return ((msgSpaceId)resNzgId);
|
|
|
|
|
}
|