[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi libCERTI/CMakeLists.txt libCERTI/Semaphor... [br_CERTI
From: |
certi-cvs |
Subject: |
[certi-cvs] certi libCERTI/CMakeLists.txt libCERTI/Semaphor... [br_CERTI_SHM_NEWGEN_dev] |
Date: |
Mon, 12 Oct 2009 09:08:45 +0000 |
CVSROOT: /sources/certi
Module name: certi
Branch: br_CERTI_SHM_NEWGEN_dev
Changes by: Adelantado <adele> 09/10/12 09:08:45
Modified files:
libCERTI : CMakeLists.txt SemaphorePosix.hh
test/utility : Main_SocketSHM.cc
Log message:
Introducing RingBuffer class to emulate Socket Unix Send and Receive
Operations through shared memory. Available under UNIX, Linux (Posix and SysV
implementation) and Win32 OS.
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.6&r2=1.25.4.7
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SemaphorePosix.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/test/utility/Main_SocketSHM.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&r1=1.1.2.3&r2=1.1.2.4
Patches:
Index: libCERTI/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/libCERTI/CMakeLists.txt,v
retrieving revision 1.25.4.6
retrieving revision 1.25.4.7
diff -u -b -r1.25.4.6 -r1.25.4.7
--- libCERTI/CMakeLists.txt 22 Sep 2009 09:56:45 -0000 1.25.4.6
+++ libCERTI/CMakeLists.txt 12 Oct 2009 09:08:45 -0000 1.25.4.7
@@ -131,7 +131,7 @@
SET(CERTI_SOCKET_SHM_SRC
SocketSHM.cc SocketSHM.hh
SocketSHMWin32.cc SocketSHMWin32.hh
- )
+ RingBuffer.cc RingBuffer.hh)
LIST(APPEND CERTI_SOCKET_SRCS ${CERTI_SHM_SRCS} ${CERTI_SEMAPHORE_SRCS}
${CERTI_SOCKET_SHM_SRC})
else(WIN32)
@@ -153,6 +153,7 @@
SocketSHM.cc SocketSHM.hh
SocketSHMPosix.cc SocketSHMPosix.hh
SocketSHMSysV.cc SocketSHMSysV.hh
+ RingBuffer.cc RingBuffer.hh
)
LIST(APPEND CERTI_SOCKET_SRCS ${CERTI_SHM_SRCS} ${CERTI_SEMAPHORE_SRCS}
${CERTI_SOCKET_SHM_SRC})
Index: libCERTI/SemaphorePosix.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Attic/SemaphorePosix.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
--- libCERTI/SemaphorePosix.hh 1 Sep 2009 11:14:13 -0000 1.1.2.2
+++ libCERTI/SemaphorePosix.hh 12 Oct 2009 09:08:45 -0000 1.1.2.3
@@ -4,7 +4,7 @@
// Posix Semaphores systems includes
// Don't forget to add "-lrt" to compilation line
#include <sys/types.h>
-#include <semaphore.h>
+#include <Semaphore.hh>
#include <fcntl.h>
// Others Systems includes
Index: test/utility/Main_SocketSHM.cc
===================================================================
RCS file: /sources/certi/certi/test/utility/Attic/Main_SocketSHM.cc,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- test/utility/Main_SocketSHM.cc 22 Sep 2009 09:56:46 -0000 1.1.2.3
+++ test/utility/Main_SocketSHM.cc 12 Oct 2009 09:08:45 -0000 1.1.2.4
@@ -1,8 +1,24 @@
-//
*****************************************************************************
-// To Compile without cmake :
-// g++ Main_SocketSHM_A.cc SocketSHMPosix.cc SemaphorePosix.cc
SemaphoreWin32.cc SocketSHMSysV.cc SocketSHMWin32.cc SHMSysV.cc
SemaphoreSysV.cc SemaphoreWin32.cc -o Processus_A -lrt
-//
*****************************************************************************
-// For SysV use :
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002-2005 ONERA
+//
+// This program is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+// ----------------------------------------------------------------------------
+
+// WARNING 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
@@ -10,9 +26,8 @@
// Systems includes
#include <limits>
-#include "SocketSHM.hh"
-// Specifics includes
+// Specifics includes
#ifdef _WIN32
#include <windows.h>
#include <process.h>
@@ -22,10 +37,12 @@
#include "SocketSHMSysV.hh"
#endif
+#include "RingBuffer.hh"
#include "SharedStruct.hh"
#define NAME_AB "SocketAB" // Socket Name
+#define MAX_SIZE 50
/****************************************/
@@ -40,20 +57,21 @@
int i = 1 ; // Count for while
shared_struct Data_Read ; // Data read in the Socket
shared_struct Data_Write ; // Data write in the Socket
+std::string Shm_Sem_Type = "Win32" ;
#ifdef SIDE_SC
SocketSHM::SHM_SIDE_t Socket_Side = SocketSHM::SHM_SC ; // which side am I?
-std::cout << "I am side : " << Socket_Side << std::endl ;
+RingBuffer::BUFFER_SIDE_t Buffer_Side = RingBuffer::BUFFER_SC ; // which
Buffer side am I?
#else
SocketSHM::SHM_SIDE_t Socket_Side = SocketSHM::SHM_CS ; // which side am I?
-std::cout << "I am side : " << Socket_Side << std::endl ;
+RingBuffer::BUFFER_SIDE_t Buffer_Side = RingBuffer::BUFFER_CS ; // which
Buffer side am I?
#endif
std::string command;
-int size ;
-size = (int) sizeof(shared_struct) ;
+int Size ;
+Size = (int) sizeof(shared_struct) ;
// Initialize Datas
Data_Read.Header = 0 ; Data_Read.Body =0.0 ;
@@ -62,18 +80,27 @@
// ************
// CODE
// ************
-
#ifdef _WIN32
-SocketSHMWin32 Socket_Win32_AB(NAME_AB,Socket_Side,size) ;
+SocketSHMWin32 Socket_Win32_AB(NAME_AB,Socket_Side,Size) ;
#else
// Posix Socket SHM
-SocketSHMPosix Socket_Posix_AB(NAME_AB,Socket_Side,size) ;
+SocketSHMPosix Socket_Posix_AB(NAME_AB,
+ Socket_Side,
+ Size) ;
+
// SystemV Socket SHM
-SocketSHMSysV Socket_SysV_AB(NAME_AB,Socket_Side,size) ;
-#endif
+SocketSHMSysV Socket_SysV_AB(NAME_AB,
+ Socket_Side,
+ Size) ;
+#endif
+// RingBuffer Socket SHM
+RingBuffer RingBuffer_AB(NAME_AB,
+ Buffer_Side,
+ MAX_SIZE,
+ Shm_Sem_Type ) ;
+// ****************************
// Wainting for User Command n1
-
std::cout << "************************************************************" <<
std::endl ;
std::cout << "******* END OF INITIALIZATION PHASE 1 : ********************" <<
std::endl ;
#ifdef SIDE_SC
@@ -90,57 +117,121 @@
Socket_Posix_AB.Connect() ; // Connect to created Semaphores
Socket_SysV_AB.Connect() ; // Connect to created Semaphores
#endif
-#ifndef _WIN32
+RingBuffer_AB.Attach() ;
+
+// ****************************
// Wainting for User Command n2
std::cout << "*******************************************************" <<
std::endl ;
std::cout << "*********** END OF INITIALIZATION PHASE 2 : ***********" <<
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 ;
+#ifdef _WIN32
+std::cout << "*** Click \"Win32\" to Open Win32 Socket SHM ************" <<
std::endl ;
+#else
+std::cout << "*** Click \"Posix\" to Open Posix Socket SHM ************" <<
std::endl ;
+std::cout << "*** Click \"SysV\" to Open Systeme V Socket SHM *********" <<
std::endl ;
+#endif
+std::cout << "*** Click \"RB\" to Open Ring Buffer SHM **************" <<
std::endl ;
std::cout << "*******************************************************" <<
std::endl ;
std::cin >> command;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
-#endif
+// Verify the command
+while (command !="Win32" && command != "Posix" && command != "SysV" && command
!= "RB") {
+ std::cout << "Wrong Command : Command must be : Win32 , Posix , SysV or
RB" << std ::endl ;
+ std::cin >> command;
+ std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); }
+
+// Open the Socket
#ifdef _WIN32
-Socket_Win32_AB.Open() ;
+if (command=="Win32") Socket_Win32_AB.Open() ;
#else
-// Open the Socket
if (command=="Posix") Socket_Posix_AB.Open() ;
if (command=="SysV") Socket_SysV_AB.Open() ;
#endif
+// ****************************
// Wainting for User Command n3
std::cout << "************************************************************" <<
std::endl ;
-#ifdef _WIN32
-std::cout << "******* END OF INITIALIZATION PHASE 2 : ********************" <<
std::endl ;
-#else
std::cout << "******* END OF INITIALIZATION PHASE 3 : ********************" <<
std::endl ;
-#endif
-std::cout << "****** Click \"ENTER\" to RunInter Process Exchange... *****" <<
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' );
-#ifdef SIDE_SC
-// Send to B For the First Time (INITIALIZE)
-// Send to B
-#ifdef _WIN32
-Socket_Win32_AB.Send(&Data_Write);
-#else
-if (command=="Posix") Socket_Posix_AB.Send(&Data_Write) ;
-if (command=="SysV") Socket_SysV_AB.Send(&Data_Write) ;
-#endif
-#endif
-
+// If Ring Buffer USE
+if (command=="RB"){
+ shared_struct Data_Read_RB ; // Data read in the Socket
+ Data_Read_RB.Header = 0 ; Data_Read_RB.Body =0.0 ;
+ shared_struct Data_Write_RB ; // Data write in the Socket
+ Data_Write_RB.Header = 0 ; Data_Write_RB.Body =0.0 ;
+ std::string command_RB ;
+ // *********************************************
+ // Wainting for User Command n4 (For Ring Buffer)
+ std::cout << "********************************************************" <<
std::endl ;
+ std::cout << "*** Put \"S\" to Send Data on RingBuffer ***************" <<
std::endl ;
+ std::cout << "*** Put \"R\" to Receive Data on RingBuffer ************" <<
std::endl ;
+ std::cout << "*** Put \"END\" to Close RingBuffer Exchange ***********" <<
std::endl ;
+ std::cout << "********************************************************" <<
std::endl ;
+
+ // *************************
+ // Computing RingBuffer SHM
+ // *************************
+ while(i<1000) {
+ // Initialize Datas
+ Data_Write_RB.Header = i ; Data_Write_RB.Body = i * 0.1 ;
+ std::cin >> command_RB ;
+ std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
+ if (command_RB=="S"){
+ RingBuffer_AB.Send(&Data_Write_RB,Size) ;
+ std::cout << " ******** SEND ********" << std ::endl ;
+ #ifdef SIDE_SC
+ std::cout << "Processus A ::Â DataWrite_RB.Header = " <<
Data_Write_RB.Header << std ::endl ;
+ std::cout << "Processus A :: DataWrite_RB.Body = " <<
Data_Write_RB.Body << std ::endl ;
+ #else
+ std::cout << "Processus B ::Â DataWrite_RB.Header = " <<
Data_Write_RB.Header << std ::endl ;
+ std::cout << "Processus B :: DataWrite_RB.Body = " <<
Data_Write_RB.Body << std ::endl ;
+ #endif
+ std::cout << " ************************ " << std ::endl ;
+ i++ ;
+ }
+ else if (command_RB=="R"){
+ RingBuffer_AB.Receive(&Data_Read_RB,Size) ;
+ std::cout << " ****** RECEIVE ******" << std ::endl ;
+ #ifdef SIDE_SC
+ std::cout << "Processus A ::Â DataRead_RB.Header = " <<
Data_Read_RB.Header << std ::endl ;
+ std::cout << "Processus A :: DataRead_RB.Body = " <<
Data_Read_RB.Body << std ::endl ;
+ #else
+ std::cout << "Processus B ::Â DataRead_RB.Header = " <<
Data_Read_RB.Header << std ::endl ;
+ std::cout << "Processus B :: DataRead_RB.Body = " <<
Data_Read_RB.Body << std ::endl ;
+ #endif
+ std::cout << " ************************** " << std::endl ;
+ }
+ else if (command_RB=="END"){ i=1000; }
+ else{std::cout << "Wrong Command : Command must be : S , R or END" <<
std ::endl ;}
+ } // End of while
+ }
+else{ // else SocketSHM (SysV and Posix) Use
+ #ifdef SIDE_SC
+ // Send to B For the First Time (INITIALIZE)
+ // Send to B
+ #ifdef _WIN32
+ if (command=="Win32") Socket_Win32_AB.Send(&Data_Write) ;
+ #else
+ if (command=="Posix") Socket_Posix_AB.Send(&Data_Write) ;
+ if (command=="SysV") Socket_SysV_AB.Send(&Data_Write) ;
+ #endif
+ #endif
+ // *********************
+ // Computing Socket SHM
+ // *********************
while(i<1000) {
std::cout << " *********** COMPUTING PHASE n°= " << i << "*************"
<< std ::endl ;
/**************************************/
/************* RECEIVING **************/
/**************************************/
+ // Read from B
#ifdef _WIN32
- Socket_Win32_AB.Receive(&Data_Read) ;
+ if (command=="Win32") Socket_Win32_AB.Receive(&Data_Read) ;
#else
- // Read from B
if (command=="Posix") Socket_Posix_AB.Receive(&Data_Read) ;
if (command=="SysV") Socket_SysV_AB.Receive(&Data_Read) ;
#endif
@@ -150,8 +241,13 @@
/**************************************/
// Print Receiving Data
std::cout << " ****** RECEIVE ******" << std ::endl ;
- std::cout << "Processus A ||Â DataRead.Header = " << Data_Read.Header <<
std ::endl ;
- std::cout << " Processus A || DataRead.Body = " << Data_Read.Body << std
::endl ;
+ #ifdef SIDE_SC
+ std::cout << "Processus A ::Â DataRead.Header = " << Data_Read.Header
<< std ::endl ;
+ std::cout << "Processus A :: DataRead.Body = " << Data_Read.Body << std
::endl ;
+ #else
+ std::cout << "Processus B ::Â DataRead.Header = " << Data_Read.Header
<< std ::endl ;
+ std::cout << "Processus B :: DataRead.Body = " << Data_Read.Body << std
::endl ;
+ #endif
std::cout << " ************************** " << std::endl ;
// Product a new Data
@@ -160,8 +256,13 @@
// Print Sending Data
std::cout << " ******** SEND ********" << std ::endl ;
- std::cout << "Processus A ||Â DataWrite.Header = " << Data_Write.Header <<
std ::endl ;
- std::cout << " Processus A || DataWrite.Body = " << Data_Write.Body << std
::endl ;
+ #ifdef SIDE_SC
+ std::cout << "Processus A ::Â DataWrite.Header = " << Data_Write.Header
<< std ::endl ;
+ std::cout << "Processus A :: DataWrite.Body = " << Data_Write.Body <<
std ::endl ;
+ #else
+ std::cout << "Processus B ::Â DataWrite.Header = " << Data_Write.Header
<< std ::endl ;
+ std::cout << "Processus B :: DataWrite.Body = " << Data_Write.Body <<
std ::endl ;
+ #endif
std::cout << " ************************ " << std ::endl ;
/**************************************/
@@ -169,7 +270,7 @@
/**************************************/
// Send to B
#ifdef _WIN32
- Socket_Win32_AB.Send(&Data_Write) ;
+ if (command=="Win32") Socket_Win32_AB.Send(&Data_Write) ;
#else
if (command=="Posix") Socket_Posix_AB.Send(&Data_Write) ;
if (command=="SysV") Socket_SysV_AB.Send(&Data_Write) ;
@@ -180,18 +281,25 @@
} // End of while (i<1000)
-// Waiting the two process are out of while boucle
-#ifdef _WIN32
-Sleep(1000);
-#else
-sleep(1) ;
-#endif
+ } // end of else for if (commande=="RB")
+
+ // Waiting the two process are out of while boucle
+ #ifdef _WIN32
+ Sleep(1000) ;
+ #else
+ sleep(1) ;
+ #endif
+
+ // Close the Ring Buffer
+ RingBuffer_AB.Close() ;
+ // Close the socket
+ #ifdef _WIN32
+ if (command=="Win32") Socket_Win32_AB.Close() ;
+ #else
+ if (command=="Posix") Socket_Posix_AB.Close() ;;
+ if (command=="SysV") Socket_SysV_AB.Close() ;
+ #endif
+ std::cout << "END OF THE PROGRAM : SEE YOU SOON :) !!!!!!!!!!!" << std
::endl ;
+return 0 ;
-// Close the socket
-#ifdef _WIN32
-Socket_Win32_AB.Close();
-#else
-if (command=="Posix") Socket_Posix_AB.Close() ;
-if (command=="SysV") Socket_SysV_AB.Close() ;
-#endif
} // End of Main Program
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi libCERTI/CMakeLists.txt libCERTI/Semaphor... [br_CERTI_SHM_NEWGEN_dev],
certi-cvs <=