osg::BinaryDataHandler Class Reference
[Base]

#include <OSGBinaryDataHandler.h>

Inheritance diagram for osg::BinaryDataHandler:

osg::BINLoader::BinaryFileHandler osg::BINWriter::BinaryFileHandler osg::Connection osg::GroupConnection osg::PointConnection osg::GroupSockConnection osg::PointSockConnection osg::GroupMCastConnection osg::GroupSockPipeline osg::PointMCastConnection osg::PointSockPipeline

List of all members.

Public Member Functions

Constructors


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


virtual ~BinaryDataHandler (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 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)

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)
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

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


void pushBuffer (void)
void pullBuffer (void)
void freeMem (void)

Classes

struct  MemoryBlock
struct  ReadError
struct  WriteError


Detailed Description

Definition at line 60 of file OSGBinaryDataHandler.h.


Member Typedef Documentation

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

Definition at line 213 of file OSGBinaryDataHandler.h.

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

Definition at line 214 of file OSGBinaryDataHandler.h.


Constructor & Destructor Documentation

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

Definition at line 57 of file OSGBinaryDataHandler.cpp.

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

BinaryDataHandler::~BinaryDataHandler ( void   )  [virtual]

Definition at line 75 of file OSGBinaryDataHandler.cpp.

References freeMem().

00076 {
00077     freeMem();
00078 }

osg::BinaryDataHandler::BinaryDataHandler ( const BinaryDataHandler source  )  [private]


Member Function Documentation

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

Definition at line 83 of file OSGBinaryDataHandler.cpp.

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

Referenced by putAndFree(), putValue(), 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 
)

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 _freeMem, _zeroCopyThreshold, and 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]

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

Definition at line 71 of file OSGBinaryDataHandler.inl.

References put().

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

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

Definition at line 77 of file OSGBinaryDataHandler.inl.

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

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

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

Definition at line 85 of file OSGBinaryDataHandler.inl.

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

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

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

Definition at line 93 of file OSGBinaryDataHandler.inl.

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

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

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

Definition at line 101 of file OSGBinaryDataHandler.inl.

References put().

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

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

Definition at line 107 of file OSGBinaryDataHandler.inl.

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

00108 {
00109     Int16 z = osghtons(value);
00110 
00111     put(&z, sizeof(Int16));
00112 }

void osg::BinaryDataHandler::putValue ( const Int32 value  )  [inline]

Definition at line 115 of file OSGBinaryDataHandler.inl.

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

00116 {
00117     Int32 z = osghtonl(value);
00118 
00119     put(&z, sizeof(Int32));
00120 }

void osg::BinaryDataHandler::putValue ( const Int64 value  )  [inline]

Definition at line 123 of file OSGBinaryDataHandler.inl.

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

00124 {
00125     Int64 z = osghtonll(value);
00126     put(&z, sizeof(Int64));
00127 
00128 }

void osg::BinaryDataHandler::putValue ( const Real16 value  )  [inline]

Definition at line 131 of file OSGBinaryDataHandler.inl.

References osg::Real16::bits(), osg::osghtons(), and put().

00132 {
00133     UInt16 v = osghtons(value.bits());
00134 
00135     put(&v, sizeof(Real16));
00136 }

void osg::BinaryDataHandler::putValue ( const Real32 value  )  [inline]

Definition at line 139 of file OSGBinaryDataHandler.inl.

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

00140 {
00141     UInt32 v = osghtonl( *((const UInt32 *)(&value)) );
00142 
00143     put(&v, sizeof(Real32));
00144 }

void osg::BinaryDataHandler::putValue ( const Real64 value  )  [inline]

Definition at line 147 of file OSGBinaryDataHandler.inl.

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

00148 {
00149     UInt64 v = osghtonll( *((const UInt64 *)(&value)) );
00150 
00151     put(&v, sizeof(Real64));
00152 }

void osg::BinaryDataHandler::putValue ( const Real128 value  )  [inline]

Definition at line 155 of file OSGBinaryDataHandler.inl.

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

00156 {
00157     UInt64 v = osghtonll( *( (const UInt64 *)(&value)) );
00158     UInt64 w = osghtonll( *(((const UInt64 *)(&value)) + 1) );
00159 
00160 #if BYTE_ORDER == LITTLE_ENDIAN
00161     put(&w, sizeof(UInt64));
00162     put(&v, sizeof(UInt64));
00163 #else
00164     put(&v, sizeof(UInt64));
00165     put(&w, sizeof(UInt64));
00166 #endif
00167 }

void osg::BinaryDataHandler::putValue ( const std::string &  value  )  [inline]

Definition at line 170 of file OSGBinaryDataHandler.inl.

References put(), putValue(), and osg::stringlen().

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

void osg::BinaryDataHandler::putValues ( const bool *  value,
UInt32  size 
) [inline]

