Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

MEM_SAP.h

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

Generated on Mon Jun 16 11:20:18 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002