mmsengine/mmsserver/src/mmsreadreport.cpp
changeset 31 ebfee66fde93
child 47 5b14749788d7
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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:   operation for sending a read report
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <msvstd.h>
       
    21 #include <msventry.h>
       
    22 
       
    23 #include "mmsreadreport.h"
       
    24 #include "mmsheaders.h"
       
    25 #include "mmsservercommon.h"
       
    26 #include "mmsserverentry.h"
       
    27 #include "mmsencode.h"
       
    28 #include "mmserrors.h"
       
    29 #include "mmssettings.h"
       
    30 
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 // ---------------------------------------------------------
       
    35 //
       
    36 // ---------------------------------------------------------
       
    37 //
       
    38 CMmsReadReport::CMmsReadReport( RFs& aFs ):
       
    39     CMmsBaseOperation( aFs )
       
    40     {
       
    41     //
       
    42     // members that get initial value 0, need not be initialized here
       
    43     //
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CMmsReadReport::ConstructL( CMmsSettings* aMmsSettings )
       
    52     {
       
    53     CMmsBaseOperation::ConstructL( aMmsSettings );
       
    54     iMmsHeaders = CMmsHeaders::NewL( iMmsSettings->MmsVersion()  );
       
    55     CActiveScheduler::Add( this );
       
    56     }
       
    57     
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // 
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CMmsReadReport* CMmsReadReport::NewL( RFs& aFs,  CMmsSettings* aMmsSettings  )
       
    64     {
       
    65     CMmsReadReport* self = new( ELeave ) CMmsReadReport( aFs );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL( aMmsSettings );
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // 
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CMmsReadReport::~CMmsReadReport()
       
    78     {
       
    79     Cancel(); // has to be called first
       
    80     delete iMmsHeaders;
       
    81     }
       
    82     
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 CMsvEntrySelection& CMmsReadReport::Failed() const
       
    88     {
       
    89     return *iFailed;
       
    90     }
       
    91     
       
    92 // ---------------------------------------------------------------------------
       
    93 // From class CMmsBaseOperation
       
    94 //
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CMmsReadReport::StartL(
       
    98             CMsvEntrySelection& aSelection,
       
    99             CMsvServerEntry& aServerEntry,
       
   100             TMsvId aService,
       
   101             TRequestStatus& aStatus )
       
   102     {
       
   103 #ifndef _NO_MMSS_LOGGING_
       
   104     TMmsLogger::Log( _L("CMmsReadReport::StartL") );
       
   105 #endif
       
   106     // initialize common variables
       
   107     CMmsBaseOperation::InitializeL( aSelection, aServerEntry, aService );
       
   108     iMmsHeaders->Reset();
       
   109     
       
   110     if ( iCurrentMessageNo < 1 )
       
   111         {
       
   112         // nothing to send. Give up immediately
       
   113         aStatus = KRequestPending;
       
   114         TRequestStatus* status = &aStatus;
       
   115         User::RequestComplete( status, KErrNotFound );
       
   116         return;
       
   117         }
       
   118     
       
   119     Queue( aStatus );
       
   120     FallThrough();   
       
   121     }
       
   122     
       
   123 // ---------------------------------------------------------------------------
       
   124 // From class CActive
       
   125 //
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void CMmsReadReport::DoCancel()
       
   129     {
       
   130     #ifndef _NO_MMSS_LOGGING_
       
   131     TMmsLogger::Log( _L("CMmsReadReport::DoCancel") );
       
   132     #endif
       
   133     CMmsBaseOperation::DoCancel();
       
   134     
       
   135     // Unhandled entries are deleted in CMmsServerMtm::UpdateEntriesL()
       
   136     }
       
   137     
       
   138     
       
   139 // ---------------------------------------------------------
       
   140 // From class CMsgActive
       
   141 //
       
   142 // ---------------------------------------------------------
       
   143 //
       
   144 void CMmsReadReport::DoComplete( TInt& aError )
       
   145     {
       
   146 
       
   147 #ifndef _NO_MMSS_LOGGING_
       
   148     TMmsLogger::Log( _L("CMmsReadReport DoComplete"));
       
   149 #endif
       
   150     // We should get here if we are cancelled, or if
       
   151     // the cycle has completed (with or without error)
       
   152 
       
   153     // Only final cleanup can be done here, nothing asychronous is allowed
       
   154     
       
   155     if ( aError == KMmsErrorOfflineMode )
       
   156         {
       
   157         // if we cannot connect, read report is not sent
       
   158         // It will not be retried.
       
   159         aError = KErrNone;
       
   160         }
       
   161     
       
   162     // Normally we are not supposed to have anything in the failed list
       
   163     // Even if read report sending fails, entries are deleted.
       
   164     // Read report sending is "best effort" only, no retries.
       
   165     UnSetSendMask( *iFailed, aError );
       
   166 
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // From class CMmsBaseOperation
       
   171 //
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CMmsReadReport::EncodePDUL()
       
   175     {
       
   176     #ifndef _NO_MMSS_LOGGING_
       
   177     TMmsLogger::Log( _L("CMmsReadReport::EncodePDU") );
       
   178     #endif
       
   179     
       
   180     if( iError != KErrNone )
       
   181         {
       
   182         FallThrough();
       
   183         return;
       
   184         }
       
   185     // Encode the PDU to be sent to MMSC    
       
   186     //
       
   187     // Set entry's context to next message in the selection
       
   188     //
       
   189     iError = iServerEntry->SetEntry( iSelection->At( iCurrentMessageNo - 1 ) );
       
   190     if( iError != KErrNone )
       
   191         {
       
   192         FallThrough();
       
   193         return;
       
   194         }
       
   195 
       
   196     CMsvStore* store = NULL;
       
   197     TRAP( iError, store = iServerEntry->ReadStoreL(); )
       
   198     if ( iError != KErrNone )
       
   199         {
       
   200         FallThrough();
       
   201         return;
       
   202         }
       
   203     CleanupStack::PushL( store );
       
   204 
       
   205     //
       
   206     // Filling headers object from the data in the MessageStore
       
   207     //
       
   208     iMmsHeaders->RestoreL( *store );
       
   209     iMmsHeaders->SetMessageType( KMmsMessageTypeReadRecInd );
       
   210     CleanupStack::PopAndDestroy( store );
       
   211     store = NULL;
       
   212 
       
   213     iError = iEntryWrapper->SetCurrentEntry( iSelection->At( iCurrentMessageNo - 1 ) );
       
   214     if ( iError != KErrNone )
       
   215         {
       
   216         FallThrough();
       
   217         }
       
   218     else
       
   219         {
       
   220         iEncoder->EncodeHeadersL( *iMmsHeaders, *iEncodeBuffer );
       
   221         FallThrough();
       
   222         }
       
   223 
       
   224     }
       
   225     
       
   226     
       
   227 // ---------------------------------------------------------------------------
       
   228 // From class CMmsBaseOperation
       
   229 //
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 void CMmsReadReport::MoveEntryL()
       
   233     {
       
   234     #ifndef _NO_MMSS_LOGGING_
       
   235     TMmsLogger::Log( _L( "CMmsReadReport::MoveEntryL" ) );
       
   236     #endif
       
   237     
       
   238     // The entry will be just deleted - no need to report failure
       
   239     TInt error = KErrNone;
       
   240     error = iServerEntry->SetEntry( iSelection->At( iCurrentMessageNo - 1 ) );
       
   241     if ( error == KErrNone )
       
   242         {
       
   243         TMsvEntry entry = iServerEntry->Entry();
       
   244         error = iServerEntry->SetEntry( entry.Parent() );
       
   245         
       
   246         if ( error == KErrNone )
       
   247             {
       
   248             // Delete entry
       
   249             error = iServerEntry->DeleteEntry( entry.Id() );
       
   250             }
       
   251         if ( error == KErrNone )
       
   252             {
       
   253             // Everything has been originally appended to the failed list
       
   254             // If an entry was successfully deleted, it is removed from
       
   255             // the list. The rest will be deleted in MMS Server MTM -
       
   256             // or garbage collected later.
       
   257             iFailed->Delete( iCurrentMessageNo - 1 );
       
   258             }
       
   259         }
       
   260         
       
   261     iServerEntry->SetEntry( KMsvNullIndexEntryId );
       
   262     FallThrough();
       
   263 
       
   264     }
       
   265