Definition at line 184 of file OSGBinaryDataHandler.inl.

References putValue().

00185 {
00186     for(UInt32 i = 0; i < size; ++i)
00187         putValue(value[i]);
00188 }

void osg::BinaryDataHandler::putValues ( const UInt8 value,
UInt32  size 
) [inline]

Definition at line 191 of file OSGBinaryDataHandler.inl.

References put().

00192 {
00193     put(value, size * sizeof(UInt8));
00194 }

void osg::BinaryDataHandler::putValues ( const UInt16 value,
UInt32  size 
) [inline]

Definition at line 197 of file OSGBinaryDataHandler.inl.

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

00198 {
00199 #if BYTE_ORDER == LITTLE_ENDIAN
00200 
00201     if(_networkOrder == true)
00202     {
00203         for(UInt32 i = 0; i < size; ++i)
00204         {
00205             putValue(value[i]);
00206         }
00207     }
00208     else
00209 #endif
00210     {
00211         put(value, size * sizeof(UInt16));
00212     }
00213 }

void osg::BinaryDataHandler::putValues ( const UInt32 value,
UInt32  size 
) [inline]

Definition at line 216 of file OSGBinaryDataHandler.inl.

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

00217 {
00218 #if BYTE_ORDER == LITTLE_ENDIAN
00219     if(_networkOrder == true)
00220     {
00221         for(UInt32 i = 0; i < size; ++i)
00222         {
00223             putValue(value[i]);
00224         }
00225     }
00226     else
00227 #endif
00228     {
00229         put(value, size * sizeof(UInt32));
00230     }
00231 }

void osg::BinaryDataHandler::putValues ( const UInt64 value,
UInt32  size 
) [inline]

Definition at line 234 of file OSGBinaryDataHandler.inl.

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

00235 {
00236 #if BYTE_ORDER == LITTLE_ENDIAN
00237     if(_networkOrder == true)
00238     {
00239         for(UInt32 i = 0; i < size; ++i)
00240         {
00241             putValue(value[i]);
00242         }
00243     }
00244     else
00245 #endif
00246     {
00247         put(value, size * sizeof(UInt64));
00248     }
00249 }

void osg::BinaryDataHandler::putValues ( const Int8 value,
UInt32  size 
) [inline]

Definition at line 252 of file OSGBinaryDataHandler.inl.

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

00253 {
00254 #if BYTE_ORDER == LITTLE_ENDIAN
00255     if(_networkOrder == true)
00256     {
00257         for(UInt32 i = 0; i < size; ++i)
00258         {
00259             putValue(value[i]);
00260         }
00261     }
00262     else
00263 #endif
00264     {
00265         put(value, size * sizeof(Int8));
00266     }
00267 }

void osg::BinaryDataHandler::putValues ( const Int16 value,
UInt32  size 
) [inline]

Definition at line 270 of file OSGBinaryDataHandler.inl.

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

00271 {
00272 #if BYTE_ORDER == LITTLE_ENDIAN
00273     if(_networkOrder == true)
00274     {
00275         for(UInt32 i = 0; i < size; ++i)
00276         {
00277             putValue(value[i]);
00278         }
00279     }
00280     else
00281 #endif
00282     {
00283         put(value, size * sizeof(Int16));
00284     }
00285 }

void osg::BinaryDataHandler::putValues ( const Int32 value,
UInt32  size 
) [inline]

Definition at line 288 of file OSGBinaryDataHandler.inl.

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

00289 {
00290 #if BYTE_ORDER == LITTLE_ENDIAN
00291     if(_networkOrder == true)
00292     {
00293         for(UInt32 i = 0; i < size; ++i)
00294         {
00295             putValue(value[i]);
00296         }
00297     }
00298     else
00299 #endif
00300     {
00301         put(value, size * sizeof(Int32));
00302     }
00303 }

void osg::BinaryDataHandler::putValues ( const Int64 value,
UInt32  size 
) [inline]

Definition at line 306 of file OSGBinaryDataHandler.inl.

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

00307 {
00308 #if BYTE_ORDER == LITTLE_ENDIAN
00309     if(_networkOrder == true)
00310     {
00311         for(UInt32 i = 0; i < size; ++i)
00312         {
00313             putValue(value[i]);
00314         }
00315     }
00316     else
00317 #endif
00318     {
00319         put(value, size * sizeof(Int64));
00320     }
00321 }

void osg::BinaryDataHandler::putValues ( const Real16 value,
UInt32  size 
) [inline]

Definition at line 324 of file OSGBinaryDataHandler.inl.

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

