|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "CIRCancelObserver.h" |
|
17 |
|
18 /** |
|
19 Standard 2-phase constructor. |
|
20 @param aObserverRequestStatus Request status of the observer to be completed when the operation completes. |
|
21 @param aSession Handle to an opened session with the message server. |
|
22 @param aEntryId The entry id for the message for the IR operation. |
|
23 @return Pointer to the newly created object. |
|
24 */ |
|
25 CIRCancelObserver* CIRCancelObserver::NewL(TRequestStatus& aObserverRequestStatus, CMsvSession& aSession, TMsvId aEntryId) |
|
26 { |
|
27 CIRCancelObserver* me = new(ELeave) CIRCancelObserver(aObserverRequestStatus, aSession, aEntryId); |
|
28 return me; |
|
29 } |
|
30 |
|
31 CIRCancelObserver::CIRCancelObserver(TRequestStatus& aObserverRequestStatus, CMsvSession& aSession, TMsvId aEntryId) |
|
32 :CMsvOperation(aSession, EPriorityStandard, aObserverRequestStatus), iEntryId(aEntryId) |
|
33 { |
|
34 CActiveScheduler::Add(this); |
|
35 iObserverRequestStatus = KRequestPending; |
|
36 SetActive(); |
|
37 } |
|
38 |
|
39 /** |
|
40 Default destructor. |
|
41 */ |
|
42 CIRCancelObserver::~CIRCancelObserver() |
|
43 { |
|
44 Cancel(); |
|
45 delete iMsvOperation; |
|
46 } |
|
47 |
|
48 void CIRCancelObserver::RunL() |
|
49 { |
|
50 // The operation has completed, relay the status completion to the observer |
|
51 TRequestStatus* observerStatus = &iObserverRequestStatus; |
|
52 User::RequestComplete(observerStatus, iStatus.Int()); |
|
53 } |
|
54 |
|
55 TInt CIRCancelObserver::RunError(TInt /*aError*/) |
|
56 { |
|
57 // The RunL does not leave |
|
58 return KErrNone; |
|
59 } |
|
60 |
|
61 void CIRCancelObserver::DoCancel() |
|
62 { |
|
63 // This is an explicit cancel from the user, cancel the operation and complete the client |
|
64 if( iMsvOperation!=NULL ) |
|
65 iMsvOperation->Cancel(); |
|
66 TRequestStatus* st = &iObserverRequestStatus; |
|
67 User::RequestComplete(st, KErrCancel); |
|
68 |
|
69 // If the operation is queued, clean up the entries |
|
70 if(!iOperationStarted) |
|
71 CleanupEntry(); |
|
72 } |
|
73 |
|
74 void CIRCancelObserver::CleanupEntryL() const |
|
75 { |
|
76 // Delete the entry |
|
77 CMsvEntry* entry = iMsvSession.GetEntryL(iEntryId); |
|
78 CleanupStack::PushL(entry); |
|
79 entry->DeleteL(iEntryId); |
|
80 CleanupStack::PopAndDestroy(entry); |
|
81 } |
|
82 |
|
83 void CIRCancelObserver::CleanupEntry() const |
|
84 { |
|
85 // Call leaving version of CleanupEntry and ignore any errors |
|
86 TRAPD(err, CleanupEntryL()); |
|
87 } |
|
88 |
|
89 void CIRCancelObserver::SetOperation(CMsvOperation* aMsvOperation) |
|
90 { |
|
91 __ASSERT_DEBUG(iMsvOperation==NULL, User::Invariant()); |
|
92 |
|
93 // Initialise the members now that we have the operation |
|
94 iMsvOperation = aMsvOperation; |
|
95 iMtm = iMsvOperation->Mtm(); |
|
96 iService = iMsvOperation->Service(); |
|
97 } |
|
98 |
|
99 TRequestStatus& CIRCancelObserver::Status() |
|
100 { |
|
101 return iStatus; |
|
102 } |
|
103 |
|
104 const TDesC8& CIRCancelObserver::ProgressL() |
|
105 { |
|
106 __ASSERT_DEBUG(iMsvOperation!=NULL, User::Invariant()); |
|
107 |
|
108 // This call will leave if the operation is queued |
|
109 const TDesC8& progressDes = iMsvOperation->ProgressL(); |
|
110 |
|
111 // Will only get to here when the operation has started so updated the flag if not already done |
|
112 if(!iOperationStarted) |
|
113 iOperationStarted = ETrue; |
|
114 |
|
115 return progressDes; |
|
116 |
|
117 } |
|
118 |
|
119 const TDesC8& CIRCancelObserver::FinalProgress() |
|
120 { |
|
121 __ASSERT_DEBUG(iMsvOperation!=NULL, User::Invariant()); |
|
122 |
|
123 return iMsvOperation->FinalProgress(); |
|
124 } |
|
125 |