OSG::ExceptionBinaryDataHandler Class Reference

#include <OSGExceptionBinaryDataHandler.h>

Inheritance diagram for OSG::ExceptionBinaryDataHandler:

OSG::Connection OSG::NFIOBase::BinaryReadHandler OSG::NFIOBase::BinaryWriteHandler OSG::OSBElementBase::BinaryReadHandler OSG::OSBElementBase::BinaryWriteHandler OSG::GroupConnection OSG::PointConnection OSG::GroupSockConnection OSG::PointSockConnection OSG::GroupMCastConnection OSG::GroupSockPipeline OSG::PointMCastConnection OSG::PointSockPipeline List of all members.

Public Member Functions

Constructors


 ExceptionBinaryDataHandler (UInt32 zeroCopyThreshold=0, bool networkOrder=true)
Destructors


virtual ~ExceptionBinaryDataHandler (void)
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 Fixed32 &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 Fixed32 *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) throw (ReadError)
void getAndAlloc (MemoryHandle &src, UInt32 size) throw (ReadError)
void getValue (bool &value) throw (ReadError)
void getValue (UInt8 &value) throw (ReadError)
void getValue (UInt16 &value) throw (ReadError)
void getValue (UInt32 &value) throw (ReadError)
void getValue (UInt64 &value) throw (ReadError)
void getValue (Int8 &value) throw (ReadError)
void getValue (Int16 &value) throw (ReadError)
void getValue (Int32 &value) throw (ReadError)
void getValue (Int64 &value) throw (ReadError)
void getValue (Real16 &value) throw (ReadError)
void getValue (Fixed32 &value) throw (ReadError)
void getValue (Real32 &value) throw (ReadError)
void getValue (Real64 &value) throw (ReadError)
void getValue (Real128 &value) throw (ReadError)
void getValue (std::string &value) throw (ReadError)
void getValues (bool *value, UInt32 size) throw (ReadError)
void getValues (UInt8 *value, UInt32 size) throw (ReadError)
void getValues (UInt16 *value, UInt32 size) throw (ReadError)
void getValues (UInt32 *value, UInt32 size) throw (ReadError)
void getValues (UInt64 *value, UInt32 size) throw (ReadError)
void getValues (Int8 *value, UInt32 size) throw (ReadError)
void getValues (Int16 *value, UInt32 size) throw (ReadError)
void getValues (Int32 *value, UInt32 size) throw (ReadError)
void getValues (Int64 *value, UInt32 size) throw (ReadError)
void getValues (Real16 *value, UInt32 size) throw (ReadError)
void getValues (Fixed32 *value, UInt32 size) throw (ReadError)
void getValues (Real32 *value, UInt32 size) throw (ReadError)
void getValues (Real64 *value, UInt32 size) throw (ReadError)
void getValues (Real128 *value, UInt32 size) throw (ReadError)
void getValues (std::string *value, UInt32 size) throw (ReadError)
Helper


virtual void forceCopy (void)
virtual void forceDirectIO (void)
void flush (void)
 write data not yet written
void setNetworkOrder (bool value)
bool getNetworkOrder (void)

Protected Types

typedef std::vector< MemoryBlockBuffersT
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) throw (ReadError)
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

Private Member Functions

 ExceptionBinaryDataHandler (const ExceptionBinaryDataHandler &source)
 prohibit default function (move to 'public' if needed)
void operator= (const ExceptionBinaryDataHandler &source)
 prohibit default function (move to 'public' if needed)
Internal Helper


void pushBuffer (void)
void pullBuffer (void) throw (ReadError)
void freeMem (void)

Classes

struct  MemoryBlock
struct  ReadError
struct  WriteError

Detailed Description

Definition at line 60 of file OSGExceptionBinaryDataHandler.h.


Member Typedef Documentation

typedef std::vector<MemoryBlock> OSG::ExceptionBinaryDataHandler::BuffersT [protected]

Definition at line 229 of file OSGExceptionBinaryDataHandler.h.

Definition at line 230 of file OSGExceptionBinaryDataHandler.h.


Constructor & Destructor Documentation

ExceptionBinaryDataHandler::ExceptionBinaryDataHandler ( UInt32  zeroCopyThreshold = 0,
bool  networkOrder = true 
)

Definition at line 57 of file OSGExceptionBinaryDataHandler.cpp.

00059                               :
00060 
00061     _readBuffers          (                 ),
00062     _writeBuffers         (                 ),
00063     _zeroCopyBuffers      (                 ),
00064     _zeroCopyThreshold    (zeroCopyThreshold),
00065     _freeMem              (                 ),
00066     _currentReadBuffer    (                 ),
00067     _currentReadBufferPos (0                ),
00068     _currentWriteBuffer   (                 ),
00069     _currentWriteBufferPos(0                ),
00070     _networkOrder         (networkOrder     )
00071 {
00072 }

