Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::Connection Class Reference
[Network]

Abstract 1 to n connection. More...

#include <OSGConnection.h>

Inheritance diagram for osg::Connection:

osg::BinaryDataHandler osg::GroupConnection osg::PointConnection osg::GroupSockConnection osg::PointSockConnection osg::GroupMCastConnection osg::GroupSockPipeline osg::PointMCastConnection osg::PointSockPipeline List of all members.

Public Member Functions

Put
*void put (void const *src, UInt32 size)
void putAndFree (MemoryHandle src, UInt32 size)
void putValue (const bool &value)
void putValue (const UInt8 &value)
void putValue (const UInt16 &value)
void putValue (const UInt32 &value)
void putValue (const UInt64 &value)
void putValue (const Int8 &value)
void putValue (const Int16 &value)
void putValue (const Int32 &value)
void putValue (const Int64 &value)
void putValue (const Real16 &value)
void putValue (const Real32 &value)
void putValue (const Real64 &value)
void putValue (const Real128 &value)
void putValue (const std::string &value)
void putValues (const bool *value, UInt32 size)
void putValues (const UInt8 *value, UInt32 size)
void putValues (const UInt16 *value, UInt32 size)
void putValues (const UInt32 *value, UInt32 size)
void putValues (const UInt64 *value, UInt32 size)
void putValues (const Int8 *value, UInt32 size)
void putValues (const Int16 *value, UInt32 size)
void putValues (const Int32 *value, UInt32 size)
void putValues (const Int64 *value, UInt32 size)
void putValues (const Real16 *value, UInt32 size)
void putValues (const Real32 *value, UInt32 size)
void putValues (const Real64 *value, UInt32 size)
void putValues (const Real128 *value, UInt32 size)
void putValues (const std::string *value, UInt32 size)
Get
*void get (void *dst, UInt32 size)
void getAndAlloc (MemoryHandle &src, UInt32 size)
void getValue (bool &value)
void getValue (UInt8 &value)
void getValue (UInt16 &value)
void getValue (UInt32 &value)
void getValue (UInt64 &value)
void getValue (Int8 &value)
void getValue (Int16 &value)
void getValue (Int32 &value)
void getValue (Int64 &value)
void getValue (Real16 &value)
void getValue (Real32 &value)
void getValue (Real64 &value)
void getValue (Real128 &value)
void getValue (std::string &value)
void getValues (bool *value, UInt32 size)
void getValues (UInt8 *value, UInt32 size)
void getValues (UInt16 *value, UInt32 size)
void getValues (UInt32 *value, UInt32 size)
void getValues (UInt64 *value, UInt32 size)
void getValues (Int8 *value, UInt32 size)
void getValues (Int16 *value, UInt32 size)
void getValues (Int32 *value, UInt32 size)
void getValues (Int64 *value, UInt32 size)
void getValues (Real16 *value, UInt32 size)
void getValues (Real32 *value, UInt32 size)
void getValues (Real64 *value, UInt32 size)
void getValues (Real128 *value, UInt32 size)
void getValues (std::string *value, UInt32 size)
Helper
*virtual void forceCopy (void)
virtual void forceDirectIO (void)
void flush (void)
 write data not yet written
