certi-cvs
[Top][All Lists]
Advanced

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

[certi-cvs] certi/libCERTI SocketSHMWin32.cc [br_CERTI_SHM_NEWGEN_dev]


From: certi-cvs
Subject: [certi-cvs] certi/libCERTI SocketSHMWin32.cc [br_CERTI_SHM_NEWGEN_dev]
Date: Wed, 20 Jan 2010 11:26:57 +0000

CVSROOT:        /sources/certi
Module name:    certi
Branch:         br_CERTI_SHM_NEWGEN_dev
Changes by:     Adelantado <adele>      10/01/20 11:26:56

Added files:
        libCERTI       : SocketSHMWin32.cc 

Log message:
        

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHMWin32.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1

Patches:
Index: SocketSHMWin32.cc
===================================================================
RCS file: SocketSHMWin32.cc
diff -N SocketSHMWin32.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ SocketSHMWin32.cc   20 Jan 2010 11:26:56 -0000      1.1.2.1
@@ -0,0 +1,307 @@
+// ----------------------------------------------------------------------------
+// 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
+// ----------------------------------------------------------------------------
+
+#include "SocketSHMWin32.hh"
+
+// ************************************************
+// Constructor with args
+// ************************************************
+SocketSHMWin32::SocketSHMWin32(const std::string& Socket_Name,
+                             const SHM_SIDE_t& Socket_Side,
+                             const int Socket_Size )
+                             throw (certi::SocketSHMNotCreated): 
SocketSHM(Socket_Name,Socket_Side,Socket_Size)
+                             {
+
+if(_Side == SHM_SC){
+_Shm_SC = new SHMWin32(SHM::buildShmName(Socket_Name+"_SC"), Socket_Size,true) 
;
+_Shm_CS = new SHMWin32(SHM::buildShmName(Socket_Name+"_CS"), Socket_Size) ;
+  }
+else {
+_Shm_CS = new SHMWin32(SHM::buildShmName(Socket_Name+"_CS"), Socket_Size,true) 
;
+_Shm_SC = new SHMWin32(SHM::buildShmName(Socket_Name+"_SC"), Socket_Size) ;
+}
+
+// Semaphores
+_Sem_full_SC = new SemaphoreWin32() ;
+_Sem_empty_SC = new SemaphoreWin32() ;
+_Sem_full_CS = new SemaphoreWin32() ;
+_Sem_empty_CS = new SemaphoreWin32() ;
+
+int init_full = 0, init_empty = 1 ; // Initialisation values
+
+if(_Side == SHM_SC){
+    try {
+       _Sem_full_SC->Create_Init(init_full, 
Semaphore::buildSemName(Socket_Name+"_FULL_SC")) ;
+    }
+    catch(certi::SemaphoreNotCreated& e)
+    {
+        std::cout << "SocketSHMWin32() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotCreated("SocketSHMWin32() failed.")) ;
+    }
+    try {
+       _Sem_empty_SC->Create_Init(init_empty, 
Semaphore::buildSemName(Socket_Name+"_EMPTY_SC")) ;
+    }
+    catch(certi::SemaphoreNotCreated& e)
+    {
+        std::cout << "SocketSHMWin32() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotCreated("SocketSHMWin32() failed.")) ;
+    }
+  }
+else{
+    try {
+       _Sem_full_CS->Create_Init(init_full, 
Semaphore::buildSemName(Socket_Name+"_FULL_CS")) ;
+    }
+    catch(certi::SemaphoreNotCreated& e)
+    {
+        std::cout << "SocketSHMWin32() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotCreated("SocketSHMWin32() failed.")) ;
+    }
+    try {
+       _Sem_empty_CS->Create_Init(init_empty, 
Semaphore::buildSemName(Socket_Name+"_EMPTY_CS")) ;
+    }
+    catch(certi::SemaphoreNotCreated& e)
+    {
+        std::cout << "SocketSHMWin32() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotCreated("SocketSHMWin32() failed.")) ;
+    }
+  }
+
+}
+
+// ************************************************
+// Destructor
+// ************************************************
+SocketSHMWin32::~SocketSHMWin32()
+                                throw(certi::SocketSHMNotDeleted) {
+
+if(_Side == SHM_SC){
+    try {
+       _Sem_full_SC->Delete() ;
+    }
+    catch(certi::HandleNotClosed& e)
+    {
+        std::cout << "~SocketSHMWin32() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotDeleted("~SocketSHMWin32() failed.")) ;
+    }
+    try {
+       _Sem_empty_SC->Delete() ;
+    }
+    catch(certi::HandleNotClosed& e)
+    {
+        std::cout << "~SocketSHMWin32() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotDeleted("~SocketSHMWin32() failed.")) ;
+    }
+   }
+else{
+    try {
+       _Sem_full_CS->Delete() ;
+    }
+    catch(certi::HandleNotClosed& e)
+    {
+        std::cout << "~SocketSHMWin32() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotDeleted("~SocketSHMWin32() failed.")) ;
+    }
+    try {
+       _Sem_empty_CS->Delete() ;
+    }
+    catch(certi::HandleNotClosed& e)
+    {
+        std::cout << "~SocketSHMWin32() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotDeleted("~SocketSHMWin32() failed.")) ;
+    }
+   }
+delete _Sem_full_SC  ;
+delete _Sem_empty_SC  ;
+delete _Sem_full_CS  ;
+delete _Sem_empty_CS ;
+
+delete _Shm_SC ;
+delete _Shm_CS ;
+
+} // End of ~SocketSHMWin32()
+
+
+// ************************************************
+// Method : SocketSHMWin32::Open()
+// ************************************************
+void SocketSHMWin32::Open()
+                        throw(certi::SocketSHMNotOpen){
+
+if(_Side == SHM_SC) {
+    try {
+       _Sem_empty_SC->P() ;
+    }
+    catch(certi::SemaphoreHandlingError& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Shm_SC->Open() ;
+    }
+    catch(certi::SharedMemoryNotOpen& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Shm_SC->Attach() ;
+    }
+    catch(certi::SharedMemoryNotAttached& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Sem_full_SC->V() ;
+    }
+    catch(certi::SemaphoreHandlingError& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+
+    #ifdef DEBUG
+    std::cout << " The SHM from Server to Customer is Open " << std::endl ;
+    #endif
+
+     }
+else{
+    try {
+       _Sem_empty_CS->P() ;
+    }
+    catch(certi::SemaphoreHandlingError& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Shm_CS->Open() ;
+    }
+    catch(certi::SharedMemoryNotOpen& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Shm_CS->Attach() ;
+    }
+    catch(certi::SharedMemoryNotAttached& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Sem_full_CS->V() ;
+    }
+    catch(certi::SemaphoreHandlingError& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+
+     #ifdef DEBUG
+     std::cout << " The SHM from Customer to Server is Create and Attach" << 
std::endl ;
+     #endif
+
+     }
+if(_Side == SHM_CS){
+    try {
+       _Sem_full_SC->P() ;
+    }
+    catch(certi::SemaphoreHandlingError& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Shm_SC->Open() ;
+    }
+    catch(certi::SharedMemoryNotOpen& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Shm_SC->Attach() ;
+    }
+    catch(certi::SharedMemoryNotAttached& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Sem_empty_SC->V() ;
+    }
+    catch(certi::SemaphoreHandlingError& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+
+     #ifdef DEBUG
+     std::cout << " The SHM from Server to Customer is identified and attached 
" << std::endl ;
+     #endif
+
+     }
+else{
+    try {
+       _Sem_full_CS->P() ;
+    }
+    catch(certi::SemaphoreHandlingError& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Shm_CS->Open() ;
+    }
+    catch(certi::SharedMemoryNotOpen& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Shm_CS->Attach() ;
+    }
+    catch(certi::SharedMemoryNotAttached& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+    try {
+       _Sem_empty_CS->V() ;
+    }
+    catch(certi::SemaphoreHandlingError& e)
+    {
+        std::cout << "SocketSHMWin32::Open() Exception. " <<  "Name is : " << 
e._name << " Reason is : " << e._reason << std::endl ;
+        throw (certi::SocketSHMNotOpen("SocketSHMWin32::Open() failed.")) ;
+    }
+
+     #ifdef DEBUG
+     std::cout << " The SHM from Customer to Server is identified and attached 
" << std::endl ;
+     #endif
+
+     }
+
+} // End of Open()
+
+
+




reply via email to

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