MEM_SAP.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    MEM_SAP.h
00006  *
00007  *  MEM_SAP.h,v 4.25 2006/02/10 10:01:01 jwillemsen Exp
00008  *
00009  *  @author Nanbor Wang <nanbor@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_MEM_SAP_H
00014 #define ACE_MEM_SAP_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 // MEM_SAP requries position independent pointers to work
00025 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00026 
00027 #include "ace/PI_Malloc.h"
00028 #include "ace/Malloc_T.h"
00029 #include "ace/MMAP_Memory_Pool.h"
00030 #include "ace/Process_Mutex.h"
00031 
00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00033 
00034 class ACE_MEM_SAP;
00035 class ACE_Reactive_MEM_IO;
00036 class ACE_MT_MEM_IO;
00037 class ACE_MEM_IO;
00038 
00039 // Internal data structure
00040 // MEM_SAP uses to queue up
00041 // data.
00042 class ACE_MEM_SAP_Node
00043 {
00044 public:
00045 //    friend class ACE_MEM_SAP;
00046 //    friend class ACE_Reactive_MEM_IO;
00047 //    friend class ACE_MT_MEM_IO;
00048 //    friend class ACE_MEM_IO;
00049 
00050   typedef ACE_Based_Pointer<ACE_MEM_SAP_Node> ACE_MEM_SAP_NODE_PTR;
00051 
00052   /// Initialize the node with its capacity.
00053   ACE_MEM_SAP_Node (size_t cap);
00054 
00055   /// Get the size of the data we hold.
00056   size_t size (void) const;
00057 
00058   /// Get the capacity of this block of data.
00059   size_t capacity (void) const;
00060 
00061   /// Get the pointer to the block of data we hold.
00062   void *data (void);
00063 
00064   /// The maximum size of this memory block.
00065   size_t capacity_;
00066 
00067   /// The actualy size used.
00068   size_t size_;
00069 
00070   ACE_MEM_SAP_NODE_PTR next_;
00071 };
00072 
00073 /**
00074  * @class ACE_MEM_SAP
00075  *
00076  * @brief Defines the methods of shared memory management for
00077  * shared memory transport.
00078  */
00079 class ACE_Export ACE_MEM_SAP
00080 {
00081 public:
00082   // = Initialization and termination methods.
00083 
00084   typedef ACE_Malloc_T<ACE_MMAP_MEMORY_POOL, ACE_Process_Mutex, ACE_PI_Control_Block> MALLOC_TYPE;
00085   typedef ACE_MMAP_Memory_Pool_Options MALLOC_OPTIONS;
00086 
00087   /// Destructor.
00088   virtual ~ACE_MEM_SAP (void);
00089 
00090   /**
00091    * Initialize the MEM_SAP object.
00092    */
00093   virtual int init (ACE_HANDLE handle,
00094                     const ACE_TCHAR *name,
00095                     MALLOC_OPTIONS *options) = 0;
00096 
00097   /**
00098    * Finalizing the MEM_SAP object.  This method doesn't invoke
00099    * the <remove> method.
00100    */
00101   virtual int fini ();
00102 
00103   /**
00104    * Fetch location of next available data into <recv_buffer_>.
00105    * As this operation read the address of the data off the socket
00106    * using ACE::recv, @a timeout only applies to ACE::recv.
00107    */
00108   virtual ssize_t recv_buf (ACE_MEM_SAP_Node *&buf,
00109                             int flags,
00110                             const ACE_Time_Value *timeout) = 0;
00111 
00112   /**
00113    * Wait to to <timeout> amount of time to send <buf>.  If <send>
00114    * times out a -1 is returned with <errno == ETIME>.  If it succeeds
00115    * the number of bytes sent is returned.  */
00116   virtual ssize_t send_buf (ACE_MEM_SAP_Node *buf,
00117                             int flags,
00118                             const ACE_Time_Value *timeout) = 0;
00119 
00120   /// request a buffer of size <size>.  Return 0 if the <shm_malloc_> is
00121   /// not initialized.
00122   ACE_MEM_SAP_Node *acquire_buffer (const ssize_t size);
00123 
00124   /// release a buffer pointed by <buf>.  Return -1 if the <shm_malloc_>
00125   /// is not initialized.
00126   int release_buffer (ACE_MEM_SAP_Node *buf);
00127 
00128   /// Dump the state of an object.
00129   void dump (void) const;
00130 
00131   /// Declare the dynamic allocation hooks.
00132   ACE_ALLOC_HOOK_DECLARE;
00133 
00134 protected:
00135   // = Class initializing methods to create/connect to a shared memory pool.
00136 
00137   /**
00138    * Create a new shm_malloc object.  Return 0 if succeed and -1
00139    * otherwise.  This method should only be called from an acceptor
00140    * class that wants to create a new memory pool for inter process
00141    * communication.
00142    */
00143   int create_shm_malloc (const ACE_TCHAR *name,
00144                          MALLOC_OPTIONS *options);
00145 
00146   /// Close down the share memory pool.  Clean up the
00147   /// mmap file if we are the last one using it.
00148   int close_shm_malloc (void);
00149 
00150   ACE_HANDLE handle_;
00151 
00152   /// Data exchange channel.
00153   MALLOC_TYPE *shm_malloc_;
00154 
00155   /// Constructor.  Prevent this class from being instantiated.
00156   ACE_MEM_SAP (void);
00157 };
00158 
00159 ACE_END_VERSIONED_NAMESPACE_DECL
00160 
00161 #if defined (__ACE_INLINE__)
00162 #include "ace/MEM_SAP.inl"
00163 #endif /* __ACE_INLINE__ */
00164 
00165 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00166 
00167 #include /**/ "ace/post.h"
00168 
00169 #endif /* ACE_SOCK_IO_H */

Generated on Thu Nov 9 09:41:55 2006 for ACE by doxygen 1.3.6