ShmemDataLink.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef OPENDDS_SHMEMDATALINK_H
00009 #define OPENDDS_SHMEMDATALINK_H
00010 
00011 #include "Shmem_Export.h"
00012 
00013 #include "ShmemSendStrategy.h"
00014 #include "ShmemSendStrategy_rch.h"
00015 #include "ShmemReceiveStrategy.h"
00016 #include "ShmemReceiveStrategy_rch.h"
00017 
00018 #include "dds/DCPS/transport/framework/DataLink.h"
00019 
00020 #include "ace/Local_Memory_Pool.h"
00021 #include "ace/Malloc_T.h"
00022 #include "ace/Pagefile_Memory_Pool.h"
00023 #include "ace/PI_Malloc.h"
00024 #include "ace/Process_Mutex.h"
00025 #include "ace/Shared_Memory_Pool.h"
00026 
00027 #include <string>
00028 
00029 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00030 
00031 namespace OpenDDS {
00032 namespace DCPS {
00033 
00034 class ShmemInst;
00035 class ShmemTransport;
00036 class ReceivedDataSample;
00037 typedef RcHandle<ShmemTransport> ShmemTransport_rch;
00038 
00039 #ifdef ACE_WIN32
00040   typedef ACE_Pagefile_Memory_Pool ShmemPool;
00041 #elif !defined ACE_LACKS_SYSV_SHMEM
00042   typedef ACE_Shared_Memory_Pool ShmemPool;
00043 #else // no shared memory support (will yield a runtime error if used)
00044   typedef ACE_Local_Memory_Pool ShmemPool;
00045 #endif
00046 
00047 #ifdef ACE_WIN32
00048   typedef HANDLE ShmemSharedSemaphore;
00049 #elif defined ACE_HAS_POSIX_SEM
00050   typedef sem_t ShmemSharedSemaphore;
00051 #else
00052   typedef int ShmemSharedSemaphore;
00053 #endif
00054 
00055 typedef ACE_Malloc_T<ShmemPool, ACE_Process_Mutex, ACE_PI_Control_Block>
00056   ShmemAllocator;
00057 
00058 struct ShmemData {
00059   int status_;
00060   char transport_header_[TRANSPORT_HDR_SERIALIZED_SZ];
00061   ACE_Based_Pointer_Basic<char> payload_;
00062 };
00063 
00064 enum { // values for ShmemData::status_
00065   SHMEM_DATA_FREE = 0,
00066   SHMEM_DATA_IN_USE = 1,
00067   SHMEM_DATA_RECV_DONE = 2,
00068   SHMEM_DATA_END_OF_ALLOC = -1
00069 };
00070 
00071 class OpenDDS_Shmem_Export ShmemDataLink
00072   : public DataLink {
00073 public:
00074 
00075   ShmemDataLink(ShmemTransport& transport);
00076 
00077   bool open(const std::string& peer_address);
00078 
00079   void control_received(ReceivedDataSample& sample);
00080 
00081   std::string local_address();
00082   std::string peer_address();
00083   pid_t peer_pid();
00084 
00085   ShmemAllocator* local_allocator();
00086   ShmemAllocator* peer_allocator() { return peer_alloc_; }
00087 
00088   void read() { recv_strategy_->read(); }
00089   void signal_semaphore();
00090   ShmemTransport& impl() const;
00091 
00092 protected:
00093   ShmemInst* config_;
00094 
00095   ShmemSendStrategy_rch send_strategy_;
00096   ShmemReceiveStrategy_rch recv_strategy_;
00097 
00098   virtual void stop_i();
00099 
00100 private:
00101   std::string peer_address_;
00102   ShmemAllocator* peer_alloc_;
00103 };
00104 
00105 } // namespace DCPS
00106 } // namespace OpenDDS
00107 
00108 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00109 
00110 #ifdef __ACE_INLINE__
00111 # include "ShmemDataLink.inl"
00112 #endif  /* __ACE_INLINE__ */
00113 
00114 #endif  /* OPENDDS_SHMEMDATALINK_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1