|
1 /* |
|
2 * Copyright (c) 2010 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: Cps command buffer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System includes |
|
20 #include <liwservicehandler.h> |
|
21 #include <liwvariant.h> |
|
22 #include <liwgenericparam.h> |
|
23 |
|
24 // User includes |
|
25 #include "caicpscommandbuffer.h" |
|
26 #include "aicpsexecuteparam.h" |
|
27 #include <debug.h> |
|
28 |
|
29 // Constants |
|
30 _LIT8( KCPSConfigurationIf, "IContentPublishing" ); |
|
31 _LIT8( KCPS, "Service.ContentPublishing" ); |
|
32 _LIT8( KExecuteAction, "ExecuteAction" ); |
|
33 _LIT8( KExecuteMultipleActions, "ExecuteMultipleActions" ); |
|
34 _LIT8( KFilters, "filters" ); |
|
35 |
|
36 // ======== LOCAL FUNCTIONS ======== |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 // --------------------------------------------------------------------------- |
|
40 // CAiCpsCommandBuffer::CAiCpsCommandBuffer |
|
41 // |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CAiCpsCommandBuffer::CAiCpsCommandBuffer() |
|
45 { |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CAiCpsCommandBuffer::ConstructL |
|
50 // |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 void CAiCpsCommandBuffer::ConstructL() |
|
54 { |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CAiCpsCommandBuffer::NewL |
|
59 // |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CAiCpsCommandBuffer* CAiCpsCommandBuffer::NewL() |
|
63 { |
|
64 CAiCpsCommandBuffer* self = CAiCpsCommandBuffer::NewLC(); |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CAiCpsCommandBuffer::NewLC |
|
71 // |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CAiCpsCommandBuffer* CAiCpsCommandBuffer::NewLC() |
|
75 { |
|
76 CAiCpsCommandBuffer* self = new ( ELeave ) CAiCpsCommandBuffer; |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 return self; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CAiCpsCommandBuffer::~CAiCpsCommandBuffer |
|
84 // |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CAiCpsCommandBuffer::~CAiCpsCommandBuffer() |
|
88 { |
|
89 // Flush any pending commands |
|
90 Flush(); |
|
91 |
|
92 if ( iCpsInterface ) |
|
93 { |
|
94 // Close interface |
|
95 iCpsInterface->Close(); |
|
96 } |
|
97 |
|
98 TRAP_IGNORE( DetachL() ); |
|
99 |
|
100 delete iCpsService; |
|
101 delete iServiceHandler; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CAiCpsCommandBuffer::DetachL |
|
106 // |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CAiCpsCommandBuffer::DetachL() |
|
110 { |
|
111 if ( iServiceHandler && iCpsService ) |
|
112 { |
|
113 // Detach services from the handler |
|
114 RCriteriaArray list; |
|
115 CleanupClosePushL( list ); |
|
116 |
|
117 list.AppendL( iCpsService ); |
|
118 |
|
119 iServiceHandler->DetachL( list ); |
|
120 |
|
121 CleanupStack::PopAndDestroy( &list ); |
|
122 } |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CAiCpsCommandBuffer::GetCPSInterfaceL |
|
127 // |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CAiCpsCommandBuffer::GetCPSInterfaceL() |
|
131 { |
|
132 if ( iCpsInterface ) |
|
133 { |
|
134 return; |
|
135 } |
|
136 |
|
137 RCriteriaArray interestList; |
|
138 CleanupClosePushL( interestList ); |
|
139 |
|
140 CLiwServiceHandler* serviceHandler = CLiwServiceHandler::NewL(); |
|
141 CleanupStack::PushL( serviceHandler ); |
|
142 |
|
143 // Attach to CPS: |
|
144 CLiwCriteriaItem* cpsService = CLiwCriteriaItem::NewL( 1, KCPSConfigurationIf, KCPS ); |
|
145 CleanupStack::PushL( cpsService ); |
|
146 |
|
147 cpsService->SetServiceClass( TUid::Uid( KLiwClassBase ) ); |
|
148 |
|
149 interestList.AppendL( cpsService ); |
|
150 serviceHandler->AttachL( interestList ); |
|
151 |
|
152 CLiwGenericParamList& inParamList( serviceHandler->InParamListL() ); |
|
153 CLiwGenericParamList& outParamList( serviceHandler->OutParamListL() ); |
|
154 |
|
155 serviceHandler->ExecuteServiceCmdL( |
|
156 *cpsService, |
|
157 inParamList, |
|
158 outParamList ); |
|
159 |
|
160 TInt pos( 0 ); |
|
161 |
|
162 outParamList.FindFirst( pos, KCPSConfigurationIf ); |
|
163 |
|
164 if ( pos != KErrNotFound ) |
|
165 { |
|
166 iCpsInterface = (outParamList)[pos].Value().AsInterface(); |
|
167 inParamList.Reset(); |
|
168 outParamList.Reset(); |
|
169 } |
|
170 else |
|
171 { |
|
172 inParamList.Reset(); |
|
173 outParamList.Reset(); |
|
174 User::Leave( KErrNotFound ); |
|
175 } |
|
176 |
|
177 CleanupStack::Pop( cpsService ); |
|
178 iCpsService = cpsService; |
|
179 |
|
180 CleanupStack::Pop( serviceHandler ); |
|
181 iServiceHandler = serviceHandler; |
|
182 |
|
183 CleanupStack::PopAndDestroy( &interestList ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CAiCpsCommandBuffer::AddCommand |
|
188 // |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CAiCpsCommandBuffer::AddCommand( const TDesC& aPluginId, |
|
192 const TDesC& aType, CLiwDefaultMap* aFilter, |
|
193 const TDesC8& aAction ) |
|
194 { |
|
195 __PRINTS( "CAiCpsCommandBuffer::AddCommand, start" ); |
|
196 |
|
197 TRAP_IGNORE( DoAddCommandL( aPluginId, aType, aFilter, aAction ) ); |
|
198 |
|
199 __PRINTS( "CAiCpsCommandBuffer::AddCommand - done" ); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CAiCpsCommandBuffer::ServiceHandler |
|
204 // |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 CLiwServiceHandler* CAiCpsCommandBuffer::ServiceHandler() const |
|
208 { |
|
209 return iServiceHandler; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CAiCpsCommandBuffer::CpsInterface |
|
214 // |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 MLiwInterface* CAiCpsCommandBuffer::CpsInterface() const |
|
218 { |
|
219 return iCpsInterface; |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CAiCpsCommandBuffer::DoAddCommandL |
|
224 // |
|
225 // --------------------------------------------------------------------------- |
|
226 // |
|
227 void CAiCpsCommandBuffer::DoAddCommandL( const TDesC& aPluginId, |
|
228 const TDesC& aType, CLiwDefaultMap* aFilter, |
|
229 const TDesC8& aAction ) |
|
230 { |
|
231 TInt found( KErrNotFound ); |
|
232 |
|
233 for ( TInt i = 0; i < iPlugins.Count(); i++ ) |
|
234 { |
|
235 if ( aPluginId == iPlugins[i]->PluginId() ) |
|
236 { |
|
237 found = i; |
|
238 break; |
|
239 } |
|
240 } |
|
241 |
|
242 if ( found != KErrNotFound ) |
|
243 { |
|
244 iPlugins[found]->AddActionL( aAction ); |
|
245 } |
|
246 else |
|
247 { |
|
248 CAiCpsExecuteParam* param = CAiCpsExecuteParam::NewLC(); |
|
249 param->SetPluginIdL( aPluginId ); |
|
250 param->SetRegistryTypeL( aType ); |
|
251 param->SetFilterL( aFilter ); |
|
252 param->AddActionL( aAction ); |
|
253 iPlugins.AppendL( param ); |
|
254 CleanupStack::Pop( param ); |
|
255 } |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // CAiCpsCommandBuffer::Flush |
|
260 // |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void CAiCpsCommandBuffer::Flush() |
|
264 { |
|
265 __PRINTS( "CAiCpsCommandBuffer::Flush, start" ); |
|
266 |
|
267 if ( iPlugins.Count() > 0 ) |
|
268 { |
|
269 TRAP_IGNORE( DoFlushL() ); |
|
270 } |
|
271 |
|
272 __PRINTS( "CAiCpsCommandBuffer::Flush - done" ); |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // CAiCpsCommandBuffer::DoFlushL |
|
277 // |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void CAiCpsCommandBuffer::DoFlushL() |
|
281 { |
|
282 if ( !iCpsInterface ) |
|
283 { |
|
284 GetCPSInterfaceL(); |
|
285 } |
|
286 |
|
287 if ( iCpsInterface ) |
|
288 { |
|
289 __PRINTS( "CAiCpsCommandBuffer::DoFlush : Execute" ); |
|
290 |
|
291 TInt pluginCount( iPlugins.Count() ); |
|
292 |
|
293 CLiwDefaultList* pluginCmdList = CLiwDefaultList::NewLC(); |
|
294 |
|
295 for ( TInt i = 0; i < pluginCount; i++ ) |
|
296 { |
|
297 CLiwDefaultMap* inParamMap = iPlugins[i]->InParamMapLC(); |
|
298 pluginCmdList->AppendL( inParamMap ); |
|
299 CleanupStack::PopAndDestroy( inParamMap ); |
|
300 } |
|
301 |
|
302 CLiwGenericParamList* inParamList = CLiwGenericParamList::NewLC(); |
|
303 CLiwGenericParamList* outParamList = CLiwGenericParamList::NewLC(); |
|
304 |
|
305 TLiwGenericParam item( KFilters, TLiwVariant ( pluginCmdList ) ); |
|
306 inParamList->AppendL( item ); |
|
307 |
|
308 iCpsInterface->ExecuteCmdL( KExecuteMultipleActions, *inParamList, *outParamList); |
|
309 |
|
310 CleanupStack::PopAndDestroy( 3, pluginCmdList ); // outparamList, inParamList |
|
311 |
|
312 iPlugins.ResetAndDestroy(); |
|
313 } |
|
314 } |
|
315 |
|
316 // End of file |