-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathshmem.hpp
77 lines (62 loc) · 1.55 KB
/
shmem.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* win32/shmem.hpp
*
* Copyright (C) 2007 Antonio Di Monaco
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#pragma once
#ifndef __SHMEM_HPP__
#define __SHMEM_HPP__
#include <functional>
#include "win32/handle.hpp"
#include "win32/synch.hpp"
#include "win32/uuid.hpp"
#include "log/log.hpp"
#include "util/memory.hpp"
#include "util/constraints.hpp"
namespace Windows
{
class BaseRawSharedMemory : public Handle<>
{
NON_COPYABLE(BaseRawSharedMemory);
Synch::Mutex _m;
DWORD _size;
LPVOID _ptr;
protected:
explicit BaseRawSharedMemory(DWORD dwSize, const std::wstring &sName);
~BaseRawSharedMemory();
void access(std::function< void(DWORD, LPVOID) > f);
};
class RawSharedMemory : public BaseRawSharedMemory
{
NON_COPYABLE(RawSharedMemory);
public:
explicit RawSharedMemory(DWORD dwSize, const std::wstring &sName);
~RawSharedMemory();
void access(std::function< void(DWORD, LPVOID) > f);
};
template< typename T >
class SharedMemory : public BaseRawSharedMemory
{
NON_COPYABLE(SharedMemory);
public:
explicit SharedMemory(const std::wstring &sName) :
BaseRawSharedMemory(sizeof(T),sName)
{
::Log::Method m(__SIGNATURE__);
}
~SharedMemory()
{
::Log::Method m(__SIGNATURE__);
}
void access(std::function< void(T *) > f)
{
BaseRawSharedMemory::access([f] (DWORD, LPVOID ptr)
{
f(reinterpret_cast< T * >(ptr));
});
}
};
}
#endif