certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi/libCERTI CMakeLists.txt SHM.hh SHMPosix.c... [br_CERTI


From: certi-cvs
Subject: [certi-cvs] certi/libCERTI CMakeLists.txt SHM.hh SHMPosix.c... [br_CERTI_SHM_NEWGEN_dev]
Date: Fri, 04 Sep 2009 08:00:22 +0000

CVSROOT:        /sources/certi
Module name:    certi
Branch:         br_CERTI_SHM_NEWGEN_dev
Changes by:     jbchaudron <jbchaudron> 09/09/04 08:00:20

Modified files:
        libCERTI       : CMakeLists.txt SHM.hh SHMPosix.cc SHMPosix.hh 
                         SHMSysV.cc SHMSysV.hh Semaphore.hh 
                         SemaphorePosix.cc SemaphoreSysV.cc 
                         SemaphoreSysV.hh SocketSHMPosix.cc 
                         SocketSHMPosix.hh SocketSHMSysV.cc 
                         SocketSHMSysV.hh 
Added files:
        libCERTI       : SocketSHM.cc SocketSHM.hh 

Log message:
        

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/CMakeLists.txt?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.25.4.2&r2=1.25.4.3
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHM.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.4&r2=1.1.2.5
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMPosix.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMPosix.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMSysV.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMSysV.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Semaphore.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.3&r2=1.1.2.4
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SemaphorePosix.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SemaphoreSysV.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SemaphoreSysV.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMPosix.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMPosix.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMSysV.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMSysV.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHM.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.4.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHM.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.4.2

Patches:
Index: CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libCERTI/CMakeLists.txt,v
retrieving revision 1.25.4.2
retrieving revision 1.25.4.3
diff -u -b -r1.25.4.2 -r1.25.4.3
--- CMakeLists.txt      1 Sep 2009 12:51:10 -0000       1.25.4.2
+++ CMakeLists.txt      4 Sep 2009 08:00:19 -0000       1.25.4.3
@@ -135,6 +135,7 @@
         )
         
     SET(CERTI_SOCKET_SHM_SRC 
+        SocketSHM.cc SocketSHM.hh
         SocketSHMPosix.cc SocketSHMPosix.hh
         SocketSHMSysV.cc SocketSHMSysV.hh
         )

Index: SHM.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SHM.hh,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -b -r1.1.2.4 -r1.1.2.5
--- SHM.hh      1 Sep 2009 12:51:10 -0000       1.1.2.4
+++ SHM.hh      4 Sep 2009 08:00:19 -0000       1.1.2.5
@@ -16,27 +16,22 @@
        bool _IsCreator ;
        void *_Shm ;
 
-       /**
-        * Build a proper SHM name from a user provided name.
-        * Idea kindly borrowed from TSP (https://savannah.nongnu.org)
-        * bb_utils_build_shm_name
-        */
-       std::string buildShmName(std::string& ShmName) {
-         return "/"+ShmName+"_shm";
-       }
-
 public :
        /**
         * Constructor.
         * @param[in] SHNName, the name of the shared memory segment.
         *            this should be unique on a specified host.
         * @param[in] SHMSize, the requested size of the SHM
-        * @param[in] isCreator,
         */
-       SHM(const std::string& SHMName, const int SHMSize, const bool isCreator)
+       SHM(const std::string& SHMName, const int SHMSize, const bool True)
                {_Name=SHMName;
                 _Size=SHMSize;
-                _IsCreator=isCreator;
+                _IsCreator=True;
+                }
+       SHM(const std::string& SHMName, const int SHMSize)
+               {_Name=SHMName;
+                _Size=SHMSize;
+                _IsCreator=false;
                 }
        virtual ~SHM() {};
        const std::string getName() const {return _Name ; } ;
@@ -46,6 +41,15 @@
        virtual void Open() = 0 ;
        virtual void Attach() = 0 ;
        virtual void Close() = 0 ;
+
+        /**
+        * Build a proper SHM name from a user provided name.
+        * Idea kindly borrowed from TSP (https://savannah.nongnu.org)
+        * bb_utils_build_shm_name
+        */
+       static std::string buildShmName(const std::string& ShmName) {
+         return "/"+ShmName+"_shm";
+       }
 } ;
 
 #endif

Index: SHMPosix.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SHMPosix.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- SHMPosix.cc 1 Sep 2009 12:51:10 -0000       1.1.2.2
+++ SHMPosix.cc 4 Sep 2009 08:00:19 -0000       1.1.2.3
@@ -16,8 +16,11 @@
 // ************************************************
 // Constructor with args
 // ************************************************
-SHMPosix::SHMPosix(const std::string& New_Shm_Name, const int New_Shm_Size, 
const bool It_IsCreator) 
-  : SHM(New_Shm_Name, New_Shm_Size, It_IsCreator) { 
+SHMPosix::SHMPosix(const std::string& SHMName, const int SHMSize, const bool 
True)  : SHM(SHMName, SHMSize, True) { 
+    _Id = 0 ;  
+}
+
+SHMPosix::SHMPosix(const std::string& SHMName, const int SHMSize)  : 
SHM(SHMName,SHMSize) { 
     _Id = 0 ;  
 }
 
@@ -36,10 +39,12 @@
     ret = shm_unlink(_Name.c_str());
     _Id = shm_open(_Name.c_str(), O_CREAT | O_EXCL | O_RDWR , S_IRWXU | 
S_IRWXG);
     if (_Id < 0) {
-        perror("In shm_open()");
+        perror("Error with shm_open() in SHMPosix::Open()");
         exit(1);
         }
-    fprintf(stderr, "Created shared memory object %s\n", _Name.c_str());
+#ifdef DEBUG
+std::cout <<  "Created shared memory object : " << _Name.c_str() << std::endl ;
+#endif
 
     ret = ftruncate(_Id, _Size);
      if (ret < 0) {
@@ -51,10 +56,12 @@
  else{
     _Id = shm_open(_Name.c_str(), O_RDONLY, S_IRWXU | S_IRWXG);
     if (_Id < 0) {
-        perror("In shm_open()");
+        perror("Error with shm_open() in SHMPosix::Open()");
         exit(1);
         }
-       fprintf(stderr, "Attach shared memory object %s\n", _Name.c_str());
+#ifdef DEBUG
+std::cout <<  "Attach shared memory object : " << _Name.c_str() << std::endl ;
+#endif
  } // End of else IsCreator()
 
 } // End of Open()
@@ -68,10 +75,10 @@
     /* requesting the shared segment for write    --  mmap() */    
     _Shm = mmap(NULL, _Size, PROT_READ | PROT_WRITE , MAP_SHARED, _Id, 0);
     if (_Shm == NULL) {
-        perror("In mmap()");
+        perror("Error with mmap() in SHMPosix::Attach() ");
         exit(1);}
     if (_Shm == MAP_FAILED) {
-        perror("In mmap()");
+        perror("Error with mmap() in SHMPosix::Attach() ");
         exit(1);}
     close(_Id) ;
 } // End of IsServer
@@ -79,10 +86,10 @@
  /* requesting the shared segment for write    --  mmap() */    
     _Shm = mmap(NULL, _Size, PROT_READ , MAP_SHARED, _Id, 0);
     if (_Shm == NULL) {
-        perror("In mmap()");
+        perror("Error with mmap() in SHMPosix::Attach() ");
         exit(1);}
     if (_Shm == MAP_FAILED) {
-        perror("In mmap()");
+        perror("Error with mmap() in SHMPosix::Attach() ");
         exit(1);}
     close(_Id) ;
 } // End of else (IsServer)
