All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Protected Member Functions
GpCoreTools::DynamicBuffer Class Reference

Brief description of class still missing. More...

#include <DynamicBuffer.h>

Inheritance diagram for GpCoreTools::DynamicBuffer:
CrystalfontzBuffer CubeBuffer CubeTcpBuffer GpsBuffer LinkBuffer MasterBuffer NetBuffer PPSBuffer SystemBuffer TimeMasterBuffer TimeSlaveBuffer UbxBuffer

List of all members.

Public Member Functions

 DynamicBuffer (int fileDescriptor)
bool read ()
int send (const char *bytes, int bytesCount) const
int sendNoGateway (const char *bytes, int bytesCount) const
int sendPartial (const char *bytes, int bytesCount) const
int sendPartialNoGateway (const char *bytes, int bytesCount) const
void setFileDescriptor (int fileDescriptor)
virtual ~DynamicBuffer ()

Protected Member Functions

virtual int bytesAvailable (char *bytes, int bytesCount)=0
void debugBuffer () const
void debugEndIgnoreByte ()
void debugIgnoreByte ()

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

Description of constructor still missing

References TRACE.

{
  TRACE;
  _fileDescriptor=fileDescriptor;
  _bufferCapacity=64;
  _buffer=(char *)malloc(_bufferCapacity);
  _bufferIn=0;
  _bufferOut=0;
  _debugIgnoreByteCount=0;
  _debugIgnoreByteColumnCount=8;
}

Description of destructor still missing

References TRACE.

{
  TRACE;
  delete [] _buffer;
}

Member Function Documentation

virtual int GpCoreTools::DynamicBuffer::bytesAvailable ( char *  bytes,
int  bytesCount 
) [protected, pure virtual]
void GpCoreTools::DynamicBuffer::debugBuffer ( ) const [protected]

References GpCoreTools::Log::stream(), TRACE, and GpCoreTools::Log::write().

Referenced by UbxBuffer::bytesAvailable(), and CubeBuffer::bytesAvailable().

{
  TRACE;
  Log::write(0, "out %i in %i (available %i) capacity %i\n",
             _bufferOut, _bufferIn, _bufferIn-_bufferOut, _bufferCapacity);
  int nLine=7;
  for(int i=0; i<_bufferIn; i++) {
    if(nLine==7) {
      nLine=0;
      fprintf(Log::stream(), "\n%05i ", i);
    } else {
      nLine++;
    }
    fprintf(Log::stream(), "%02hhX ", _buffer[i]);
  }
  fprintf(Log::stream(), "\n");
}

References GpCoreTools::Log::stream().

Referenced by CubeBuffer::bytesAvailable().

{
  if(_debugIgnoreByteCount>0) {
    fprintf(Log::stream(), "\n");
    _debugIgnoreByteColumnCount=8;
    _debugIgnoreByteCount=0;
  }
}

References GpCoreTools::Log::stream(), TRACE, and GpCoreTools::Log::write().

Referenced by UbxBuffer::bytesAvailable(), and CubeBuffer::bytesAvailable().

{
  TRACE;
  if(_debugIgnoreByteCount==0) {
    Log::write(0, "start ignoring bytes");
  }
  if(_debugIgnoreByteColumnCount==8) {
    _debugIgnoreByteColumnCount=1;
    fprintf(Log::stream(), "\n%05i ", _debugIgnoreByteCount);
  } else {
    _debugIgnoreByteColumnCount++;
  }
  fprintf(Log::stream(), "%02hhX ", _buffer[_bufferOut]);
  _debugIgnoreByteCount++;
}

Returns false if data cannot be read.

References bytesAvailable(), TRACE, and GpCoreTools::Log::write().

Referenced by SystemBuffer::bytesAvailable(), TimeMasterBuffer::bytesAvailable(), TimeSlaveBuffer::bytesAvailable(), UbxBuffer::bytesAvailable(), CubeBuffer::bytesAvailable(), GpCoreTools::UnixClientStream::event(), GpCoreTools::Serial::event(), and GpCoreTools::TcpClientStream::event().

{
  TRACE;
  // Makes as much space as possible without moving anything
  if(_bufferOut==_bufferIn) { // Everything is processed, force return to 0
    _bufferIn=0;
    _bufferOut=0;
  }
  // Reads as much as possible
  int maxNRead=0, nRead=0;
  while(nRead==maxNRead) {
    if(_bufferIn==_bufferCapacity) {
      _bufferCapacity=_bufferCapacity << 1;
      Log::write(10, "increase capacity to %i\n", _bufferCapacity);
      _buffer=(char *)realloc(_buffer, _bufferCapacity);
    }
    maxNRead=_bufferCapacity-_bufferIn;
    nRead=::read(_fileDescriptor, _buffer+_bufferIn, maxNRead);
    if(nRead>0) {
      _bufferIn+=nRead;
    } else {
      break;
    }
  }
  // Processes read bytes
  //Log::write(10, "buffer filled up to %i (%.1f %%)\n", _bufferIn, (float)_bufferIn*100.0/_bufferCapacity);
  int nProcessed=0;
  do {
    nProcessed=bytesAvailable(_buffer+_bufferOut, _bufferIn-_bufferOut);
    _bufferOut+=nProcessed;
  } while (nProcessed>0 && _bufferOut<_bufferIn);
  assert(_bufferOut<=_bufferIn);
  return true;
}
int GpCoreTools::DynamicBuffer::send ( const char *  bytes,
int  bytesCount 
) const [inline]

Referenced by GpsBuffer::broadcast(), SystemBuffer::bytesAvailable(), NetBuffer::sendNeighbors(), UbxDevice::sendRaw(), and UbxDevice::sendState().

                                                     {
    return ::write(_fileDescriptor, bytes, bytesCount);
  }
int GpCoreTools::DynamicBuffer::sendNoGateway ( const char *  bytes,
int  bytesCount 
) const [inline]

Referenced by LinkBuffer::bytesAvailable(), LinkBuffer::startMeasure(), and LinkBuffer::startTest().

                                                              {
    return ::send(_fileDescriptor, bytes, bytesCount, MSG_DONTROUTE);
  }
int GpCoreTools::DynamicBuffer::sendPartial ( const char *  bytes,
int  bytesCount 
) const [inline]
                                                            {
    return ::send(_fileDescriptor, bytes, bytesCount, MSG_MORE);
  }
int GpCoreTools::DynamicBuffer::sendPartialNoGateway ( const char *  bytes,
int  bytesCount 
) const [inline]

Referenced by LinkBuffer::bytesAvailable().

                                                                     {
    return ::send(_fileDescriptor, bytes, bytesCount, MSG_DONTROUTE | MSG_MORE);
  }
void GpCoreTools::DynamicBuffer::setFileDescriptor ( int  fileDescriptor) [inline]
{_fileDescriptor=fileDescriptor;}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines