|
1 /* |
|
2 * Copyright (c) 2007-2008 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwservicehandler.h> |
|
20 |
|
21 #include "hnqueryresultcollector.h" |
|
22 #include "hnmdquery.h" |
|
23 #include "hnmdqueries.h" |
|
24 #include "hnconvutils.h" |
|
25 #include "hnservicehandler.h" |
|
26 #include "hnmdservice.h" |
|
27 #include "hnmdservicecommand.h" |
|
28 |
|
29 using namespace LIW; |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CHnQueryResultCollector* CHnQueryResultCollector::NewL( |
|
36 const CHnMdQueries& aQueries , const CLiwGenericParamList& aParams ) |
|
37 { |
|
38 CHnQueryResultCollector* self = NewLC( aQueries , aParams ); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CHnQueryResultCollector* CHnQueryResultCollector::NewLC( |
|
47 const CHnMdQueries& aQueries , const CLiwGenericParamList& aParams ) |
|
48 { |
|
49 CHnQueryResultCollector* self = |
|
50 new ( ELeave ) CHnQueryResultCollector( aQueries , aParams ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CHnQueryResultCollector::CHnQueryResultCollector( |
|
60 const CHnMdQueries& aQueries , |
|
61 const CLiwGenericParamList& aParams) : CActive ( EPriorityStandard ), |
|
62 iQueries( aQueries ), |
|
63 iParams( aParams ) |
|
64 { |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CHnQueryResultCollector::~CHnQueryResultCollector() |
|
72 { |
|
73 Cancel(); |
|
74 delete iResults; |
|
75 delete iCurrentQueryResults; |
|
76 delete iSh; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CHnQueryResultCollector::ConstructL() |
|
84 { |
|
85 iResults = CLiwGenericParamList::NewL(); |
|
86 iCurrentQueryResults = CLiwGenericParamList::NewL(); |
|
87 CActiveScheduler::Add( this ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CHnQueryResultCollector::StartAsynchL( |
|
95 MHnQueryResultCollectorNotification* aNotification ) |
|
96 { |
|
97 __ASSERT_DEBUG( aNotification , User::Panic( KMatrixPanic , 0) ); |
|
98 iNotification = aNotification; |
|
99 ResetL(); |
|
100 if( iQueryIterator < iQueries.Count()) |
|
101 { |
|
102 ExecQueryAsynchL(); |
|
103 } |
|
104 else |
|
105 { |
|
106 iNotification->ResultsCollectedL( iResults ); |
|
107 } |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CHnQueryResultCollector::ResetL() |
|
115 { |
|
116 iQueryIterator = 0; |
|
117 iCurrentQueryResults->Reset(); |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CHnQueryResultCollector::DoCancel() |
|
125 { |
|
126 iCurrentQueryResults->Reset(); |
|
127 delete iSh; |
|
128 iSh = NULL; |
|
129 } |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 TBool CHnQueryResultCollector::NextQuery() |
|
135 { |
|
136 iQueryIterator++; |
|
137 return iQueryIterator < iQueries.Count(); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CHnQueryResultCollector::HandleQueryResultsL() |
|
145 { |
|
146 HBufC8* name8 = HnConvUtils::StrToStr8FastLC( |
|
147 iQueries.Query( iQueryIterator ).NameSpace() ); |
|
148 CLiwDefaultMap* map = CLiwDefaultMap::NewL(); |
|
149 map->PushL(); |
|
150 |
|
151 TLiwGenericParam param; |
|
152 param.PushL(); |
|
153 for (TInt i = 0; i < iCurrentQueryResults->Count(); i++) |
|
154 { |
|
155 iCurrentQueryResults->AtL(i, param); |
|
156 map->InsertL( param.Name(), param.Value() ); |
|
157 param.Reset(); |
|
158 } |
|
159 |
|
160 param.SetNameAndValueL( *name8, TLiwVariant( map) ); |
|
161 iResults->AppendL(param); |
|
162 |
|
163 CleanupStack::PopAndDestroy( ¶m); |
|
164 CleanupStack::PopAndDestroy( map); |
|
165 CleanupStack::PopAndDestroy(name8); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CHnQueryResultCollector::RunL() |
|
173 { |
|
174 if ( !iStatus.Int() ) |
|
175 { |
|
176 HandleQueryResultsL(); |
|
177 } |
|
178 |
|
179 if( NextQuery() ) |
|
180 { |
|
181 ExecQueryAsynchL(); |
|
182 } |
|
183 else |
|
184 { |
|
185 iNotification->ResultsCollectedL( iResults ); |
|
186 } |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 void CHnQueryResultCollector::ExecQueryAsynchL() |
|
194 { |
|
195 __ASSERT_DEBUG( iQueryIterator < iQueries.Count() , |
|
196 User::Panic( KMatrixPanic , 0) ); |
|
197 //cancel any running evaulations |
|
198 Cancel(); |
|
199 ExecQueryL( iQueries.Query( iQueryIterator ) ); |
|
200 SetActive(); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 void CHnQueryResultCollector::ExecQueryL( CHnMdQuery& aQuery ) |
|
208 { |
|
209 CLiwGenericParamList* constructor |
|
210 = aQuery.GetService().EvaluateConstructorL( iParams ); |
|
211 CleanupStack::PushL( constructor ); |
|
212 CLiwGenericParamList* command |
|
213 = aQuery.GetService().EvaluateCommandL( iParams ); |
|
214 CleanupStack::PushL( command ); |
|
215 |
|
216 delete iSh; |
|
217 iSh = NULL; |
|
218 iSh = CHnServiceHandler::NewL( |
|
219 aQuery.GetService().GetServiceName(), |
|
220 aQuery.GetService().GetInterfaceName(), |
|
221 aQuery.GetService().GetCommand().GetCommandName(), |
|
222 aQuery.GetService().GetCommand().GetCommandMode(), |
|
223 constructor, |
|
224 command ); |
|
225 |
|
226 CleanupStack::Pop( command ); |
|
227 CleanupStack::Pop( constructor ); |
|
228 |
|
229 iSh->ExecuteL( *iCurrentQueryResults, iStatus ); |
|
230 } |
|
231 |
|
232 |
|
233 |
|
234 // End of file |