00325 {
00326 #if BYTE_ORDER == LITTLE_ENDIAN
00327     if(_networkOrder == true)
00328     {
00329         for(UInt32 i = 0; i < size; ++i)
00330         {
00331             putValue(value[i]);
00332         }
00333     }
00334     else
00335 #endif
00336     {
00337         put(value, size * sizeof(Real16));
00338     }
00339 }

void osg::BinaryDataHandler::putValues ( const Real32 value,
UInt32  size 
) [inline]

Definition at line 342 of file OSGBinaryDataHandler.inl.

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

00343 {
00344 #if BYTE_ORDER == LITTLE_ENDIAN
00345     if(_networkOrder == true)
00346     {
00347         for(UInt32 i = 0; i < size; ++i)
00348         {
00349             putValue(value[i]);
00350         }
00351     }
00352     else
00353 #endif
00354     {
00355         put(value, size * sizeof(Real32));
00356     }
00357 }

void osg::BinaryDataHandler::putValues ( const Real64 value,
UInt32  size 
) [inline]

Definition at line 360 of file OSGBinaryDataHandler.inl.

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

00361 {
00362 #if BYTE_ORDER == LITTLE_ENDIAN
00363     if(_networkOrder == true)
00364     {
00365         for(UInt32 i = 0; i < size; ++i)
00366         {
00367             putValue(value[i]);
00368         }
00369     }
00370     else
00371 #endif
00372     {
00373         put(value, size * sizeof(Real64));
00374     }
00375 }

void osg::BinaryDataHandler::putValues ( const Real128 value,
UInt32  size 
) [inline]

Definition at line 378 of file OSGBinaryDataHandler.inl.

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

00379 {
00380 #if BYTE_ORDER == LITTLE_ENDIAN
00381     if(_networkOrder == true)
00382     {
00383         for(UInt32 i = 0; i < size; ++i)
00384         {
00385             putValue(value[i]);
00386         }
00387     }
00388     else
00389 #endif
00390     {
00391         put(value, size * sizeof(Real128));
00392     }
00393 }

void osg::BinaryDataHandler::putValues ( const std::string *  value,
UInt32  size 
) [inline]

Definition at line 396 of file OSGBinaryDataHandler.inl.

References putValue().

00397 {
00398     for(UInt32 i = 0; i<size; ++i)
00399     {
00400         putValue(value[i]);    
00401     }
00402 }

void BinaryDataHandler::get ( void *  dst,
UInt32  size 
)

Definition at line 161 of file OSGBinaryDataHandler.cpp.

References _currentReadBuffer, _currentReadBufferPos, _zeroCopyThreshold, osg::osgMin(), pullBuffer(), read(), and readBufEnd().

Referenced by osg::RemoteAspect::receiveSync(), and osg::ClusterViewBuffer::recv().

00162 {
00163     MemoryHandle data = static_cast<MemoryHandle>(dst);
00164 
00165     if(_zeroCopyThreshold && size >= _zeroCopyThreshold)
00166     {
00167         if(_zeroCopyThreshold > 1)
00168         {
00169             UInt8 tag;
00170 
00171             // we have to read the tag, to force reading of data blocks
00172             // if the first data field was zero copied
00173             get(&tag, sizeof(tag));
00174         }
00175 
00176         // read direct into destination
00177         read(data, size);
00178     }
00179     else
00180     {
00181         UInt32 copySize;
00182 
00183         while(size != 0)
00184         {
00185             // read new data if nothing left
00186             if(_currentReadBuffer == readBufEnd())
00187             {
00188                 pullBuffer();
00189             }
00190 
00191             // num bytes to copy
00192             copySize = osgMin((_currentReadBuffer->getDataSize() -
00193                                _currentReadBufferPos),
00194                               size);
00195 
00196             // no data in buffer ?
00197             if(copySize != 0)
00198             {
00199                 memcpy( data,
00200                        _currentReadBuffer->getMem() + _currentReadBufferPos,
00201                         copySize);
00202 
00203                  size                 -= copySize;
00204                 _currentReadBufferPos += copySize;
00205                  data                 += copySize;
00206             }
00207 
00208             // skip to next buffer if current buffer is full
00209             if(_currentReadBufferPos == _currentReadBuffer->getDataSize())
00210             {
00211                 _currentReadBuffer++;
00212                 _currentReadBufferPos = 0;
00213             }
00214         }
00215     }
00216 }

void BinaryDataHandler::getAndAlloc ( MemoryHandle src,
UInt32  size 
)

read data in a dynamic allocated block

If data was compressed or converted then it is not possible to write it into the destination memory. BinaryDataHandler doesn't store data in continous memory areas. If the caller needs a continuous memory then we provide a dynamic allocated block. The caller is responsible to free this block.

Definition at line 227 of file OSGBinaryDataHandler.cpp.

00228 {
00229     src = new UInt8[size];
00230 
00231     get(src, size);
00232 }

void osg::BinaryDataHandler::getValue ( bool &  value  )  [inline]

