ncdengine/provider/server/src/ncdreportomadownload.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:   CNcdReportOmaDownload implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdreportomadownload.h"
       
    20 #include "ncdreportmanager.h"
       
    21 #include "ncdpanics.h"
       
    22 #include "ncdnodeidentifier.h"
       
    23 #include "catalogsutils.h"
       
    24 #include "catalogsconstants.h"
       
    25 #include "ncdrequestinstallation.h"
       
    26 #include "ncdprotocol.h"
       
    27 #include "catalogshttpoperation.h"
       
    28 #include "catalogshttpconfig.h"
       
    29 #include "ncdrequestgenerator.h"
       
    30 #include "ncdproviderutils.h"
       
    31 
       
    32 #include "catalogsdebug.h"
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 // ---------------------------------------------------------------------------
       
    37 CNcdReportOmaDownload* CNcdReportOmaDownload::NewLC(
       
    38     CNcdReportManager& aReportManager,
       
    39     const TDesC& aUri,
       
    40     const CNcdNodeIdentifier& aMetadataId,    
       
    41     const TNcdReportStatusInfo& aStatus,     
       
    42     const TDesC& aReportUri )
       
    43     {
       
    44     CNcdReportOmaDownload* self = new( ELeave ) CNcdReportOmaDownload( 
       
    45         aStatus, aReportManager );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL( 
       
    48         aUri,
       
    49         aMetadataId,
       
    50         aReportUri );
       
    51     return self;
       
    52     }
       
    53         
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Create new CNcdReportOmaDownload from the given stream
       
    57 // ---------------------------------------------------------------------------
       
    58 CNcdReportOmaDownload* CNcdReportOmaDownload::NewLC( 
       
    59     CNcdReportManager& aReportManager,
       
    60     RReadStream& aStream )
       
    61     {
       
    62     TNcdReportStatusInfo tmpStatus;
       
    63     CNcdReportOmaDownload* self = new( ELeave ) CNcdReportOmaDownload( 
       
    64         tmpStatus, aReportManager );
       
    65     CleanupStack::PushL( self );
       
    66     self->InternalizeL( aStream );
       
    67     return self;    
       
    68     }
       
    69     
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 // ---------------------------------------------------------------------------
       
    75 CNcdReportOmaDownload::~CNcdReportOmaDownload()
       
    76     {
       
    77     DLTRACEIN((""));
       
    78     }
       
    79     
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 // ---------------------------------------------------------------------------
       
    84 TBool CNcdReportOmaDownload::IsSendable() const
       
    85     {
       
    86     DLTRACEIN((""));
       
    87     TInt value = ReportStatusToDownloadReportStatus( Status() );
       
    88     
       
    89     // Can send if status code is good and it's not being sent already
       
    90     return value != KNcdDownloadReportNotSupported && 
       
    91            !ReportTransaction() &&
       
    92            Attributes().AttributeInt32(
       
    93                 ENcdReportAttributeSendable );
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 // ---------------------------------------------------------------------------
       
   100 TBool CNcdReportOmaDownload::CanBeRemoved() const
       
   101     {
       
   102     DLTRACEIN((""));
       
   103     return Status().iStatus >= ENcdReportCancel && 
       
   104            Status().iStatus == Attributes().AttributeInt32( 
       
   105                 ENcdReportAttributeLatestSentReport );
       
   106     }
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 // ---------------------------------------------------------------------------
       
   112 HBufC8* CNcdReportOmaDownload::CreateReportL() const
       
   113     {
       
   114     DLTRACEIN((""));
       
   115     
       
   116     TInt value = ReportStatusToDownloadReportStatus( Status() );
       
   117     HBufC8* data = NULL;
       
   118     
       
   119     switch ( value )
       
   120         {
       
   121         case KNcdDownloadReportSuccess:
       
   122             {
       
   123             DLTRACE(("Success report"));
       
   124             data = KNcdReportOmaSuccess().AllocL();
       
   125             break;
       
   126             }
       
   127         
       
   128         case KNcdDownloadReportCancel:
       
   129             {
       
   130             DLTRACE(("Cancel report"));
       
   131             data = KNcdReportOmaCancel().AllocL();
       
   132             break;
       
   133             }
       
   134         
       
   135         default:
       
   136             {
       
   137             DLERROR(("Unsupported case"));
       
   138             User::Leave( KErrNotSupported );
       
   139             }
       
   140         }
       
   141     
       
   142     return data;
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 // ---------------------------------------------------------------------------
       
   149 void CNcdReportOmaDownload::UpdateTransactionConfigL( 
       
   150     MCatalogsHttpOperation& aTransaction )
       
   151     {
       
   152     DLTRACEIN((""));
       
   153     aTransaction.Config().SetConnectionMethod( ConnectionMethod() );
       
   154     aTransaction.Config().SetPriority( ECatalogsPriorityLow );
       
   155     aTransaction.SetContentTypeL( KMimeTypeMatchTxt );
       
   156     }
       
   157 
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // Returns ETrue if the status cannot change anymore
       
   161 // ---------------------------------------------------------------------------
       
   162 TBool CNcdReportOmaDownload::StatusIsFinal() const
       
   163     {
       
   164     DLTRACEIN((""));
       
   165     return IsOneOf( 
       
   166         Status().iStatus, 
       
   167         ENcdReportCancel, 
       
   168         ENcdReportSuccess );    
       
   169     }
       
   170 
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // PRIVATE METHODS
       
   174 // ---------------------------------------------------------------------------
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Constructor
       
   179 // ---------------------------------------------------------------------------
       
   180 CNcdReportOmaDownload::CNcdReportOmaDownload( 
       
   181     const TNcdReportStatusInfo& aStatus,
       
   182     CNcdReportManager& aReportManager )
       
   183     : CNcdReport( ENcdReportOmaDownload, aReportManager, aStatus )     
       
   184     {
       
   185     }
       
   186 
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // ConstructL
       
   190 // ---------------------------------------------------------------------------
       
   191 void CNcdReportOmaDownload::ConstructL( 
       
   192     const TDesC& aUri,
       
   193     const CNcdNodeIdentifier& aMetadataId,
       
   194     const TDesC& aReportUri )
       
   195     {
       
   196     DLTRACEIN((""));
       
   197     BaseConstructL( aMetadataId );
       
   198     
       
   199     if ( !aUri.Length() ||
       
   200          !aReportUri.Length() )
       
   201         {
       
   202         DLERROR(("Either URI or report URI is empty"));
       
   203         User::Leave( KErrArgument );
       
   204         }
       
   205     
       
   206     Attributes().SetAttributeL( 
       
   207         ENcdReportAttributeGenericId, 
       
   208         aUri );
       
   209         
       
   210     Attributes().SetAttributeL( 
       
   211         ENcdReportAttributeReportUri, 
       
   212         aReportUri );
       
   213 
       
   214     DLTRACEOUT((""));
       
   215     }
       
   216 
       
   217 
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // 
       
   221 // ---------------------------------------------------------------------------
       
   222 TInt CNcdReportOmaDownload::ReportStatusToDownloadReportStatus( 
       
   223     const TNcdReportStatusInfo& aStatus ) const    
       
   224     {
       
   225     DLTRACEIN(("aStatus: %d", aStatus.iStatus ));
       
   226 
       
   227     // Here we always return the general error information instead
       
   228     // of S60 specific information. If this needs to be changed, then
       
   229     // see CNcdReportInstall::ReportStatusToInstallReportStatus
       
   230     // and CNcdReportDownload::ReportStatusToDownloadReportStatus 
       
   231     // for an example implementation.
       
   232     
       
   233     TInt status = 0;
       
   234     switch ( aStatus.iStatus ) 
       
   235         {
       
   236         
       
   237         case ENcdReportCancel:
       
   238             {
       
   239             status = KNcdDownloadReportCancel;
       
   240             break;
       
   241             }
       
   242 
       
   243 
       
   244         case ENcdReportSuccess:
       
   245             {
       
   246             status = KNcdDownloadReportSuccess;
       
   247             break;
       
   248             }
       
   249 
       
   250         // Unsupported cases
       
   251         case ENcdReportNone:        
       
   252         case ENcdReportCreate:        
       
   253         case ENcdReportStart:
       
   254         case ENcdReportPause:
       
   255         case ENcdReportResume:
       
   256         case ENcdReportFail:        
       
   257             {
       
   258             DLTRACE(("Status not supported for download reporting"));
       
   259             status = KNcdDownloadReportNotSupported;
       
   260             break;
       
   261             }
       
   262                 
       
   263         default:            
       
   264             {            
       
   265             NCD_ASSERT_ALWAYS( 0, ENcdPanicIndexOutOfRange );
       
   266             }
       
   267         }
       
   268         
       
   269     DLTRACEOUT(("Download report status: %d", status));
       
   270     return status;
       
   271     }
       
   272 
       
   273