@@ -95,14 +102,14 @@
 
 // Close
 if (shm_unlink(_Name.c_str()) != 0) {
-    perror("In shm_unlink()");
+    perror("Error with shm_unlink() in SHMPosix::Close() ");
     exit(1);
     }
 
 // Destroy
 if (IsCreator()){
 if(munmap(_Shm, _Size)){
-   perror("munmap(_Shm, size) : ");
+   perror("Error with munmap() in SHMPosix::Close() ");
    exit(1);
    } // End of if
 }

Index: SHMPosix.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SHMPosix.hh,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- SHMPosix.hh 1 Sep 2009 12:51:10 -0000       1.1.2.2
+++ SHMPosix.hh 4 Sep 2009 08:00:19 -0000       1.1.2.3
@@ -10,7 +10,8 @@
     int _Id ;  // identifiant du segment memoire affecté dans la methode : 
Open()
    
     public :
-    SHMPosix(const std::string& New_Shm_Name, const int New_Shm_Size, const 
bool It_IsServer) ;
+    SHMPosix(const std::string& SHMName, const int SHMSize, const bool True) ;
+    SHMPosix(const std::string& SHMName, const int SHMSize) ;  
     ~SHMPosix() ;
 
     void Open() ;

Index: SHMSysV.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SHMSysV.cc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- SHMSysV.cc  1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SHMSysV.cc  4 Sep 2009 08:00:19 -0000       1.1.2.2
@@ -1,11 +1,67 @@
 #include "SHMSysV.hh"
+#include "sha1.h"
+
+key_t SHMSysV::ntokUser(const char* name, int32_t user_specific_value) {
+
+key_t s_key ;
+int32_t retcode ;
+
+SHA1Context sha ;
+ uint8_t Message_Digest[20] ;
+
+/* We use the first byte of a SHA1 hash of the BBname
+ * unless the algorithm fail.
+ * If SHA1 fail we go back to poor key generation method
+ * using the name length.
+ * In both case we must Xored the key with user_specific in order
+ * to isolate different user from using the same key
+ */
+         
+retcode  = SHA1Reset(&sha) ;
+retcode &= SHA1Input(&sha, (const unsigned char *) name,strlen(name)) ;
+retcode &= SHA1Result(&sha, Message_Digest);
+
+/* SHA 1 NOK back to old poor method */
+if (0 != retcode) {
+   s_key = ((strlen(name) << 16) & 0xFFFF0000) ^ (user_specific_value & 
0x0000FFFF);
+   } 
+else { s_key = (Message_Digest[0]        |
+       (Message_Digest[1] << 8) |
+       (Message_Digest[2] << 16)|
+       (Message_Digest[3] << 24)) ^
+        user_specific_value;
+       }
+       return s_key;
+}
+
+key_t
+SHMSysV::ntok(const char* name) {
+       return SHMSysV::ntokUser(name,getuid());
+        // return SHMSysV::ntokUser(name,1);
+}
+
 
 // ************************************************
-// Constructor with args
+// Constructors with args
 // ************************************************