void osg::BinaryDataHandler::getValue ( UInt8 value  )  [inline]

Definition at line 414 of file OSGBinaryDataHandler.inl.

00415 {
00416     get(&value, sizeof(UInt8));
00417 }

void osg::BinaryDataHandler::getValue ( UInt16 value  )  [inline]

Definition at line 420 of file OSGBinaryDataHandler.inl.

References osg::osgntohs().

00421 {
00422     get(&value, sizeof(UInt16));
00423 
00424     value = osgntohs(value);
00425 }

void osg::BinaryDataHandler::getValue ( UInt32 value  )  [inline]

Definition at line 428 of file OSGBinaryDataHandler.inl.

References osg::osgntohl().

00429 {
00430     get(&value, sizeof(UInt32));
00431 
00432     value = osgntohl(value);
00433 }

void osg::BinaryDataHandler::getValue ( UInt64 value  )  [inline]

Definition at line 436 of file OSGBinaryDataHandler.inl.

References osg::osgntohll().

00437 {
00438     get(&value, sizeof(UInt64));
00439 
00440     value = osgntohll(value);
00441 }

void osg::BinaryDataHandler::getValue ( Int8 value  )  [inline]

Definition at line 444 of file OSGBinaryDataHandler.inl.

00445 {
00446     get(&value, sizeof(Int8));
00447 }

void osg::BinaryDataHandler::getValue ( Int16 value  )  [inline]

Definition at line 450 of file OSGBinaryDataHandler.inl.

References osg::osgntohs().

00451 {
00452     get(&value, sizeof(Int16));
00453 
00454     value = osgntohs(value);
00455 }

void osg::BinaryDataHandler::getValue ( Int32 value  )  [inline]

Definition at line 458 of file OSGBinaryDataHandler.inl.

References osg::osgntohl().

00459 {
00460     get(&value, sizeof(Int32));
00461 
00462     value = osgntohl(value);
00463 }

void osg::BinaryDataHandler::getValue ( Int64 value  )  [inline]

Definition at line 466 of file OSGBinaryDataHandler.inl.

References osg::osgntohll().

00467 {
00468     get(&value, sizeof(Int64));
00469 
00470     value = osgntohll(value);
00471 }

void osg::BinaryDataHandler::getValue ( Real16 value  )  [inline]

Definition at line 474 of file OSGBinaryDataHandler.inl.

References osg::osgntohs(), and osg::Real16::setBits().

00475 {
00476     UInt16 v;
00477 
00478     get(&v, sizeof(Real16));
00479 
00480     v     = osgntohs(v);
00481     value.setBits(v);
00482 }

void osg::BinaryDataHandler::getValue ( Real32 value  )  [inline]

Definition at line 485 of file OSGBinaryDataHandler.inl.

References osg::osgntohf(), and osg::osgntohl().

00486 {
00487     get(&value, sizeof(Real32));
00488 
00489     value = osgntohf(value);
00490 
00491 #if 0
00492     // doesn't work on my 64 bit linux ...
00493     UInt32 v;
00494 
00495     get(&v, sizeof(Real32));
00496 
00497     v     = osgntohl(v);
00498     value = *(reinterpret_cast<Real32 *>(&v));
00499 #endif
00500 }

void osg::BinaryDataHandler::getValue ( Real64 value  )  [inline]

Definition at line 503 of file OSGBinaryDataHandler.inl.

References osg::osgntohd(), and osg::osgntohll().

00504 {
00505     get(&value, sizeof(Real64));
00506 
00507     value = osgntohd(value);
00508 
00509 #if 0
00510     UInt64 v;
00511 
00512     get(&v, sizeof(Real64));
00513 
00514     v     = osgntohll(v);
00515     value = *(reinterpret_cast<Real64 *>(&v));
00516 #endif
00517 }

void osg::BinaryDataHandler::getValue ( Real128 value  )  [inline]

Definition at line 520 of file OSGBinaryDataHandler.inl.

References osg::osgntohdd(), and osg::osgntohll().

00521 {
00522     get(&value, sizeof(Real128));
00523 
00524     value = osgntohdd(value);
00525 
00526 #if 0
00527     UInt64 v[2];
00528 
00529 #if BYTE_ORDER == LITTLE_ENDIAN
00530     get(&v[1], sizeof(UInt64));
00531     get(&v[0], sizeof(UInt64));
00532 #else
00533     get(&v[0], sizeof(UInt64));
00534     get(&v[1], sizeof(UInt64));
00535 #endif
00536 
00537     v[0]     = osgntohll(v[0]);
00538     v[1]     = osgntohll(v[1]);
00539     value = *(reinterpret_cast<Real128 *>(&v));
00540 #endif
00541 }

void osg::BinaryDataHandler::getValue ( std::string &  value  )  [inline]