ExceptionBinaryDataHandler::~ExceptionBinaryDataHandler ( void   )  [virtual]

Definition at line 77 of file OSGExceptionBinaryDataHandler.cpp.

References freeMem().

00078 {
00079     freeMem();
00080 }

OSG::ExceptionBinaryDataHandler::ExceptionBinaryDataHandler ( const ExceptionBinaryDataHandler source  )  [private]


Member Function Documentation

void ExceptionBinaryDataHandler::put ( void const *  src,
UInt32  size 
)

Definition at line 85 of file OSGExceptionBinaryDataHandler.cpp.

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

Referenced by OSG::BalancedMultiWindow::clientRender(), OSG::PipelineComposer::composeViewport(), OSG::BinarySwapComposer::composeViewport(), OSG::BalancedMultiWindow::drawSendAndRecv(), putAndFree(), putValue(), putValues(), OSG::ClusterViewBuffer::send(), OSG::BinarySwapComposer::sendToClient(), OSG::BalancedMultiWindow::serverRender(), OSG::PipelineComposer::setTransInfo(), OSG::BinarySwapComposer::writeCombine(), and OSG::PipelineComposer::writeResult().

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

void ExceptionBinaryDataHandler::putAndFree ( MemoryHandle  src,
UInt32  size 
)

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 146 of file OSGExceptionBinaryDataHandler.cpp.

References _freeMem, _zeroCopyThreshold, and put().

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

void OSG::ExceptionBinaryDataHandler::putValue ( const bool &  value  )  [inline]

Definition at line 56 of file OSGExceptionBinaryDataHandler.inl.

References put().

Referenced by OSG::SortFirstWindow::clientInit(), OSG::BalancedMultiWindow::clientRender(), OSG::ClusterNetwork::connectAllGroupToPoint(), OSG::RenderNode::copyToBin(), OSG::ParticleBSPTree::copyToBin(), OSG::MField< ParentFieldContainerPtr, 0 >::copyToBin(), OSG::MField< FieldContainerPtr, 0 >::copyToBin(), OSG::BalancedMultiWindow::drawSendAndRecv(), OSG::RemoteAspect::handleFCMapping(), OSG::ClusterWindow::init(), putValue(), putValues(), OSG::ClusterViewBuffer::send(), OSG::RemoteAspect::sendSync(), OSG::SortFirstWindow::serverInit(), OSG::BalancedMultiWindow::serverRender(), OSG::GroupMCastConnection::signal(), OSG::ClusterServer::start(), OSG::OSBRootElement::write(), OSG::OSBNodeElement::write(), OSG::OSBNameElement::write(), OSG::OSBGeometryElement::write(), OSG::OSBGenericElement::write(), OSG::NFIOImage::writeCompressedPixel(), OSG::OSBImageElement::writeCompressedPixelData(), OSG::OSBCommonElement::writeEndMarker(), OSG::NFIOBase::writeEndMarker(), OSG::NFIOVoidPAttachment::writeFC(), OSG::NFIOName::writeFC(), OSG::NFIOImageGenericAtt::writeFC(), OSG::NFIOImage::writeFC(), OSG::NFIOGeometry::writeFC(), NFIOGeoConversion< PropType >::writeFC(), OSG::NFIOGenericAtt::writeFC(), OSG::NFIOGeneric::writeFC(), OSG::NFIOBase::writeFCFields(), OSG::NFIOBase::writeFCId(), OSG::NFIOBase::writeFieldContainer(), OSG::OSBCommonElement::writeFieldHeader(), OSG::NFIOBase::writeMFFieldContainerPtr(), OSG::NFIOGeometry::writePackedIndices(), OSG::NFIOGeometry::writeQuantizedVectors(), and OSG::NFIOBase::writeSFAttachmentMap().

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

void OSG::ExceptionBinaryDataHandler::putValue ( const UInt8 &  value  )  [inline]

Definition at line 67 of file OSGExceptionBinaryDataHandler.inl.

References put().

00068 {
00069     put(&value, sizeof(UInt8));
00070 }

void OSG::ExceptionBinaryDataHandler::putValue ( const UInt16 &  value  )  [inline]

Definition at line 73 of file OSGExceptionBinaryDataHandler.inl.

References put().

00074 {
00075     UInt16 z = osgHostToNet<UInt16>(value);
00076 
00077     put(&z, sizeof(UInt16));
00078 }

void OSG::ExceptionBinaryDataHandler::putValue ( const UInt32 &  value  )  [inline]

Definition at line 81 of file OSGExceptionBinaryDataHandler.inl.

