|
1 /* |
|
2 * Copyright (c) 2007-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 the License "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: This Class is observer for the mgservice class (core class) |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <liwcommon.h> |
|
19 #include <mclfitemlistmodel.h> |
|
20 |
|
21 #include "mgserviceobserver.h" |
|
22 #include "mgitemslist.h" |
|
23 #include "mginterface.h" |
|
24 #include "serviceerrno.h" |
|
25 //using namespace LIW; |
|
26 //Output Keys/arguments |
|
27 _LIT8(KResponse,"ReturnValue"); |
|
28 _LIT8(KErrorCode,"ErrorCode"); |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CMgServiceObserver::NewL |
|
32 // Returns the instance of CMgServiceObserver. |
|
33 // ----------------------------------------------------------------------------- |
|
34 CMgServiceObserver* CMgServiceObserver::NewL() |
|
35 { |
|
36 |
|
37 CMgServiceObserver* self = new ( ELeave )CMgServiceObserver(); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 |
|
43 } |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CMgServiceObserver::MgNotify |
|
51 // Called by CMgService class when asynch operation complete |
|
52 // ----------------------------------------------------------------------------- |
|
53 void CMgServiceObserver :: MgNotifyL( TUint aTransactionID, |
|
54 MCLFItemListModel* aListModel, |
|
55 TMgOperationEvent& aOperationEvent, |
|
56 const TInt& aError ) |
|
57 |
|
58 |
|
59 { |
|
60 iOutput->Reset(); |
|
61 //const CLiwGenericParamList& temp1 = *iOutput; |
|
62 //const CLiwGenericParamList* temp2 = &temp1; |
|
63 //delete temp2; |
|
64 |
|
65 if ( EMgModelCancel == aOperationEvent ) |
|
66 { |
|
67 if( iCallBack ) |
|
68 |
|
69 { |
|
70 iOutput->AppendL( TLiwGenericParam ( KErrorCode,TLiwVariant( (TInt32)SErrNone ) ) ); |
|
71 TRAP_IGNORE(iCallBack->HandleNotifyL ( aTransactionID, KLiwEventCanceled, *iOutput,*iInput )); |
|
72 //self destruction should be done here in future |
|
73 // instead of below four lines |
|
74 iCallBack = NULL ; |
|
75 //iOutput= NULL; |
|
76 iInput = NULL; |
|
77 iCmdId= EMgBlankCmdId; |
|
78 |
|
79 } |
|
80 |
|
81 } |
|
82 |
|
83 // Fill the Error code inside Generic Param List |
|
84 TInt sapiErr = SErrNone; |
|
85 if (aError) |
|
86 { |
|
87 sapiErr = CMgInterface::SapiError( aError ); |
|
88 } |
|
89 |
|
90 iOutput->AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)sapiErr))); |
|
91 // if not error create the iterator class and put it into output list |
|
92 if( ( EMgRefreshComplete == aOperationEvent )&& ( KErrNone == aError ) ) |
|
93 { |
|
94 // Fill the Iterator in Generic Paaram List |
|
95 TLiwVariant response; |
|
96 |
|
97 // Iterator will accept the cmd Id and iListmodel and |
|
98 // it will become the owner of iListModel,Ownership of |
|
99 // Iterator is transfered to consumer |
|
100 |
|
101 CMgItemsList *iterator = CMgItemsList::NewL( aListModel, iCmdId ); |
|
102 CleanupStack::PushL( iterator ); |
|
103 response.Set( iterator ); |
|
104 iOutput->AppendL( TLiwGenericParam ( KResponse, response ) ); |
|
105 CleanupStack::Pop( iterator ); |
|
106 iterator->DecRef(); |
|
107 } |
|
108 else |
|
109 { |
|
110 delete aListModel; |
|
111 aListModel = NULL; |
|
112 } |
|
113 |
|
114 if( NULL != iCallBack ) |
|
115 { |
|
116 // call callback of consumer |
|
117 if( KErrNone == aError ) |
|
118 { |
|
119 TRAP_IGNORE( |
|
120 iCallBack->HandleNotifyL |
|
121 ( aTransactionID, KLiwEventCompleted, *iOutput,*iInput )); |
|
122 |
|
123 } |
|
124 else |
|
125 { |
|
126 iCallBack->HandleNotifyL ( aTransactionID, KLiwEventError, *iOutput,*iInput ); |
|
127 } |
|
128 |
|
129 } |
|
130 |
|
131 iCmdId = EMgBlankCmdId; |
|
132 iCallBack = NULL; |
|
133 iInput=NULL; |
|
134 |
|
135 } |
|
136 |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CMgServiceObserver::SetMemberVar |
|
140 // set the member varibale for the current request. |
|
141 // ----------------------------------------------------------------------------- |
|
142 void CMgServiceObserver::SetMemberVar(const TMgCmdId& aCmdId, |
|
143 const CLiwGenericParamList* aInput, |
|
144 MLiwNotifyCallback* aCallBack) |
|
145 { |
|
146 |
|
147 iCmdId= EMgBlankCmdId; |
|
148 |
|
149 iCallBack = aCallBack; |
|
150 iInput = aInput; |
|
151 iCmdId = aCmdId; |
|
152 |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CMgServiceObserver::Cancel |
|
157 // Cancel the pending asynchronous request |
|
158 // ----------------------------------------------------------------------------- |
|
159 void CMgServiceObserver::CancelL() |
|
160 { |
|
161 if( iCallBack ) |
|
162 { |
|
163 iCallBack->HandleNotifyL ( 0, |
|
164 KLiwEventCanceled, |
|
165 *iOutput, |
|
166 *iInput ); |
|
167 |
|
168 iCallBack = NULL ; |
|
169 iOutput->Reset(); |
|
170 iInput = NULL; |
|
171 iCmdId= EMgBlankCmdId; |
|
172 } |
|
173 } |
|
174 |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CMgServiceObserver::CMgServiceObserver |
|
178 // constructor of class |
|
179 // ----------------------------------------------------------------------------- |
|
180 |
|
181 CMgServiceObserver::CMgServiceObserver() |
|
182 :iCallBack(NULL), |
|
183 iOutput(NULL), |
|
184 iInput(NULL), |
|
185 iCmdId(EMgBlankCmdId) |
|
186 { |
|
187 |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CMgServiceObserver::~CMgServiceObserver |
|
192 // Destructor |
|
193 // ----------------------------------------------------------------------------- |
|
194 |
|
195 CMgServiceObserver::~CMgServiceObserver() |
|
196 { |
|
197 //release output Parameter List |
|
198 if ( iOutput ) |
|
199 { |
|
200 iOutput->Reset(); |
|
201 delete iOutput; |
|
202 } |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CMgServiceObserver::ConstructL |
|
207 // Destructor |
|
208 // ----------------------------------------------------------------------------- |
|
209 |
|
210 void CMgServiceObserver::ConstructL() |
|
211 { |
|
212 iOutput = CLiwGenericParamList::NewL(); |
|
213 } |