cwritefile.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: cwritefile.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 "CWriteFile.h"
  50. #include "hxassert.h"
  51. CWriteFile::CWriteFile (void) 
  52. : mLow(NULL)
  53. , mBufSize(0)
  54. , mWrittenSize(0)
  55. , mCurPos(0)
  56. , fWriteLow (1)
  57. , ioPosOffset (0)
  58. { /* begin CWriteFile */
  59. } /* end CWriteFile */
  60. CWriteFile::~CWriteFile ()
  61. { /* begin ~CWriteFile */
  62. // wait for all writes to complete
  63. while(a_PB.ioResult > 1 || b_PB.ioResult > 1)
  64. {
  65. }
  66. // flush remaining data from buffer
  67. if(mWrittenSize > 0)
  68. {
  69. long count;
  70. ::SetFPos(a_PB.ioRefNum,fsFromStart,ioPosOffset);
  71. count = mWrittenSize;
  72. if(mWrittenSize >= mBufSize >> 1)
  73. {
  74. count -= (mBufSize >> 1);
  75. ::FSWrite(a_PB.ioRefNum,&count,mHigh);
  76. }
  77. else
  78. {
  79. ::FSWrite(a_PB.ioRefNum,&count,mLow);
  80. }
  81. //Update file position for fRefNum
  82. ::SetFPos(a_PB.ioRefNum,fsFromStart,ioPosOffset + count);
  83. }
  84. if(mLow) 
  85. delete [] mLow;
  86. mLow = NULL;
  87. } /* end ~CWriteFile */
  88. Boolean CWriteFile::Specify(short fRefNum, long offset,long bufSize)
  89. {
  90. Boolean OK = TRUE;
  91. if(mLow)
  92. {
  93. delete [] mLow;
  94. mLow = NULL;
  95. }
  96. mLow = new char[bufSize];
  97. OK = mLow != NULL;
  98. fWriteLow = TRUE;
  99. ioPosOffset = offset;
  100. if(OK)
  101. {
  102. mBufSize = bufSize;
  103. mWrittenSize = 0;
  104. mCurPos = 0;
  105. mHigh = mLow + (mBufSize >> 1);
  106. a_PB.ioCompletion = NULL;
  107. a_PB.ioVersNum = 0;
  108. a_PB.ioPermssn = fsWrPerm;
  109. a_PB.ioPosMode = fsFromStart;
  110. a_PB.ioMisc = 0;
  111. a_PB.ioRefNum = fRefNum;
  112. a_PB.ioResult = 0;
  113. b_PB = a_PB;
  114. }
  115. return(OK);
  116. }
  117. void CWriteFile::Seek(long pos)
  118. {
  119. HX_ASSERT( pos <= mWrittenSize );
  120. mCurPos = pos;
  121. }
  122. void CWriteFile::write_data(Ptr buf, long numBytes)
  123. {
  124. long count;
  125. if(mCurPos + numBytes < mBufSize)
  126. {
  127. count = numBytes;
  128. ::BlockMoveData(buf, &mLow[mCurPos], numBytes);
  129. mCurPos += numBytes;
  130. if(mCurPos > mBufSize >> 1 && fWriteLow)
  131. {
  132. Write(kWriteBufLow);
  133. fWriteLow = FALSE;
  134. }
  135. if(mCurPos > mWrittenSize )
  136. {
  137. mWrittenSize = mCurPos;
  138. }
  139. }
  140. else
  141. {
  142. count = mBufSize - mCurPos;
  143. ::BlockMoveData(buf,&mLow[mCurPos], count);
  144. ::BlockMoveData(&buf[count], mLow, numBytes - count);
  145. mCurPos = numBytes - count;
  146. if(mCurPos < mBufSize >> 1 && !fWriteLow)
  147. {
  148. Write(kWriteBufHigh);
  149. fWriteLow = TRUE;
  150. }
  151. }
  152. }
  153. void CWriteFile::Write(short writeFlag)
  154. {
  155. long count;
  156. Ptr   buf;
  157. IOParam *thePB;
  158. switch(writeFlag)
  159. {
  160. case kWriteBufLow:
  161. count = mBufSize >> 1;
  162. buf = mLow;
  163. thePB = &a_PB;
  164. break;
  165. case kWriteBufHigh:
  166. count = mBufSize >> 1;
  167. buf = mHigh;
  168. thePB = &b_PB;
  169. break;
  170. case kWriteBoth:
  171. count = mBufSize;
  172. buf = mLow;
  173. thePB = &a_PB;
  174. break;
  175. default:
  176. count = 0;
  177. break;
  178. }
  179. if(count > 0)
  180. {
  181. thePB->ioReqCount = count;
  182. thePB->ioPosOffset = ioPosOffset;
  183. thePB->ioBuffer = buf;
  184. thePB->ioVersNum = 0;
  185. thePB->ioMisc = 0;
  186. ::PBWriteAsync((ParmBlkPtr)thePB);
  187. ioPosOffset += count;
  188. }
  189. }