[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi libCERTI/CMakeLists.txt test/utility/CMak... [br_CERTI
From: |
certi-cvs |
Subject: |
[certi-cvs] certi libCERTI/CMakeLists.txt test/utility/CMak... [br_CERTI_SHM_NEWGEN_dev] |
Date: |
Tue, 01 Sep 2009 11:09:25 +0000 |
CVSROOT: /sources/certi
Module name: certi
Branch: br_CERTI_SHM_NEWGEN_dev
Changes by: Eric NOULARD <erk> 09/09/01 11:09:23
Modified files:
libCERTI : CMakeLists.txt
test/utility : CMakeLists.txt
Added files:
libCERTI : Semaphore.hh SHMPosix.cc SocketSHMSysV.cc
SemaphorePosix.cc SocketSHMPosix.hh
SemaphorePosix.hh SocketSHMPosix.cc SHMSysV.hh
SemaphoreSysV.hh SHMSysV.cc SHM.hh SHMPosix.hh
SemaphoreSysV.cc SocketSHMSysV.hh
test/utility : Main_SocketSHM_A.cc SharedStruct.hh
Main_SocketSHM_B.cc
Log message:
Add First draft of Socket over SHM+Semaphore from Jean-Baptiste
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&r2=1.25.4.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Semaphore.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMPosix.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMSysV.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SemaphorePosix.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMPosix.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SemaphorePosix.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMPosix.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMSysV.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SemaphoreSysV.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMSysV.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHM.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMPosix.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SemaphoreSysV.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMSysV.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/test/utility/CMakeLists.txt?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.4&r2=1.4.8.1
http://cvs.savannah.gnu.org/viewcvs/certi/test/utility/Main_SocketSHM_A.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/test/utility/SharedStruct.hh?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/test/utility/Main_SocketSHM_B.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
Patches:
Index: libCERTI/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libCERTI/CMakeLists.txt,v
retrieving revision 1.25
retrieving revision 1.25.4.1
diff -u -b -r1.25 -r1.25.4.1
--- libCERTI/CMakeLists.txt 2 Apr 2009 19:58:08 -0000 1.25
+++ libCERTI/CMakeLists.txt 1 Sep 2009 11:09:21 -0000 1.25.4.1
@@ -119,6 +119,27 @@
Socket.hh
)
+if (WIN32)
+ message(STATUS "Shared Memory communication is currently unsupported on
Windows")
+else(WIN32)
+ SET(CERTI_SHM_SRCS
+ SHM.hh
+ SHMPosix.cc SHMPosix.hh
+ SHMSysV.cc SHMSysV.hh)
+
+ SET(CERTI_SEMAPHORE_SRCS
+ Semaphore.hh
+ SemaphorePosix.cc SemaphorePosix.hh
+ SemaphoreSysV.cc SemaphoreSysV.hh
+ )
+
+ SET(CERTI_SOCKET_SHM_SRC
+ SocketSHMPosix.cc SocketSHMPosix.hh
+ SocketSHMSysV.cc SocketSHMSysV.hh
+ )
+ LIST(APPEND CERTI_SOCKET_SRCS ${CERTI_SHM_SRCS} ${CERTI_SEMAPHORE_SRCS}
${CERTI_SOCKET_SHM_SRC})
+endif(WIN32)
+
SET(CERTI_SOCKET_SRCS ${CERTI_SOCKET_SRCS} SocketUDP.cc SocketMC.cc
SocketUN.cc SocketUDP.hh SocketMC.hh SocketUN.hh)
SOURCE_GROUP("Source Files\\Socket" FILES ${CERTI_SOCKET_SRCS})
Index: test/utility/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/test/utility/CMakeLists.txt,v
retrieving revision 1.4
retrieving revision 1.4.8.1
diff -u -b -r1.4 -r1.4.8.1
--- test/utility/CMakeLists.txt 7 Dec 2008 20:16:17 -0000 1.4
+++ test/utility/CMakeLists.txt 1 Sep 2009 11:09:22 -0000 1.4.8.1
@@ -8,7 +8,7 @@
ADD_EXECUTABLE(CertiUtilTests ${CertiUtil_SRCS})
-TARGET_LINK_LIBRARIES(CertiUtilTests CERTI RTI FedTime)
+TARGET_LINK_LIBRARIES(CertiUtilTests CERTI)
INSTALL(TARGETS CertiUtilTests
RUNTIME DESTINATION bin
@@ -16,3 +16,14 @@
ARCHIVE DESTINATION lib)
ADD_TEST(CertiUtilTests CertiUtilTests)
+
+ADD_EXECUTABLE(CertiProcessus_A Main_SocketSHM_A.cc SharedStruct.hh)
+TARGET_LINK_LIBRARIES(CertiProcessus_A CERTI rt)
+
+ADD_EXECUTABLE(CertiProcessus_B Main_SocketSHM_B.cc SharedStruct.hh)
+TARGET_LINK_LIBRARIES(CertiProcessus_B CERTI rt)
+
+INSTALL(TARGETS CertiProcessus_A CertiProcessus_B
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
\ No newline at end of file
Index: libCERTI/Semaphore.hh
===================================================================
RCS file: libCERTI/Semaphore.hh
diff -N libCERTI/Semaphore.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/Semaphore.hh 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,26 @@
+#ifndef SEMAPHORE_H
+#define SEMAPHORE_H
+
+// Systems includes
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+
+class Semaphore {
+ private :
+ // int _Sem_Id ;
+
+ public :
+ // Semaphore() ;
+ // ~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 P() = 0 ;
+ virtual void V() = 0 ;
+ virtual void Delete() = 0 ;
+
+} ;
+
+#endif
Index: libCERTI/SHMPosix.cc
===================================================================
RCS file: libCERTI/SHMPosix.cc
diff -N libCERTI/SHMPosix.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SHMPosix.cc 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,98 @@
+#include "SHMPosix.hh"
+
+// ************************************************
+// 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) {
+ _Id = 0 ;
+}
+
+// ************************************************
+// Destructor
+SHMPosix::~SHMPosix() {}
+
+// ************************************************
+// Method : SHMPosix::Open()
+// ************************************************
+void SHMPosix::Open() {
+
+int ret ;
+
+ if (IsCreator()){
+ 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()");
+ exit(1);
+ }
+ fprintf(stderr, "Created shared memory object %s\n", _Name.c_str());
+
+ ret = ftruncate(_Id, _Size);
+ if (ret < 0) {
+ perror("In ftruncate()");
+ exit(1);
+ }
+
+ } // End of if IsCreator()
+ else{
+ _Id = shm_open(_Name.c_str(), O_RDONLY, S_IRWXU | S_IRWXG);
+ if (_Id < 0) {
+ perror("In shm_open()");
+ exit(1);
+ }
+ fprintf(stderr, "Attach shared memory object %s\n", _Name.c_str());
+ } // End of else IsCreator()
+
+} // End of Open()
+
+// ************************************************
+// Method : SHMPosix::Attach()
+// ************************************************
+void SHMPosix::Attach() {
+
+if (IsCreator()){
+ /* 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()");
+ exit(1);}
+ if (_Shm == MAP_FAILED) {
+ perror("In mmap()");
+ exit(1);}
+ close(_Id) ;
+} // End of IsServer
+else{
+ /* requesting the shared segment for write -- mmap() */
+ _Shm = mmap(NULL, _Size, PROT_READ , MAP_SHARED, _Id, 0);
+ if (_Shm == NULL) {
+ perror("In mmap()");
+ exit(1);}
+ if (_Shm == MAP_FAILED) {
+ perror("In mmap()");
+ exit(1);}
+ close(_Id) ;
+} // End of else (IsServer)
+} // End of Attach()
+
+// ************************************************
+// Method : SHMPosix::Close()
+// ************************************************
+void SHMPosix::Close() {
+
+// Close
+if (shm_unlink(_Name.c_str()) != 0) {
+ perror("In shm_unlink()");
+ exit(1);
+ }
+
+// Destroy
+if (IsCreator()){
+if(munmap(_Shm, _Size)){
+ perror("munmap(_Shm, size) : ");
+ exit(1);
+ } // End of if
+}
+
+} // End of Close()
+
Index: libCERTI/SocketSHMSysV.cc
===================================================================
RCS file: libCERTI/SocketSHMSysV.cc
diff -N libCERTI/SocketSHMSysV.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHMSysV.cc 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,119 @@
+#include "SocketSHMSysV.hh"
+
+// ************************************************
+// 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) {
+
+// 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) ;
+
+}
+
+// ************************************************
+// Destructor
+// ************************************************
+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() ;
+ }
+
+}
+
+// ************************************************
+// Method : SocketSHMSysV::Open()
+// ************************************************
+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(...)
+
+// ************************************************
+// Method : SocketSHMSysV::Close()
+// ************************************************
+void SocketSHMSysV::Close() {
+
+_Shm_SC.Close() ;
+_Shm_CS.Close() ;
+
+} // End of Close()
+
Index: libCERTI/SemaphorePosix.cc
===================================================================
RCS file: libCERTI/SemaphorePosix.cc
diff -N libCERTI/SemaphorePosix.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SemaphorePosix.cc 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,87 @@
+#include "SemaphorePosix.hh"
+
+// ************************************************
+// Constructor
+// ************************************************
+SemaphorePosix::SemaphorePosix(){}
+
+// ************************************************
+// Destructor
+// ************************************************
+SemaphorePosix::~SemaphorePosix() {}
+
+// ************************************************
+// Method : SemaphorePosix::Create_Init(...)
+// ************************************************
+void SemaphorePosix::Create_Init(const int initval, const std::string&
New_Semname) {
+int flag ;
+
+ _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);
+if(_Sem == SEM_FAILED) {
+ printf("Erreur de creation du semaphore ") ;
+ }
+
+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) ;
+} // End of Create_Init(...)
+
+// ************************************************
+// Method : SemaphorePosix::Attach(...)
+// ************************************************
+void SemaphorePosix::Attach(const std::string& New_Semname) {
+
+int flag ;
+_Semname.assign(New_Semname) ;
+_Sem = sem_open( _Semname.c_str(), O_CREAT);
+if(_Sem == SEM_FAILED){
+ printf("Erreur de creation du semaphore ") ;
+ }
+
+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) ;
+} // End of Attach(...)
+
+// ************************************************
+// Method : SemaphorePosix::P()
+// ************************************************
+// Decrement Semaphore Value SV=SV-1
+
+void SemaphorePosix::P() {
+
+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_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 ) ;
+} // End of P()
+
+
+// ************************************************
+// Methode : SemaphorePosix::V()
+// ************************************************
+// Increment Semaphore Value SV=SV+1
+
+void SemaphorePosix::V() {
+
+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_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") ;
+} // End of V()
+
+// ************************************************
+// Methode : SemaphorePosix::Delete()
+// ************************************************
+void SemaphorePosix::Delete(){
+sem_close(_Sem) ;
+sem_destroy(_Sem);
+} // End of Delete()
+
Index: libCERTI/SocketSHMPosix.hh
===================================================================
RCS file: libCERTI/SocketSHMPosix.hh
diff -N libCERTI/SocketSHMPosix.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHMPosix.hh 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,43 @@
+#ifndef SOCKET_SHM_POSIX_H
+#define SOCKET_SHM_POSIX_H
+
+// Specifics includes
+#include "Semaphore.hh"
+#include "SemaphorePosix.hh"
+#include "SHM.hh"
+#include "SHMPosix.hh"
+
+class SocketSHMPosix {
+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);
+ // 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
+
+#endif
Index: libCERTI/SemaphorePosix.hh
===================================================================
RCS file: libCERTI/SemaphorePosix.hh
diff -N libCERTI/SemaphorePosix.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SemaphorePosix.hh 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,36 @@
+#ifndef SEMAPHORE_POSIX_H
+#define SEMAPHORE_POSIX_H
+
+// Posix Semaphores systems includes
+// Don't forget to add "-lrt" to compilation line
+#include <sys/types.h>
+#include <semaphore.h>
+#include <fcntl.h>
+
+// Others Systems includes
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+
+// Specifics includes
+#include "Semaphore.hh"
+
+class SemaphorePosix : public Semaphore {
+ private :
+ std::string _Semname ;
+ sem_t *_Sem ;
+
+ public :
+ SemaphorePosix() ;
+ ~SemaphorePosix() ;
+ void Create_Init(const int initval, const std::string& New_Semname ) ;
+ void Attach(const std::string& New_Semname ) ;
+ void P() ;
+ void V() ;
+ void Delete() ;
+
+} ;
+
+#endif
Index: libCERTI/SocketSHMPosix.cc
===================================================================
RCS file: libCERTI/SocketSHMPosix.cc
diff -N libCERTI/SocketSHMPosix.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHMPosix.cc 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,141 @@
+#include "SocketSHMPosix.hh"
+
+// ************************************************
+// 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) {
+
+// 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) ;
+ }
+
+}
+// ************************************************
+// Destructor
+// ************************************************
+SocketSHMPosix ::~SocketSHMPosix() {
+
+if(_Shm_SC.IsCreator()){
+ _Sem_plein_SC.Delete() ;
+ _Sem_vide_SC.Delete() ;
+ }
+
+if(_Shm_CS.IsCreator()){
+ _Sem_plein_CS.Delete() ;
+ _Sem_vide_CS.Delete() ;
+ }
+} // End of ~SocketSHMPosix()
+
+// ************************************************
+// Method : SocketSHMPosix::Open()
+// ************************************************
+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())
+
+} // 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: libCERTI/SHMSysV.hh
===================================================================
RCS file: libCERTI/SHMSysV.hh
diff -N libCERTI/SHMSysV.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SHMSysV.hh 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,41 @@
+#ifndef SHM_SYSV_H
+#define SHM_SYSV_H
+
+// SHMs useful systems includes
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+// Others systems includes
+#include <fcntl.h>
+#include <math.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <iostream>
+#include <string.h>
+
+// Specifics includes
+#include "SHM.hh"
+
+class SHMSysV : public SHM {
+
+ private :
+ int _Id ;
+ int _Key ;
+
+ public :
+ SHMSysV(const std::string& New_Name, const int New_Key, const int
New_Size, const bool It_IsCreator) ;
+ ~SHMSysV() ;
+ void Open() ;
+ void Attach() ;
+ void Close() ;
+
+} ;
+
+
+
+
+
+
+#endif
Index: libCERTI/SemaphoreSysV.hh
===================================================================
RCS file: libCERTI/SemaphoreSysV.hh
diff -N libCERTI/SemaphoreSysV.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SemaphoreSysV.hh 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,32 @@
+#ifndef SEMAPHORESYSV_H
+#define SEMAPHORESYSV_H
+
+// Semaphores usefull systems includes
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+// Others systems includes
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+// Specifics includes
+#include "Semaphore.hh"
+
+
+class SemaphoreSysV : public Semaphore {
+ private :
+ int _Sem_Id ;
+
+ public :
+ SemaphoreSysV() ;
+ ~SemaphoreSysV() ;
+ void Create_Init(const int initval, const int cle) ;
+ void P() ;
+ void V() ;
+ void Delete() ;
+
+} ;
+
+#endif
Index: libCERTI/SHMSysV.cc
===================================================================
RCS file: libCERTI/SHMSysV.cc
diff -N libCERTI/SHMSysV.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SHMSysV.cc 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,61 @@
+#include "SHMSysV.hh"
+
+// ************************************************
+// Constructor 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) {
+ _Id = 0 ;
+ _Key = New_Key ;
+}
+
+
+// ************************************************
+// Destructor
+// ************************************************
+SHMSysV::~SHMSysV() {}
+
+// ************************************************
+// Method : SHMSysV::Open()
+// ************************************************
+void SHMSysV::Open() {
+
+if ((_Id = shmget((key_t)_Key, (size_t) _Size, IPC_CREAT| 0666 )) < 0){
+ perror("Error in shmget ");
+ exit(1);
+ } // End of if
+
+} // End of Open()
+
+// ************************************************
+// Method : SHMSysV::Attach()
+// ************************************************
+void SHMSysV::Attach() {
+
+if ( ( _Shm = shmat(_Id, NULL, 0) ) == (void*) -1){
+ perror("Error in shmat ");
+ exit(1);
+ } // End of if
+
+} // End of Attach(...)
+
+// ************************************************
+// Method : Close()
+// ************************************************
+void SHMSysV::Close() {
+
+// Close
+if(shmdt(_Shm)){
+ perror("Error in shmdt ");
+ exit(1);
+ } // End of if(shmdt(_Shm))
+
+if(_IsCreator){
+// Destroy
+if(shmctl(_Id, IPC_RMID,0)){
+ perror("Error in shmctl(IPC_RMID) ");
+ exit(1);
+ } // End of if(shmctl(_Shm_Id, IPC_RMID,0))
+} // End of (_IsServer)
+
+} // End of Close()
+
Index: libCERTI/SHM.hh
===================================================================
RCS file: libCERTI/SHM.hh
diff -N libCERTI/SHM.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SHM.hh 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,35 @@
+#ifndef SHM_H
+#define SHM_H
+
+// Systems includes
+#include <math.h>
+#include <iostream>
+#include <string.h>
+
+// Correctly define BOOL type
+#ifndef __bool_true_false_are_defined
+# define TRUE 1
+# define FALSE 0
+# define bool int
+# define __bool_true_false_are_defined
+#endif
+
+class SHM {
+ 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; }
+ const std::string getName() const {return _Name ; } ;
+ inline void* GetShm(){return _Shm ; } ;
+ inline bool IsCreator(){return _IsCreator ; } ;
+ inline int GetSize(){return _Size ; } ;
+ virtual void Open() = 0 ;
+ virtual void Attach() = 0 ;
+ virtual void Close() = 0 ;
+} ;
+
+#endif
Index: libCERTI/SHMPosix.hh
===================================================================
RCS file: libCERTI/SHMPosix.hh
diff -N libCERTI/SHMPosix.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SHMPosix.hh 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,36 @@
+#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 :
+ 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() ;
+
+ void Open() ;
+ void Attach() ;
+ void Close() ;
+
+} ;
+
+#endif
Index: libCERTI/SemaphoreSysV.cc
===================================================================
RCS file: libCERTI/SemaphoreSysV.cc
diff -N libCERTI/SemaphoreSysV.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SemaphoreSysV.cc 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,103 @@
+#include "SemaphoreSysV.hh"
+
+// ************************************************
+// Constructor
+// ************************************************
+SemaphoreSysV::SemaphoreSysV(){
+_Sem_Id = 0 ;
+}
+
+// ************************************************
+// Destructor
+// ************************************************
+SemaphoreSysV::~SemaphoreSysV() {}
+
+// ************************************************
+// 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 ;
+ if (_Sem_Id == -1){
+ _Sem_Id = semget(cle,1,0666) ;
+ flag = 2 ;
+ if (_Sem_Id == -1) {
+ perror("Error with semget()") ;
+ 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) ;
+
+ union semun{
+ int val ;
+ struct semid_ds *buf ; // Not use here
+ ushort *array; // Not use here
+ } arg_ctl ;
+
+ // Maintenant on affecte une valeur initiale au s\'emaphore
+ 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) ;
+
+} // End of method : sem_create
+
+// ************************************************
+// Method : SemaphoreSysV::P
+// ************************************************
+// Decrement Semaphore Value SV=SV-1
+
+void SemaphoreSysV::P() {
+printf("Begin of Operation P for the semaphore identified by number
%d\n",_Sem_Id) ;
+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()") ;
+ exit(1);
+ }
+printf("End of Operation P for the semaphore identified by number
%d\n",_Sem_Id) ;
+} // End of P()
+
+
+// ************************************************
+// Method : SemaphoreSysV::V
+// ************************************************
+// Increment Semaphore Value SV=SV+1
+
+void SemaphoreSysV::V() {
+printf("Begin of Operation V for the semaphore identified by number
%d\n",_Sem_Id) ;
+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()") ;
+ exit(1);
+ }
+printf("End of Operation V for the semaphore identified by number
%d\n",_Sem_Id) ;
+} // End of V()
+
+// ************************************************
+// Method : SemaphoreSysV::Delete
+// ************************************************
+void SemaphoreSysV::Delete(){
+
+printf("Destroy the semaphore identified by number %d\n",_Sem_Id) ;
+
+if(semctl(_Sem_Id,0,IPC_RMID,0) == -1)
+ perror("Erreur in Destroy Semaphore") ;
+
+} // End of Delete()
+
Index: libCERTI/SocketSHMSysV.hh
===================================================================
RCS file: libCERTI/SocketSHMSysV.hh
diff -N libCERTI/SocketSHMSysV.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHMSysV.hh 1 Sep 2009 11:09:21 -0000 1.1.2.1
@@ -0,0 +1,45 @@
+#ifndef SOCKET_SHM_SYSV_H
+#define SOCKET_SHM_SYSV_H
+
+// Specifics includes
+#include "Semaphore.hh"
+#include "SemaphoreSysV.hh"
+#include "SHM.hh"
+#include "SHMSysV.hh"
+
+class SocketSHMSysV {
+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 ;
+
+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);
+ // 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
+
+#endif
Index: test/utility/Main_SocketSHM_A.cc
===================================================================
RCS file: test/utility/Main_SocketSHM_A.cc
diff -N test/utility/Main_SocketSHM_A.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/utility/Main_SocketSHM_A.cc 1 Sep 2009 11:09:22 -0000 1.1.2.1
@@ -0,0 +1,167 @@
+//
*****************************************************************************
+// To Compile without cmake :
+// g++ Main_SocketSHM_A.cc SocketSHMPosix.cc SemaphorePosix.cc
SocketSHMSysV.cc SHMSysV.cc SemaphoreSysV.cc -o Processus_A -lrt
+//
*****************************************************************************
+// For SysV use :
+// Before Use : --> #ipcs
+// You can see all the semaphore and the shared memory in use
+// --> #ipcrm -m id_memory to erase a memory segment
+// --> #ipcrm -s id_semaphore to erase a semaphore
+
+// Systems includes
+#include <limits>
+
+// Specifics includes
+#include "SocketSHMPosix.hh"
+#include "SocketSHMSysV.hh"
+#include "SharedStruct.hh"
+
+
+#define NAME_A_TO_B "/foo1234" // Name SHM to broadcast from A to B
+#define NAME_B_TO_A "/foo5678" // Name SHM to broadcast from B to A
+
+#define KEY_A_TO_B 0x12345 // Key SHM to broadcast from A to B
+#define KEY_B_TO_A 0x6789 // Key SHM to broadcast from B to A
+
+#define NAME_FULL_AB "/Sem_full_AB" // Name Full Semaphore to synchronise
broadcast from A to B (Useful for Posix Semaphore)
+#define NAME_EMPTY_AB "/Sem_empty_AB" // Name Empty Semaphore to synchronise
broadcast from A to B (Useful for Posix Semaphore)
+#define NAME_FULL_BA "/Sem_full_BA" // Name Full Semaphore to synchronise
broadcast from B to A (Useful for Posix Semaphore)
+#define NAME_EMPTY_BA "/Sem_empty_BA" // Name Empty Semaphore to synchronise
broadcast from B to A (Useful for Posix Semaphore)
+
+#define KEY_FULL_AB 0x12 // // Key Full Semaphore to synchronise broadcast
from A to B (Useful for SysV Semaphore)
+#define KEY_EMPTY_AB 0x34 // Key Empty Semaphore to synchronise broadcast from
A to B (Useful for SysV Semaphore)
+#define KEY_FULL_BA 0x56 // Key Full Semaphore to synchronise broadcast from B
to A (Useful for SysV Semaphore)
+#define KEY_EMPTY_BA 0x78 // Key Empty Semaphore to synchronise broadcast from
B to A (Useful for SysV Semaphore)
+
+
+
+/****************************************/
+/*********** MAIN PROGRAM ***************/
+/****************************************/
+
+int main(){
+
+// ************
+// DECLARATIONS
+// ************
+int i = 1 ; // variable quelconque qui me sers pour un compteur plus bas...
+shared_struct Data_Read_A ; // Data lue dans la socketSHM.
+shared_struct Data_Write_A ; // Data ecrite dans la socketSHM.
+std::string command;
+
+
+int size ;
+size = (int) sizeof(shared_struct) ;
+
+// Initialisation des variables Data pour aucun soucis
+Data_Read_A.Header = 0 ; Data_Read_A.Body =0.0 ;
+Data_Write_A.Header = 0 ; Data_Write_A.Body =0.0 ;
+
+// ************
+// CODE
+// ************
+
+// Posix Socket SHM
+SocketSHMPosix Socket_Posix_AB(NAME_A_TO_B,
+ NAME_B_TO_A,
+ TRUE,
+ FALSE,
+ size,
+ size,
+ NAME_FULL_AB,
+ NAME_EMPTY_AB,
+ NAME_FULL_BA,
+ NAME_EMPTY_BA) ;
+
+// SystemV Socket SHM
+SocketSHMSysV Socket_SysV_AB(NAME_A_TO_B,
+ NAME_B_TO_A,
+ KEY_A_TO_B,
+ KEY_B_TO_A,
+ TRUE,
+ FALSE,
+ size,
+ size,
+ KEY_FULL_AB,
+ KEY_EMPTY_AB,
+ KEY_FULL_BA,
+ KEY_EMPTY_BA) ;
+
+
+// Wainting for User Command n1
+std::cout << "*******************************************************" <<
std::endl ;
+std::cout << "*********** END OF INITIALIZATION PHASE 1 : ***********" <<
std::endl ;
+std::cout << "*** Click \"Posix\" to Open Posix Socket SHM **********" <<
std::endl ;
+std::cout << "*** Click \"SysV\" to Open Systeme V Socket SHM *******" <<
std::endl ;
+std::cout << "*******************************************************" <<
std::endl ;
+std::cin >> command;
+std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
+
+// Open the Socket
+if (command=="Posix") Socket_Posix_AB.Open() ;
+if (command=="SysV") Socket_SysV_AB.Open() ;
+
+// Wainting for User Command n2
+std::cout << "************************************************************" <<
std::endl ;
+std::cout << "******* END OF INITIALIZATION PHASE 2 : ********************" <<
std::endl ;
+std::cout << "****** Click \"ENTER\" to RunInter Process Exchange... *****" <<
std::endl ;
+std::cout << "************************************************************" <<
std::endl ;
+std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
+
+
+
+// Send to B For the First Time (INITIALIZE)
+// Send to B
+if (command=="Posix") Socket_Posix_AB.Send(&Data_Write_A) ;
+if (command=="SysV") Socket_SysV_AB.Send(&Data_Write_A) ;
+
+
+ while(i<1000) {
+ std::cout << " *********** COMPUTING PHASE n°= " << i << "*************"
<< std ::endl ;
+
+ /**************************************/
+ /************* RECEIVING **************/
+ /**************************************/
+ // Read from B
+ if (command=="Posix") Socket_Posix_AB.Receive(&Data_Read_A) ;
+ if (command=="SysV") Socket_SysV_AB.Receive(&Data_Read_A) ;
+
+ /**************************************/
+ /************* COMPUTE ****************/
+ /**************************************/
+ // Print Receiving Data
+ std::cout << " ****** RECEIVE ******" << std ::endl ;
+ std::cout << "Processus A ||Â DataRead.Header = " << Data_Read_A.Header <<
std ::endl ;
+ std::cout << " Processus A || DataRead.Body = " << Data_Read_A.Body << std
::endl ;
+ std::cout << " ************************** " << std::endl ;
+
+ // Product a new Data
+ Data_Write_A.Header = Data_Read_A.Header + 1 ;
+ Data_Write_A.Body = Data_Read_A.Body + 0.1 ;
+
+ // Print Sending Data
+ std::cout << " ******** SEND ********" << std ::endl ;
+ std::cout << "Processus A ||Â DataWrite.Header = " << Data_Write_A.Header
<< std ::endl ;
+ std::cout << " Processus A || DataWrite.Body = " << Data_Write_A.Body <<
std ::endl ;
+ std::cout << " ************************ " << std ::endl ;
+
+ /**************************************/
+ /************* SENDING ****************/
+ /**************************************/
+ // Send to B
+ if (command=="Posix") Socket_Posix_AB.Send(&Data_Write_A) ;
+ if (command=="SysV") Socket_SysV_AB.Send(&Data_Write_A) ;
+
+ // On incremente le compteur
+ i++ ;
+
+ } // End of while (i<1000)
+
+// Waiting the two process are out of while boucle
+sleep(1) ;
+
+// Close the socket
+if (command=="Posix") Socket_Posix_AB.Close() ;
+if (command=="SysV") Socket_SysV_AB.Close() ;
+
+} // End of Main Program
Index: test/utility/SharedStruct.hh
===================================================================
RCS file: test/utility/SharedStruct.hh
diff -N test/utility/SharedStruct.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/utility/SharedStruct.hh 1 Sep 2009 11:09:22 -0000 1.1.2.1
@@ -0,0 +1,14 @@
+#ifndef SHARED_STRUCT_H
+#define SHARED_STRUCT_H
+
+/* For FILE */
+#include <stdio.h>
+
+typedef struct {
+ int Header;
+ double Body;
+} shared_struct ;
+
+#endif
+
+
Index: test/utility/Main_SocketSHM_B.cc
===================================================================
RCS file: test/utility/Main_SocketSHM_B.cc
diff -N test/utility/Main_SocketSHM_B.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/utility/Main_SocketSHM_B.cc 1 Sep 2009 11:09:22 -0000 1.1.2.1
@@ -0,0 +1,153 @@
+//
*****************************************************************************
+// To Compile without cmake :
+// g++ Main_SocketSHM_B.cc SocketSHMPosix.cc SemaphorePosix.cc
SocketSHMSysV.cc SHMSysV.cc SemaphoreSysV.cc -o Processus_B -lrt
+//
*****************************************************************************
+// For SysV use :
+// Before Use : --> #ipcs
+// You can see all the semaphore and the shared memory in use
+// --> #ipcrm -m id_memory to erase a memory segment
+// --> #ipcrm -s id_semaphore to erase a semaphore
+
+// Systems includes
+#include <limits>
+
+// Specifics includes
+#include "SocketSHMPosix.hh"
+#include "SocketSHMSysV.hh"
+#include "SharedStruct.hh"
+
+#define NAME_A_TO_B "/foo1234" // Name SHM to broadcast from A to B
+#define NAME_B_TO_A "/foo5678" // Name SHM to broadcast from B to A
+
+#define KEY_A_TO_B 0x12345 // Key SHM to broadcast from A to B
+#define KEY_B_TO_A 0x6789 // Key SHM to broadcast from B to A
+
+#define NAME_FULL_AB "/Sem_full_AB" // Name Full Semaphore to synchronise
broadcast from A to B (Useful for Posix Semaphore)
+#define NAME_EMPTY_AB "/Sem_empty_AB" // Name Empty Semaphore to synchronise
broadcast from A to B (Useful for Posix Semaphore)
+#define NAME_FULL_BA "/Sem_full_BA" // Name Full Semaphore to synchronise
broadcast from B to A (Useful for Posix Semaphore)
+#define NAME_EMPTY_BA "/Sem_empty_BA" // Name Empty Semaphore to synchronise
broadcast from B to A (Useful for Posix Semaphore)
+
+#define KEY_FULL_AB 0x12 // // Key Full Semaphore to synchronise broadcast
from A to B (Useful for SysV Semaphore)
+#define KEY_EMPTY_AB 0x34 // Key Empty Semaphore to synchronise broadcast from
A to B (Useful for SysV Semaphore)
+#define KEY_FULL_BA 0x56 // Key Full Semaphore to synchronise broadcast from B
to A (Useful for SysV Semaphore)
+#define KEY_EMPTY_BA 0x78 // Key Empty Semaphore to synchronise broadcast from
B to A (Useful for SysV Semaphore)
+
+
+/****************************************/
+/******** PROGRAMME PRINCIPAL ***********/
+/****************************************/
+
+int main(){
+
+// ************
+// DECLARATIONS
+// ************
+
+int i = 1 ; // variable quelconque qui me sers pour un compteur plus bas...
+shared_struct Data_Read_B ; // Data lue dans la socketSHM.
+shared_struct Data_Write_B ; // Data ecrite dans la socketSHM.
+std::string command;
+
+int size ;
+size = (int) sizeof(shared_struct) ;
+
+// ************
+// CODE
+// ************
+
+// Posix Socket SHM
+SocketSHMPosix Socket_Posix_AB(NAME_A_TO_B,
+ NAME_B_TO_A,
+ FALSE,
+ TRUE,
+ size,
+ size,
+ NAME_FULL_AB,
+ NAME_EMPTY_AB,
+ NAME_FULL_BA,
+ NAME_EMPTY_BA) ;
+
+// SystemV Socket SHM
+SocketSHMSysV Socket_SysV_AB(NAME_A_TO_B,
+ NAME_B_TO_A,
+ KEY_A_TO_B,
+ KEY_B_TO_A,
+ FALSE,
+ TRUE,
+ size,
+ size,
+ KEY_FULL_AB,
+ KEY_EMPTY_AB,
+ KEY_FULL_BA,
+ KEY_EMPTY_BA) ;
+
+// Wainting for User Command n1
+std::cout << "*******************************************************" <<
std::endl ;
+std::cout << "*********** END OF INITIALIZATION PHASE 1 : ***********" <<
std::endl ;
+std::cout << "*** Click \"Posix\" to Open Posix Socket SHM **********" <<
std::endl ;
+std::cout << "*** Click \"SysV\" to Open Systeme V Socket SHM *******" <<
std::endl ;
+std::cout << "*******************************************************" <<
std::endl ;
+std::cin >> command;
+std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
+
+// Open the Socket
+if (command=="Posix") Socket_Posix_AB.Open() ;
+if (command=="SysV") Socket_SysV_AB.Open() ;
+
+// Wainting for User Command n2
+std::cout << "******************************************************" <<
std::endl ;
+std::cout << "******* END OF INITIALIZATION PHASE 2 : **************" <<
std::endl ;
+std::cout << "*** Click \"ENTER\" to Run Inter Process Exchange ****" <<
std::endl ;
+std::cout << "******************************************************" <<
std::endl ;
+std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
+
+ while(i<1000) {
+ std::cout << " " << std
::endl ;
+ std::cout << " *********** COMPUTING PHASE n°= " << i << "*************"
<< std ::endl ;
+
+ /**************************************/
+ /************* RECEIVING **************/
+ /**************************************/
+ // Receive from A
+ if (command=="Posix") Socket_Posix_AB.Receive(&Data_Read_B) ;
+ if (command=="SysV") Socket_SysV_AB.Receive(&Data_Read_B) ;
+
+ /**************************************/
+ /************* COMPUTE ****************/
+ /**************************************/
+ // Print Receiving Data
+ std::cout << " ****** RECEIVE ******" << std ::endl ;
+ std::cout << "Processus B ||Â DataRead.Header = " << Data_Read_B.Header <<
std ::endl ;
+ std::cout << " Processus B || DataRead.Body = " << Data_Read_B.Body << std
::endl ;
+ std::cout << " ************************** " << std ::endl ;
+
+ // Product a new Data
+ Data_Write_B.Header = Data_Read_B.Header + 1 ;
+ Data_Write_B.Body = Data_Read_B.Body + 0.1 ;
+
+ // Print Sending Data
+ std::cout << " ******** SEND ********" << std ::endl ;
+ std::cout << "Processus B ||Â DataWrite.Header = " << Data_Write_B.Header
<< std ::endl ;
+ std::cout << " Processus B || DataWrite.Body = " << Data_Write_B.Body <<
std ::endl ;
+ std::cout << " ************************ " << std ::endl ;
+
+ /**************************************/
+ /************* SENDING ****************/
+ /**************************************/
+ // Send to A
+ if (command=="Posix") Socket_Posix_AB.Send(&Data_Write_B) ;
+ if (command=="SysV") Socket_SysV_AB.Send(&Data_Write_B) ;
+
+ // On incremente le compteur
+ i++ ;
+
+ } // Fin de la boucle while
+
+// Waiting the two process are out of while boucle
+sleep(1) ;
+
+// Close the socket
+if (command=="Posix") Socket_Posix_AB.Close() ;
+if (command=="SysV") Socket_SysV_AB.Close() ;
+
+} // Fin Programme Principal
- [certi-cvs] certi libCERTI/CMakeLists.txt test/utility/CMak... [br_CERTI_SHM_NEWGEN_dev],
certi-cvs <=