[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi/libCERTI SHMWin32.cc [br_CERTI_SHM_NEWGEN_dev]
From: |
certi-cvs |
Subject: |
[certi-cvs] certi/libCERTI SHMWin32.cc [br_CERTI_SHM_NEWGEN_dev] |
Date: |
Wed, 20 Jan 2010 11:24:15 +0000 |
CVSROOT: /sources/certi
Module name: certi
Branch: br_CERTI_SHM_NEWGEN_dev
Changes by: Adelantado <adele> 10/01/20 11:24:15
Added files:
libCERTI : SHMWin32.cc
Log message:
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMWin32.cc?cvsroot=certi&only_with_tag=br_CERTI_SHM_NEWGEN_dev&rev=1.1.2.1
Patches:
Index: SHMWin32.cc
===================================================================
RCS file: SHMWin32.cc
diff -N SHMWin32.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SHMWin32.cc 20 Jan 2010 11:24:15 -0000 1.1.2.1
@@ -0,0 +1,107 @@
+// SHM useful systems includes
+#include <windows.h>
+#include <conio.h>
+#include <tchar.h>
+
+// Others Systems includes
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <iostream.h>
+#include <string.h>
+
+#include "SHMWin32.hh"
+
+// ************************************************
+// Constructor with args
+// ************************************************
+SHMWin32::SHMWin32(const std::string& SHMName, const int SHMSize, const bool
True) : SHM(SHMName, SHMSize, True) {
+ _hMapFile = NULL ;
+ _pBuf = NULL ;
+}
+
+SHMWin32::SHMWin32(const std::string& SHMName, const int SHMSize) :
SHM(SHMName,SHMSize) {
+ _hMapFile = NULL ;
+ _pBuf = NULL ;
+}
+
+// ************************************************
+// Destructor
+SHMWin32::~SHMWin32() {}
+
+// ************************************************
+// Method : SHMWin32::Open()
+// ************************************************
+void SHMWin32::Open() throw(certi::SharedMemoryNotOpen) {
+
+int ret ;
+
+ _hMapFile = CreateFileMapping(
+ INVALID_HANDLE_VALUE, // use paging file
+ NULL, // default security
+ PAGE_READWRITE, // read/write access
+ (DWORD)0, // max.
object size
+ (DWORD)_Size, // buffer size
+ (LPCTSTR)(_Name.c_str())); // name of mapping
object
+
+ if (_hMapFile == NULL) {
+ throw(certi::SharedMemoryNotOpen("CreateFileMapping() failed.")) ;
+ }
+
+#ifdef DEBUG
+std::cout << "Created shared memory object : " << _Name.c_str() << std::endl ;
+#endif
+
+} // End of Open()
+
+// ************************************************
+// Method : SHMWin32::Attach()
+// ************************************************
+void SHMWin32::Attach() throw(certi::SharedMemoryNotAttached) {
+
+BOOL WINAPI retcode ;
+
+_pBuf = (LPTSTR) MapViewOfFile(_hMapFile,
+ FILE_MAP_ALL_ACCESS, // read/write permission
+ 0,
+ 0,
+ (SIZE_T)(GetSize()));
+
+ if (_pBuf == NULL) {
+ retcode=UnmapViewOfFile((PVOID)_pBuf);
+ CloseHandle(_hMapFile);
+ throw(certi::SharedMemoryNotAttached("MapViewOfFile() failed.")) ;
+ }
+
+ _Shm = (void *) _pBuf ;
+
+} // End of Attach()
+
+// ************************************************
+// Method : SHMWin32::Close()
+// ************************************************
+void SHMWin32::Close() throw(certi::SharedMemoryNotClosed,
+ certi::HandleNotClosed) {
+
+BOOL WINAPI retcode ;
+
+// Unmap
+ retcode=UnmapViewOfFile((PVOID)_pBuf);
+
+if (retcode == 0) {
+ throw(certi::SharedMemoryNotClosed("UnMapViewOfFile() failed.")) ;
+ }
+
+#ifdef DEBUG
+std::cout << "Close SHM (UnmapViewOfFile) : " << _Name.c_str() << std::endl ;
+#endif
+
+// Close handle
+ retcode = CloseHandle(_hMapFile);
+
+if(retcode == 0){
+ throw(certi::HandleNotClosed("CloseHandle() failed.")) ;
+ } // End of if
+
+} // End of Close()
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi/libCERTI SHMWin32.cc [br_CERTI_SHM_NEWGEN_dev],
certi-cvs <=