Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
ipcMessageWriter Class Reference

#include <ipcMessageWriter.h>

List of all members.

Public Member Functions

 ipcMessageWriter (PRUint32 initialCapacity)
 ~ipcMessageWriter ()
PRBool HasError ()
void PutInt8 (PRUint8 val)
void PutInt16 (PRUint16 val)
void PutInt32 (PRUint32 val)
PRUint32 PutBytes (const void *src, PRUint32 n)
PRUint8GetBuffer ()
PRInt32 GetSize ()

Private Member Functions

PRBool EnsureCapacity (PRInt32 sizeNeeded)
PRBool GrowCapacity (PRInt32 sizeNeeded)

Private Attributes

PRUint8mBuf
PRUint8mBufPtr
PRUint8mBufEnd
PRInt32 mCapacity
PRBool mError

Detailed Description

Definition at line 52 of file ipcMessageWriter.h.


Constructor & Destructor Documentation

ipcMessageWriter::ipcMessageWriter ( PRUint32  initialCapacity) [inline]

Definition at line 55 of file ipcMessageWriter.h.

                                                             :
                    mBuf(NULL),
                    mBufPtr(NULL), mBufEnd(NULL),
                    mCapacity(0),
                    mError(PR_FALSE)
                  {
                    EnsureCapacity(initialCapacity);
                  }

Here is the call graph for this function:

Definition at line 47 of file ipcMessageWriter.cpp.

{
  if (mBuf)
    free(mBuf);
}

Member Function Documentation

PRBool ipcMessageWriter::EnsureCapacity ( PRInt32  sizeNeeded) [inline, private]

Definition at line 85 of file ipcMessageWriter.h.

                  {
                    return (mBuf && ((mBufPtr + sizeNeeded) <= mBufEnd)) ?
                      PR_TRUE : GrowCapacity(sizeNeeded);
                  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 78 of file ipcMessageWriter.h.

                  { return mBuf; }

Here is the caller graph for this function:

Definition at line 81 of file ipcMessageWriter.h.

                  { return mBufPtr - mBuf; }

Here is the caller graph for this function:

PRBool ipcMessageWriter::GrowCapacity ( PRInt32  sizeNeeded) [private]

Definition at line 95 of file ipcMessageWriter.cpp.

{
  if (sizeNeeded < 0)
    return PR_FALSE;
  PRInt32 newCapacity = (mBufPtr - mBuf) + sizeNeeded;
  if (mCapacity == 0)
    mCapacity = newCapacity;
  else
  {
    while (newCapacity > mCapacity && (mCapacity << 1) > 0)
      mCapacity <<= 1;
    if (newCapacity > mCapacity) // if we broke out because of rollover
      return PR_FALSE;
  }
    
  PRInt32 curPos = mBufPtr - mBuf;
  mBuf = (PRUint8*)realloc(mBuf, mCapacity);
  if (!mBuf) {
    mError = PR_TRUE;
    return PR_FALSE;
  }
  mBufPtr = mBuf + curPos;
  mBufEnd = mBuf + mCapacity;
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 69 of file ipcMessageWriter.h.

                  { return mError; }

Here is the caller graph for this function:

Definition at line 85 of file ipcMessageWriter.cpp.

{
  if (EnsureCapacity(n)) {
    memcpy(mBufPtr, src, n);
    mBufPtr += n;
    return n;
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 63 of file ipcMessageWriter.cpp.

{
  if (EnsureCapacity(sizeof(PRUint16))) {
    PRUint8 temp[2];
    *(PRUint16*)temp = val;
    *mBufPtr++ = temp[0];
    *mBufPtr++ = temp[1];
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 73 of file ipcMessageWriter.cpp.

{
  if (EnsureCapacity(sizeof(PRUint32))) {
    PRUint8 temp[4];
    *(PRUint32*)temp = val;
    *mBufPtr++ = temp[0];
    *mBufPtr++ = temp[1];
    *mBufPtr++ = temp[2];
    *mBufPtr++ = temp[3];    
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 53 of file ipcMessageWriter.cpp.

{
  if (EnsureCapacity(sizeof(PRUint8))) 
    *mBufPtr++ = val;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 93 of file ipcMessageWriter.h.

Definition at line 94 of file ipcMessageWriter.h.

Definition at line 94 of file ipcMessageWriter.h.

Definition at line 95 of file ipcMessageWriter.h.

Definition at line 96 of file ipcMessageWriter.h.


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