-SHMSysV::SHMSysV(const std::string& New_Name, const int New_Key, const int 
New_Size, const bool It_IsCreator) : SHM(New_Name, New_Size, It_IsCreator) {
+SHMSysV::SHMSysV(const std::string& SHMName, const int SHMSize, const bool 
True)  : SHM(SHMName, SHMSize, True) { 
+    _Key = ntok(SHMName.c_str());
+
+#ifdef DEBUG
+std::cout << " Cle produite : " << _Key << std::endl ;
+#endif
+
+    _Id = 0 ;  
+}
+
+SHMSysV::SHMSysV(const std::string& SHMName, const int SHMSize)  : 
SHM(SHMName, SHMSize) { 
+     _Key = ntok(SHMName.c_str());
+
+#ifdef DEBUG
+std::cout << " Cle produite : " << _Key << std::endl ;
+#endif
+
     _Id = 0 ;  
-    _Key = New_Key ;
 }
 
 
@@ -19,8 +75,8 @@
 // ************************************************
 void SHMSysV::Open() {
 
-if ((_Id = shmget((key_t)_Key, (size_t) _Size, IPC_CREAT| 0666 )) < 0){  
-    perror("Error in shmget "); 
+if ((_Id = shmget(_Key, (size_t)_Size, IPC_CREAT| 0666 )) < 0){  
+    perror("Error with shmget in SHMSysV::Open()"); 
     exit(1);
     } // End of if
 
@@ -32,7 +88,7 @@
 void SHMSysV::Attach() {
 
 if ( ( _Shm = shmat(_Id, NULL, 0) ) == (void*) -1){
-    perror("Error in shmat "); 
+    perror("Error with shmat() in SHMSysV::Attach() "); 
     exit(1);
     } // End of if
 
@@ -45,14 +101,14 @@
 
 // Close
 if(shmdt(_Shm)){
-        perror("Error in shmdt ");
+        perror("Error with shmdt() in SHMSysV::Close()");
         exit(1);
       } // End of if(shmdt(_Shm))
 
 if(_IsCreator){
 // Destroy
 if(shmctl(_Id, IPC_RMID,0)){
-   perror("Error in shmctl(IPC_RMID) ");
+   perror("Error with shmctl() in SHMSysV::Close()");
    exit(1);
    } // End of if(shmctl(_Shm_Id, IPC_RMID,0))
 } // End of (_IsServer)

Index: SHMSysV.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SHMSysV.hh,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- SHMSysV.hh  1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SHMSysV.hh  4 Sep 2009 08:00:19 -0000       1.1.2.2
@@ -22,20 +22,47 @@
 
     private :
     int _Id ;  
-    int _Key ; 
+    key_t _Key ; 
    
     public :
-    SHMSysV(const std::string& New_Name, const int New_Key, const int 
New_Size, const bool It_IsCreator) ;
+    SHMSysV(const std::string& SHMName, const int SHMSize, const bool True) ;
+    SHMSysV(const std::string& SHMName, const int SHMSize) ;  
     ~SHMSysV() ;
     void Open() ;
     void Attach() ;
     void Close() ;
 
-} ;
-
-
-
+        /**
+     * Build a SysV IPC key from a name and user specific value.
+     * The purpose of this function is to build a (quasi) unique
+     * key from unique entry as ftok(3) do with existing file name.
+     * We use SHA1 hash function Xored with the user_specific
+     * value supplied.
+     * @param[in] name, the name representing the IPC element for which
+     *                 we want a key.
+     * @param[in] user_specific_value, any user specific value
+     *                               (for example uid).
+     * @return The generated SysV IPC key corresponding to the specified entry
+     */
+    key_t
+    static ntokUser(const char* name, int32_t user_specific_value);
+
+    /**
+     * Build a SysV IPC key from a name.
+     * L'objectif de cette fonction est de generer des
+     * clefs differentes pour des noms differents, a la maniere
+     * d'une fonction de hachage ou checksum parfaite.
+     * Cette fonction vise les meme objectifs que ftok(3)
+     * avec les noms de fichiers mais avec une chaine
+     * de caractere quelconque.
+     * @param name un nom representant l'element IPC pour lequel on
+     *                veut generer une clef.
+     * @return SysV IPC key corresponding to the specified name.
+     */
+    key_t
+    static ntok(const char* name);
 
 
+} ;
 
 #endif

Index: Semaphore.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/Semaphore.hh,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- Semaphore.hh        1 Sep 2009 12:51:10 -0000       1.1.2.3
+++ Semaphore.hh        4 Sep 2009 08:00:19 -0000       1.1.2.4
@@ -7,25 +7,26 @@
 class Semaphore {
 
 protected:
-       /**
-        * Build a proper Semaphore name from a user provided name.
-        * Idea kindly borrowed from TSP (https://savannah.nongnu.org)
-        * bb_utils_build_sem_name
-        */
-       std::string buildSemName(std::string& SemName) {
-               return "/"+SemName+"_sem";
-       }
 
     public :
     // Semaphore() ;
     virtual ~Semaphore() {};
-    // virtual void Sem_create_init(int initval, char * semname) = 0 ;
-    // virtual void Sem_create(key_t cle) = 0 ;
-    // virtual void Sem_init(int initval) = 0 ;
+    virtual void Create_Init(const int initval, const std::string& 
New_Semname) = 0 ;
+    virtual void Attach(const std::string& New_Semname ) = 0 ;
     virtual void P() = 0 ;
     virtual void V() = 0 ;
     virtual void Delete() = 0 ;
 
+
+       /**
+        * Build a proper Semaphore name from a user provided name.
+        * Idea kindly borrowed from TSP (https://savannah.nongnu.org)
+        * bb_utils_build_sem_name
+        */
+       static std::string buildSemName(const std::string& SemName) {
+               return "/"+SemName+"_sem";
+       }
+
 } ;
 
 #endif

Index: SemaphorePosix.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SemaphorePosix.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- SemaphorePosix.cc   1 Sep 2009 11:14:13 -0000       1.1.2.2
+++ SemaphorePosix.cc   4 Sep 2009 08:00:19 -0000       1.1.2.3
@@ -3,12 +3,18 @@
 // ************************************************
 // Constructor
 // ************************************************
-SemaphorePosix::SemaphorePosix(){}
+SemaphorePosix::SemaphorePosix(){
+_Sem = NULL ;
+}
 
 // ************************************************
 // Destructor
 // ************************************************
-SemaphorePosix::~SemaphorePosix() {}
+SemaphorePosix::~SemaphorePosix() {
+if (_Sem!=NULL) {
+  Delete() ;
+}
+}
 
 // ************************************************
 // Method : SemaphorePosix::Create_Init(...)
@@ -17,14 +23,17 @@
 
  _Semname.assign(New_Semname) ;
 sem_unlink(_Semname.c_str()) ;
-_Sem = sem_open( _Semname.c_str(), O_CREAT | O_EXCL, S_IRUSR | S_IWUSR 
,(int)initval);
+_Sem = sem_open( _Semname.c_str(), O_CREAT | O_EXCL , S_IRUSR | S_IWUSR 
,(int)initval) ;
 if(_Sem == SEM_FAILED) {
-     printf("Erreur de creation du semaphore ") ; 
+     perror("Error with sem_open() in SemaphorePosix::Create_Init(...)") ; 
      }
 
+#ifdef DEBUG
 int sem_val ;
-sem_getvalue(_Sem, &sem_val); 
-printf("On a ouvert le semaphore %s avec une valeur %d\n", _Semname.c_str(), 
sem_val) ; 
+sem_getvalue(_Sem, &sem_val) ; 
+std::cout << "We create the semaphore identified by name : " << 
_Semname.c_str() << " with an init value : " <<  sem_val << std ::endl ; 
+#endif
+
 } // End of Create_Init(...)
 
 // ************************************************
@@ -32,15 +41,17 @@
 // ************************************************
 void SemaphorePosix::Attach(const std::string& New_Semname) {
 
-_Semname.assign(New_Semname) ;
-_Sem = sem_open( _Semname.c_str(), O_CREAT);  
+ _Semname.assign(New_Semname) ;
+_Sem = sem_open( New_Semname.c_str(), O_CREAT ) ;  
 if(_Sem == SEM_FAILED){
-   printf("Erreur de creation du semaphore ") ; 
+   perror("Error with sem_open() in SemaphorePosix::Attach(...)") ; 
    } 
 
+#ifdef DEBUG
 int sem_val ;
-sem_getvalue(_Sem, &sem_val); 
-printf("On a attaché le semaphore %s avec une valeur %d\n", _Semname.c_str(), 
sem_val) ; 
+sem_getvalue(_Sem, &sem_val) ; 
+std::cout << "We attach the semaphore identified by name : " << 
_Semname.c_str() << " which have the value : " <<  sem_val << std ::endl ; 
+#endif
 } // End of Attach(...)
 
 // ************************************************
@@ -50,12 +61,19 @@
 
 void SemaphorePosix::P() {
 
+#ifdef DEBUG
 int sem_val ;
-sem_getvalue(_Sem, &sem_val); 
-printf("Debut P() Pour le Semaphore %s qui a une valeur %d \n", 
_Semname.c_str(), sem_val ) ;
+sem_getvalue(_Sem, &sem_val) ; 
+std::cout << "Begin of Operation P for the semaphore identified by name : " << 
_Semname << " which have the value : " << sem_val << std::endl ;
+#endif
+
 sem_wait(_Sem) ;
-sem_getvalue(_Sem, &sem_val);
-printf("Fin P() Pour le Semaphore %s qui a une valeur %d \n", 
_Semname.c_str(), sem_val ) ; 
+
+#ifdef DEBUG
+sem_getvalue(_Sem, &sem_val) ;
+std::cout << "End of Operation P for the semaphore identified by name : " << 
_Semname << " which have the value : " << sem_val << std::endl ; 
+#endif
+
 } // End of P()
 
 
@@ -66,20 +84,28 @@
 
 void SemaphorePosix::V() {
 
+#ifdef DEBUG
 int sem_val ;
-sem_getvalue(_Sem, &sem_val); 
-printf("Debut V() Pour le Semaphore %s qui a une valeur %d \n", 
_Semname.c_str(), sem_val ) ;
+sem_getvalue(_Sem, &sem_val) ; 
+std::cout << "Begin of Operation V for the semaphore identified by name <" << 
_Semname << "> which have the value : " << sem_val << std::endl ;
+#endif
+
 sem_post(_Sem) ;
-sem_getvalue(_Sem, &sem_val);
-printf("Fin V() Pour le Semaphore %s qui a une valeur %d \n", 
_Semname.c_str(), sem_val ) ; 
-printf("\n") ; 
+
+#ifdef DEBUG
+sem_getvalue(_Sem, &sem_val) ;
+std::cout << "End of Operation V for the semaphore identified by name <" << 
_Semname << "> which have the value : " << sem_val << std::endl ; 
+#endif
+
 } // End of V()
 
 // ************************************************
 // Methode : SemaphorePosix::Delete()
 // ************************************************
 void SemaphorePosix::Delete(){
+
 sem_close(_Sem) ;
-sem_destroy(_Sem);
+sem_destroy(_Sem) ;
+
 } // End of Delete()
 

Index: SemaphoreSysV.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SemaphoreSysV.cc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- SemaphoreSysV.cc    1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SemaphoreSysV.cc    4 Sep 2009 08:00:19 -0000       1.1.2.2
@@ -1,10 +1,50 @@
 #include "SemaphoreSysV.hh"
+#include "sha1.h"
 
+key_t SemaphoreSysV::ntokUser(const char* name, int32_t user_specific_value) {
+
+key_t s_key ;
+int32_t retcode ;
+
+SHA1Context sha ;
+ uint8_t Message_Digest[20] ;
+
+/* We use the first byte of a SHA1 hash of the BBname
+ * unless the algorithm fail.
+ * If SHA1 fail we go back to poor key generation method
+ * using the name length.
+ * In both case we must Xored the key with user_specific in order
+ * to isolate different user from using the same key
+ */
+         
+retcode  = SHA1Reset(&sha) ;
+retcode &= SHA1Input(&sha, (const unsigned char *) name,strlen(name)) ;
+retcode &= SHA1Result(&sha, Message_Digest);
+
+/* SHA 1 NOK back to old poor method */
+if (0 != retcode) {
+   s_key = ((strlen(name) << 16) & 0xFFFF0000) ^ (user_specific_value & 
0x0000FFFF);
+   } 
+else { s_key = (Message_Digest[0]        |
+       (Message_Digest[1] << 8) |
+       (Message_Digest[2] << 16)|
+       (Message_Digest[3] << 24)) ^
+        user_specific_value;
+       }
+       return s_key;
+}
+
+key_t SemaphoreSysV::ntok(const char* name) {
+       return SemaphoreSysV::ntokUser(name,getuid());
+        // return SemaphoreSysV::ntokUser(name,1);
+
+}
 // ************************************************
 // Constructor
 // ************************************************
 SemaphoreSysV::SemaphoreSysV(){
 _Sem_Id = 0 ;
+_Sem_Key = 0 ;
 }
 
 // ************************************************
@@ -15,24 +55,17 @@
 // ************************************************
 // Method : SemaphoreSysV::Create_Init(...)
 // ************************************************
-void SemaphoreSysV::Create_Init(const int initval, const int cle) {
-int flag ;
- // On commence par cr\'eer le s\'emaphore 
- _Sem_Id = semget((key_t)cle,1,IPC_CREAT | IPC_EXCL |0666);
- flag = 1 ;
+void SemaphoreSysV::Create_Init(const int initval, const std::string& 
New_Semname) {
+
+ _Sem_Key = ntok(New_Semname.c_str()) ;
+ _Sem_Id = semget(_Sem_Key,1,IPC_CREAT |0666);
  if (_Sem_Id == -1){
-   _Sem_Id = semget(cle,1,0666) ;
-   flag = 2 ;
-   if (_Sem_Id == -1) {
-      perror("Error with semget()") ;
+      perror("Error with semget() in SemaphoreSysV::Create_Init(...)") ;
       exit(1) ;
    }
- }
- /* dans le code ci-dessus, deux processus sans liens
-  * de parent\'e peuvent utiliser le m\^eme s\'emaphore \`a condition
-  * de conna\^\i{}tre la cl\'e et la cha\^\i{}ne de caract\`eres */
- if (flag == 1) printf("We create the semaphore identified by number 
%d\n",_Sem_Id) ;
- if (flag == 2) printf("We attach the semaphore identified by number 
%d\n",_Sem_Id) ;
+ #ifdef DEBUG
+ std::cout << "We create the semaphore identified by number : " << _Sem_Id << 
std::endl ;
+ #endif
 
  union semun{
      int val ;  
@@ -40,15 +73,34 @@
    ushort *array; // Not use here       
  } arg_ctl ;
 
- // Maintenant on affecte une valeur initiale au s\'emaphore
+ // Initialize
  arg_ctl.val = initval ;
  if (semctl(_Sem_Id,0,SETVAL,arg_ctl) == -1){
     perror("Error during semaphore initialization") ;
     exit(1) ;
         }
-printf("We init the semaphore with value %d\n",initval) ;
+ #ifdef DEBUG
+ std::cout <<"We init the semaphore with value : " << initval << std::endl ;
+ #endif
 
-} // End of method : sem_create
+} // End of method : Create_Init(...)
+
+// ************************************************
+// Method : SemaphoreSysV::Attach(...)
+// ************************************************
+void SemaphoreSysV::Attach(const std::string& New_Semname) {
+
+_Sem_Key = ntok(New_Semname.c_str()) ;
+_Sem_Id = semget(_Sem_Key,1,0666) ;
+if (_Sem_Id == -1) {
+      perror("Error with semget() in SemaphoreSysV::Attach(...)") ;
+      exit(1) ;
+      }
+ #ifdef DEBUG
+ std::cout <<  "We attach the semaphore identified by number : " << _Sem_Id << 
std::endl ;
+ #endif
+
+} // End of method : Attach(...)
 
 // ************************************************
 // Method : SemaphoreSysV::P
@@ -56,17 +108,25 @@
 // Decrement Semaphore Value SV=SV-1 
 
 void SemaphoreSysV::P() {
-printf("Begin of Operation P for the semaphore identified by number 
%d\n",_Sem_Id) ;
+
+#ifdef DEBUG
+std::cout << "Begin of Operation P for the semaphore identified by number : " 
<< _Sem_Id << std::endl ;
+#endif
+
 struct sembuf semparP ;
   semparP.sem_num = 0 ;
   semparP.sem_op = -1 ;
   semparP.sem_flg = SEM_UNDO ;
 
  if (semop(_Sem_Id,&semparP,1) == -1) {
-    perror("Error in P() : semop()") ;
+    perror("Error with semop() in SemaphoreSysV::P()") ;
     exit(1);
     } 
-printf("End of Operation P for the semaphore identified by number 
%d\n",_Sem_Id) ;
+
+#ifdef DEBUG
+std::cout << "End of Operation P for the semaphore identified by number : " << 
_Sem_Id << std::endl  ;
+#endif
+
 } // End of P()
 
 
@@ -76,17 +136,25 @@
 // Increment Semaphore Value SV=SV+1 
 
 void SemaphoreSysV::V() {
-printf("Begin of Operation V for the semaphore identified by number 
%d\n",_Sem_Id) ;
+
+#ifdef DEBUG
+std::cout << "Begin of Operation V for the semaphore identified by number : " 
<< _Sem_Id << std::endl ;
+#endif
+
 struct sembuf semparV ;
   semparV.sem_num = 0 ;
   semparV.sem_op = 1 ;
   semparV.sem_flg = SEM_UNDO ;
 
   if (semop(_Sem_Id,&semparV,1) ==-1) {
-    perror("Error in V() : semop()") ;
+    perror("Error with semop() in SemaphoreSysV::V() ") ;
     exit(1);
     } 
-printf("End of Operation V for the semaphore identified by number 
%d\n",_Sem_Id) ;
+
+#ifdef DEBUG
+std::cout << "End of Operation V for the semaphore identified by number : " << 
_Sem_Id << std::endl  ;
+#endif
+
 } // End of V()
 
 // ************************************************
@@ -94,10 +162,12 @@
 // ************************************************
 void SemaphoreSysV::Delete(){
 
-printf("Destroy the semaphore identified by number %d\n",_Sem_Id) ;
+#ifdef DEBUG
+std::cout << "Destroy the semaphore identified by number : " << _Sem_Id << 
std::endl ;
+#endif
 
 if(semctl(_Sem_Id,0,IPC_RMID,0) == -1)
-    perror("Erreur in Destroy Semaphore") ;
+    perror("Error with semctl() in SemaphoreSysV::Delete()") ;
 
 } // End of Delete()
 

Index: SemaphoreSysV.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SemaphoreSysV.hh,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- SemaphoreSysV.hh    1 Sep 2009 11:14:13 -0000       1.1.2.2
+++ SemaphoreSysV.hh    4 Sep 2009 08:00:19 -0000       1.1.2.3
@@ -7,9 +7,9 @@
 #include <sys/sem.h>
 
 // Others systems includes 
-#include <stdio.h>
 #include <unistd.h>
-#include <stdlib.h>
+#include <cstdlib>
+#include <iostream>
 
 // Specifics includes
 #include "Semaphore.hh"
@@ -18,15 +18,47 @@
 class SemaphoreSysV : public Semaphore {
     private :
     int _Sem_Id ;
+    key_t _Sem_Key ;
 
     public :
     SemaphoreSysV() ;
     virtual ~SemaphoreSysV() ;
-    void Create_Init(const int initval, const int cle) ;
+    void Create_Init(const int initval, const std::string& New_Semname) ;
+    void Attach(const std::string& New_Semname ) ;
     void P() ;
     void V() ;
     void Delete() ;
 
+    /**
+     * Build a SysV IPC key from a name and user specific value.
+     * The purpose of this function is to build a (quasi) unique
+     * key from unique entry as ftok(3) do with existing file name.
+     * We use SHA1 hash function Xored with the user_specific
+     * value supplied.
+     * @param[in] name, the name representing the IPC element for which
+     *                 we want a key.
+     * @param[in] user_specific_value, any user specific value
+     *                               (for example uid).
+     * @return The generated SysV IPC key corresponding to the specified entry
+     */
+    key_t
+    static ntokUser(const char* name, int32_t user_specific_value);
+
+    /**
+     * Build a SysV IPC key from a name.
+     * L'objectif de cette fonction est de generer des
+     * clefs differentes pour des noms differents, a la maniere
+     * d'une fonction de hachage ou checksum parfaite.
+     * Cette fonction vise les meme objectifs que ftok(3)
+     * avec les noms de fichiers mais avec une chaine
+     * de caractere quelconque.
+     * @param name un nom representant l'element IPC pour lequel on
+     *                veut generer une clef.
+     * @return SysV IPC key corresponding to the specified name.
+     */
+    key_t
+    static ntok(const char* name);
+
 } ;
 
 #endif

Index: SocketSHMPosix.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SocketSHMPosix.cc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- SocketSHMPosix.cc   1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SocketSHMPosix.cc   4 Sep 2009 08:00:19 -0000       1.1.2.2
@@ -3,37 +3,43 @@
 // ************************************************
 // Constructor with args
 // ************************************************
-SocketSHMPosix ::SocketSHMPosix (const std::string& New_Shm_Name_SC, 
-                                const std::string& New_Shm_Name_CS, 
-                                 const bool& IsServerSC,
-                                 const bool& IsServerCS,
-                                 const int& Size_Shm_SC,
-                                 const int& Size_Shm_CS,
-                                 const std::string& Nom_Sem_plein_SC, 
-                                const std::string& Nom_Sem_vide_SC,
-                                 const std::string& Nom_Sem_plein_CS, 
-                                const std::string& Nom_Sem_vide_CS) 
-                              : _Shm_SC(New_Shm_Name_SC, Size_Shm_SC, 
IsServerSC) ,
-                                _Shm_CS(New_Shm_Name_CS, Size_Shm_CS, 
IsServerCS) {
+SocketSHMPosix ::SocketSHMPosix (const std::string& Socket_Name, 
+                                 const SHM_SIDE_t& Socket_Side,
+                                 const int Socket_Size ) : 
SocketSHM(Socket_Name,Socket_Side,Socket_Size) {
+std::string New_Name ;
+// SHMs
+if(_Side == SHM_SC){
+_Shm_SC = new SHMPosix(SHM::buildShmName(Socket_Name+"_SC"), Socket_Size, 
true) ;
+_Shm_CS = new SHMPosix(SHM::buildShmName(Socket_Name+"_CS"), Socket_Size) ;
+  }
+else {
+_Shm_CS = new SHMPosix(SHM::buildShmName(Socket_Name+"_CS"), Socket_Size, 
true) ;
+_Shm_SC = new SHMPosix(SHM::buildShmName(Socket_Name+"_SC"), Socket_Size) ;
+}
 
 // Semaphores
-int init_plein = 0, init_vide = 1 ;
 
-if(_Shm_SC.IsCreator()){
-  _Sem_plein_SC.Create_Init(init_plein, Nom_Sem_plein_SC) ;
-  _Sem_vide_SC.Create_Init(init_vide, Nom_Sem_vide_SC) ;
-  }
-if(_Shm_CS.IsCreator()){
-  _Sem_plein_CS.Create_Init(init_plein, Nom_Sem_plein_CS) ;
-  _Sem_vide_CS.Create_Init(init_vide, Nom_Sem_vide_CS) ;
-  }
-if(_Shm_SC.IsCreator()){
-  _Sem_plein_CS.Attach(Nom_Sem_plein_CS) ;
-  _Sem_vide_CS.Attach(Nom_Sem_vide_CS) ;
-  }
-if(_Shm_CS.IsCreator()){
-  _Sem_plein_SC.Attach(Nom_Sem_plein_SC) ;
-  _Sem_vide_SC.Attach(Nom_Sem_vide_SC) ;
+_Sem_full_SC = new SemaphorePosix() ;
+_Sem_empty_SC = new SemaphorePosix() ;
+_Sem_full_CS = new SemaphorePosix() ;
+_Sem_empty_CS = new SemaphorePosix() ;
+
+int init_full = 0, init_empty = 1 ;
+if(_Side == SHM_SC){
+  _Sem_full_SC->Create_Init(init_full, 
Semaphore::buildSemName(Socket_Name+"_FULL_SC")) ;
+  _Sem_empty_SC->Create_Init(init_empty, 
Semaphore::buildSemName(Socket_Name+"_EMPTY_SC")) ;
+  }
+else{
+  _Sem_full_CS->Create_Init(init_full, 
Semaphore::buildSemName(Socket_Name+"_FULL_CS")) ;
+  _Sem_empty_CS->Create_Init(init_empty, 
Semaphore::buildSemName(Socket_Name+"_EMPTY_CS")) ;
+  }
+if(_Side == SHM_CS){
+  _Sem_full_SC->Attach(Semaphore::buildSemName(Socket_Name+"_FULL_SC")) ;
+  _Sem_empty_SC->Attach(Semaphore::buildSemName(Socket_Name+"_EMPTY_SC")) ;
+  }
+else{
+  _Sem_full_CS->Attach(Semaphore::buildSemName(Socket_Name+"_FULL_CS")) ;
+  _Sem_empty_CS->Attach(Semaphore::buildSemName(Socket_Name+"_EMPTY_CS")) ;
   }
 
 }
@@ -42,15 +48,23 @@
 // ************************************************
 SocketSHMPosix ::~SocketSHMPosix() {
 
-if(_Shm_SC.IsCreator()){
-   _Sem_plein_SC.Delete() ;
-   _Sem_vide_SC.Delete() ;
+if(_Side == SHM_SC){
+   _Sem_full_SC->Delete() ;
+   _Sem_empty_SC->Delete() ;
    }
 
-if(_Shm_CS.IsCreator()){
-   _Sem_plein_CS.Delete() ;
-   _Sem_vide_CS.Delete() ;
+else{
+   _Sem_full_CS->Delete() ;
+   _Sem_empty_CS->Delete() ;
    } 
+
+delete _Sem_full_SC  ;
+delete _Sem_empty_SC  ;
+delete _Sem_full_CS  ;
+delete _Sem_empty_CS ;
+
+delete _Shm_SC ;
+delete _Shm_CS ;
 } // End of ~SocketSHMPosix()
 
 // ************************************************
@@ -59,83 +73,43 @@
 void SocketSHMPosix::Open() {
 
 
-if(_Shm_SC.IsCreator()){
-    _Sem_vide_SC.P() ; 
-     _Shm_SC.Open() ;
-     _Shm_SC.Attach() ;
-    _Sem_vide_SC.V() ;
-     } // End of --> if(_Shm_SC.GetIsServer())
-
-if(_Shm_CS.IsCreator()){
-     _Sem_vide_SC.P() ;  
-     _Shm_SC.Open() ;
-     _Shm_SC.Attach() ;
-     _Sem_vide_SC.V() ;
-     } // End of --> if(_Shm_CS.GetIsServer())
-
-if(_Shm_CS.IsCreator()){
-     _Sem_vide_CS.P() ;
-     _Shm_CS.Open() ;
-     _Shm_CS.Attach() ;
-     _Sem_vide_CS.V() ;
-     } // End of --> if(_Shm_CS.GetIsServer())
-
-if(_Shm_SC.IsCreator()){
-     _Sem_vide_CS.P() ;  
-     _Shm_CS.Open() ;
-     _Shm_CS.Attach() ;
-     _Sem_vide_CS.V() ;
-     } // End of --> if(_Shm_CS.GetIsServer())
+if(_Side == SHM_SC){
+    _Sem_empty_SC->P() ; 
+     _Shm_SC->Open() ;
+     _Shm_SC->Attach() ;
+    _Sem_empty_SC->V() ;
+    #ifdef DEBUG
+    std::cout << " The SHM from Server to Customer is Open " << std::endl ;
+    #endif
+     } 
+else{
+     _Sem_empty_CS->P() ;
+     _Shm_CS->Open() ;
+     _Shm_CS->Attach() ;
+     _Sem_empty_CS->V() ;
+     #ifdef DEBUG
+     std::cout << " The SHM from Customer to Server is Create and Attach" << 
std::endl ;
+     #endif
+     } 
+if(_Side == SHM_CS){
+     _Sem_empty_SC->P() ;  
+     _Shm_SC->Open() ;
+     _Shm_SC->Attach() ;
+     _Sem_empty_SC->V() ;
+     #ifdef DEBUG
+     std::cout << " The SHM from Server to Customer is identified and attached 
" << std::endl ;
+     #endif
+     } 
+else{
+     _Sem_empty_CS->P() ;  
+     _Shm_CS->Open() ;
+     _Shm_CS->Attach() ;
+     _Sem_empty_CS->V() ;
+     #ifdef DEBUG
+     std::cout << " The SHM from Customer to Server is identified and attached 
" << std::endl ;
+     #endif
+     } 
 
 } // End of Open()
 
-// ************************************************
-// Method : SocketSHMPosix::Send(...)
-// ************************************************
-void SocketSHMPosix::Send(void *Buffer) {
-printf("On veut envoyer \n") ;
-
-if(_Shm_SC.IsCreator()){
-     _Sem_vide_SC.P() ;     
-    memcpy(_Shm_SC.GetShm(), Buffer, _Shm_SC.GetSize());
-     _Sem_plein_SC.V() ;
-     } // End of --> if(_Shm_SC.GetIsServer())
-
-if(_Shm_CS.IsCreator()){
-     _Sem_vide_CS.P() ;  
-     memcpy(_Shm_CS.GetShm(), Buffer, _Shm_CS.GetSize());
-     _Sem_plein_CS.V() ;
-     } // End of --> if(_Shm_CS.GetIsServer())
-
-} // End of Send(...)
-
-// ************************************************
-// Method : SocketSHMPosix::Receive(...)
-// ************************************************
-void SocketSHMPosix::Receive(void *Buffer) {
-printf("On veut recevoir \n") ;
-
-if(_Shm_SC.IsCreator()){
-     _Sem_plein_CS.P() ; 
-    memcpy(Buffer, _Shm_CS.GetShm(), _Shm_CS.GetSize());
-     _Sem_vide_CS.V() ;
-     } // End of --> if(_Shm_SC.GetIsServer())
-
-if(_Shm_CS.IsCreator()){
-      _Sem_plein_SC.P() ;  
-     memcpy( Buffer, _Shm_SC.GetShm(), _Shm_SC.GetSize());
-    _Sem_vide_SC.V() ;
-     } // End of --> if(_Shm_CS.GetIsServer())
-
-} // End of --> SocketSHM::Receive(...)
-
-// ************************************************
-// Method : SocketSHMPosix::Close()
-// ************************************************
-void SocketSHMPosix::Close() {
-
-_Shm_SC.Close() ;
-_Shm_CS.Close() ;
-
-} // End of --> SocketSHM::Close()
 

Index: SocketSHMPosix.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SocketSHMPosix.hh,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- SocketSHMPosix.hh   1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SocketSHMPosix.hh   4 Sep 2009 08:00:19 -0000       1.1.2.2
@@ -2,41 +2,24 @@
 #define SOCKET_SHM_POSIX_H
 
 // Specifics includes
-#include "Semaphore.hh"
 #include "SemaphorePosix.hh"
-#include "SHM.hh"
 #include "SHMPosix.hh"
+#include "SocketSHM.hh"
+#include "SHM.hh"
+#include "Semaphore.hh"
 
-class SocketSHMPosix {
+class SocketSHMPosix : public SocketSHM {
 private:   
-    /***** Server -->>> Customer ******/
-    SHMPosix _Shm_SC ;
-    SemaphorePosix _Sem_plein_SC, _Sem_vide_SC ;
-
-    /***** Customer -->>> Server ******/
-    SHMPosix _Shm_CS ; 
-    SemaphorePosix _Sem_plein_CS, _Sem_vide_CS ;  
 
 public :
     // Constructor
-    SocketSHMPosix (const std::string& New_Shm_Name_SC, 
-                   const std::string& New_Shm_Name_CS, 
-                    const bool& IsServerSC,
-                    const bool& IsServerCS,
-                    const int& Size_Shm_SC,
-                    const int& Size_Shm_CS,
-                    const std::string& Nom_Sem_plein_SC, 
-                   const std::string& Nom_Sem_vide_SC,
-                    const std::string& Nom_Sem_plein_CS, 
-                   const std::string& Nom_Sem_vide_CS);  
+    SocketSHMPosix (const std::string& Socket_Name, 
+                    const SHM_SIDE_t& Socket_Side,
+                    const int Socket_Size ); 
     // Destructor
     ~SocketSHMPosix (); 
      
     void Open();
-    void Close(); // To Close the two SHMs
-
-    void Send(void *Buffer) ; // To send Data on a memory segment
-    void Receive(void *Buffer) ; // To receive Data on a memory segment
 
 }; // End of --> class SocketSHM
 

Index: SocketSHMSysV.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SocketSHMSysV.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- SocketSHMSysV.cc    1 Sep 2009 12:51:10 -0000       1.1.2.2
+++ SocketSHMSysV.cc    4 Sep 2009 08:00:19 -0000       1.1.2.3
@@ -1,70 +1,45 @@
 #include "SocketSHMSysV.hh"
-#include "sha1.h"
-
-
-key_t
-SocketSHMSysV::ntokUser(const char* name, int32_t user_specific_value) {
-         key_t s_key;
-         int32_t retcode;
-
-         SHA1Context sha;
-         uint8_t Message_Digest[20];
-
-         /* We use the first byte of a SHA1 hash of the BBname
-          * unless the algorithm fail.
-          * If SHA1 fail we go back to poor key generation method
-          * using the name length.
-          * In both case we must Xored the key with user_specific in order
-          * to isolate different user from using the same key
-          */
-         retcode  = SHA1Reset(&sha);
-         retcode &= SHA1Input(&sha, (const unsigned char *) name,strlen(name));
-         retcode &= SHA1Result(&sha, Message_Digest);
-
-         /* SHA 1 NOK back to old poor method */
-         if (0 != retcode) {
-           s_key = ((strlen(name) << 16) & 0xFFFF0000) ^ (user_specific_value 
& 0x0000FFFF);
-         } else {
-           s_key = (Message_Digest[0]        |
-                    (Message_Digest[1] << 8) |
-                    (Message_Digest[2] << 16)|
-                    (Message_Digest[3] << 24)) ^
-             user_specific_value;
-         }
-         return s_key;
-}
-
-key_t
-SocketSHMSysV::ntok(const char* name) {
-       return SocketSHMSysV::ntokUser(name,getuid());
-}
 
 // ************************************************
 // Constructor with args
 // ************************************************
-SocketSHMSysV::SocketSHMSysV(const std::string& New_Shm_Name_SC, 
-                            const std::string& New_Shm_Name_CS, 
-                             const int New_Shm_Key_SC, 
-                            const int New_Shm_Key_CS, 
-                             const bool IsServerSC,
-                             const bool IsServerCS,
-                             const int Size_Shm_SC,
-                             const int Size_Shm_CS,
-                             const int Key_Sem_plein_SC, 
-                            const int Key_Sem_vide_SC,
-                             const int Key_Sem_plein_CS, 
-                            const int Key_Sem_vide_CS) 
-                            : _Shm_SC(New_Shm_Name_SC, New_Shm_Key_SC, 
Size_Shm_SC, IsServerSC) ,
-                              _Shm_CS(New_Shm_Name_CS, New_Shm_Key_CS, 
Size_Shm_CS, IsServerCS) {
+SocketSHMSysV::SocketSHMSysV(const std::string& Socket_Name, 
+                             const SHM_SIDE_t& Socket_Side,
+                             const int Socket_Size ) : 
SocketSHM(Socket_Name,Socket_Side,Socket_Size) {
+
+if(_Side == SHM_SC){
+_Shm_SC = new SHMSysV(SHM::buildShmName(Socket_Name+"_SC"), Socket_Size,true) ;
+_Shm_CS = new SHMSysV(SHM::buildShmName(Socket_Name+"_CS"), Socket_Size) ;
+  }
+else {
+_Shm_CS = new SHMSysV(SHM::buildShmName(Socket_Name+"_CS"), Socket_Size,true) ;
+_Shm_SC = new SHMSysV(SHM::buildShmName(Socket_Name+"_SC"), Socket_Size) ;
+}
 
 // Semaphores
-int init_plein = 0, init_vide = 1 ; // Initialisation values
-
-_Sem_plein_SC.Create_Init(init_plein, Key_Sem_plein_SC) ;
-_Sem_vide_SC.Create_Init(init_vide, Key_Sem_vide_SC) ;
-
-_Sem_plein_CS.Create_Init(init_plein, Key_Sem_plein_CS) ;
-_Sem_vide_CS.Create_Init(init_vide, Key_Sem_vide_CS) ;
+_Sem_full_SC = new SemaphoreSysV() ;
+_Sem_empty_SC = new SemaphoreSysV() ;
+_Sem_full_CS = new SemaphoreSysV() ;
+_Sem_empty_CS = new SemaphoreSysV() ;
+
+int init_full = 0, init_empty = 1 ; // Initialisation values
+
+if(_Side == SHM_SC){
+  _Sem_full_SC->Create_Init(init_full, 
Semaphore::buildSemName(Socket_Name+"_FULL_SC")) ;
+  _Sem_empty_SC->Create_Init(init_empty, 
Semaphore::buildSemName(Socket_Name+"_EMPTY_SC")) ;
+  }
+else{
+  _Sem_full_CS->Create_Init(init_full, 
Semaphore::buildSemName(Socket_Name+"_FULL_CS")) ;
+  _Sem_empty_CS->Create_Init(init_empty, 
Semaphore::buildSemName(Socket_Name+"_EMPTY_CS")) ;
+  }
+if(_Side == SHM_CS){
+  _Sem_full_SC->Attach(Semaphore::buildSemName(Socket_Name+"_FULL_SC")) ;
+  _Sem_empty_SC->Attach(Semaphore::buildSemName(Socket_Name+"_EMPTY_SC")) ;
+  }
+else{
+  _Sem_full_CS->Attach(Semaphore::buildSemName(Socket_Name+"_FULL_CS")) ;
+  _Sem_empty_CS->Attach(Semaphore::buildSemName(Socket_Name+"_EMPTY_CS")) ;
+  }
 
 }
 
@@ -73,13 +48,13 @@
 // ************************************************
 SocketSHMSysV::~SocketSHMSysV() {
 
-if(_Shm_SC.IsCreator()){
-   _Sem_plein_SC.Delete() ;
-   _Sem_vide_SC.Delete() ;
-   }
-if(_Shm_CS.IsCreator()){
-   _Sem_plein_CS.Delete() ;
-   _Sem_vide_CS.Delete() ;
+if(_Side == SHM_SC){
+   _Sem_full_SC->Delete() ;
+   _Sem_empty_SC->Delete() ;
+   }
+else{
+   _Sem_full_CS->Delete() ;
+   _Sem_empty_CS->Delete() ;
    } 
 
 }
@@ -89,70 +64,44 @@
 // ************************************************
 void SocketSHMSysV::Open() {
 
-std::cout << " Open the socket from Server to Customer " << std::endl ;
-_Shm_SC.Open() ;
-std::cout << " Attach the socket from Server to Customer  " << std::endl ;
-_Shm_SC.Attach() ;
-std::cout << " Open the socket from Customer to Server " << std::endl ;
-_Shm_CS.Open() ;
-std::cout << " Attach the socket from Customer to Server " << std::endl ;
-_Shm_CS.Attach() ;
-} // End of Open()
-
-
-// ************************************************
-// Method : SocketSHMSysV::Send(...)
-// ************************************************
-void SocketSHMSysV::Send(void *Buffer) {
-
-printf("Try to Send \n") ;
-
-if(_Shm_SC.IsCreator()){
-     _Sem_vide_SC.P() ;     
-    memcpy(_Shm_SC.GetShm(), Buffer, _Shm_SC.GetSize());
-     _Sem_plein_SC.V() ;
-     } // End of --> if(_Shm_SC.GetIsServer())
-
-if(_Shm_CS.IsCreator()){
-     _Sem_vide_CS.P() ;  
-     memcpy(_Shm_CS.GetShm(), Buffer, _Shm_CS.GetSize());
-     _Sem_plein_CS.V() ;
-     } // End of --> if(_Shm_CS.GetIsServer())
-
-printf("Send Complete !!\n") ;
-
-} // End of Send(...)
-
-// ************************************************
-// Method : SocketSHMSysV::Receive(...)
-// ************************************************
-void SocketSHMSysV::Receive(void *Buffer) {
-
-printf("Try to Receive\n") ;
-
-if(_Shm_SC.IsCreator()){
-     _Sem_plein_CS.P() ; 
-    memcpy(Buffer, _Shm_CS.GetShm(), _Shm_CS.GetSize());
-     _Sem_vide_CS.V() ;
-     } // End of --> if(_Shm_SC.GetIsServer())
-
-if(_Shm_CS.IsCreator()){
-     _Sem_plein_SC.P() ;  
-     memcpy( Buffer, _Shm_SC.GetShm(), _Shm_SC.GetSize());
-    _Sem_vide_SC.V() ;
-     } // End of --> if(_Shm_CS.GetIsServer())
-
-printf("Receive complete\n") ;
-
-} // End of Receive(...)
+if(_Side == SHM_SC){
+    _Sem_empty_SC->P() ; 
+     _Shm_SC->Open() ;
+     _Shm_SC->Attach() ;
+    _Sem_empty_SC->V() ;
+    #ifdef DEBUG
+    std::cout << " The SHM from Server to Customer is Create and attach " << 
std::endl ;
+    #endif
+     } 
+else{
+     _Sem_empty_CS->P() ;
+     _Shm_CS->Open() ;
+     _Shm_CS->Attach() ;
+     _Sem_empty_CS->V() ;
+     #ifdef DEBUG
+     std::cout << " The SHM from Customer to Server is Create and Attach" << 
std::endl ;
+     #endif
+     } 
+if(_Side == SHM_CS){
+     _Sem_empty_SC->P() ;  
+     _Shm_SC->Open() ;
+     _Shm_SC->Attach() ;
+     _Sem_empty_SC->V() ;
+     #ifdef DEBUG
+     std::cout << " The SHM from Server to Customer is identified and attached 
" << std::endl ;
+     #endif
+     } 
+else{
+     _Sem_empty_CS->P() ;  
+     _Shm_CS->Open() ;
+     _Shm_CS->Attach() ;
+     _Sem_empty_CS->V() ;
+     #ifdef DEBUG
+     std::cout << " The SHM from Customer to Server is identified and attached 
" << std::endl ;
+     #endif
+     } 
 
-// ************************************************
-// Method : SocketSHMSysV::Close()
-// ************************************************
-void SocketSHMSysV::Close() {
+} // End of Open()
 
-_Shm_SC.Close() ;
-_Shm_CS.Close() ;
 
-} // End of Close()
 

Index: SocketSHMSysV.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SocketSHMSysV.hh,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- SocketSHMSysV.hh    1 Sep 2009 12:51:10 -0000       1.1.2.2
+++ SocketSHMSysV.hh    4 Sep 2009 08:00:19 -0000       1.1.2.3
@@ -4,69 +4,20 @@
 // Specifics includes
 #include "SemaphoreSysV.hh"
 #include "SHMSysV.hh"
+#include "SocketSHM.hh"
 
-class SocketSHMSysV {
+class SocketSHMSysV : public SocketSHM {
 private:  
-    /***** Server -->>> Customer ******/
-    SHMSysV _Shm_SC ;
-    SemaphoreSysV _Sem_plein_SC, _Sem_vide_SC ;
-
-    /***** Customer -->>> Server ******/
-    SHMSysV _Shm_CS ;
-    SemaphoreSysV _Sem_plein_CS, _Sem_vide_CS ;      
-
-    /**
-     * Build a SysV IPC key from a name and user specific value.
-     * The purpose of this function is to build a (quasi) unique
-     * key from unique entry as ftok(3) do with existing file name.
-     * We use SHA1 hash function Xored with the user_specific
-     * value supplied.
-     * @param[in] name, the name representing the IPC element for which
-     *                 we want a key.
-     * @param[in] user_specific_value, any user specific value
-     *                               (for example uid).
-     * @return The generated SysV IPC key corresponding to the specified entry
-     */
-    key_t
-    static ntokUser(const char* name, int32_t user_specific_value);
-
-    /**
-     * Build a SysV IPC key from a name.
-     * L'objectif de cette fonction est de g�n�rer des
-     * clefs diff�rentes pour des noms diff�rents, � la mani�re
-     * d'une fonction de hachage ou checksum parfaite.
-     * Cette fonction vise les m�me objectifs que ftok(3)
-     * avec les noms de fichiers mais avec une chaine
-     * de caractere quelconque.
-     * @param name un nom repr�sentant l'�l�ment IPC pour lequel on
-     *                veut g�n�rer une clef.
-     * @return SysV IPC key corresponding to the specified name.
-     */
-    key_t
-    static ntok(const char* name);
 
 public :
     // Constructor
-    SocketSHMSysV (const std::string& New_Shm_Name_SC, 
-                  const std::string& New_Shm_Name_CS,
-                   const int New_Shm_Key_SC, 
-                  const int New_Shm_Key_CS, 
-                   const bool IsServerSC,
-                   const bool IsServerCS,
-                   const int Size_Shm_SC,
-                   const int Size_Shm_CS,
-                   const int Key_Sem_plein_SC, 
-                  const int Key_Sem_vide_SC,
-                   const int Key_Sem_plein_CS, 
-                  const int Key_Sem_vide_CS);  
+    SocketSHMSysV (const std::string& Socket_Name, 
+                   const SHM_SIDE_t& Socket_Side,
+                   const int Socket_size );  
     // Destructor
     ~SocketSHMSysV (); 
      
     void Open();
-    void Close(); // To Close the two SHMs
-
-    void Send(void *Buffer) ; // To send Data on a memory segment
-    void Receive(void *Buffer) ; // To receive Data on a memory segment
    
 }; // End of --> class SocketSHM
 

Index: SocketSHM.cc
===================================================================
RCS file: SocketSHM.cc
diff -N SocketSHM.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ SocketSHM.cc        4 Sep 2009 08:00:19 -0000       1.1.4.2
@@ -0,0 +1,69 @@
+#include "SocketSHM.hh"
+
+// ************************************************
+// Destructor
+// ************************************************
+SocketSHM ::~SocketSHM (){}
+
+// ************************************************
+// Method : SocketSHM::Send(...)
+// ************************************************
+void SocketSHM::Send(void *Buffer) {
+
+#ifdef DEBUG
+std::cout << "Try to Send..." << std::endl ;
+#endif
+
+if(_Side == SHM_SC){
+     _Sem_empty_SC->P() ;     
+    memcpy(_Shm_SC->GetShm(), Buffer, _Shm_SC->GetSize());
+     _Sem_full_SC->V() ;
+     } 
+else{
+     _Sem_empty_CS->P() ;  
+     memcpy(_Shm_CS->GetShm(), Buffer, _Shm_CS->GetSize());
+     _Sem_full_CS->V() ;
+     } 
+
+#ifdef DEBUG
+std::cout << "Send Complete !!" << std::endl ;
+#endif
+
+} // End of Send(...)
+
+// ************************************************
+// Method : SocketSHMS::Receive(...)
+// ************************************************
+void SocketSHM::Receive(void *Buffer) {
+
+#ifdef DEBUG
+std::cout << "Try to Receive..." << std::endl ;
+#endif
+
+if(_Side == SHM_SC){
+     _Sem_full_CS->P() ; 
+    memcpy(Buffer, _Shm_CS->GetShm(), _Shm_CS->GetSize());
+     _Sem_empty_CS->V() ;
+     } 
+else{
+     _Sem_full_SC->P() ;  
+     memcpy( Buffer, _Shm_SC->GetShm(), _Shm_SC->GetSize());
+    _Sem_empty_SC->V() ;
+     } 
+
+#ifdef DEBUG
+std::cout << "Receive complete!!!" << std::endl ;
+#endif
+
+} // End of Receive(...)
+
+// ************************************************
+// Method : SocketSHM::Close()
+// ************************************************
+void SocketSHM::Close() {
+
+_Shm_SC->Close() ;
+_Shm_CS->Close() ;
+
+} // End of --> SocketSHM::Close()
+

Index: SocketSHM.hh
===================================================================
RCS file: SocketSHM.hh
diff -N SocketSHM.hh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ SocketSHM.hh        4 Sep 2009 08:00:19 -0000       1.1.4.2
@@ -0,0 +1,42 @@
+#ifndef SOCKET_SHM_H
+#define SOCKET_SHM_H
+
+#include <iostream>
+
+// Specifics includes
+#include "Semaphore.hh"
+#include "SHM.hh"
+
+class SocketSHM {
+public :
+    // Typedef Side
+    typedef enum{SHM_SC,SHM_CS} SHM_SIDE_t ; 
+
+    // Constructor
+    SocketSHM (const std::string& Socket_Name, 
+               const SHM_SIDE_t& Socket_Side,
+               const int Socket_Size ) { _Name = Socket_Name ; _Side = 
Socket_Side ; _Size_Side = Socket_Size ; } 
+    // Destructor
+    virtual ~SocketSHM ();
+
+    virtual void Send(void *Buffer) ; // To send Data on a memory segment
+    virtual void Receive(void *Buffer) ; // To receive Data on a memory 
segment 
+
+    virtual void Close(); // To Close the two SHMs
+
+protected :   
+    std::string _Name ;
+    SHM_SIDE_t _Side ;
+    size_t _Size_Side ;
+
+    /***** Server -->>> Customer ******/
+    SHM *_Shm_SC ;
+    Semaphore *_Sem_full_SC, *_Sem_empty_SC ;
+
+    /***** Customer -->>> Server ******/
+    SHM *_Shm_CS ; 
+    Semaphore *_Sem_full_CS, *_Sem_empty_CS ;  
+
+}; // End of --> class SocketSHM
+
+#endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]