void setNetworkOrder (bool value)
bool getNetworkOrder (void)
Constructors
Connection (int zeroCopyThreshold)
virtual ~Connection (void)
type info
*virtual const ConnectionTypegetType (void)=0
connection
*virtual Channel connectPoint (const std::string &address, Time timeout=-1)=0
virtual Channel acceptPoint (Time timeout=-1)=0
synchronisation
*virtual bool wait (Time timeout=-1)=0 throw (ReadError )
virtual void signal (void)=0 throw (WriteError)
channel handling
*virtual Channel selectChannel (Time timeout=-1)=0 throw (ReadError)
bind to interface
*virtual std::string bind (const std::string &address="")=0
params
*virtual void setParams (const std::string &params)
interface
*const std::string & getInterface (void)
void setInterface (const std::string &interf)
Put
*void put (void const *src, UInt32 size)
void putAndFree (MemoryHandle src, UInt32 size)
void putValue (const bool &value)
void putValue (const UInt8 &value)
void putValue (const UInt16 &value)
void putValue (const UInt32 &value)
void putValue (const UInt64 &value)
void putValue (const Int8 &value)
void putValue (const Int16 &value)
void putValue (const Int32 &value)
void putValue (const Int64 &value)
void putValue (const Real16 &value)
void putValue (const Real32 &value)
void putValue (const Real64 &value)
void putValue (const Real128 &value)
void putValue (const std::string &value)
void putValues (const bool *value, UInt32 size)
void putValues (const UInt8 *value, UInt32 size)
void putValues (const UInt16 *value, UInt32 size)
void putValues (const UInt32 *value, UInt32 size)
void putValues (const UInt64 *value, UInt32 size)
void putValues (const Int8 *value, UInt32 size)
void putValues (const Int16 *value, UInt32 size)
void putValues (const Int32 *value, UInt32 size)
void putValues (const Int64 *value, UInt32 size)
void putValues (const Real16 *value, UInt32 size)
void putValues (const Real32 *value, UInt32 size)
void putValues (const Real64 *value, UInt32 size)
void putValues (const Real128 *value, UInt32 size)
void putValues (const std::string *value, UInt32 size)
Get
*void get (void *dst, UInt32 size)
void getAndAlloc (MemoryHandle &src, UInt32 size)
void getValue (bool &value)
void getValue (UInt8 &value)
void getValue (UInt16 &value)
void getValue (UInt32 &value)
void getValue (UInt64 &value)
void getValue (Int8 &value)
void getValue (Int16 &value)
void getValue (Int32 &value)
void getValue (Int64 &value)
void getValue (Real16 &value)
void getValue (Real32 &value)
void getValue (Real64 &value)
void getValue (Real128 &value)
void getValue (std::string &value)
void getValues (bool *value, UInt32 size)
void getValues (UInt8 *value, UInt32 size)
void getValues (UInt16 *value, UInt32 size)
void getValues (UInt32 *value, UInt32 size)
void getValues (UInt64 *value, UInt32 size)
void getValues (Int8 *value, UInt32 size)
void getValues (Int16 *value, UInt32 size)
void getValues (Int32 *value, UInt32 size)
void getValues (Int64 *value, UInt32 size)
void getValues (Real16 *value, UInt32 size)
void getValues (Real32 *value, UInt32 size)
void getValues (Real64 *value, UInt32 size)
void getValues (Real128 *value, UInt32 size)
void getValues (std::string *value, UInt32 size)
Helper
*virtual void forceCopy (void)
virtual void forceDirectIO (void)
void flush (void)
 write data not yet written
void setNetworkOrder (bool value)
bool getNetworkOrder (void)

Public Attributes

public types
*typedef Int32 Channel

Protected Types

typedef std::vector< MemoryBlock > BuffersT
typedef std::list< MemoryHandleFreeMemT

Protected Member Functions

Read
*BuffersT::iterator readBufBegin (void)
BuffersT::iterator readBufEnd (void)
void readBufAdd (MemoryHandle mem, UInt32 size, UInt32 dataSize=0)
void readBufClear (void)
virtual void read (MemoryHandle src, UInt32 size)
virtual void readBuffer (void)
Write
*BuffersT::iterator writeBufBegin (void)
BuffersT::iterator writeBufEnd (void)
void writeBufAdd (MemoryHandle mem, UInt32 size, UInt32 dataSize=0)
void writeBufClear (void)
virtual void write (MemoryHandle src, UInt32 size)
virtual void writeBuffer (void)
Helper
*bool isReadBufferEmpty (void)
Read
*BuffersT::iterator readBufBegin (void)
BuffersT::iterator readBufEnd (void)
void readBufAdd (MemoryHandle mem, UInt32 size, UInt32 dataSize=0)
void readBufClear (void)
virtual void read (MemoryHandle src, UInt32 size)
virtual void readBuffer (void)
Write
*BuffersT::iterator writeBufBegin (void)
BuffersT::iterator writeBufEnd (void)
void writeBufAdd (MemoryHandle mem, UInt32 size, UInt32 dataSize=0)
void writeBufClear (void)
virtual void write (MemoryHandle src, UInt32 size)
virtual void writeBuffer (void)
Helper
*bool isReadBufferEmpty (void)

Protected Attributes

Member
*BuffersT _readBuffers
BuffersT _writeBuffers
BuffersT _zeroCopyBuffers
UInt32 _zeroCopyThreshold
FreeMemT _freeMem
BuffersT::iterator _currentReadBuffer
UInt32 _currentReadBufferPos
BuffersT::iterator _currentWriteBuffer
UInt32 _currentWriteBufferPos
bool _networkOrder
protected members
*std::string _interface
Member
*BuffersT _readBuffers
BuffersT _writeBuffers
BuffersT _zeroCopyBuffers
UInt32 _zeroCopyThreshold
FreeMemT _freeMem
BuffersT::iterator _currentReadBuffer
UInt32 _currentReadBufferPos
BuffersT::iterator _currentWriteBuffer
UInt32 _currentWriteBufferPos
bool _networkOrder

