OpenDDS::DCPS::ShmemDataLink Class Reference

#include <ShmemDataLink.h>

Inheritance diagram for OpenDDS::DCPS::ShmemDataLink:

Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::ShmemDataLink:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ShmemDataLink (ShmemTransport *transport)
void configure (ShmemInst *config)
void send_strategy (ShmemSendStrategy *send_strategy)
void receive_strategy (ShmemReceiveStrategy *recv_strategy)
ShmemInstconfig ()
bool open (const std::string &peer_address)
void control_received (ReceivedDataSample &sample)
std::string local_address ()
std::string peer_address ()
pid_t peer_pid ()
ShmemAllocatorlocal_allocator ()
ShmemAllocatorpeer_allocator ()
void read ()
void signal_semaphore ()

Protected Member Functions

virtual void stop_i ()

Protected Attributes

ShmemInstconfig_
ShmemSendStrategy_rch send_strategy_
 The transport send strategy object for this DataLink.
ShmemReceiveStrategy_rch recv_strategy_

Private Attributes

std::string peer_address_
ShmemAllocatorpeer_alloc_

Detailed Description

Definition at line 68 of file ShmemDataLink.h.


Constructor & Destructor Documentation

OpenDDS::DCPS::ShmemDataLink::ShmemDataLink ( ShmemTransport transport  )  [explicit]

Definition at line 23 of file ShmemDataLink.cpp.

00024   : DataLink(transport,
00025              0,     // priority
00026              false, // is_loopback,
00027              false) // is_active
00028   , config_(0)
00029   , peer_alloc_(0)
00030 {
00031 }


Member Function Documentation

ACE_INLINE ShmemInst * OpenDDS::DCPS::ShmemDataLink::config (  ) 

Definition at line 30 of file ShmemDataLink.inl.

References config_.

Referenced by configure(), and OpenDDS::DCPS::ShmemSendStrategy::start_i().

00031 {
00032   return this->config_;
00033 }

ACE_INLINE void OpenDDS::DCPS::ShmemDataLink::configure ( ShmemInst config  ) 

Definition at line 12 of file ShmemDataLink.inl.

References config(), and config_.

00013 {
00014   this->config_ = config;
00015 }

void OpenDDS::DCPS::ShmemDataLink::control_received ( ReceivedDataSample sample  ) 

Definition at line 93 of file ShmemDataLink.cpp.

Referenced by OpenDDS::DCPS::ShmemReceiveStrategy::deliver_sample().

00094 {
00095 }

std::string OpenDDS::DCPS::ShmemDataLink::local_address (  ) 

Definition at line 114 of file ShmemDataLink.cpp.

References OpenDDS::DCPS::DataLink::impl().

Referenced by OpenDDS::DCPS::ShmemReceiveStrategy::read().

00115 {
00116   return static_rchandle_cast<ShmemTransport>(impl())->address();
00117 }

ShmemAllocator * OpenDDS::DCPS::ShmemDataLink::local_allocator (  ) 

Definition at line 108 of file ShmemDataLink.cpp.

References OpenDDS::DCPS::DataLink::impl().

Referenced by OpenDDS::DCPS::ShmemSendStrategy::send_bytes_i(), and OpenDDS::DCPS::ShmemSendStrategy::start_i().

00109 {
00110   return static_rchandle_cast<ShmemTransport>(impl())->alloc();
00111 }

bool OpenDDS::DCPS::ShmemDataLink::open ( const std::string &  peer_address  ) 

Definition at line 34 of file ShmemDataLink.cpp.

References peer_address_, peer_alloc_, recv_strategy_, send_strategy_, OpenDDS::DCPS::DataLink::start(), stop_i(), and VDBG_LVL.

00035 {
00036   peer_address_ = peer_address;
00037   const ACE_TString name = ACE_TEXT_CHAR_TO_TCHAR(peer_address.c_str());
00038   ShmemAllocator::MEMORY_POOL_OPTIONS alloc_opts;
00039 
00040 #ifdef ACE_WIN32
00041   const bool use_opts = true;
00042   const ACE_TString name_under = name + ACE_TEXT('_');
00043   // Find max size of peer's pool so enough local address space is reserved.
00044   HANDLE fm = ACE_TEXT_CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READONLY,
00045     0, ACE_DEFAULT_PAGEFILE_POOL_CHUNK, name_under.c_str());
00046   void* view;
00047   if (fm == 0 || (view = MapViewOfFile(fm, FILE_MAP_READ, 0, 0, 0)) == 0) {
00048     stop_i();
00049     ACE_ERROR_RETURN((LM_ERROR,
00050                       ACE_TEXT("(%P|%t) ERROR: ShmemDataLink::open: ")
00051                       ACE_TEXT("peer's shared memory area not found (%C)\n"),
00052                       peer_address.c_str()),
00053                      false);
00054   }
00055   // location of max_size_ in ctrl block: a size_t after two void*s
00056   const size_t* pmax = (const size_t*)(((void**)view) + 2);
00057   alloc_opts.max_size_ = *pmax;
00058   UnmapViewOfFile(view);
00059   CloseHandle(fm);
00060 #else
00061   const bool use_opts = false;
00062 #endif
00063 
00064   peer_alloc_ = new ShmemAllocator(name.c_str(), 0 /*lock_name*/,
00065                                    use_opts ? &alloc_opts : 0);
00066 
00067   if (-1 == peer_alloc_->find("Semaphore")) {
00068     stop_i();
00069     ACE_ERROR_RETURN((LM_ERROR,
00070                       ACE_TEXT("(%P|%t) ERROR: ShmemDataLink::open: ")
00071                       ACE_TEXT("peer's shared memory area not found (%C)\n"),
00072                       peer_address.c_str()),
00073                      false);
00074   }
00075 
00076   if (start(static_rchandle_cast<TransportSendStrategy>(send_strategy_),
00077             static_rchandle_cast<TransportStrategy>(recv_strategy_))
00078       != 0) {
00079     stop_i();
00080     ACE_ERROR_RETURN((LM_ERROR,
00081                       ACE_TEXT("(%P|%t) ERROR: ")
00082                       ACE_TEXT("ShmemDataLink::open: start failed!\n")),
00083                      false);
00084   }
00085 
00086   VDBG_LVL((LM_INFO, "(%P|%t) ShmemDataLink link %@ open to peer %C\n",
00087             this, peer_address_.c_str()), 1);
00088 
00089   return true;
00090 }

