ReactOS 0.4.15-dev-8236-g99f0937
cicfmap.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Cicero
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Cicero file mapping
5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include "precomp.h"
9#include "cicfmap.h"
10
12{
14 m_pView = NULL;
18 m_pMutex = NULL;
19 Init(pszName, pMutex);
20}
21
23{
24 if (m_pView)
25 {
27 m_pView = NULL;
28 }
29
30 if (m_hMapping)
31 {
34 }
35
37}
38
40{
41 if (pMutex)
42 m_pMutex = pMutex;
43
45 m_pszName = pszName;
46 m_bHasMutex = (pMutex != NULL);
47}
48
52 DWORD dwMaximumSizeLow,
53 LPBOOL pbAlreadyExists)
54{
55 if (!m_pszName)
56 return NULL;
57
59 pSA,
61 0,
62 dwMaximumSizeLow,
63 m_pszName);
64 if (pbAlreadyExists)
65 *pbAlreadyExists = (::GetLastError() == ERROR_ALREADY_EXISTS);
66 if (!m_hMapping)
67 return NULL;
68
70 return _Map();
71}
72
74{
75 if (!m_pszName)
76 return NULL;
78 if (!m_hMapping)
79 return NULL;
80
81 return _Map();
82}
83
85{
87 if (!m_pView)
88 {
89 Close();
90 return NULL;
91 }
92 return m_pView;
93}
94
96{
97 if (!m_bHasMutex)
98 return TRUE;
99 return m_pMutex->Enter();
100}
101
103{
104 if (!m_bHasMutex)
105 return;
106 m_pMutex->Leave();
107}
108
110{
111 if (!m_pView)
112 return FALSE;
113 return ::FlushViewOfFile(m_pView, dwNumberOfBytesToFlush);
114}
115
117{
118 if (!m_bHasMutex)
119 return;
120
121 Close();
122 Leave();
123}
LPCTSTR m_pszName
Definition: cicfmap.h:18
void Init(LPCTSTR pszName, CicMutex *pMutex)
Definition: cicfmap.cpp:39
LPVOID Create(LPSECURITY_ATTRIBUTES pSA, DWORD dwMaximumSizeLow, LPBOOL pbAlreadyExists)
Definition: cicfmap.cpp:50
BOOL Flush(SIZE_T dwNumberOfBytesToFlush)
Definition: cicfmap.cpp:109
CicMutex * m_pMutex
Definition: cicfmap.h:23
CicFileMapping(LPCTSTR pszName, CicMutex *pMutex)
Definition: cicfmap.cpp:11
void Leave()
Definition: cicmutex.h:46
BOOL Enter()
Definition: cicmutex.h:41
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define UnmapViewOfFile
Definition: compat.h:746
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MapViewOfFile
Definition: compat.h:745
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define PAGE_READWRITE
Definition: nt_native.h:1304
ULONG_PTR SIZE_T
Definition: typedefs.h:80
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FILE_MAP_WRITE
Definition: winbase.h:154
#define CreateFileMapping
Definition: winbase.h:3750
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156
#define OpenFileMapping
Definition: winbase.h:3887
BOOL * LPBOOL
Definition: windef.h:162
const CHAR * LPCTSTR
Definition: xmlstorage.h:193