Private Types

typedef BinaryDataHandler Inherited

Private Member Functions

 Connection (const Connection &source)
Connectionoperator= (const Connection &source)

Detailed Description

Connection defines an interface for a reliable 1 to n connection. It implements a BinaryDataHandler which is used for reading and writing binary data and OpenSG FieldContainer contents.

Writing to n destinations is easy to handle but reading from n simutanious sending sources is more complicated. To make things easier, you have to select one channel for exclusiv read. This is done by calling selectChannel. Implementations fo selectChannel should select the channel with the most pending data for getting the best read performance.

wait and signal are used to synchronize a number of programms.

Definition at line 60 of file OSGConnection.h.


Member Typedef Documentation

typedef BinaryDataHandler osg::Connection::Inherited [private]
 

Reimplemented in osg::GroupConnection, osg::PointConnection, osg::GroupMCastConnection, osg::GroupSockConnection, osg::GroupSockPipeline, osg::PointMCastConnection, osg::PointSockConnection, and osg::PointSockPipeline.

Definition at line 146 of file OSGConnection.h.

typedef std::vector<MemoryBlock> osg::BinaryDataHandler::BuffersT [protected, inherited]
 

Definition at line 213 of file OSGBinaryDataHandler.h.

typedef std::list<MemoryHandle> osg::BinaryDataHandler::FreeMemT [protected, inherited]
 

Definition at line 214 of file OSGBinaryDataHandler.h.


Constructor & Destructor Documentation

Connection::Connection int  zeroCopyThreshold  ) 
 

Constructor

Definition at line 76 of file OSGConnection.cpp.

00076                                            :
00077     BinaryDataHandler(zeroCopyThreshold),
00078     _interface("")
00079 {
00080 }

Connection::~Connection void   )  [virtual]
 

Destructor

Definition at line 85 of file OSGConnection.cpp.

00086 {
00087 }

osg::Connection::Connection const Connection source  )  [private]
 


Member Function Documentation

* virtual const ConnectionType* osg::Connection::getType void   )  [pure virtual]
 

Implemented in osg::GroupConnection, osg::PointConnection, osg::GroupMCastConnection, osg::GroupSockConnection, osg::GroupSockPipeline, osg::PointMCastConnection, osg::PointSockConnection, and osg::PointSockPipeline.

* virtual Channel osg::Connection::connectPoint const std::string &  address,
Time  timeout = -1
[pure virtual]
 

Implemented in osg::GroupMCastConnection, osg::GroupSockConnection, osg::GroupSockPipeline, and osg::PointSockConnection.

Referenced by osg::ClusterWindow::init().

virtual Channel osg::Connection::acceptPoint Time  timeout = -1  )  [pure virtual]
 

Implemented in osg::GroupMCastConnection, osg::GroupSockConnection, osg::GroupSockPipeline, and osg::PointSockConnection.

Referenced by osg::ClusterNetwork::connectAllGroupToPoint(), and osg::ClusterNetwork::connectAllPointToPoint().

* virtual bool osg::Connection::wait Time  timeout = -1  )  throw (ReadError ) [pure virtual]
 

Implemented in osg::PointConnection, osg::GroupMCastConnection, osg::GroupSockConnection, osg::PointMCastConnection, and osg::PointSockConnection.

Referenced by osg::SortFirstWindow::clientSwap(), osg::MultiDisplayWindow::clientSwap(), osg::SortFirstWindow::serverSwap(), and osg::MultiDisplayWindow::serverSwap().

virtual void osg::Connection::signal void   )  throw (WriteError) [pure virtual]
 

Implemented in osg::PointConnection, osg::GroupMCastConnection, osg::GroupSockConnection, and osg::PointSockConnection.

Referenced by osg::SortFirstWindow::clientSwap(), osg::MultiDisplayWindow::clientSwap(), osg::SortFirstWindow::serverSwap(), and osg::MultiDisplayWindow::serverSwap().

* virtual Channel osg::Connection::selectChannel Time  timeout = -1  )  throw (ReadError) [pure virtual]
 

