• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
name_initialization_routine()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:
shared_memory_creation_test_wrapper(create_only_t)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 
shared_memory_creation_test_wrapper(open_only_t)47    shared_memory_creation_test_wrapper(open_only_t)
48       :  windows_shared_memory_t(open_only, name_initialization_routine(), read_write, 0)
49    {}
50 
shared_memory_creation_test_wrapper(open_or_create_t)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 
main()57 int main ()
58 {
59    try{
60       test::test_named_creation<shared_memory_creation_test_wrapper>();
61    }
62    catch(std::exception &ex){
63       std::cout << ex.what() << std::endl;
64       return 1;
65    }
66 
67    return 0;
68 }
69 
70 #else
71 
main()72 int main()
73 {
74    return 0;
75 }
76 
77 #endif   //#ifdef BOOST_WINDOWS
78