internetradio2.0/dataprovidersrc/irhttppost.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <coemain.h>
       
    20 
       
    21 #include "irdebug.h"
       
    22 #include "irhttppost.h"
       
    23 #include "irsettings.h"
       
    24 #include "irreportsettings.h"
       
    25 
       
    26 // Maximum data part size.
       
    27 const TInt KMaxSubmitSize = 1024;
       
    28 
       
    29 //----------------------------------------------------------------------------
       
    30 // CIRHttpPost::NewL()
       
    31 // First phase constructor
       
    32 //----------------------------------------------------------------------------
       
    33 //
       
    34 CIRHttpPost* CIRHttpPost::NewL( const RHTTPTransaction& aHttpTransaction )
       
    35 	{
       
    36 	IRLOG_DEBUG( "CIRHttpPost::NewL - Entering" );
       
    37 	CIRHttpPost* self = new( ELeave ) CIRHttpPost( aHttpTransaction );
       
    38 	CleanupStack::PushL( self );
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop( self );
       
    41 	IRLOG_DEBUG( "CIRHttpPost::NewL - Exiting" );
       
    42 	return self;
       
    43 	}
       
    44 //----------------------------------------------------------------------------
       
    45 // CIRHttpPost::ConstructL()
       
    46 // 2nd phase constructor
       
    47 //----------------------------------------------------------------------------
       
    48 //
       
    49 void CIRHttpPost::ConstructL()
       
    50 	{
       
    51 	IRLOG_DEBUG( "CIRHttpPost::ConstructL - Entering" );
       
    52 	iSettings = CIRSettings::OpenL();
       
    53 	IRLOG_DEBUG( "CIRHttpPost::ConstructL - Exiting" );
       
    54 	}
       
    55 
       
    56 //----------------------------------------------------------------------------
       
    57 // CIRHttpPost::GetDataPartFromFileL()
       
    58 // Read one data part from browse log file.
       
    59 //----------------------------------------------------------------------------
       
    60 //
       
    61 void CIRHttpPost::GetDataPartFromFileL( TDes8& aDataPart )
       
    62     {
       
    63     IRLOG_DEBUG( "CIRHttpPost::GetDataPartFromFileL - Entering" );
       
    64     
       
    65     // Count data size to be read
       
    66     TInt offset = KMaxSubmitSize;
       
    67     if ( iStartPos + offset > iTotalsize )
       
    68         {
       
    69         offset = iRemainingLength ;
       
    70         }
       
    71 
       
    72     // Read data part from file
       
    73     User::LeaveIfError( iLogFile.Read( iStartPos, aDataPart, offset ) );
       
    74     
       
    75     // Count remaining data size
       
    76     iStartPos += offset;
       
    77     iRemainingLength -= offset;
       
    78 
       
    79     IRLOG_DEBUG( "CIRHttpPost::GetDataPartFromFileL - Exiting" );
       
    80     }
       
    81 
       
    82 //----------------------------------------------------------------------------
       
    83 // CIRHttpPost::CIRHttpPost()
       
    84 // C++ constructor.
       
    85 //----------------------------------------------------------------------------
       
    86 //
       
    87 CIRHttpPost::CIRHttpPost( const RHTTPTransaction& aHttpTransaction )
       
    88     {
       
    89     IRLOG_DEBUG( "CIRHttpPost::CIRHttpPost - Entering" );
       
    90     iTransaction = aHttpTransaction;
       
    91     IRLOG_DEBUG( "CIRHttpPost::CIRHttpPost - Exiting" );
       
    92     }
       
    93 
       
    94 //----------------------------------------------------------------------------
       
    95 // CIRHttpPost::~CIRHttpPost()
       
    96 // Destructor.
       
    97 //----------------------------------------------------------------------------
       
    98 //
       
    99 CIRHttpPost::~CIRHttpPost()
       
   100     {
       
   101     IRLOG_DEBUG( "CIRHttpPost::~CIRHttpPost - Entering" );
       
   102     iPartPostBuffer.Close();
       
   103     iLogFile.Close();
       
   104     if ( iSettings )
       
   105         {
       
   106         iSettings->Close();
       
   107         }
       
   108     IRLOG_DEBUG( "CIRHttpPost::~CIRHttpPost - Exit" );
       
   109     }
       
   110 
       
   111 //----------------------------------------------------------------------------
       
   112 // CIRHttpPost::CloseLogFile ()
       
   113 // Used to Close the log file LogUsage.gz externally from other sources (bug-fixing)
       
   114 //----------------------------------------------------------------------------
       
   115 //
       
   116 void CIRHttpPost::CloseLogFile ()
       
   117     {
       
   118     IRLOG_DEBUG( "CIRHttpPost::CloseLogFile - Entering" );
       
   119 	iLogFile.Close ();
       
   120 	IRLOG_DEBUG( "CIRHttpPost::CloseLogFile - Exiting" );
       
   121     }
       
   122 
       
   123 
       
   124 //----------------------------------------------------------------------------
       
   125 // CIRHttpPost::GetNextDataPart()
       
   126 // Obtains a data part from the supplier.
       
   127 //----------------------------------------------------------------------------
       
   128 //        
       
   129 TBool CIRHttpPost::GetNextDataPart( TPtrC8& aDataPart )
       
   130     {
       
   131     IRLOG_DEBUG( "CIRHttpPost::GetNextDataPart - Entering" );
       
   132     TBool retVal( EFalse ); // Default: several data parts
       
   133 
       
   134     // Get data part from browse log file
       
   135     iPartPostBuffer.Delete( 0, iPartPostBuffer.Length() );
       
   136     TRAPD( err, GetDataPartFromFileL( iPartPostBuffer ) )
       
   137     if ( KErrNone == err )
       
   138         {
       
   139         // Set data part.
       
   140         aDataPart.Set( iPartPostBuffer );
       
   141         if ( iRemainingLength <= 0 )
       
   142             {
       
   143             // Last data part.
       
   144             retVal = ETrue;
       
   145             iLogFile.Close();
       
   146             }
       
   147         }
       
   148     else
       
   149         {
       
   150         // Last data part.
       
   151         iRemainingLength = 0;
       
   152         retVal = ETrue;
       
   153         iLogFile.Close();
       
   154         }
       
   155 
       
   156 
       
   157     IRLOG_DEBUG( "CIRHttpPost::GetNextDataPart - Exiting" );
       
   158     return retVal;
       
   159     }
       
   160 
       
   161 //----------------------------------------------------------------------------
       
   162 // CIRHttpPost::ReleaseData()
       
   163 // Releases the current data part being held at the data supplier.
       
   164 //----------------------------------------------------------------------------
       
   165 //
       
   166 void CIRHttpPost::ReleaseData()
       
   167     {
       
   168     IRLOG_DEBUG( "CIRHttpPost::ReleaseData - Entering" );
       
   169     if ( iRemainingLength > 0 )
       
   170         {
       
   171         TRAP_IGNORE( iTransaction.NotifyNewRequestBodyPartL() )
       
   172         }
       
   173     IRLOG_DEBUG( "CIRHttpPost::ReleaseData - Exiting" );
       
   174     }
       
   175 
       
   176 //----------------------------------------------------------------------------
       
   177 // CIRHttpPost::OverallDataSize()
       
   178 // Obtains the overall size of the data being supplied.
       
   179 //----------------------------------------------------------------------------
       
   180 //
       
   181 TInt CIRHttpPost::OverallDataSize()
       
   182     {
       
   183     IRLOG_DEBUG( "CIRHttpPost::OverallDataSize - Entering" );
       
   184     TInt retVal( KErrNotFound );
       
   185     if ( iTotalsize > 0 )
       
   186         {    
       
   187 		retVal = iTotalsize;
       
   188         }
       
   189     IRLOG_DEBUG( "CIRHttpPost::OverallDataSize - Exiting" );
       
   190     return retVal; 
       
   191     }
       
   192 
       
   193 //----------------------------------------------------------------------------
       
   194 // CIRHttpPost::Reset()
       
   195 // Resets the data supplier.
       
   196 //----------------------------------------------------------------------------
       
   197 //
       
   198 TInt CIRHttpPost::Reset()
       
   199     {
       
   200     IRLOG_DEBUG( "CIRHttpPost::Reset - Entering" );
       
   201     iStartPos = 0;
       
   202     iRemainingLength = iTotalsize;
       
   203     IRLOG_DEBUG( "CIRHttpPost::Reset - Exiting" );
       
   204     return KErrNone;
       
   205     }
       
   206 
       
   207 //----------------------------------------------------------------------------
       
   208 // CIRHttpPost::GetFileToPostL()
       
   209 // Gets browse log file size.
       
   210 //----------------------------------------------------------------------------
       
   211 //
       
   212 void CIRHttpPost::GetFileToPostL(TInt *aFileSize)
       
   213     {
       
   214     IRLOG_DEBUG( "CIRHttpPost::GetFileToPostL - Entering" );
       
   215 
       
   216     TFileName filePath = iSettings->PrivatePath();
       
   217     filePath.Append( KGZipLogFileName );
       
   218     
       
   219     iPartPostBuffer.Close();
       
   220     iPartPostBuffer.Create( KMaxSubmitSize );
       
   221 
       
   222     User::LeaveIfError(
       
   223     	iLogFile.Open( CCoeEnv::Static()->FsSession(), filePath, EFileRead ) );
       
   224     User::LeaveIfError( iLogFile.Size( iTotalsize ) );
       
   225     *aFileSize = iTotalsize;
       
   226     
       
   227     Reset();
       
   228 
       
   229     IRLOG_DEBUG( "CIRHttpPost::GetFileToPostL - Exiting." );
       
   230     }
       
   231     
       
   232 //----------------------------------------------------------------------------
       
   233 // CIRHttpPost::SetTransaction()
       
   234 // Set the transaction.
       
   235 //----------------------------------------------------------------------------
       
   236 //
       
   237 void CIRHttpPost::SetTransaction( const RHTTPTransaction& aHttpTransaction )
       
   238     {
       
   239     IRLOG_DEBUG( "CIRHttpPost::SetTransaction - Entering." );
       
   240     iTransaction = aHttpTransaction;
       
   241     IRLOG_DEBUG( "CIRHttpPost::SetTransaction - Exiting." );
       
   242     }
       
   243 
       
   244 // End of file