3 #if (!defined (__hpux )) && (!defined (HPUX))
5 #include <Standard_ProgramError.hxx>
6 #include <Standard_NullObject.hxx>
7 #include <Standard_ConstructionError.hxx>
8 #include <OSD_SharedMemory.ixx>
9 #include <OSD_WhoAmI.hxx>
13 const OSD_WhoAmI Iam = OSD_WSharedMemory;
16 extern "C" int create_sharedmemory(int **,char *,int);
17 extern "C" int open_sharedmemory(int **,char *,int);
18 extern "C" int remove_sharedmemory(int *, char *);
21 OSD_SharedMemory::OSD_SharedMemory(){
26 // ======================================================================
27 OSD_SharedMemory::OSD_SharedMemory(const TCollection_AsciiString& Name,
28 const Standard_Integer Size)
29 // CREATE a mapping memory object ==================================
30 // ======================================================================
37 Standard_ConstructionError::Raise("OSD_SharedMemory::OSD_SharedMemory: Name");
42 Standard_ProgramError::Raise("OSD_SharedMemory::OSD_SharedMemory : invalid size");
52 // ======================================================================
53 void OSD_SharedMemory::Build()
54 // ======================================================================
56 Standard_PCharacter pStr;
58 pStr=(Standard_PCharacter)myName.ToCString();
59 myId = create_sharedmemory((int **)&myAddress, pStr, (int)mySize);
62 myError.SetValue (errno, Iam, "OSD_SharedMemory::Build");
68 // ======================================================================
69 void OSD_SharedMemory::Open(const TCollection_AsciiString& Name,
70 const Standard_Integer Size)
71 // ======================================================================
72 // OPEN a mapping memory section
73 // We suppose that the shared memory segment is already
77 if (!Name.IsAscii()) {
78 Standard_ConstructionError::Raise("OSD_SharedMemory::Open : Name");
83 Standard_ProgramError::Raise("OSD_SharedMemory::Open : invalid size");
87 Standard_PCharacter pStr;
89 pStr=(Standard_PCharacter)myName.ToCString();
90 myId = open_sharedmemory((int **)&myAddress, pStr, (int)mySize);
93 myError.SetValue (errno, Iam, "OSD_SharedMemory::Open");
97 // ======================================================================
98 void OSD_SharedMemory::Delete()
99 // ======================================================================
100 // CLOSE a mapping memory section
103 if (myError.Failed()) {
107 Standard_ProgramError::Raise("OSD_SharedMemory::Delete : shared memory not opened/created");
110 Standard_PCharacter pStr;
112 pStr=(Standard_PCharacter)myName.ToCString();
113 if (remove_sharedmemory((int *)&myId, pStr) == 0) {
114 myError.SetValue(errno, Iam, "OSD_SharedMemory::Delete");
119 // ======================================================================
120 Standard_Address OSD_SharedMemory::GiveAddress()const{
121 // ======================================================================
122 if (myAddress == NULL)
123 Standard_NullObject::Raise("OSD_SharedMemory::Address : shared memory not opened/created");
129 // ======================================================================
130 void OSD_SharedMemory::Reset(){
131 // ======================================================================
135 // ======================================================================
136 Standard_Boolean OSD_SharedMemory::Failed()const{
137 // ======================================================================
138 return( myError.Failed());
141 // ======================================================================
142 void OSD_SharedMemory::Perror() {
143 // ======================================================================
148 // ======================================================================
149 Standard_Integer OSD_SharedMemory::Error()const{
150 // ======================================================================
151 return( myError.Error());
157 //------------------------------------------------------------------------
158 //------------------- Windows NT sources for OSD_SharedMemory- ----------
159 //------------------------------------------------------------------------
164 #include <OSD_SharedMemory.ixx>
166 void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
168 OSD_SharedMemory :: OSD_SharedMemory () {
172 } // end constructor ( 1 )
174 OSD_SharedMemory :: OSD_SharedMemory (
175 const TCollection_AsciiString& Name,
176 const Standard_Integer size
183 Standard_ConstructionError :: Raise (
184 "OSD_SharedMemory :: OSD_SharedMemory : invalid size"
189 } // end constructor ( 2 )
191 void OSD_SharedMemory :: Build () {
193 HANDLE hFileMapping = CreateFileMapping (
194 ( HANDLE )0xFFFFFFFF, NULL, PAGE_READWRITE, 0, mySize,
198 if ( hFileMapping == NULL || GetLastError () == ERROR_ALREADY_EXISTS )
200 _osd_wnt_set_error ( myError, OSD_WSharedMemory );
204 myAddress = MapViewOfFile ( hFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
206 if ( myAddress == NULL )
208 _osd_wnt_set_error ( myError, OSD_WSharedMemory );
212 myId = ( Standard_Integer )hFileMapping;
216 } // end OSD_SharedMemory :: Build
218 void OSD_SharedMemory :: Open (
219 const TCollection_AsciiString& Name,
220 const Standard_Integer size
227 Standard_ProgramError :: Raise ( "OSD_SharedMemory :: Open : invalid size" );
231 HANDLE hFileMapping = OpenFileMapping (
232 FILE_MAP_ALL_ACCESS, FALSE, myName.ToCString ()
235 if ( hFileMapping == NULL )
237 _osd_wnt_set_error ( myError, OSD_WSharedMemory );
241 myAddress = MapViewOfFile ( hFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, mySize );
243 if ( myAddress == NULL )
245 _osd_wnt_set_error ( myError, OSD_WSharedMemory );
249 myId = ( Standard_Integer )hFileMapping;
251 CloseHandle ( hFileMapping );
255 } // end OSD_SharedMemory :: Open
257 void OSD_SharedMemory :: Delete () {
259 if ( Failed () ) Perror ();
263 Standard_ProgramError :: Raise (
264 "OSD_SharedMemory :: Delete : shared memory not opened/created"
267 UnmapViewOfFile ( myAddress );
268 CloseHandle ( ( HANDLE )myId );
270 } // end OSD_SharedMemory :: Delete
272 Standard_Address OSD_SharedMemory :: GiveAddress () const {
274 if ( myAddress == NULL )
276 Standard_NullObject :: Raise (
277 "OSD_SharedMemory :: Address : shared memory not opened/created"
282 } // end OSD_SharedMemory :: GiveAddress
284 Standard_Boolean OSD_SharedMemory :: Failed () const {
286 return myError.Failed ();
288 } // end OSD_SharedMemory :: Failed
290 void OSD_SharedMemory :: Reset () {
294 } // end OSD_SharedMemory :: Reset
296 void OSD_SharedMemory :: Perror () {
300 } // end OSD_SharedMemory :: Perror
302 Standard_Integer OSD_SharedMemory :: Error () const{
304 return myError.Error ();
306 } // end OSD_SharedMemory :: Error