examples/ForumNokia/DescriptorExample/src/FileForwarder.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 #include <e32base.h>
00006 #include <e32cons.h>
00007 #include <e32std.h>
00008 #include <f32file.h>
00009 #include "DescriptorExamples.h"
00010 
00011 // -----------------------------------------------------------------------------
00012 // @see documentation from the header file "DescriptorExamples.h".
00013 // -----------------------------------------------------------------------------
00014 void CFileForwarder::ConstructL(const TDesC &logFileName)
00015     {
00016     iBuf = HBufC::NewL( 4096 );
00017 
00018     int pos = logFileName.LocateReverse( '\\' );
00019     TPtrC dirName = logFileName.Left( pos+1 );
00020 
00021     User::LeaveIfError(iFsSession.Connect()); // connect session
00022     iFsSession.MkDirAll(dirName);
00023 
00024     if( iFile.Open(iFsSession,logFileName,EFileWrite|EFileStreamText)
00025          == KErrNone )
00026         {
00027         // go to the end of the file
00028         TInt tmp = 0;
00029         iFile.Seek(ESeekEnd, tmp);
00030         } else
00031         {
00032         // file doesn't exist, create a new
00033         User::LeaveIfError(iFile.Replace(iFsSession,logFileName,
00034                                          EFileWrite|EFileStreamText));
00035         }
00036     }
00037 
00038 // -----------------------------------------------------------------------------
00039 // @see documentation from the header file "DescriptorExamples.h".
00040 // -----------------------------------------------------------------------------
00041 TPtr CFileForwarder::GetViewBuffer()
00042     {
00043     return iBuf->Des();
00044     }
00045 
00046 // -----------------------------------------------------------------------------
00047 // @see documentation from the header file "DescriptorExamples.h".
00048 // -----------------------------------------------------------------------------
00049 void CFileForwarder::UpdateView()
00050     {
00051     TPtrC8 representation((TUint8*)iBuf->Ptr(), iBuf->Size());
00052     iFile.Write(representation);
00053     iFile.Flush();
00054 
00055     iBuf->Des().SetLength( 0 );
00056     }
00057 
00058 // -----------------------------------------------------------------------------
00059 // @see documentation from the header file "DescriptorExamples.h".
00060 // -----------------------------------------------------------------------------
00061 CFileForwarder::~CFileForwarder()
00062     {
00063     iFile.Close();
00064     iFsSession.Close();
00065     delete iBuf;
00066     }

Generated by  doxygen 1.6.2