Definition at line 544 of file OSGBinaryDataHandler.inl.

References getValue().

00545 {
00546     UInt32  len;
00547     Char8  *str = NULL;
00548 
00549     getValue(len);
00550 
00551     if(len != 0)
00552     {
00553         str = new Char8[len];
00554         
00555         get(str, len);
00556 
00557         value = str;
00558         
00559         delete [] str;
00560     }
00561     else
00562     {
00563         value.erase();
00564     }
00565 }

void osg::BinaryDataHandler::getValues ( bool *  value,
UInt32  size 
) [inline]

Definition at line 568 of file OSGBinaryDataHandler.inl.

References getValue().

00569 {
00570     for(UInt32 i = 0; i < size; ++i)
00571         getValue(value[i]);
00572 }

void osg::BinaryDataHandler::getValues ( UInt8 value,
UInt32  size 
) [inline]

Definition at line 575 of file OSGBinaryDataHandler.inl.

00576 {
00577     get(value, size * sizeof(UInt8));
00578 }

void osg::BinaryDataHandler::getValues ( UInt16 value,
UInt32  size 
) [inline]

Definition at line 581 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohs().

00582 {
00583     get(value, size * sizeof(UInt16));
00584 
00585 #if BYTE_ORDER == LITTLE_ENDIAN
00586     if(_networkOrder == true)
00587     {
00588         for(UInt32 i = 0; i < size; ++i)
00589         {
00590             value[i] = osgntohs(value[i]);
00591         }
00592     }
00593 #endif
00594 }

void osg::BinaryDataHandler::getValues ( UInt32 value,
UInt32  size 
) [inline]

Definition at line 597 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohl().

00598 {
00599     get(value, size * sizeof(UInt32));
00600 
00601 #if BYTE_ORDER == LITTLE_ENDIAN
00602     if(_networkOrder == true)
00603     {
00604         for(UInt32 i = 0; i < size; ++i)
00605         {
00606             value[i] = osgntohl(value[i]);
00607         }
00608     }
00609 #endif
00610 }

void osg::BinaryDataHandler::getValues ( UInt64 value,
UInt32  size 
) [inline]

Definition at line 613 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohll().

00614 {
00615     get(value, size * sizeof(UInt64));
00616 
00617 #if BYTE_ORDER == LITTLE_ENDIAN
00618     if(_networkOrder == true)
00619     {
00620         for(UInt32 i = 0; i < size; ++i)
00621         {
00622             value[i] = osgntohll(value[i]);
00623         }
00624     }
00625 #endif
00626 }

void osg::BinaryDataHandler::getValues ( Int8 value,
UInt32  size 
) [inline]

Definition at line 629 of file OSGBinaryDataHandler.inl.

00630 {
00631     get(value, size * sizeof(Int8));
00632 }

void osg::BinaryDataHandler::getValues ( Int16 value,
UInt32  size 
) [inline]

Definition at line 635 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohs().

00636 {
00637     get(value, size * sizeof(Int16));
00638 
00639 #if BYTE_ORDER == LITTLE_ENDIAN
00640     if(_networkOrder == true)
00641     {
00642         for(UInt32 i = 0; i < size; ++i)
00643         {
00644             value[i] = osgntohs(value[i]);
00645         }
00646     }
00647 #endif
00648 }

void osg::BinaryDataHandler::getValues ( Int32 value,
UInt32  size 
) [inline]

Definition at line 651 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohl().

00652 {
00653     get(value, size * sizeof(Int32));
00654 
00655 #if BYTE_ORDER == LITTLE_ENDIAN
00656     if(_networkOrder == true)
00657     {
00658         for(UInt32 i = 0; i < size; ++i)
00659         {
00660             value[i] = osgntohl(value[i]);
00661         }
00662     }
00663 #endif
00664 }

void osg::BinaryDataHandler::getValues ( Int64 value,
UInt32  size 
) [inline]

Definition at line 667 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohll().

00668 {
00669     get(value, size * sizeof(Int64));
00670 
00671 #if BYTE_ORDER == LITTLE_ENDIAN
00672     if(_networkOrder == true)
00673     {
00674         for(UInt32 i = 0; i < size; ++i)
00675         {
00676             value[i] = osgntohll(value[i]);
00677         }
00678     }
00679 #endif
00680 }

void osg::BinaryDataHandler::getValues ( Real16 value,
UInt32  size 
) [inline]

Definition at line 683 of file OSGBinaryDataHandler.inl.

References _networkOrder, osg::osgntohs(), and osg::Real16::setBits().

