mmsengine/genutils/src/mmsattachmentwaiter.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005-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 *     Attachment Waiter for MMS Client MTM and UI.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <mmsvattachmentmanager.h>
       
    23 #include <msvstore.h>
       
    24 
       
    25 #include "mmsattachmentwaiter.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // 
       
    31 // ---------------------------------------------------------
       
    32 //
       
    33 EXPORT_C CMmsAttachmentWaiter* CMmsAttachmentWaiter::NewL()
       
    34     {
       
    35     CMmsAttachmentWaiter* self = new(ELeave) CMmsAttachmentWaiter();
       
    36     return self;
       
    37     }
       
    38     
       
    39 // ---------------------------------------------------------
       
    40 // 
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 CMmsAttachmentWaiter::CMmsAttachmentWaiter()
       
    44     : CActive(EPriorityStandard)
       
    45     {
       
    46     CActiveScheduler::Add(this);
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // 
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 CMmsAttachmentWaiter::~CMmsAttachmentWaiter()
       
    54     {
       
    55     Cancel();
       
    56     delete iStore;
       
    57     }    
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // 
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 EXPORT_C void CMmsAttachmentWaiter::StartWaitingL(
       
    64     TRequestStatus& aStatus, CMsvStore* aStore, MMsvAttachmentManager* aAttachmentManager)
       
    65     {
       
    66     if( IsActive() )
       
    67         User::Leave(KErrInUse);
       
    68     // We cannot set our own status to pending state because the component
       
    69     // we are giving our status to must do it
       
    70     // However, we must set our client's status to pending
       
    71     aStatus = KRequestPending;
       
    72     iReportStatus = &aStatus;
       
    73     iStore = aStore;
       
    74     iAttachmentManager = aAttachmentManager;
       
    75     SetActive();
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // 
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 void CMmsAttachmentWaiter::Reset()
       
    83     {
       
    84     iReportStatus = NULL;
       
    85     iAttachmentManager = NULL;
       
    86     delete iStore;
       
    87     iStore = NULL;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // 
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 void CMmsAttachmentWaiter::RunL()
       
    95     {
       
    96     User::LeaveIfError(iStatus.Int());
       
    97     iStore->CommitL();
       
    98     User::RequestComplete(iReportStatus, KErrNone);
       
    99     Reset();
       
   100     }
       
   101     
       
   102 // ---------------------------------------------------------
       
   103 // 
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 void CMmsAttachmentWaiter::DoCancel()
       
   107     {
       
   108     iAttachmentManager->CancelRequest();
       
   109     User::RequestComplete(iReportStatus, KErrCancel);
       
   110     Reset();
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------
       
   114 // 
       
   115 // ---------------------------------------------------------
       
   116 //
       
   117 TInt CMmsAttachmentWaiter::RunError(TInt aError)
       
   118     {
       
   119     User::RequestComplete(iReportStatus, aError);
       
   120     Reset();
       
   121     return KErrNone;
       
   122     }