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