Implemented in osg::GroupSockConnection, osg::PointMCastConnection, osg::PointSockConnection, and osg::PointSockPipeline.

Referenced by osg::SortFirstWindow::clientInit(), osg::MultiDisplayWindow::clientSwap(), osg::ClusterNetwork::connectAllGroupToPoint(), osg::ClusterNetwork::connectAllPointToPoint(), osg::ClusterWindow::init(), osg::RemoteAspect::receiveSync(), osg::ClusterViewBuffer::recv(), osg::SortFirstWindow::serverInit(), and osg::ClusterServer::start().

* virtual std::string osg::Connection::bind const std::string &  address = ""  )  [pure virtual]
 

Implemented in osg::GroupSockConnection, and osg::PointSockConnection.

Referenced by osg::ClusterServer::acceptClient().

void Connection::setParams const std::string &  params  )  [virtual]
 

set connections parameters, a comma separated list e.g. "TTL=255"

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockConnection.

Definition at line 91 of file OSGConnection.cpp.

Referenced by osg::ClusterWindow::init().

00092 {
00093     // do nothing this is implemented in the derived classes e.g. OSGGroupMCastConnection.cpp
00094 }

const std::string & Connection::getInterface void   ) 
 

get network interface

Definition at line 98 of file OSGConnection.cpp.

References _interface.

Referenced by osg::PointSockConnection::bind(), osg::GroupSockConnection::bind(), osg::PointSockPipeline::initialize(), osg::PointMCastConnection::initialize(), and osg::GroupMCastConnection::initialize().

00099 {
00100     return _interface;
00101 }

void Connection::setInterface const std::string &  interf  ) 
 

set network interface

Definition at line 105 of file OSGConnection.cpp.

References _interface.

Referenced by osg::ClusterServer::acceptClient(), and osg::ClusterWindow::init().

00106 {
00107     _interface = interf;
00108 }

Connection& osg::Connection::operator= const Connection source  )  [private]
 

void BinaryDataHandler::put void const *  src,
UInt32  size
[inherited]
 

Definition at line 83 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_currentWriteBuffer, osg::BinaryDataHandler::_currentWriteBufferPos, osg::BinaryDataHandler::_zeroCopyBuffers, osg::BinaryDataHandler::_zeroCopyThreshold, osg::osgMin(), osg::BinaryDataHandler::pushBuffer(), osg::BinaryDataHandler::write(), and osg::BinaryDataHandler::writeBufEnd().

Referenced by osg::BinaryDataHandler::putAndFree(), osg::BinaryDataHandler::putValue(), osg::BinaryDataHandler::putValues(), and osg::ClusterViewBuffer::send().

00084 {
00085     UInt8 const *data = static_cast<UInt8 const *>(src);
00086 
00087     if(_zeroCopyThreshold && size >= _zeroCopyThreshold)
00088     {
00089         if(_zeroCopyThreshold == 1)
00090         {
00091             write(const_cast<MemoryHandle>(data), size);
00092         }
00093         else
00094         {
00095             UInt8 tag = 1;
00096 
00097             // we have to write a tag, to indicate the membership
00098             // of this zero copy block to the current data block
00099             put(&tag, sizeof(tag));
00100 
00101             _zeroCopyBuffers.push_back(
00102                 MemoryBlock(const_cast<MemoryHandle>(data), size, size));
00103         }
00104     }
00105     else
00106     {
00107         UInt32 copySize;
00108 
00109         while(size != 0)
00110         {
00111             if(_currentWriteBuffer == writeBufEnd())
00112             {
00113                 pushBuffer();
00114             }
00115 
00116             copySize = osgMin((_currentWriteBuffer->getSize() -
00117                                _currentWriteBufferPos),
00118                               size);
00119 
00120             memcpy(_currentWriteBuffer->getMem() + _currentWriteBufferPos,
00121                     data,
00122                     copySize);
00123 
00124              size                  -= copySize;
00125             _currentWriteBufferPos += copySize;
00126              data                  += copySize;
00127 
00128             // skip to next buffer if current buffer is full
00129             if(_currentWriteBufferPos == _currentWriteBuffer->getSize())
00130             {
00131                 _currentWriteBuffer->setDataSize(_currentWriteBufferPos);
00132                 _currentWriteBuffer++;
00133                 _currentWriteBufferPos = 0;
00134             }
00135         }
00136     }
00137 }

