|
1 /* |
|
2 * Copyright (c) 2004 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: NWSessionOperation base class. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngNWSessionOperation.h" |
|
20 #include "MPEngNWSessionOperationOwner.h" |
|
21 #include "CPEngTransactionStatus.h" |
|
22 #include "CPEngSessionSlotId.h" |
|
23 #include "CPEngNWSessionSlotID2Imp.h" |
|
24 #include "CPEngNWSessionProxy.h" |
|
25 |
|
26 |
|
27 #include <CPEngNWSessionSlot2.h> |
|
28 #include <CPEngNWSessionSlotID2.h> |
|
29 #include <MPEngNWSessionOperationObserver2.h> |
|
30 |
|
31 |
|
32 |
|
33 //LOCAL constants |
|
34 #ifdef _DEBUG |
|
35 namespace |
|
36 { |
|
37 //Panic |
|
38 _LIT( KPEngNWSessionOpPanic, "PEngNwSesOp" ); |
|
39 |
|
40 //Panic reasons |
|
41 enum TPEngNWSessionOpPanicReasons |
|
42 { |
|
43 EEngNWSesOpHasAlreadyOwner, |
|
44 }; |
|
45 |
|
46 void PEngNWSessionOpPanic( TPEngNWSessionOpPanicReasons aPanicReason ) |
|
47 { |
|
48 User::Panic( KPEngNWSessionOpPanic, aPanicReason ); |
|
49 } |
|
50 } |
|
51 #endif |
|
52 |
|
53 |
|
54 |
|
55 // ================= MEMBER FUNCTIONS ======================= |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CPEngNWSessionOperation::CPEngNWSessionOperation |
|
58 // ----------------------------------------------------------------------------- |
|
59 CPEngNWSessionOperation::CPEngNWSessionOperation( TInt aPriority, |
|
60 CPEngNWSessionProxy& aNWSessionProxy, |
|
61 CPEngNWSessionSlot2& aInterface, |
|
62 MPEngNWSessionOperationObserver2& aObserver ) |
|
63 : CActive( aPriority ), |
|
64 iNWSessionProxy( aNWSessionProxy ), |
|
65 iInterface( aInterface ), |
|
66 iObserver( aObserver ), |
|
67 iCancelling( EFalse ) |
|
68 { |
|
69 CActiveScheduler::Add( this ); |
|
70 } |
|
71 |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CPEngNWSessionOperation::~CPEngNWSessionOperation() |
|
75 // ----------------------------------------------------------------------------- |
|
76 CPEngNWSessionOperation::~CPEngNWSessionOperation() |
|
77 { |
|
78 if ( iOperationOwner ) |
|
79 { |
|
80 iOperationOwner->HandleNWSessionOperationDestruction( this ); |
|
81 } |
|
82 |
|
83 delete iTransactionStatus; |
|
84 } |
|
85 |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CPEngNWSessionOperation::BaseConstructL() |
|
89 // ----------------------------------------------------------------------------- |
|
90 void CPEngNWSessionOperation::BaseConstructL() |
|
91 { |
|
92 iTransactionStatus = CPEngTransactionStatus::NewL(); |
|
93 } |
|
94 |
|
95 |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CPEngNWSessionOperation::SetOwner() |
|
99 // ----------------------------------------------------------------------------- |
|
100 void CPEngNWSessionOperation::SetOwner( MPEngNWSessionOperationOwner& aOperationOwner ) |
|
101 { |
|
102 __ASSERT_DEBUG( !iOperationOwner, |
|
103 PEngNWSessionOpPanic( EEngNWSesOpHasAlreadyOwner ) ); |
|
104 |
|
105 iOperationOwner = &aOperationOwner; |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CPEngNWSessionOperation::CancelOpD() |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CPEngNWSessionOperation::CancelOpD() |
|
115 { |
|
116 if ( iCancelling ) |
|
117 { |
|
118 //Cancel already running... |
|
119 //==>This call is coming from observer callback which |
|
120 //was called from DoCancel(). Break the nesting here |
|
121 return; |
|
122 } |
|
123 |
|
124 iCancelling = ETrue; |
|
125 CActive::Cancel(); |
|
126 iCancelling = EFalse; |
|
127 |
|
128 delete this; |
|
129 } |
|
130 |
|
131 |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CPEngNWSessionOperation::HandleOperationIssued() |
|
135 // ----------------------------------------------------------------------------- |
|
136 void CPEngNWSessionOperation::HandleOperationIssued( TInt aError, |
|
137 TInt aNWSessionSlotOp ) |
|
138 { |
|
139 iNWSessionSlotOp = aNWSessionSlotOp; |
|
140 |
|
141 if ( aError == KErrNone ) |
|
142 { |
|
143 SetActive(); |
|
144 } |
|
145 |
|
146 else |
|
147 { |
|
148 //Complete with the error |
|
149 iStatus = KRequestPending; |
|
150 TRequestStatus *pS = &iStatus; |
|
151 User::RequestComplete( pS, aError ); |
|
152 SetActive(); |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CPEngNWSessionOperation::NotifyObserverFromCancel() |
|
160 // ----------------------------------------------------------------------------- |
|
161 void CPEngNWSessionOperation::NotifyObserverFromCancel() |
|
162 { |
|
163 iTransactionStatus->Reset(); |
|
164 iTransactionStatus->SetStatus( iStatus.Int() ); |
|
165 |
|
166 TRAPD( err, |
|
167 iObserver.HandleNWSessionOperationCompleteL( *iTransactionStatus, |
|
168 iInterface, |
|
169 iNWSessionSlotOp ); ); |
|
170 |
|
171 if ( err != KErrNone ) |
|
172 { |
|
173 iObserver.HandleNWSessionOperationNotifyError( err, |
|
174 iInterface, |
|
175 iNWSessionSlotOp ); |
|
176 } |
|
177 } |
|
178 |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CPEngNWSessionOperation::RunL() |
|
183 // ----------------------------------------------------------------------------- |
|
184 void CPEngNWSessionOperation::RunL() |
|
185 { |
|
186 |
|
187 iTransactionStatus->Reset(); |
|
188 iTransactionStatus->SetStatus( iStatus.Int() ); |
|
189 DoHandleOpCompleted( iStatus.Int() ); |
|
190 |
|
191 iObserver.HandleNWSessionOperationCompleteL( *iTransactionStatus, |
|
192 iInterface, |
|
193 iNWSessionSlotOp ); |
|
194 //All done, delete self |
|
195 delete this; |
|
196 } |
|
197 |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CPEngNWSessionOperation::RunError() |
|
201 // ----------------------------------------------------------------------------- |
|
202 TInt CPEngNWSessionOperation::RunError( TInt aError ) |
|
203 { |
|
204 //Leave from observer callback, see RunL() above |
|
205 iObserver.HandleNWSessionOperationNotifyError( aError, |
|
206 iInterface, |
|
207 iNWSessionSlotOp ); |
|
208 |
|
209 //All done, delete self |
|
210 delete this; |
|
211 return KErrNone; |
|
212 } |
|
213 |
|
214 |
|
215 // End of file |
|
216 |