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 namespace OpenDDS { 00030 namespace DCPS { 00031 00032 class ShmemInst; 00033 class ShmemTransport; 00034 class ReceivedDataSample; 00035 00036 #ifdef ACE_WIN32 00037 typedef ACE_Pagefile_Memory_Pool ShmemPool; 00038 #elif !defined ACE_LACKS_SYSV_SHMEM 00039 typedef ACE_Shared_Memory_Pool ShmemPool; 00040 #else // no shared memory support (will yield a runtime error if used) 00041 typedef ACE_Local_Memory_Pool ShmemPool; 00042 #endif 00043 00044 #ifdef ACE_WIN32 00045 typedef HANDLE ShmemSharedSemaphore; 00046 #elif defined ACE_HAS_POSIX_SEM 00047 typedef sem_t ShmemSharedSemaphore; 00048 #else 00049 typedef int ShmemSharedSemaphore; 00050 #endif 00051 00052 typedef ACE_Malloc_T<ShmemPool, ACE_Process_Mutex, ACE_PI_Control_Block> 00053 ShmemAllocator; 00054 00055 struct ShmemData { 00056 int status_; 00057 char transport_header_[TRANSPORT_HDR_SERIALIZED_SZ]; 00058 ACE_Based_Pointer_Basic<char> payload_; 00059 }; 00060 00061 enum { // values for ShmemData::status_ 00062 SHMEM_DATA_FREE = 0, 00063 SHMEM_DATA_IN_USE = 1, 00064 SHMEM_DATA_RECV_DONE = 2, 00065 SHMEM_DATA_END_OF_ALLOC = -1 00066 }; 00067 00068 class OpenDDS_Shmem_Export ShmemDataLink 00069 : public DataLink { 00070 public: 00071 explicit ShmemDataLink(ShmemTransport* transport); 00072 00073 void configure(ShmemInst* config); 00074 00075 void send_strategy(ShmemSendStrategy* send_strategy); 00076 void receive_strategy(ShmemReceiveStrategy* recv_strategy); 00077 00078 ShmemInst* config(); 00079 00080 bool open(const std::string& peer_address); 00081 00082 void control_received(ReceivedDataSample& sample); 00083 00084 std::string local_address(); 00085 std::string peer_address(); 00086 pid_t peer_pid(); 00087 00088 ShmemAllocator* local_allocator(); 00089 ShmemAllocator* peer_allocator() { return peer_alloc_; } 00090 00091 void read() { recv_strategy_->read(); } 00092 void signal_semaphore(); 00093 00094 protected: 00095 ShmemInst* config_; 00096 00097 ShmemSendStrategy_rch send_strategy_; 00098 ShmemReceiveStrategy_rch recv_strategy_; 00099 00100 virtual void stop_i(); 00101 00102 private: 00103 std::string peer_address_; 00104 ShmemAllocator* peer_alloc_; 00105 }; 00106 00107 } // namespace DCPS 00108 } // namespace OpenDDS 00109 00110 #ifdef __ACE_INLINE__ 00111 # include "ShmemDataLink.inl" 00112 #endif /* __ACE_INLINE__ */ 00113 00114 #endif /* OPENDDS_SHMEMDATALINK_H */