Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:44:13

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2009. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_XSI_KEY_HPP
0012 #define BOOST_INTERPROCESS_XSI_KEY_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024 #include <boost/detail/workaround.hpp>
0025 
0026 #if !defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
0027 #error "This header can't be used in operating systems without XSI (System V) shared memory support"
0028 #endif
0029 
0030 #include <boost/interprocess/creation_tags.hpp>
0031 #include <boost/interprocess/exceptions.hpp>
0032 #include <boost/interprocess/detail/utilities.hpp>
0033 #include <boost/move/utility_core.hpp>
0034 #include <boost/interprocess/detail/os_file_functions.hpp>
0035 #include <boost/interprocess/interprocess_fwd.hpp>
0036 #include <boost/interprocess/exceptions.hpp>
0037 #include <sys/types.h>
0038 #include <sys/ipc.h>
0039 #include <cstddef>
0040 #include <boost/cstdint.hpp>
0041 
0042 //!\file
0043 //!Describes a class representing a xsi key type.
0044 
0045 namespace boost {
0046 namespace interprocess {
0047 
0048 //!A class that wraps XSI (System V) key_t type.
0049 //!This type calculates key_t from path and id using ftok,
0050 //!sets key to a specified value,
0051 //!or sets key to IPC_PRIVATE using the default constructor.
0052 class xsi_key
0053 {
0054    public:
0055 
0056    //!Default constructor.
0057    //!Represents a private xsi_key.
0058    xsi_key()
0059       : m_key(IPC_PRIVATE)
0060    {}
0061 
0062    //!Creates a new XSI key using a specified value. Constructor is explicit to avoid ambiguity with shmid.
0063    explicit xsi_key(key_t key)
0064       : m_key(key)
0065    {}
0066 
0067    //!Creates a new XSI  shared memory with a key obtained from a call to ftok (with path
0068    //!"path" and id "id"), of size "size" and permissions "perm".
0069    //!If the shared memory previously exists, throws an error.
0070    xsi_key(const char *path, boost::uint8_t id)
0071    {
0072       key_t key;
0073       if(path){
0074          key  = ::ftok(path, id);
0075          if(((key_t)-1) == key){
0076             error_info err = system_error_code();
0077             throw interprocess_exception(err);
0078          }
0079       }
0080       else{
0081          key = IPC_PRIVATE;
0082       }
0083       m_key = key;
0084    }
0085 
0086    //!Returns the internal key_t value
0087    key_t get_key() const
0088    {  return m_key;  }
0089 
0090    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0091    private:
0092    key_t m_key;
0093    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0094 };
0095 
0096 }  //namespace interprocess {
0097 }  //namespace boost {
0098 
0099 #include <boost/interprocess/detail/config_end.hpp>
0100 
0101 #endif   //BOOST_INTERPROCESS_XSI_KEY_HPP