ACE_INLINE std::string OpenDDS::DCPS::ShmemDataLink::peer_address (  ) 

Definition at line 36 of file ShmemDataLink.inl.

References peer_address_.

Referenced by OpenDDS::DCPS::ShmemSendStrategy::start_i().

00037 {
00038   return this->peer_address_;
00039 }

ShmemAllocator* OpenDDS::DCPS::ShmemDataLink::peer_allocator (  )  [inline]

Definition at line 89 of file ShmemDataLink.h.

Referenced by OpenDDS::DCPS::ShmemReceiveStrategy::read(), OpenDDS::DCPS::ShmemReceiveStrategy::receive_bytes(), and OpenDDS::DCPS::ShmemSendStrategy::start_i().

00089 { return peer_alloc_; }

pid_t OpenDDS::DCPS::ShmemDataLink::peer_pid (  ) 

Definition at line 126 of file ShmemDataLink.cpp.

References peer_address_.

Referenced by OpenDDS::DCPS::ShmemSendStrategy::start_i().

00127 {
00128   return std::atoi(peer_address_.c_str() + peer_address_.find('-') + 1);
00129 }

void OpenDDS::DCPS::ShmemDataLink::read (  )  [inline]

Definition at line 91 of file ShmemDataLink.h.

00091 { recv_strategy_->read(); }

ACE_INLINE void OpenDDS::DCPS::ShmemDataLink::receive_strategy ( ShmemReceiveStrategy recv_strategy  ) 

Definition at line 24 of file ShmemDataLink.inl.

References recv_strategy_.

00025 {
00026   this->recv_strategy_ = recv_strategy;
00027 }

ACE_INLINE void OpenDDS::DCPS::ShmemDataLink::send_strategy ( ShmemSendStrategy send_strategy  ) 

Definition at line 18 of file ShmemDataLink.inl.

References send_strategy_.

00019 {
00020   this->send_strategy_ = send_strategy;
00021 }

void OpenDDS::DCPS::ShmemDataLink::signal_semaphore (  ) 

Definition at line 120 of file ShmemDataLink.cpp.

References OpenDDS::DCPS::DataLink::impl().

Referenced by OpenDDS::DCPS::ShmemReceiveStrategy::receive_bytes().

00121 {
00122   return static_rchandle_cast<ShmemTransport>(impl())->signal_semaphore();
00123 }

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 98 of file ShmemDataLink.cpp.

References peer_alloc_.

Referenced by open().

00099 {
00100   if (peer_alloc_) {
00101     peer_alloc_->release(0 /*don't close*/);
00102   }
00103   delete peer_alloc_;
00104   peer_alloc_ = 0;
00105 }


Member Data Documentation

ShmemInst* OpenDDS::DCPS::ShmemDataLink::config_ [protected]

Definition at line 95 of file ShmemDataLink.h.

Referenced by config(), and configure().

std::string OpenDDS::DCPS::ShmemDataLink::peer_address_ [private]

Definition at line 103 of file ShmemDataLink.h.

Referenced by open(), peer_address(), and peer_pid().

ShmemAllocator* OpenDDS::DCPS::ShmemDataLink::peer_alloc_ [private]

Definition at line 104 of file ShmemDataLink.h.

Referenced by open(), and stop_i().

ShmemReceiveStrategy_rch OpenDDS::DCPS::ShmemDataLink::recv_strategy_ [protected]

Definition at line 98 of file ShmemDataLink.h.

Referenced by open(), and receive_strategy().

ShmemSendStrategy_rch OpenDDS::DCPS::ShmemDataLink::send_strategy_ [protected]

The transport send strategy object for this DataLink.

Reimplemented from OpenDDS::DCPS::DataLink.

Definition at line 97 of file ShmemDataLink.h.

Referenced by open(), and send_strategy().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:37 2016 for OpenDDS by  doxygen 1.4.7