References put().

00082 {
00083     UInt32 z = osgHostToNet<UInt32>(value);
00084 
00085     put(&z, sizeof(UInt32));
00086 }

void OSG::ExceptionBinaryDataHandler::putValue ( const UInt64 &  value  )  [inline]

Definition at line 89 of file OSGExceptionBinaryDataHandler.inl.

References put().

00090 {
00091     UInt64 z = osgHostToNet<UInt64>(value);
00092 
00093     put(&z, sizeof(UInt64));
00094 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Int8 &  value  )  [inline]

Definition at line 97 of file OSGExceptionBinaryDataHandler.inl.

References put().

00098 {
00099     put(&value, sizeof(Int8));
00100 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Int16 &  value  )  [inline]

Definition at line 103 of file OSGExceptionBinaryDataHandler.inl.

References put().

00104 {
00105     Int16 z = osgHostToNet<Int16>(value);
00106 
00107     put(&z, sizeof(Int16));
00108 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Int32 &  value  )  [inline]

Definition at line 111 of file OSGExceptionBinaryDataHandler.inl.

References put().

00112 {
00113     Int32 z = osgHostToNet<Int32>(value);
00114 
00115     put(&z, sizeof(Int32));
00116 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Int64 &  value  )  [inline]

Definition at line 119 of file OSGExceptionBinaryDataHandler.inl.

References put().

00120 {
00121     Int64 z = osgHostToNet<Int64>(value);
00122 
00123     put(&z, sizeof(Int64));
00124 
00125 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Real16 value  )  [inline]

Definition at line 128 of file OSGExceptionBinaryDataHandler.inl.

References put().

00129 {
00130     UInt16 v = osgHostToNet<UInt16>(value.bits());
00131 
00132     put(&v, sizeof(Real16));
00133 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Fixed32 value  )  [inline]

Definition at line 136 of file OSGExceptionBinaryDataHandler.inl.

References put().

00137 {
00138     Int32 v = osgHostToNet<Int32>(value.getValue());
00139 
00140     put(&v, sizeof(Int32));
00141 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Real32 &  value  )  [inline]

Definition at line 144 of file OSGExceptionBinaryDataHandler.inl.

References put().

00145 {
00146     Real32 v = osgHostToNet<Real32>(value);
00147 
00148     put(&v, sizeof(Real32));
00149 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Real64 &  value  )  [inline]

Definition at line 152 of file OSGExceptionBinaryDataHandler.inl.

References put().

00153 {
00154     Real64 v = osgHostToNet<Real64>(value);
00155 
00156     put(&v, sizeof(Real64));
00157 }

void OSG::ExceptionBinaryDataHandler::putValue ( const Real128 &  value  )  [inline]

Definition at line 160 of file OSGExceptionBinaryDataHandler.inl.

References put().

00161 {
00162     Real128 v = osgHostToNet<Real128>(value);
00163     
00164     // sizeof(Real128) != 16 on most arch - force it.
00165     put(&v, 16);
00166 }

void OSG::ExceptionBinaryDataHandler::putValue ( const std::string &  value  )  [inline]

Definition at line 169 of file OSGExceptionBinaryDataHandler.inl.

References put(), and putValue().

00170 {
00171     UInt32 len = value.length() + 1;
00172 
00173     putValue(len);
00174 
00175     if(len != 0)
00176     {
00177         put(value.c_str(), len);
00178     }
00179 }

void OSG::ExceptionBinaryDataHandler::putValues ( const bool *  value,
UInt32  size 
) [inline]

Definition at line 192 of file OSGExceptionBinaryDataHandler.inl.

References putValue().

Referenced by OSG::BalancedMultiWindow::serverRender().

00193 {
00194     for(UInt32 i = 0; i < size; ++i)
00195         putValue(value[i]);
00196 }

void OSG::ExceptionBinaryDataHandler::putValues ( const UInt8 *  value,
UInt32  size 
) [inline]

Definition at line 199 of file OSGExceptionBinaryDataHandler.inl.

References put().

00200 {
00201     put(value, size * sizeof(UInt8));
00202 }

void OSG::ExceptionBinaryDataHandler::putValues ( const UInt16 *  value,
UInt32  size 
) [inline]

Definition at line 205 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00206 {
00207 #if BYTE_ORDER == LITTLE_ENDIAN
00208 
00209     if(_networkOrder == true)
00210     {
00211         for(UInt32 i = 0; i < size; ++i)
00212         {
00213             putValue(value[i]);
00214         }
00215     }
00216     else
00217 #endif
00218     {
00219         put(value, size * sizeof(UInt16));
00220     }
00221 }

