1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2009. 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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_XSI_KEY_HPP
12 #define BOOST_INTERPROCESS_XSI_KEY_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
24 #include <boost/detail/workaround.hpp>
26 #if !defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
27 #error "This header can't be used in operating systems without XSI (System V) shared memory support"
30 #include <boost/interprocess/creation_tags.hpp>
31 #include <boost/interprocess/exceptions.hpp>
32 #include <boost/interprocess/detail/utilities.hpp>
33 #include <boost/move/utility_core.hpp>
34 #include <boost/interprocess/detail/os_file_functions.hpp>
35 #include <boost/interprocess/interprocess_fwd.hpp>
36 #include <boost/interprocess/exceptions.hpp>
37 #include <sys/types.h>
40 #include <boost/cstdint.hpp>
43 //!Describes a class representing a xsi key type.
46 namespace interprocess {
48 //!A class that wraps XSI (System V) key_t type.
49 //!This type calculates key_t from path and id using ftok,
50 //!sets key to a specified value,
51 //!or sets key to IPC_PRIVATE using the default constructor.
56 //!Default constructor.
57 //!Represents a private xsi_key.
62 //!Creates a new XSI key using a specified value. Constructor is explicit to avoid ambiguity with shmid.
63 explicit xsi_key(key_t key)
67 //!Creates a new XSI shared memory with a key obtained from a call to ftok (with path
68 //!"path" and id "id"), of size "size" and permissions "perm".
69 //!If the shared memory previously exists, throws an error.
70 xsi_key(const char *path, boost::uint8_t id)
74 key = ::ftok(path, id);
75 if(((key_t)-1) == key){
76 error_info err = system_error_code();
77 throw interprocess_exception(err);
86 //!Returns the internal key_t value
90 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
93 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
96 } //namespace interprocess {
99 #include <boost/interprocess/detail/config_end.hpp>
101 #endif //BOOST_INTERPROCESS_XSI_KEY_HPP