certi-cvs
[Top][All Lists]
Advanced

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

[certi-cvs] certi/libCERTI Semaphore.hh SHMPosix.cc SocketS... [br_CERTI


From: certi-cvs
Subject: [certi-cvs] certi/libCERTI Semaphore.hh SHMPosix.cc SocketS... [br_CERTI_SHM_NEWGEN_dev]
Date: Tue, 01 Sep 2009 12:51:11 +0000

CVSROOT:        /sources/certi
Module name:    certi
Branch:         br_CERTI_SHM_NEWGEN_dev
Changes by:     Eric NOULARD <erk>      09/09/01 12:51:11

Modified files:
        libCERTI       : Semaphore.hh SHMPosix.cc SocketSHMSysV.cc 
                         SHM.hh SHMPosix.hh CMakeLists.txt 
                         SocketSHMSysV.hh 

Log message:
        Prepare cleaner interface for choosing IPC names, keys and the like.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Semaphore.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/SHMPosix.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/SocketSHMSysV.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/SHM.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/SHMPosix.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/CMakeLists.txt?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.25.4.1&r2=1.25.4.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMSysV.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.1&r2=1.1.2.2

Patches:
Index: Semaphore.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/Semaphore.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
--- Semaphore.hh        1 Sep 2009 11:14:13 -0000       1.1.2.2
+++ Semaphore.hh        1 Sep 2009 12:51:10 -0000       1.1.2.3
@@ -2,14 +2,19 @@
 #define SEMAPHORE_H
 
 // Systems includes
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
+#include <string>
 
 class Semaphore {
-    private :
-    // int _Sem_Id ;
+
+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() ;

Index: SHMPosix.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SHMPosix.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
--- SHMPosix.cc 1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SHMPosix.cc 1 Sep 2009 12:51:10 -0000       1.1.2.2
@@ -1,3 +1,16 @@
+// SHM useful systems includes
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+
+// Others Systems includes
+#include <math.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <iostream>
+#include <string.h>
+
 #include "SHMPosix.hh"
 
 // ************************************************

Index: SocketSHMSysV.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SocketSHMSysV.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
--- SocketSHMSysV.cc    1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SocketSHMSysV.cc    1 Sep 2009 12:51:10 -0000       1.1.2.2
@@ -1,4 +1,43 @@
 #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

Index: SHM.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SHM.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
--- SHM.hh      1 Sep 2009 11:15:43 -0000       1.1.2.3
+++ SHM.hh      1 Sep 2009 12:51:10 -0000       1.1.2.4
@@ -1,20 +1,43 @@
 #ifndef SHM_H
 #define SHM_H
 
-// Systems includes
-#include <math.h>
-#include <iostream>
-#include <string.h>
+#include <string>
 
+/**
+ * A Shared Memory class.
+ * This class is an abstract base for representing a shared memory
+ * segment. A shared memory segment is identified by its name and
+ * has a size and a creator process.
+ */
 class SHM {
-    protected :
+protected :
     std::string _Name ;
     int  _Size ;
     bool _IsCreator ;
     void *_Shm ;
 
-    public :
-    SHM(const std::string& SHMName, const int SHMSize,const bool isCreator) 
{_Name=SHMName; _Size=SHMSize; _IsCreator=isCreator; }
+       /**
+        * 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)
+               {_Name=SHMName;
+                _Size=SHMSize;
+                _IsCreator=isCreator;
+                }
     virtual ~SHM() {};
     const std::string getName() const {return _Name ; } ; 
     inline void* GetShm(){return _Shm ; } ;

Index: SHMPosix.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SHMPosix.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
--- SHMPosix.hh 1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SHMPosix.hh 1 Sep 2009 12:51:10 -0000       1.1.2.2
@@ -1,23 +1,9 @@
 #ifndef SHM_POSIX_H
 #define SHM_POSIX_H
 
-// SHM useful systems includes
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-
-// Others Systems includes
-#include <math.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <iostream>
-#include <string.h>
-
 // Specifics includes
 #include "SHM.hh"
 
-
 class SHMPosix : public SHM {
 
     private :

Index: CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libCERTI/CMakeLists.txt,v
retrieving revision 1.25.4.1
retrieving revision 1.25.4.2
diff -u -b -r1.25.4.1 -r1.25.4.2
--- CMakeLists.txt      1 Sep 2009 11:09:21 -0000       1.25.4.1
+++ CMakeLists.txt      1 Sep 2009 12:51:10 -0000       1.25.4.2
@@ -122,6 +122,7 @@
 if (WIN32)
     message(STATUS "Shared Memory communication is currently unsupported on 
Windows")
 else(WIN32)
+    include_directories(${CERTI_SOURCE_DIR}/libHLA)
     SET(CERTI_SHM_SRCS 
         SHM.hh
         SHMPosix.cc SHMPosix.hh
@@ -218,7 +219,7 @@
 TARGET_LINK_LIBRARIES(CERTI
     ${LIBXML2_LIBRARIES}
     ${GEN_LIBRARY}
-    ${SOCKET_LIBRARY})
+    ${SOCKET_LIBRARY} HLA)
 IF (MINGW)
     SET_TARGET_PROPERTIES(CERTI PROPERTIES LINK_FLAGS 
"-Wl,--output-def,${LIBRARY_OUTPUT_PATH}/libCERTI.def")
     INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/libCERTI.def

Index: SocketSHMSysV.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SocketSHMSysV.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
--- SocketSHMSysV.hh    1 Sep 2009 11:09:21 -0000       1.1.2.1
+++ SocketSHMSysV.hh    1 Sep 2009 12:51:10 -0000       1.1.2.2
@@ -2,9 +2,7 @@
 #define SOCKET_SHM_SYSV_H
 
 // Specifics includes
-#include "Semaphore.hh"
 #include "SemaphoreSysV.hh"
-#include "SHM.hh"
 #include "SHMSysV.hh"
 
 class SocketSHMSysV {
@@ -17,6 +15,36 @@
     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, 




reply via email to

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