Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
18 #include "T_ActiveCallbackIO.h"
23 _LIT(KLogErrorFileNotFound, "File '%S' Not Found. Error %d");
24 _LIT(KLogErrorFileNotOpened, "File '%S' Not Opened. Error %d");
25 _LIT(KLogErrorFormatError, "Format Error");
28 CT_ActiveCallbackIO* CT_ActiveCallbackIO::NewL(CDataWrapperBase& aCallback, TInt aPriority)
30 CT_ActiveCallbackIO* self=new(ELeave) CT_ActiveCallbackIO(aCallback, aPriority);
31 CleanupStack::PushL(self);
37 CT_ActiveCallbackIO::~CT_ActiveCallbackIO()
43 CT_ActiveCallbackIO::CT_ActiveCallbackIO(CDataWrapperBase& aCallback, TInt aPriority)
44 : CActiveCallbackBase(aCallback, aPriority)
50 TInt CT_ActiveCallbackIO::BufferLength()
52 return iBuffer->Length();
55 const TDesC8& CT_ActiveCallbackIO::Buffer()
60 void CT_ActiveCallbackIO::PrepareFromStringL(TInt aRepeat, const TDesC& aString)
65 TInt bufferLength=aString.Length()*aRepeat;
66 iBuffer=HBufC8::NewL(bufferLength);
67 iBuffer->Des().Copy(aString);
68 ConvertAndRepeatBuffer(aRepeat);
71 void CT_ActiveCallbackIO::PrepareFromFileL(TInt aRepeat, const TDesC& aFilename)
76 TFindFile findFile(iDataWrapperBase.FileServer());
77 TInt err=findFile.FindByDir(aFilename, KStrNull);
80 iDataWrapperBase.ERR_PRINTF3(KLogErrorFileNotFound, &aFilename, err);
81 iDataWrapperBase.SetBlockResult(EFail);
85 const TDesC& fileName=findFile.File();
87 err=file.Open(iDataWrapperBase.FileServer(), fileName, EFileRead|EFileShareAny);
90 iDataWrapperBase.ERR_PRINTF3(KLogErrorFileNotOpened, &aFilename, err);
91 iDataWrapperBase.SetBlockResult(EFail);
95 CleanupClosePushL(file);
96 iDataWrapperBase.INFO_PRINTF1(_L("File Opened."));
100 User::LeaveIfError(file.Size(bufferLength));
101 bufferLength*=aRepeat;
102 iDataWrapperBase.INFO_PRINTF2(_L("File Size=%d."), bufferLength);
105 iBuffer=HBufC8::NewL(bufferLength);
106 iDataWrapperBase.INFO_PRINTF1(_L("Buffer created."));
108 TPtr8 fileData = iBuffer->Des();
109 User::LeaveIfError(file.Read(fileData));
110 CleanupStack::PopAndDestroy(&file);
112 ConvertAndRepeatBuffer(aRepeat);
117 void CT_ActiveCallbackIO::ConvertAndRepeatBuffer(TInt aRepeat)
119 ConvertEscapeChars(iBuffer->Des());
121 TPtr8 ptr=iBuffer->Des();
123 for ( TInt index=1; index<aRepeat; ++index )
125 iBuffer->Des().Append(ptr);
129 void CT_ActiveCallbackIO::ConvertEscapeChars(TPtr8 aBuffer)
132 TInt length=aBuffer.Length();
134 TBool escapeFound=EFalse;
136 for ( TInt index=0; index<length; ++index )
138 TChar nextChar=aBuffer[index];
145 // Check that we have a further 2 characters
146 if ( (index+2)<length )
150 TLex8 lex(aBuffer.Mid(index,2));
151 ret = lex.Val(charCode ,EHex);
152 aBuffer[position++]=TChar(charCode);
154 nextChar = aBuffer[index];
166 aBuffer[position++]='\n';
171 // \t found horizontal tab
173 aBuffer[position++]='\t';
178 // \v found vertical tab
180 aBuffer[position++]='\v';
185 // \b found backspace
187 aBuffer[position++]='\b';
192 // \r found carriage return
194 aBuffer[position++]='\r';
199 // \f found form feed
201 aBuffer[position++]='\f';
206 // \a found audible alert (bell)
208 aBuffer[position++]='\a';
213 aBuffer[position++]=nextChar;
220 if ( aBuffer[index]=='\\' )
226 aBuffer[position++]=aBuffer[index];
233 iDataWrapperBase.ERR_PRINTF1(KLogErrorFormatError);
234 iDataWrapperBase.SetBlockResult(EFail);
237 aBuffer.SetLength(position);