SV_Shared_Memory.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    SV_Shared_Memory.h
00006  *
00007  *  SV_Shared_Memory.h,v 4.19 2005/11/26 03:13:13 ossama Exp
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //==========================================================================
00012 
00013 #ifndef ACE_SV_SHARED_MEMORY_H
00014 #define ACE_SV_SHARED_MEMORY_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/ACE_export.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "ace/os_include/sys/os_stat.h"
00025 #include "ace/os_include/sys/os_ipc.h"
00026 #include "ace/Default_Constants.h"
00027 
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029 
00030 /**
00031  * @class ACE_SV_Shared_Memory
00032  *
00033  * @brief This is a wrapper for System V shared memory.
00034  */
00035 class ACE_Export ACE_SV_Shared_Memory
00036 {
00037 public:
00038   enum
00039   {
00040     ACE_CREATE = IPC_CREAT,
00041     ACE_OPEN   = 0
00042   };
00043 
00044   // = Initialization and termination methods.
00045   ACE_SV_Shared_Memory (void);
00046   ACE_SV_Shared_Memory (key_t external_id,
00047                         size_t size,
00048                         int create,
00049                         int perms = ACE_DEFAULT_FILE_PERMS,
00050                         void *virtual_addr = 0,
00051                         int flags = 0);
00052 
00053   ACE_SV_Shared_Memory (ACE_HANDLE internal_id,
00054                         int flags = 0);
00055 
00056   int  open (key_t external_id,
00057              size_t size,
00058              int create = ACE_SV_Shared_Memory::ACE_OPEN,
00059              int perms = ACE_DEFAULT_FILE_PERMS);
00060 
00061   int  open_and_attach (key_t external_id,
00062                         size_t size,
00063                         int create = ACE_SV_Shared_Memory::ACE_OPEN,
00064                         int perms = ACE_DEFAULT_FILE_PERMS,
00065                         void *virtual_addr = 0,
00066                         int flags = 0);
00067 
00068   /// Attach this shared memory segment.
00069   int  attach (void *virtual_addr = 0,
00070                int flags =0);
00071 
00072   /// Detach this shared memory segment.
00073   int  detach (void);
00074 
00075   /// Remove this shared memory segment.
00076   int  remove (void);
00077 
00078   /// Forward to underlying System V <shmctl>.
00079   int  control (int cmd, void *buf);
00080 
00081   // = Segment-related info.
00082   void *get_segment_ptr (void) const;
00083   size_t get_segment_size (void) const;
00084 
00085   /// Return the ID of the shared memory segment (i.e., an ACE_HANDLE).
00086   ACE_HANDLE get_id (void) const;
00087 
00088   /// Dump the state of an object.
00089   void dump (void) const;
00090 
00091   /// Declare the dynamic allocation hooks.
00092   ACE_ALLOC_HOOK_DECLARE;
00093 
00094 protected:
00095   enum
00096   {
00097     /// Most restrictive alignment.
00098     ALIGN_WORDB = 8
00099   };
00100 
00101   /// Internal identifier.
00102   ACE_HANDLE internal_id_;
00103 
00104   /// Size of the mapped segment.
00105   size_t size_;
00106 
00107   /// Pointer to the beginning of the segment.
00108   void *segment_ptr_;
00109 
00110   /// Round up to an appropriate page size.
00111   size_t round_up (size_t len);
00112 };
00113 
00114 ACE_END_VERSIONED_NAMESPACE_DECL
00115 
00116 #if defined (__ACE_INLINE__)
00117 #include "ace/SV_Shared_Memory.inl"
00118 #endif /* __ACE_INLINE__ */
00119 
00120 #include /**/ "ace/post.h"
00121 
00122 #endif /* ACE_SV_SHARED_MEMORY_H */

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6