00684 {
00685     get(value, size * sizeof(Real16));
00686 
00687 #if BYTE_ORDER == LITTLE_ENDIAN
00688     if(_networkOrder == true)
00689     {
00690         UInt16 *intValue = reinterpret_cast<UInt16 *>(value);
00691 
00692         for(UInt32 i = 0; i < size; ++i)
00693         {
00694             value[i].setBits(osgntohs(intValue[i]));
00695         }
00696     }
00697 #endif
00698 }

void osg::BinaryDataHandler::getValues ( Real32 value,
UInt32  size 
) [inline]

Definition at line 701 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohl().

00702 {
00703     get(value, size * sizeof(Real32));
00704 
00705 #if BYTE_ORDER == LITTLE_ENDIAN
00706     if(_networkOrder == true)
00707     {
00708         UInt32 *intValue = reinterpret_cast<UInt32 *>(value);
00709 
00710         for(UInt32 i = 0; i < size; ++i)
00711         {
00712             intValue[i] = osgntohl(intValue[i]);
00713         }
00714     }
00715 #endif
00716 }

void osg::BinaryDataHandler::getValues ( Real64 value,
UInt32  size 
) [inline]

Definition at line 719 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohll().

00720 {
00721     get(value, size * sizeof(Real64));
00722 
00723 #if BYTE_ORDER == LITTLE_ENDIAN
00724     if(_networkOrder == true)
00725     {
00726         UInt64 *longValue = reinterpret_cast<UInt64 *>(value);
00727 
00728         for(UInt32 i = 0; i < size; ++i)
00729         {
00730             longValue[i] = osgntohll(longValue[i]);
00731         }
00732     }
00733 #endif
00734 }

void osg::BinaryDataHandler::getValues ( Real128 value,
UInt32  size 
) [inline]

Definition at line 737 of file OSGBinaryDataHandler.inl.

References _networkOrder, and osg::osgntohll().

00738 {
00739     get(value, size * sizeof(UInt64) * 2);
00740 
00741 #if BYTE_ORDER == LITTLE_ENDIAN
00742     if(_networkOrder == true)
00743     {
00744         UInt64 *longValue = reinterpret_cast<UInt64 *>(value);
00745 
00746         for(UInt32 i = 0; i < size; i += 2)
00747         {
00748             UInt64 l = longValue[i];
00749             longValue[i]     = osgntohll(longValue[i + 1]);
00750             longValue[i + 1] = osgntohll(longValue[l    ]);
00751         }
00752     }
00753 #endif
00754 }

void osg::BinaryDataHandler::getValues ( std::string *  value,
UInt32  size 
) [inline]

Definition at line 757 of file OSGBinaryDataHandler.inl.

References getValue().

00758 {
00759     for(UInt32 i = 0; i < size; ++i)
00760     {
00761         getValue(value[i]);
00762     }
00763 }

void BinaryDataHandler::forceCopy ( void   )  [virtual]

always copy memory blocks befor write forceCopy must be called for all endpoints of this connection

Definition at line 260 of file OSGBinaryDataHandler.cpp.

References _zeroCopyThreshold.

00261 {
00262     _zeroCopyThreshold = 0;
00263 }

void BinaryDataHandler::forceDirectIO ( void   )  [virtual]

always read or write directly into or from memory blocks forceDirectIO must be called for all endpoints of this connection

Definition at line 268 of file OSGBinaryDataHandler.cpp.

References _zeroCopyThreshold.

00269 {
00270     _zeroCopyThreshold = 1;
00271 }

void BinaryDataHandler::flush ( void   ) 

void BinaryDataHandler::setNetworkOrder ( bool  value  ) 

always copy memory blocks befor write forceCopy must be called for all endpoints of this connection

Definition at line 277 of file OSGBinaryDataHandler.cpp.

References _networkOrder.

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

00278 {
00279     _networkOrder = value;    
00280 }

bool BinaryDataHandler::getNetworkOrder ( void   ) 

always copy memory blocks befor write forceCopy must be called for all endpoints of this connection

Definition at line 282 of file OSGBinaryDataHandler.cpp.

References _networkOrder.

00283 {
00284     return _networkOrder;
00285 }

BinaryDataHandler::BuffersT::iterator osg::BinaryDataHandler::readBufBegin ( void   )  [inline, protected]

BinaryDataHandler::BuffersT::iterator osg::BinaryDataHandler::readBufEnd ( void   )  [inline, protected]

Definition at line 818 of file OSGBinaryDataHandler.inl.

References _readBuffers.

Referenced by get(), isReadBufferEmpty(), readBufAdd(), readBufClear(), readBuffer(), and osg::GroupSockConnection::selectChannel().

00819 {
00820     return _readBuffers.end();
00821 }

void BinaryDataHandler::readBufAdd ( MemoryHandle  mem,
UInt32  size,
UInt32  dataSize = 0 
) [protected]

Definition at line 290 of file OSGBinaryDataHandler.cpp.

