[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi/libCERTI SHMWin32.hh SHMWin32.cc
From: |
certi-cvs |
Subject: |
[certi-cvs] certi/libCERTI SHMWin32.hh SHMWin32.cc |
Date: |
Wed, 20 Jan 2010 12:57:09 +0000 |
CVSROOT: /sources/certi
Module name: certi
Changes by: Eric NOULARD <erk> 10/01/20 12:57:09
Added files:
libCERTI : SHMWin32.hh SHMWin32.cc
Log message:
Add missing Win32 files from SHM new gen merge
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMWin32.hh?cvsroot=certi&rev=1.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SHMWin32.cc?cvsroot=certi&rev=1.2
Patches:
Index: SHMWin32.hh
===================================================================
RCS file: SHMWin32.hh
diff -N SHMWin32.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SHMWin32.hh 20 Jan 2010 12:57:09 -0000 1.2
@@ -0,0 +1,27 @@
+#ifndef SHM_WIN32_H
+#define SHM_WIN32_H
+
+// Specifics includes
+#include "SHM.hh"
+#include "certi.hh"
+#include "Exception.hh"
+
+class CERTI_EXPORT SHMWin32 : public SHM {
+
+ private :
+ HANDLE _hMapFile ;
+ LPCTSTR _pBuf;
+
+ public :
+ SHMWin32(const std::string& SHMName, const int SHMSize, const bool True) ;
+ SHMWin32(const std::string& SHMName, const int SHMSize) ;
+ ~SHMWin32() ;
+
+ void Open() throw(certi::SharedMemoryNotOpen) ;
+ void Attach() throw(certi::SharedMemoryNotAttached) ;
+ void Close() throw(certi::SharedMemoryNotClosed,
+ certi::HandleNotClosed);
+
+} ;
+
+#endif
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 12:57:09 -0000 1.2
@@ -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.hh SHMWin32.cc,
certi-cvs <=