Blame boost/interprocess/xsi_key.hpp

Packit 58578d
//////////////////////////////////////////////////////////////////////////////
Packit 58578d
//
Packit 58578d
// (C) Copyright Ion Gaztanaga 2009. Distributed under the Boost
Packit 58578d
// Software License, Version 1.0. (See accompanying file
Packit 58578d
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Packit 58578d
//
Packit 58578d
// See http://www.boost.org/libs/interprocess for documentation.
Packit 58578d
//
Packit 58578d
//////////////////////////////////////////////////////////////////////////////
Packit 58578d
Packit 58578d
#ifndef BOOST_INTERPROCESS_XSI_KEY_HPP
Packit 58578d
#define BOOST_INTERPROCESS_XSI_KEY_HPP
Packit 58578d
Packit 58578d
#ifndef BOOST_CONFIG_HPP
Packit 58578d
#  include <boost/config.hpp>
Packit 58578d
#endif
Packit 58578d
#
Packit 58578d
#if defined(BOOST_HAS_PRAGMA_ONCE)
Packit 58578d
#  pragma once
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#include <boost/interprocess/detail/config_begin.hpp>
Packit 58578d
#include <boost/interprocess/detail/workaround.hpp>
Packit 58578d
#include <boost/detail/workaround.hpp>
Packit 58578d
Packit 58578d
#if !defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
Packit 58578d
#error "This header can't be used in operating systems without XSI (System V) shared memory support"
Packit 58578d
#endif
Packit 58578d
Packit 58578d
#include <boost/interprocess/creation_tags.hpp>
Packit 58578d
#include <boost/interprocess/exceptions.hpp>
Packit 58578d
#include <boost/interprocess/detail/utilities.hpp>
Packit 58578d
#include <boost/move/utility_core.hpp>
Packit 58578d
#include <boost/interprocess/detail/os_file_functions.hpp>
Packit 58578d
#include <boost/interprocess/interprocess_fwd.hpp>
Packit 58578d
#include <boost/interprocess/exceptions.hpp>
Packit 58578d
#include <sys/types.h>
Packit 58578d
#include <sys/ipc.h>
Packit 58578d
#include <cstddef>
Packit 58578d
#include <boost/cstdint.hpp>
Packit 58578d
Packit 58578d
//!\file
Packit 58578d
//!Describes a class representing a xsi key type.
Packit 58578d
Packit 58578d
namespace boost {
Packit 58578d
namespace interprocess {
Packit 58578d
Packit 58578d
//!A class that wraps XSI (System V) key_t type.
Packit 58578d
//!This type calculates key_t from path and id using ftok,
Packit 58578d
//!sets key to a specified value,
Packit 58578d
//!or sets key to IPC_PRIVATE using the default constructor.
Packit 58578d
class xsi_key
Packit 58578d
{
Packit 58578d
   public:
Packit 58578d
Packit 58578d
   //!Default constructor.
Packit 58578d
   //!Represents a private xsi_key.
Packit 58578d
   xsi_key()
Packit 58578d
      : m_key(IPC_PRIVATE)
Packit 58578d
   {}
Packit 58578d
Packit 58578d
   //!Creates a new XSI key using a specified value. Constructor is explicit to avoid ambiguity with shmid.
Packit 58578d
   explicit xsi_key(key_t key)
Packit 58578d
      : m_key(key)
Packit 58578d
   {}
Packit 58578d
Packit 58578d
   //!Creates a new XSI  shared memory with a key obtained from a call to ftok (with path
Packit 58578d
   //!"path" and id "id"), of size "size" and permissions "perm".
Packit 58578d
   //!If the shared memory previously exists, throws an error.
Packit 58578d
   xsi_key(const char *path, boost::uint8_t id)
Packit 58578d
   {
Packit 58578d
      key_t key;
Packit 58578d
      if(path){
Packit 58578d
         key  = ::ftok(path, id);
Packit 58578d
         if(((key_t)-1) == key){
Packit 58578d
            error_info err = system_error_code();
Packit 58578d
            throw interprocess_exception(err);
Packit 58578d
         }
Packit 58578d
      }
Packit 58578d
      else{
Packit 58578d
         key = IPC_PRIVATE;
Packit 58578d
      }
Packit 58578d
      m_key = key;
Packit 58578d
   }
Packit 58578d
Packit 58578d
   //!Returns the internal key_t value
Packit 58578d
   key_t get_key() const
Packit 58578d
   {  return m_key;  }
Packit 58578d
Packit 58578d
   #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
Packit 58578d
   private:
Packit 58578d
   key_t m_key;
Packit 58578d
   #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Packit 58578d
};
Packit 58578d
Packit 58578d
}  //namespace interprocess {
Packit 58578d
}  //namespace boost {
Packit 58578d
Packit 58578d
#include <boost/interprocess/detail/config_end.hpp>
Packit 58578d
Packit 58578d
#endif   //BOOST_INTERPROCESS_XSI_KEY_HPP