References _currentReadBuffer, _readBuffers, and readBufEnd().

Referenced by osg::BINLoader::BinaryFileHandler::BinaryFileHandler(), osg::GroupSockConnection::GroupSockConnection(), osg::PointSockConnection::PointSockConnection(), and osg::GroupSockConnection::setParams().

00293 {
00294     MemoryBlock memBlock(mem, size, dataSize);
00295 
00296     _readBuffers.push_back(memBlock);
00297 
00298     _currentReadBuffer = readBufEnd();
00299 }

void BinaryDataHandler::readBufClear ( void   )  [protected]

Definition at line 301 of file OSGBinaryDataHandler.cpp.

References _currentReadBuffer, _readBuffers, and readBufEnd().

Referenced by osg::GroupSockConnection::setParams().

00302 {
00303     _readBuffers.clear();
00304 
00305     _currentReadBuffer=readBufEnd();
00306 }

void BinaryDataHandler::read ( MemoryHandle  src,
UInt32  size 
) [protected, virtual]

direct buffer read, write data into given buffer

Reimplemented in osg::GroupSockConnection, osg::PointMCastConnection, osg::PointSockConnection, osg::PointSockPipeline, and osg::BINLoader::BinaryFileHandler.

Definition at line 389 of file OSGBinaryDataHandler.cpp.

References SWARNING.

Referenced by get(), and readBuffer().

00391 {
00392     SWARNING << "BinaryDataHandler::read(MemoryHandle src,int size) called" 
00393              << std::endl;
00394 }

void BinaryDataHandler::readBuffer ( void   )  [protected, virtual]

default buffer read

Use direct read to implement buffer read. First read buffer size and then read rest of buffer

Returns:
buffer iterator points behind the last buffer containing data

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

Definition at line 346 of file OSGBinaryDataHandler.cpp.

References osg::osgMin(), osg::osgntohl(), read(), readBufBegin(), readBufEnd(), and SFATAL.

Referenced by pullBuffer().

00347 {
00348     BuffersT::iterator i;
00349     UInt32             size,nsize;
00350     UInt32             readSize;
00351 
00352     // read buffer size
00353     read((MemoryHandle) &nsize, sizeof(UInt32));
00354     size = osgntohl(nsize);
00355 
00356     // read rest of buffer
00357     for(i = readBufBegin(); size != 0; ++i)
00358     {
00359         if(i == readBufEnd())
00360         {
00361             SFATAL << "Read buffer is to small. " << size
00362                    << "bytes missing" << std::endl;
00363 
00364             throw ReadError("Read buffer to small for whole block");
00365         }
00366 
00367         readSize = osgMin(size, i->getSize());
00368 
00369         read(i->getMem(), readSize);
00370 
00371         i->setDataSize(readSize);
00372 
00373         size -= readSize;
00374     }
00375 
00376     for(; i != readBufEnd(); ++i)
00377     {
00378         i->setDataSize(0);
00379     }
00380 }

BinaryDataHandler::BuffersT::iterator osg::BinaryDataHandler::writeBufBegin ( void   )  [inline, protected]

BinaryDataHandler::BuffersT::iterator osg::BinaryDataHandler::writeBufEnd ( void   )  [inline, protected]

Definition at line 830 of file OSGBinaryDataHandler.inl.

References _writeBuffers.

Referenced by flush(), put(), writeBufClear(), and writeBuffer().

00831 {
00832     return _writeBuffers.end();
00833 }

void BinaryDataHandler::writeBufAdd ( MemoryHandle  mem,
UInt32  size,
UInt32  dataSize = 0 
) [protected]

void BinaryDataHandler::writeBufClear ( void   )  [protected]

Definition at line 323 of file OSGBinaryDataHandler.cpp.

References _currentWriteBuffer, _writeBuffers, and writeBufEnd().

Referenced by osg::GroupSockConnection::setParams().

00324 {
00325     _writeBuffers.clear();
00326 
00327     _currentWriteBuffer = writeBufEnd();
00328 }

void BinaryDataHandler::write ( MemoryHandle  src,
UInt32  size 
) [protected, virtual]

direct buffer write, write data into given buffer

Reimplemented in osg::GroupMCastConnection, osg::GroupSockConnection, osg::GroupSockPipeline, osg::PointSockConnection, and osg::BINWriter::BinaryFileHandler.

Definition at line 446 of file OSGBinaryDataHandler.cpp.

References SWARNING.

Referenced by pushBuffer(), put(), and writeBuffer().

00448 {
00449     SWARNING << "BinaryDataHandler::write(MemoryHandle mem,int size) called" 
00450              << std::endl;
00451 }

void BinaryDataHandler::writeBuffer ( void   )  [protected, virtual]

default buffer write, use direct write to implement buffer write.

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

Definition at line 402 of file OSGBinaryDataHandler.cpp.

