#include <ShmemDataLink.h>
Public Member Functions | |
ShmemDataLink (ShmemTransport &transport) | |
bool | open (const std::string &peer_address) |
void | control_received (ReceivedDataSample &sample) |
std::string | local_address () |
std::string | peer_address () |
pid_t | peer_pid () |
ShmemAllocator * | local_allocator () |
ShmemAllocator * | peer_allocator () |
void | read () |
void | signal_semaphore () |
ShmemTransport & | impl () const |
Protected Member Functions | |
virtual void | stop_i () |
Protected Attributes | |
ShmemInst * | config_ |
ShmemSendStrategy_rch | send_strategy_ |
The transport send strategy object for this DataLink. | |
ShmemReceiveStrategy_rch | recv_strategy_ |
Private Attributes | |
std::string | peer_address_ |
ShmemAllocator * | peer_alloc_ |
Definition at line 71 of file ShmemDataLink.h.
OpenDDS::DCPS::ShmemDataLink::ShmemDataLink | ( | ShmemTransport & | transport | ) |
Definition at line 27 of file ShmemDataLink.cpp.
00028 : DataLink(transport, 00029 0, // priority 00030 false, // is_loopback, 00031 false) // is_active 00032 , config_(0) 00033 , send_strategy_(make_rch<ShmemSendStrategy>(this)) 00034 , recv_strategy_(make_rch<ShmemReceiveStrategy>(this)) 00035 , peer_alloc_(0) 00036 { 00037 }
void OpenDDS::DCPS::ShmemDataLink::control_received | ( | ReceivedDataSample & | sample | ) |
Definition at line 99 of file ShmemDataLink.cpp.
Referenced by OpenDDS::DCPS::ShmemReceiveStrategy::deliver_sample().
ShmemTransport & OpenDDS::DCPS::ShmemDataLink::impl | ( | void | ) | const |
Reimplemented from OpenDDS::DCPS::DataLink.
Definition at line 114 of file ShmemDataLink.cpp.
Referenced by local_address(), local_allocator(), and signal_semaphore().
00115 { 00116 return static_cast<ShmemTransport&>(DataLink::impl()); 00117 }
std::string OpenDDS::DCPS::ShmemDataLink::local_address | ( | ) |
Definition at line 126 of file ShmemDataLink.cpp.
References OpenDDS::DCPS::ShmemTransport::address(), and impl().
Referenced by OpenDDS::DCPS::ShmemReceiveStrategy::read().
00127 { 00128 return impl().address(); 00129 }
ShmemAllocator * OpenDDS::DCPS::ShmemDataLink::local_allocator | ( | ) |
Definition at line 120 of file ShmemDataLink.cpp.
References OpenDDS::DCPS::ShmemTransport::alloc(), and impl().
Referenced by OpenDDS::DCPS::ShmemSendStrategy::send_bytes_i(), and OpenDDS::DCPS::ShmemSendStrategy::start_i().
00121 { 00122 return impl().alloc(); 00123 }
bool OpenDDS::DCPS::ShmemDataLink::open | ( | const std::string & | peer_address | ) |
Definition at line 40 of file ShmemDataLink.cpp.
References ACE_TEXT(), ACE_TEXT_CHAR_TO_TCHAR, ACE_TEXT_CreateFileMapping, ACE_String_Base< ACE_CHAR_T >::c_str(), ACE_Malloc_T< class, ACE_LOCK, ACE_CB >::find(), LM_ERROR, LM_INFO, peer_address_, peer_alloc_, recv_strategy_, send_strategy_, OpenDDS::DCPS::DataLink::start(), stop_i(), and VDBG_LVL.
00041 { 00042 peer_address_ = peer_address; 00043 const ACE_TString name = ACE_TEXT_CHAR_TO_TCHAR(peer_address.c_str()); 00044 ShmemAllocator::MEMORY_POOL_OPTIONS alloc_opts; 00045 00046 #ifdef ACE_WIN32 00047 const bool use_opts = true; 00048 const ACE_TString name_under = name + ACE_TEXT('_'); 00049 // Find max size of peer's pool so enough local address space is reserved. 00050 HANDLE fm = ACE_TEXT_CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READONLY, 00051 0, ACE_DEFAULT_PAGEFILE_POOL_CHUNK, name_under.c_str()); 00052 void* view; 00053 if (fm == 0 || (view = MapViewOfFile(fm, FILE_MAP_READ, 0, 0, 0)) == 0) { 00054 stop_i(); 00055 ACE_ERROR_RETURN((LM_ERROR, 00056 ACE_TEXT("(%P|%t) ERROR: ShmemDataLink::open: ") 00057 ACE_TEXT("peer's shared memory area not found (%C)\n"), 00058 peer_address.c_str()), 00059 false); 00060 } 00061 // location of max_size_ in ctrl block: a size_t after two void*s 00062 const size_t* pmax = (const size_t*)(((void**)view) + 2); 00063 alloc_opts.max_size_ = *pmax; 00064 UnmapViewOfFile(view); 00065 CloseHandle(fm); 00066 #else 00067 const bool use_opts = false; 00068 #endif 00069 00070 peer_alloc_ = new ShmemAllocator(name.c_str(), 0 /*lock_name*/, 00071 use_opts ? &alloc_opts : 0); 00072 00073 if (-1 == peer_alloc_->find("Semaphore")) { 00074 stop_i(); 00075 ACE_ERROR_RETURN((LM_ERROR, 00076 ACE_TEXT("(%P|%t) ERROR: ShmemDataLink::open: ") 00077 ACE_TEXT("peer's shared memory area not found (%C)\n"), 00078 peer_address.c_str()), 00079 false); 00080 } 00081 00082 if (start(static_rchandle_cast<TransportSendStrategy>(send_strategy_), 00083 static_rchandle_cast<TransportStrategy>(recv_strategy_)) 00084 != 0) { 00085 stop_i(); 00086 ACE_ERROR_RETURN((LM_ERROR, 00087 ACE_TEXT("(%P|%t) ERROR: ") 00088 ACE_TEXT("ShmemDataLink::open: start failed!\n")), 00089 false); 00090 } 00091 00092 VDBG_LVL((LM_INFO, "(%P|%t) ShmemDataLink link %@ open to peer %C\n", 00093 this, peer_address_.c_str()), 1); 00094 00095 return true; 00096 }
ACE_INLINE std::string OpenDDS::DCPS::ShmemDataLink::peer_address | ( | ) |
Definition at line 15 of file ShmemDataLink.inl.
References peer_address_.
Referenced by OpenDDS::DCPS::ShmemSendStrategy::start_i().
00016 { 00017 return this->peer_address_; 00018 }
ShmemAllocator* OpenDDS::DCPS::ShmemDataLink::peer_allocator | ( | ) | [inline] |
Definition at line 86 of file ShmemDataLink.h.
Referenced by OpenDDS::DCPS::ShmemReceiveStrategy::read(), OpenDDS::DCPS::ShmemReceiveStrategy::receive_bytes(), and OpenDDS::DCPS::ShmemSendStrategy::start_i().
00086 { return peer_alloc_; }
pid_t OpenDDS::DCPS::ShmemDataLink::peer_pid | ( | ) |
Definition at line 138 of file ShmemDataLink.cpp.
References peer_address_.
Referenced by OpenDDS::DCPS::ShmemSendStrategy::start_i().
00139 { 00140 return std::atoi(peer_address_.c_str() + peer_address_.find('-') + 1); 00141 }
void OpenDDS::DCPS::ShmemDataLink::read | ( | void | ) | [inline] |
Definition at line 88 of file ShmemDataLink.h.
00088 { recv_strategy_->read(); }
void OpenDDS::DCPS::ShmemDataLink::signal_semaphore | ( | ) |
Definition at line 132 of file ShmemDataLink.cpp.
References impl(), and OpenDDS::DCPS::ShmemTransport::signal_semaphore().
Referenced by OpenDDS::DCPS::ShmemReceiveStrategy::receive_bytes().
00133 { 00134 return impl().signal_semaphore(); 00135 }
void OpenDDS::DCPS::ShmemDataLink::stop_i | ( | ) | [protected, virtual] |
This announces the "stop" event to our subclass. The "stop" event will occur when this DataLink is handling a release_reservations() call and determines that it has just released all of the remaining reservations on this DataLink. The "stop" event will also occur when the TransportImpl is being shutdown() - we call stop_i() from our transport_shutdown() method to handle this case.
Reimplemented from OpenDDS::DCPS::DataLink.
Definition at line 104 of file ShmemDataLink.cpp.
References peer_alloc_, and ACE_Malloc_T< class, ACE_LOCK, ACE_CB >::release().
Referenced by open().
00105 { 00106 if (peer_alloc_) { 00107 peer_alloc_->release(0 /*don't close*/); 00108 } 00109 delete peer_alloc_; 00110 peer_alloc_ = 0; 00111 }
ShmemInst* OpenDDS::DCPS::ShmemDataLink::config_ [protected] |
Definition at line 93 of file ShmemDataLink.h.
std::string OpenDDS::DCPS::ShmemDataLink::peer_address_ [private] |
Definition at line 101 of file ShmemDataLink.h.
Referenced by open(), peer_address(), and peer_pid().
Definition at line 102 of file ShmemDataLink.h.
Definition at line 96 of file ShmemDataLink.h.
Referenced by open().
The transport send strategy object for this DataLink.
Reimplemented from OpenDDS::DCPS::DataLink.
Definition at line 95 of file ShmemDataLink.h.
Referenced by open().