1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // |
3 | // (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost |
4 | // Software License, Version 1.0. (See accompanying file |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | // |
7 | // See http://www.boost.org/libs/interprocess for documentation. |
8 | // |
9 | ////////////////////////////////////////////////////////////////////////////// |
10 | |
11 | #include <boost/config.hpp> |
12 | |
13 | #ifdef BOOST_WINDOWS |
14 | |
15 | #include <boost/interprocess/windows_shared_memory.hpp> |
16 | #include <boost/interprocess/detail/managed_open_or_create_impl.hpp> |
17 | #include <boost/interprocess/exceptions.hpp> |
18 | #include "named_creation_template.hpp" |
19 | #include <cstring> //for strcmp, memset |
20 | #include <iostream> //for cout |
21 | #include <string> //for string |
22 | #include "get_process_id_name.hpp" |
23 | |
24 | using namespace boost::interprocess; |
25 | |
26 | static const char *name_initialization_routine() |
27 | { |
28 | static std::string process_name; |
29 | test::get_process_id_name(process_name); |
30 | return process_name.c_str(); |
31 | } |
32 | |
33 | static const std::size_t ShmSize = 1000; |
34 | typedef ipcdetail::managed_open_or_create_impl |
35 | <windows_shared_memory, 0, false, false> windows_shared_memory_t; |
36 | |
37 | //This wrapper is necessary to have a common constructor |
38 | //in generic named_creation_template functions |
39 | class shared_memory_creation_test_wrapper |
40 | : public windows_shared_memory_t |
41 | { |
42 | public: |
43 | shared_memory_creation_test_wrapper(create_only_t) |
44 | : windows_shared_memory_t(create_only, name_initialization_routine(), ShmSize, read_write, 0, permissions()) |
45 | {} |
46 | |
47 | shared_memory_creation_test_wrapper(open_only_t) |
48 | : windows_shared_memory_t(open_only, name_initialization_routine(), read_write, 0) |
49 | {} |
50 | |
51 | shared_memory_creation_test_wrapper(open_or_create_t) |
52 | : windows_shared_memory_t(open_or_create, name_initialization_routine(), ShmSize, read_write, 0, permissions()) |
53 | {} |
54 | }; |
55 | |
56 | #ifdef BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES |
57 | |
58 | static const wchar_t *wname_initialization_routine() |
59 | { |
60 | static std::wstring process_name; |
61 | test::get_process_id_wname(process_name); |
62 | return process_name.c_str(); |
63 | } |
64 | |
65 | class shared_memory_creation_test_wrapper_w |
66 | : public windows_shared_memory_t |
67 | { |
68 | public: |
69 | shared_memory_creation_test_wrapper_w(create_only_t) |
70 | : windows_shared_memory_t(create_only, wname_initialization_routine(), ShmSize, read_write, 0, permissions()) |
71 | {} |
72 | |
73 | shared_memory_creation_test_wrapper_w(open_only_t) |
74 | : windows_shared_memory_t(open_only, wname_initialization_routine(), read_write, 0) |
75 | {} |
76 | |
77 | shared_memory_creation_test_wrapper_w(open_or_create_t) |
78 | : windows_shared_memory_t(open_or_create, wname_initialization_routine(), ShmSize, read_write, 0, permissions()) |
79 | {} |
80 | }; |
81 | |
82 | #endif //BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES |
83 | |
84 | |
85 | int main () |
86 | { |
87 | BOOST_TRY{ |
88 | test::test_named_creation<shared_memory_creation_test_wrapper>(); |
89 | #ifdef BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES |
90 | test::test_named_creation<shared_memory_creation_test_wrapper_w>(); |
91 | #endif |
92 | } |
93 | BOOST_CATCH(std::exception &ex){ |
94 | std::cout << ex.what() << std::endl; |
95 | return 1; |
96 | } BOOST_CATCH_END |
97 | |
98 | return 0; |
99 | } |
100 | |
101 | #else |
102 | |
103 | int main() |
104 | { |
105 | return 0; |
106 | } |
107 | |
108 | #endif //#ifdef BOOST_WINDOWS |
109 | |