void OSG::ExceptionBinaryDataHandler::putValues ( const UInt32 *  value,
UInt32  size 
) [inline]

Definition at line 224 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00225 {
00226 #if BYTE_ORDER == LITTLE_ENDIAN
00227     if(_networkOrder == true)
00228     {
00229         for(UInt32 i = 0; i < size; ++i)
00230         {
00231             putValue(value[i]);
00232         }
00233     }
00234     else
00235 #endif
00236     {
00237         put(value, size * sizeof(UInt32));
00238     }
00239 }

void OSG::ExceptionBinaryDataHandler::putValues ( const UInt64 *  value,
UInt32  size 
) [inline]

Definition at line 242 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00243 {
00244 #if BYTE_ORDER == LITTLE_ENDIAN
00245     if(_networkOrder == true)
00246     {
00247         for(UInt32 i = 0; i < size; ++i)
00248         {
00249             putValue(value[i]);
00250         }
00251     }
00252     else
00253 #endif
00254     {
00255         put(value, size * sizeof(UInt64));
00256     }
00257 }

void OSG::ExceptionBinaryDataHandler::putValues ( const Int8 *  value,
UInt32  size 
) [inline]

Definition at line 260 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00261 {
00262 #if BYTE_ORDER == LITTLE_ENDIAN
00263     if(_networkOrder == true)
00264     {
00265         for(UInt32 i = 0; i < size; ++i)
00266         {
00267             putValue(value[i]);
00268         }
00269     }
00270     else
00271 #endif
00272     {
00273         put(value, size * sizeof(Int8));
00274     }
00275 }

void OSG::ExceptionBinaryDataHandler::putValues ( const Int16 *  value,
UInt32  size 
) [inline]

Definition at line 278 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00279 {
00280 #if BYTE_ORDER == LITTLE_ENDIAN
00281     if(_networkOrder == true)
00282     {
00283         for(UInt32 i = 0; i < size; ++i)
00284         {
00285             putValue(value[i]);
00286         }
00287     }
00288     else
00289 #endif
00290     {
00291         put(value, size * sizeof(Int16));
00292     }
00293 }

void OSG::ExceptionBinaryDataHandler::putValues ( const Int32 *  value,
UInt32  size 
) [inline]

Definition at line 296 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00297 {
00298 #if BYTE_ORDER == LITTLE_ENDIAN
00299     if(_networkOrder == true)
00300     {
00301         for(UInt32 i = 0; i < size; ++i)
00302         {
00303             putValue(value[i]);
00304         }
00305     }
00306     else
00307 #endif
00308     {
00309         put(value, size * sizeof(Int32));
00310     }
00311 }

void OSG::ExceptionBinaryDataHandler::putValues ( const Int64 *  value,
UInt32  size 
) [inline]

Definition at line 314 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00315 {
00316 #if BYTE_ORDER == LITTLE_ENDIAN
00317     if(_networkOrder == true)
00318     {
00319         for(UInt32 i = 0; i < size; ++i)
00320         {
00321             putValue(value[i]);
00322         }
00323     }
00324     else
00325 #endif
00326     {
00327         put(value, size * sizeof(Int64));
00328     }
00329 }

void OSG::ExceptionBinaryDataHandler::putValues ( const Real16 value,
UInt32  size 
) [inline]

Definition at line 332 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00333 {
00334 #if BYTE_ORDER == LITTLE_ENDIAN
00335     if(_networkOrder == true)
00336     {
00337         for(UInt32 i = 0; i < size; ++i)
00338         {
00339             putValue(value[i]);
00340         }
00341     }
00342     else
00343 #endif
00344     {
00345         put(value, size * sizeof(Real16));
00346     }
00347 }

void OSG::ExceptionBinaryDataHandler::putValues ( const Fixed32 value,
UInt32  size 
) [inline]

Definition at line 350 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00351 {
00352 #if BYTE_ORDER == LITTLE_ENDIAN
00353     if(_networkOrder == true)
00354     {
00355         for(UInt32 i = 0; i < size; ++i)
00356         {
00357             putValue(value[i]);
00358         }
00359     }
00360     else
00361 #endif
00362     {
00363         put(value, size * sizeof(Fixed32));
00364     }
00365 }

void OSG::ExceptionBinaryDataHandler::putValues ( const Real32 *  value,
UInt32  size 
) [inline]

Definition at line 368 of file OSGExceptionBinaryDataHandler.inl.

References _networkOrder, put(), and putValue().

00369 {
00370 #if BYTE_ORDER == LITTLE_ENDIAN
00371     if(_networkOrder == true)
00372     {
00373         for(UInt32 i = 0; i < size; ++i)
00374         {
00375             putValue(value[i]);
00376         }
00377     }
00378     else
00379 #e