casyncbuffer.cp
Upload User: dangjiwu
Upload Date: 2013-07-19
Package Size: 42019k
Code Size: 5k
Category:

Symbian

Development Platform:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: casyncbuffer.cp,v 1.1.1.1.50.3 2004/07/09 01:44:13 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "CAsyncBuffer.h"
  50. #include <string.h>
  51. const long kBlankLong[] = {'FNRD','fnrd'};
  52. CAsyncBuffer::CAsyncBuffer (
  53. Size inSize,
  54. QElemPtr inpb/*= nil*/)
  55. : mBuffer (nil)
  56. , mSize (0)
  57. , mLim (0)
  58. , mMark (0)
  59. , mBusy (FALSE)
  60. , mClearIndex (0)
  61. { /* begin CAsyncBuffer */
  62. ::memset (&mPBQueue, 0, sizeof (mPBQueue));
  63. PBFree (inpb);
  64. // if (nil != (mBuffer = (Ptr) new char [inSize])) 
  65. if (nil != (mBuffer = (Ptr) ::NewPtr(inSize)))
  66. mSize = inSize;
  67. } /* end CAsyncBuffer */
  68. CAsyncBuffer::~CAsyncBuffer (void)
  69. { /* begin ~CAsyncBuffer */
  70. if (mBuffer) 
  71. ::DisposePtr(mBuffer);
  72. // delete [] mBuffer;
  73. mBuffer = nil;
  74. mSize = 
  75. mLim = 
  76. mMark = 0;
  77. } /* end ~CAsyncBuffer */
  78. long CAsyncBuffer::Read (
  79. void *rcvBuff,
  80. long rcvBuffLen)
  81. { /* begin Read */
  82. long remaining = Remaining ();
  83. if (rcvBuffLen > remaining) rcvBuffLen = remaining;
  84. if (rcvBuffLen) {
  85. if (rcvBuff) ::BlockMoveData (mBuffer + mMark, (Ptr) rcvBuff, rcvBuffLen);
  86. mMark += rcvBuffLen;
  87. } /* if */
  88. return rcvBuffLen;
  89. } /* end Read */
  90. long CAsyncBuffer::Write (
  91. const void *sndBuff,
  92. long sndBuffLen)
  93. { /* begin Write */
  94. long remaining = mSize - mMark;
  95. if (sndBuffLen > remaining) sndBuffLen = remaining;
  96. if (sndBuffLen) {
  97. if (sndBuff) ::BlockMoveData ((Ptr) sndBuff, mBuffer + mMark, sndBuffLen);
  98. mMark += sndBuffLen;
  99. if (mLim < mMark) mLim = mMark;
  100. } /* if */
  101. return sndBuffLen;
  102. } /* end Write */
  103. void CAsyncBuffer::ClearBuffer (void)
  104. { /* begin ClearBuffer */
  105. long *p = (long *) mBuffer;
  106. for (long i = (mLim / sizeof (*p)); i-- > 0; )
  107. p[i] = kBlankLong[mClearIndex];
  108. } /* end ClearBuffer */
  109. void CAsyncBuffer::DebugBuffer (void)
  110. { /* begin DebugBuffer */
  111. for (short b = 0; b < (sizeof (kBlankLong) / sizeof (kBlankLong[0])); b++) {
  112. long blank = 0;
  113. long *p = (long *) mBuffer;
  114. for (long i = 0; i < (mLim / sizeof (*p)); i++)
  115. if (kBlankLong[b] == p [i]) blank++;
  116. if (blank > 10) DebugStr ((mClearIndex == b) ? "pNew" : "pStale");
  117. } /* for */
  118. } /* end DebugBuffer */