|
1 /* |
|
2 * Copyright (c) 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: CProgressNotifier is used to notify about |
|
15 * the current state of the request |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "ProgressNotifier.h" |
|
21 #include "ProgressNotifyHandler.h" |
|
22 |
|
23 |
|
24 // ================= MEMBER FUNCTIONS ========================================= |
|
25 |
|
26 // ---------------------------------------------------------------------------- |
|
27 // CProgressNotifier::NewL(...) |
|
28 // Two-phase constructor |
|
29 // ---------------------------------------------------------------------------- |
|
30 // |
|
31 CProgressNotifier* CProgressNotifier::NewL(RConnection& aConnection, |
|
32 MProgressNotifyHandler& aHandler) |
|
33 { |
|
34 CProgressNotifier* self = CProgressNotifier::NewLC(aConnection, aHandler); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CProgressNotifier::NewLC(...) |
|
41 // Two-phase constructor |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CProgressNotifier* CProgressNotifier::NewLC(RConnection& aConnection, |
|
45 MProgressNotifyHandler& aHandler) |
|
46 { |
|
47 CProgressNotifier* self = new (ELeave) CProgressNotifier(aConnection, aHandler); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // CProgressNotifier::CProgressNotifier(...) |
|
55 // First-phase constructor |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 CProgressNotifier::CProgressNotifier(RConnection& aConnection, |
|
59 MProgressNotifyHandler& aHandler) |
|
60 : CActive(EPriorityStandard), |
|
61 iConnection(aConnection), |
|
62 iHandler(aHandler) |
|
63 { |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CProgressNotifier::~CProgressNotifier() |
|
68 // Destructor |
|
69 // ---------------------------------------------------------------------------- |
|
70 // |
|
71 CProgressNotifier::~CProgressNotifier() |
|
72 { |
|
73 Cancel(); |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CProgressNotifier::ConstructL() |
|
78 // Second-phase constructor |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 void CProgressNotifier::ConstructL() |
|
82 { |
|
83 CActiveScheduler::Add(this); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------- |
|
87 // Start waiting for the progress notifications. |
|
88 // --------------------------------------------------------- |
|
89 void CProgressNotifier::StartNotify() |
|
90 { |
|
91 ASSERT(!IsActive()); |
|
92 iConnection.ProgressNotification(iProgressBuf, iStatus); |
|
93 SetActive(); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------- |
|
97 // CProgressNotifier::RunL() |
|
98 // Called when request has completed. |
|
99 // --------------------------------------------------------- |
|
100 // |
|
101 void CProgressNotifier::RunL() |
|
102 { |
|
103 // Active object request complete handler. |
|
104 if(iStatus == KErrNone) |
|
105 { |
|
106 NotifyL(); |
|
107 } |
|
108 else |
|
109 { |
|
110 iHandler.ProgressNotifyError(iStatus.Int()); |
|
111 } |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------- |
|
115 // CProgressNotifier::DoCancel() |
|
116 // Cancel ongoing requests. |
|
117 // --------------------------------------------------------- |
|
118 // |
|
119 void CProgressNotifier::DoCancel() |
|
120 { |
|
121 iConnection.CancelProgressNotification(); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // CProgressNotifier::Notify() |
|
126 // Get the current stage and issue a new request, unless |
|
127 // the interface has gone down. Inform the progress |
|
128 // notification handler about a new notification. |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 void CProgressNotifier::NotifyL() |
|
132 { |
|
133 // Store the values into temporary variables, otherwise we might send incorrect |
|
134 // values to iHandler, because iProgressBuf might get immediately overwritten |
|
135 // if progress notifications are already available. |
|
136 // |
|
137 // Note! This object is also sometimes deleted in iHandler.ProgressNotifyReceived |
|
138 // call (not nice, but no other workaround possible), so order of following calls |
|
139 // is crucial. |
|
140 |
|
141 TInt stage = iProgressBuf().iStage; |
|
142 TInt error = iProgressBuf().iError; |
|
143 |
|
144 // Issue new notification |
|
145 iConnection.ProgressNotification(iProgressBuf, iStatus); |
|
146 SetActive(); |
|
147 |
|
148 // Inform handler about notification |
|
149 iHandler.ProgressNotifyReceivedL(stage, error); |
|
150 } |
|
151 |
|
152 |