1 | // |
2 | // SharedMemory.cpp |
3 | // |
4 | // Library: Foundation |
5 | // Package: Processes |
6 | // Module: SharedMemory |
7 | // |
8 | // Copyright (c) 2007, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/SharedMemory.h" |
16 | #include "Poco/Exception.h" |
17 | #if defined(POCO_NO_SHAREDMEMORY) |
18 | #include "SharedMemory_DUMMY.cpp" |
19 | #elif defined(POCO_OS_FAMILY_WINDOWS) |
20 | #include "SharedMemory_WIN32.cpp" |
21 | #elif defined(POCO_OS_FAMILY_UNIX) |
22 | #include "SharedMemory_POSIX.cpp" |
23 | #else |
24 | #include "SharedMemory_DUMMY.cpp" |
25 | #endif |
26 | |
27 | |
28 | namespace Poco { |
29 | |
30 | |
31 | SharedMemory::SharedMemory(): |
32 | _pImpl(0) |
33 | { |
34 | } |
35 | |
36 | |
37 | SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint, bool server): |
38 | _pImpl(new SharedMemoryImpl(name, size, mode, addrHint, server)) |
39 | { |
40 | } |
41 | |
42 | |
43 | SharedMemory::SharedMemory(const Poco::File& file, AccessMode mode, const void* addrHint): |
44 | _pImpl(new SharedMemoryImpl(file, mode, addrHint)) |
45 | { |
46 | } |
47 | |
48 | |
49 | SharedMemory::SharedMemory(const SharedMemory& other): |
50 | _pImpl(other._pImpl) |
51 | { |
52 | if (_pImpl) |
53 | _pImpl->duplicate(); |
54 | } |
55 | |
56 | |
57 | SharedMemory::~SharedMemory() |
58 | { |
59 | if (_pImpl) |
60 | _pImpl->release(); |
61 | } |
62 | |
63 | |
64 | SharedMemory& SharedMemory::operator = (const SharedMemory& other) |
65 | { |
66 | SharedMemory tmp(other); |
67 | swap(tmp); |
68 | return *this; |
69 | } |
70 | |
71 | |
72 | char* SharedMemory::begin() const |
73 | { |
74 | if (_pImpl) |
75 | return _pImpl->begin(); |
76 | else |
77 | return 0; |
78 | } |
79 | |
80 | |
81 | char* SharedMemory::end() const |
82 | { |
83 | if (_pImpl) |
84 | return _pImpl->end(); |
85 | else |
86 | return 0; |
87 | } |
88 | |
89 | |
90 | } // namespace Poco |
91 | |