void BinaryDataHandler::putAndFree MemoryHandle  src,
UInt32  size
[inherited]
 

Put data from dynamic allocated block The caller doesn't know, when the block will be written. So we are responsible for freeing this block.

Definition at line 144 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_freeMem, osg::BinaryDataHandler::_zeroCopyThreshold, and osg::BinaryDataHandler::put().

00145 {
00146     put(src, size);
00147 
00148     if(_zeroCopyThreshold && size > _zeroCopyThreshold)
00149     {
00150         _freeMem.push_back(src);
00151     }
00152     else
00153     {
00154         delete [] src;
00155     }
00156 }

void osg::BinaryDataHandler::putValue const bool &  value  )  [inline, inherited]
 

Definition at line 60 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::put().

Referenced by osg::SortFirstWindow::clientInit(), osg::ClusterNetwork::connectAllGroupToPoint(), osg::ClusterNetwork::connectAllPointToPoint(), osg::FieldDataTraits2< bool >::copyToBin(), osg::RenderNode::copyToBin(), osg::ParticleBSPTree::copyToBin(), osg::MField< FieldTypeT, fieldNameSpace >::copyToBin(), osg::FieldTraitsIntegralRecurseMapper< Int32 >::copyToBin(), osg::FieldTraitsRecurseBase1< GLXContext >::copyToBin(), osg::FieldTraitsRecurseBase< DisplayCalibrationPtr >::copyToBin(), osg::FieldTraitsRecurseMapper< FieldContainerPtr, false >::copyToBin(), osg::FieldDataTraits< Plane >::copyToBin(), osg::FieldDataTraits1< GLenum >::copyToBin(), osg::FieldDataTraits1< BitVector >::copyToBin(), osg::FieldDataTraits< DynamicVolume >::copyToBin(), osg::FieldDataTraits1< Time >::copyToBin(), osg::FieldDataTraits< std::string >::copyToBin(), osg::FieldTraitsRecurseMapper< AttachmentMap, false >::copyToBin(), osg::BINWriter::doWriteIndexedFC(), osg::RemoteAspect::handleFCMapping(), osg::ClusterWindow::init(), osg::BinaryDataHandler::putValue(), osg::BinaryDataHandler::putValues(), osg::ClusterViewBuffer::send(), osg::RemoteAspect::sendSync(), osg::SortFirstWindow::serverInit(), osg::GroupMCastConnection::signal(), osg::ClusterServer::start(), and osg::BINWriter::writeFileHeader().

00061 {
00062     // on Mac OS X a bool is four bytes long on all other
00063     // platfroms it is one byte long. So we write now always
00064     // one byte out.
00065     // put(&value, sizeof(bool));
00066     UInt8 temp = (UInt8) value;
00067     put(&temp, sizeof(UInt8));
00068 }

void osg::BinaryDataHandler::putValue const UInt8 value  )  [inline, inherited]
 

Definition at line 71 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::put().

00072 {
00073     put(&value, sizeof(UInt8));
00074 }

void osg::BinaryDataHandler::putValue const UInt16 value  )  [inline, inherited]
 

Definition at line 77 of file OSGBinaryDataHandler.inl.

References osg::osghtons(), and osg::BinaryDataHandler::put().

00078 {
00079     UInt16 z = osghtons(value);
00080 
00081     put(&z, sizeof(UInt16));
00082 }

void osg::BinaryDataHandler::putValue const UInt32 value  )  [inline, inherited]
 

Definition at line 85 of file OSGBinaryDataHandler.inl.

References osg::osghtonl(), and osg::BinaryDataHandler::put().

00086 {
00087     UInt32 z = osghtonl(value);
00088 
00089     put(&z, sizeof(UInt32));
00090 }

void osg::BinaryDataHandler::putValue const UInt64 value  )  [inline, inherited]
 

Definition at line 93 of file OSGBinaryDataHandler.inl.

References osg::osghtonll(), and osg::BinaryDataHandler::put().

00094 {
00095     UInt64 z = osghtonll(value);
00096 
00097     put(&z, sizeof(UInt64));
00098 }

void osg::BinaryDataHandler::putValue const Int8 value  )  [inline, inherited]
 

Definition at line 101 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::put().

00102 {
00103     put(&value, sizeof(Int8));
00104 }

void osg::BinaryDataHandler::putValue const Int16 value  )  [inline, inherited]
 

Definition at line 107 of file OSGBinaryDataHandler.inl.

References osg::osghtons(), and