internetradio2.0/irdataprovider/src/irhttppost.cpp
changeset 14 896e9dbc5f19
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:
       
    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 //----------------------------------------------------------------------------
       
    46 // CIRHttpPost::ConstructL()
       
    47 // 2nd phase constructor
       
    48 //----------------------------------------------------------------------------
       
    49 //
       
    50 void CIRHttpPost::ConstructL()
       
    51     {
       
    52     IRLOG_DEBUG( "CIRHttpPost::ConstructL - Entering" );
       
    53     iSettings = CIRSettings::OpenL();
       
    54     IRLOG_DEBUG( "CIRHttpPost::ConstructL - Exiting" );
       
    55     }
       
    56 
       
    57 //----------------------------------------------------------------------------
       
    58 // CIRHttpPost::GetDataPartFromFileL()
       
    59 // Read one data part from browse log file.
       
    60 //----------------------------------------------------------------------------
       
    61 //
       
    62 void CIRHttpPost::GetDataPartFromFileL( TDes8& aDataPart )
       
    63     {
       
    64     IRLOG_DEBUG( "CIRHttpPost::GetDataPartFromFileL - Entering" );
       
    65     
       
    66     // Count data size to be read
       
    67     TInt offset = KMaxSubmitSize;
       
    68     if ( iStartPos + offset > iTotalsize )
       
    69         {
       
    70         offset = iRemainingLength ;
       
    71         }
       
    72 
       
    73     // Read data part from file
       
    74     User::LeaveIfError( iLogFile.Read( iStartPos, aDataPart, offset ) );
       
    75     
       
    76     // Count remaining data size
       
    77     iStartPos += offset;
       
    78     iRemainingLength -= offset;
       
    79 
       
    80     IRLOG_DEBUG( "CIRHttpPost::GetDataPartFromFileL - Exiting" );
       
    81     }
       
    82 
       
    83 //----------------------------------------------------------------------------
       
    84 // CIRHttpPost::CIRHttpPost()
       
    85 // C++ constructor.
       
    86 //----------------------------------------------------------------------------
       
    87 //
       
    88 CIRHttpPost::CIRHttpPost( const RHTTPTransaction& aHttpTransaction )
       
    89     {
       
    90     IRLOG_DEBUG( "CIRHttpPost::CIRHttpPost - Entering" );
       
    91     iTransaction = aHttpTransaction;
       
    92     IRLOG_DEBUG( "CIRHttpPost::CIRHttpPost - Exiting" );
       
    93     }
       
    94 
       
    95 //----------------------------------------------------------------------------
       
    96 // CIRHttpPost::~CIRHttpPost()
       
    97 // Destructor.
       
    98 //----------------------------------------------------------------------------
       
    99 //
       
   100 CIRHttpPost::~CIRHttpPost()
       
   101     {
       
   102     IRLOG_DEBUG( "CIRHttpPost::~CIRHttpPost - Entering" );
       
   103     iPartPostBuffer.Close();
       
   104     iLogFile.Close();
       
   105     if ( iSettings )
       
   106         {
       
   107         iSettings->Close();
       
   108         }
       
   109     IRLOG_DEBUG( "CIRHttpPost::~CIRHttpPost - Exit" );
       
   110     }
       
   111 
       
   112 //----------------------------------------------------------------------------
       
   113 // CIRHttpPost::CloseLogFile ()
       
   114 // Used to Close the log file LogUsage.gz externally from other sources (bug-fixing)
       
   115 //----------------------------------------------------------------------------
       
   116 //
       
   117 void CIRHttpPost::CloseLogFile()
       
   118     {
       
   119     IRLOG_DEBUG( "CIRHttpPost::CloseLogFile - Entering" );
       
   120     iLogFile.Close();
       
   121     IRLOG_DEBUG( "CIRHttpPost::CloseLogFile - Exiting" );
       
   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     IRLOG_DEBUG( "CIRHttpPost::GetNextDataPart - Exiting" );
       
   157     return retVal;
       
   158     }
       
   159 
       
   160 //----------------------------------------------------------------------------
       
   161 // CIRHttpPost::ReleaseData()
       
   162 // Releases the current data part being held at the data supplier.
       
   163 //----------------------------------------------------------------------------
       
   164 //
       
   165 void CIRHttpPost::ReleaseData()
       
   166     {
       
   167     IRLOG_DEBUG( "CIRHttpPost::ReleaseData - Entering" );
       
   168     if ( iRemainingLength > 0 )
       
   169         {
       
   170         TRAP_IGNORE( iTransaction.NotifyNewRequestBodyPartL() )
       
   171         }
       
   172     IRLOG_DEBUG( "CIRHttpPost::ReleaseData - Exiting" );
       
   173     }
       
   174 
       
   175 //----------------------------------------------------------------------------
       
   176 // CIRHttpPost::OverallDataSize()
       
   177 // Obtains the overall size of the data being supplied.
       
   178 //----------------------------------------------------------------------------
       
   179 //
       
   180 TInt CIRHttpPost::OverallDataSize()
       
   181     {
       
   182     IRLOG_DEBUG( "CIRHttpPost::OverallDataSize - Entering" );
       
   183     TInt retVal( KErrNotFound );
       
   184     if ( iTotalsize > 0 )
       
   185         {
       
   186         retVal = iTotalsize;
       
   187         }
       
   188     IRLOG_DEBUG( "CIRHttpPost::OverallDataSize - Exiting" );
       
   189     return retVal;
       
   190     }
       
   191 
       
   192 //----------------------------------------------------------------------------
       
   193 // CIRHttpPost::Reset()
       
   194 // Resets the data supplier.
       
   195 //----------------------------------------------------------------------------
       
   196 //
       
   197 TInt CIRHttpPost::Reset()
       
   198     {
       
   199     IRLOG_DEBUG( "CIRHttpPost::Reset - Entering" );
       
   200     iStartPos = 0;
       
   201     iRemainingLength = iTotalsize;
       
   202     IRLOG_DEBUG( "CIRHttpPost::Reset - Exiting" );
       
   203     return KErrNone;
       
   204     }
       
   205 
       
   206 //----------------------------------------------------------------------------
       
   207 // CIRHttpPost::GetFileToPostL()
       
   208 // Gets browse log file size.
       
   209 //----------------------------------------------------------------------------
       
   210 //
       
   211 void CIRHttpPost::GetFileToPostL(TInt *aFileSize)
       
   212     {
       
   213     IRLOG_DEBUG( "CIRHttpPost::GetFileToPostL - Entering" );
       
   214 
       
   215     TFileName filePath = iSettings->PrivatePath();
       
   216     filePath.Append( KGZipLogFileName );
       
   217     
       
   218     iPartPostBuffer.Close();
       
   219     iPartPostBuffer.CreateL( KMaxSubmitSize );
       
   220 
       
   221     User::LeaveIfError(
       
   222     	iLogFile.Open( CCoeEnv::Static()->FsSession(), filePath, EFileRead ) );
       
   223     User::LeaveIfError( iLogFile.Size( iTotalsize ) );
       
   224     *aFileSize = iTotalsize;
       
   225     
       
   226     Reset();
       
   227 
       
   228     IRLOG_DEBUG( "CIRHttpPost::GetFileToPostL - Exiting." );
       
   229     }
       
   230     
       
   231 //----------------------------------------------------------------------------
       
   232 // CIRHttpPost::SetTransaction()
       
   233 // Set the transaction.
       
   234 //----------------------------------------------------------------------------
       
   235 //
       
   236 void CIRHttpPost::SetTransaction( const RHTTPTransaction& aHttpTransaction )
       
   237     {
       
   238     IRLOG_DEBUG( "CIRHttpPost::SetTransaction - Entering." );
       
   239     iTransaction = aHttpTransaction;
       
   240     IRLOG_DEBUG( "CIRHttpPost::SetTransaction - Exiting." );
       
   241     }
       
   242 
       
   243 // End of file