From 3b24ed7282ebdcc9396211798132c2a435ab11a6 Mon Sep 17 00:00:00 2001
From: glenux <glenux>
Date: Thu, 19 Feb 2004 19:52:11 +0000
Subject: [PATCH] =?UTF-8?q?*=20modifi=C3=A9=20les=20fonctions=20de=20nomma?=
 =?UTF-8?q?ge?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/nzg_proto.h  |  1 -
 src/nzg_spaces.c | 43 +++++++++++++++++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/src/nzg_proto.h b/src/nzg_proto.h
index ee3a9dd..14cb8d0 100644
--- a/src/nzg_proto.h
+++ b/src/nzg_proto.h
@@ -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 */
 
 
diff --git a/src/nzg_spaces.c b/src/nzg_spaces.c
index 025e44c..970c2d1 100644
--- a/src/nzg_spaces.c
+++ b/src/nzg_spaces.c
@@ -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;
+}