Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // (C) Copyright Ion Gaztanaga 2009. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/interprocess for documentation. Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #ifndef BOOST_INTERPROCESS_XSI_KEY_HPP Chris@16: #define BOOST_INTERPROCESS_XSI_KEY_HPP Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: # Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@101: # pragma once Chris@101: #endif Chris@101: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if !defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS) Chris@16: #error "This header can't be used in operating systems without XSI (System V) shared memory support" Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: //!\file Chris@16: //!Describes a class representing a xsi key type. Chris@16: Chris@16: namespace boost { Chris@16: namespace interprocess { Chris@16: Chris@16: //!A class that wraps XSI (System V) key_t type. Chris@16: //!This type calculates key_t from path and id using ftok Chris@16: //!or sets key to IPC_PRIVATE using the default constructor. Chris@16: class xsi_key Chris@16: { Chris@16: public: Chris@16: Chris@16: //!Default constructor. Chris@16: //!Represents a private xsi_key. Chris@16: xsi_key() Chris@16: : m_key(IPC_PRIVATE) Chris@16: {} Chris@16: Chris@16: //!Creates a new XSI shared memory with a key obtained from a call to ftok (with path Chris@16: //!"path" and id "id"), of size "size" and permissions "perm". Chris@16: //!If the shared memory previously exists, throws an error. Chris@16: xsi_key(const char *path, boost::uint8_t id) Chris@16: { Chris@101: key_t key; Chris@16: if(path){ Chris@16: key = ::ftok(path, id); Chris@16: if(((key_t)-1) == key){ Chris@16: error_info err = system_error_code(); Chris@16: throw interprocess_exception(err); Chris@16: } Chris@16: } Chris@16: else{ Chris@16: key = IPC_PRIVATE; Chris@16: } Chris@16: m_key = key; Chris@16: } Chris@16: Chris@16: //!Returns the internal key_t value Chris@16: key_t get_key() const Chris@16: { return m_key; } Chris@16: Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: private: Chris@16: key_t m_key; Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: }; Chris@16: Chris@16: } //namespace interprocess { Chris@16: } //namespace boost { Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //BOOST_INTERPROCESS_XSI_KEY_HPP