References osg::osghtonl(), write(), writeBufBegin(), and writeBufEnd().

Referenced by pushBuffer().

00403 {
00404     BuffersT::iterator i;
00405     UInt32             size = 0;
00406     UInt32             nsize;
00407 
00408     // calculate blocksize
00409     for(i = writeBufBegin(); i != writeBufEnd(); ++i)
00410     {
00411         size += i->getDataSize();
00412     }
00413 
00414     // write buffer size
00415     nsize = osghtonl(size);
00416 
00417     write((MemoryHandle) &nsize, sizeof(UInt32));
00418 
00419     // write buffers
00420     for(i = writeBufBegin(); i != writeBufEnd(); ++i)
00421     {
00422         if(i->getDataSize() != 0)
00423         {
00424             write(i->getMem(), i->getDataSize());
00425         }
00426     }
00427 }

bool BinaryDataHandler::isReadBufferEmpty ( void   )  [protected]

check for data in read buffer

Definition at line 431 of file OSGBinaryDataHandler.cpp.

References _currentReadBuffer, _zeroCopyThreshold, and readBufEnd().

Referenced by osg::PointMCastConnection::selectChannel().

00432 {
00433     if(_zeroCopyThreshold == 1)
00434         return true;
00435     if(_currentReadBuffer == readBufEnd())
00436         return true;
00437     return false;
00438 }

void BinaryDataHandler::pushBuffer ( void   )  [private]

Definition at line 454 of file OSGBinaryDataHandler.cpp.

References _currentWriteBuffer, _currentWriteBufferPos, _zeroCopyBuffers, freeMem(), write(), writeBufBegin(), and writeBuffer().

Referenced by flush(), and put().

00455 {
00456     BuffersT::iterator i;
00457 
00458     writeBuffer();
00459 
00460     // direct write zero copy buffers
00461     for(  i  = _zeroCopyBuffers.begin();
00462           i != _zeroCopyBuffers.end  ();
00463         ++i)
00464     {
00465         write(i->getMem(), i->getDataSize());
00466     }
00467 
00468     _zeroCopyBuffers.clear();
00469 
00470     // remove buffers given with getAndFree
00471     freeMem();
00472 
00473     // reset buffer pos
00474     _currentWriteBuffer    = writeBufBegin();
00475     _currentWriteBufferPos = 0;
00476 
00477     _currentWriteBuffer->setDataSize(0);
00478 }

void BinaryDataHandler::pullBuffer ( void   )  [private]

Definition at line 480 of file OSGBinaryDataHandler.cpp.

References _currentReadBuffer, _currentReadBufferPos, readBufBegin(), and readBuffer().

Referenced by get().

00481 {
00482     readBuffer();
00483 
00484     _currentReadBuffer    = readBufBegin();
00485     _currentReadBufferPos = 0;
00486 }

void BinaryDataHandler::freeMem ( void   )  [private]

Definition at line 488 of file OSGBinaryDataHandler.cpp.

References _freeMem.

Referenced by pushBuffer(), and ~BinaryDataHandler().

00489 {
00490     for(FreeMemT::iterator i= _freeMem.begin(); i!= _freeMem.end(); ++i)
00491     {
00492         delete [] *i;
00493     }
00494 
00495     _freeMem.clear();
00496 }

void osg::BinaryDataHandler::operator= ( const BinaryDataHandler source  )  [private]


Member Data Documentation

Definition at line 220 of file OSGBinaryDataHandler.h.

Referenced by readBufAdd(), readBufBegin(), readBufClear(), and readBufEnd().

Definition at line 221 of file OSGBinaryDataHandler.h.

Referenced by writeBufAdd(), writeBufBegin(), writeBufClear(), and writeBufEnd().

Definition at line 222 of file OSGBinaryDataHandler.h.

Referenced by pushBuffer(), and put().

Definition at line 225 of file OSGBinaryDataHandler.h.

Referenced by freeMem(), and putAndFree().

BuffersT::iterator osg::BinaryDataHandler::_currentReadBuffer [protected]

Definition at line 227 of file OSGBinaryDataHandler.h.

Referenced by get(), and pullBuffer().

BuffersT::iterator osg::BinaryDataHandler::_currentWriteBuffer [protected]

Definition at line 228 of file OSGBinaryDataHandler.h.

Referenced by flush(), pushBuffer(), put(), writeBufAdd(), and writeBufClear().

Definition at line 229 of file OSGBinaryDataHandler.h.

Referenced by flush(), pushBuffer(), put(), and writeBufAdd().

Definition at line 231 of file OSGBinaryDataHandler.h.

Referenced by getNetworkOrder(), getValues(), putValues(), and setNetworkOrder().


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 11:10:43 2008 for OpenSG by  doxygen 1.5.5