|
1 /* |
|
2 * Copyright (c) 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 "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: Implementation of CSAnimPluginCtrl class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom/ecom.h> |
|
20 |
|
21 #include "sanimpluginctrl.h" |
|
22 #include "sanimplugin.h" |
|
23 #include "assert.h" |
|
24 #include "trace.h" |
|
25 |
|
26 /** Maximum length for any file name extension (actually 4 should be enough). */ |
|
27 const TInt KMaxFileExtLength = 6; |
|
28 /** Buffer long enough to hold any file name extension. */ |
|
29 typedef TBuf<KMaxFileExtLength> TFileNameExtension; |
|
30 typedef TBuf8<KMaxFileExtLength> TFileNameExtension8; |
|
31 |
|
32 // ======== LOCAL FUNCTIONS ======== |
|
33 |
|
34 static void CleanupRImplInfoPtrArray( TAny* aPtr ) |
|
35 { |
|
36 static_cast<RImplInfoPtrArray*>( aPtr )->ResetAndDestroy(); |
|
37 } |
|
38 |
|
39 |
|
40 // ======== MEMBER FUNCTIONS ======== |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CSAnimPluginCtrl::NewL |
|
44 // |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CSAnimPluginCtrl* CSAnimPluginCtrl::NewL( |
|
48 const TDesC& aFileName, |
|
49 const TUint32 aIfUid, |
|
50 TAny* aConstructionParameters ) |
|
51 { |
|
52 FUNC_LOG; |
|
53 |
|
54 CSAnimPluginCtrl* self = new( ELeave ) CSAnimPluginCtrl; |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL( aFileName, aIfUid, aConstructionParameters ); |
|
57 CleanupStack::Pop( self ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CSAnimPluginCtrl::~CSAnimPluginCtrl |
|
64 // |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CSAnimPluginCtrl::~CSAnimPluginCtrl() |
|
68 { |
|
69 FUNC_LOG; |
|
70 |
|
71 Cancel(); |
|
72 |
|
73 delete iPlugin; |
|
74 REComSession::DestroyedImplementation( iDtorIDKey ); |
|
75 |
|
76 delete iFileName; |
|
77 } |
|
78 |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // CSAnimPluginCtrl::Load |
|
82 // |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void CSAnimPluginCtrl::Load( RFs& aFs, const TCallBack& aCallBack ) |
|
86 { |
|
87 FUNC_LOG; |
|
88 ASSERT_TRACE( !IsActive(), SAnimPanic::EInternalError ); |
|
89 |
|
90 iSuccessCode = KRequestPending; |
|
91 iCallBack = aCallBack; |
|
92 |
|
93 TIMESTAMP( "Load - start" ); |
|
94 |
|
95 iPlugin->Load( aFs, *iFileName, iStatus ); |
|
96 SetActive(); |
|
97 } |
|
98 |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CSAnimPluginCtrl::Start |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CSAnimPluginCtrl::Start( const TCallBack& aCallBack ) |
|
106 { |
|
107 FUNC_LOG; |
|
108 ASSERT_TRACE( !IsActive(), SAnimPanic::EInternalError ); |
|
109 |
|
110 |
|
111 if ( !iReadyToStart ) |
|
112 { |
|
113 iSuccessCode = KErrNotReady; |
|
114 aCallBack.CallBack(); |
|
115 } |
|
116 else |
|
117 { |
|
118 iSuccessCode = KRequestPending; |
|
119 iCallBack = aCallBack; |
|
120 |
|
121 iPlugin->Start( iStatus ); |
|
122 SetActive(); |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CSAnimPluginCtrl::SuccessCode |
|
129 // |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CSAnimPluginCtrl::SuccessCode() const |
|
133 { |
|
134 return iSuccessCode; |
|
135 } |
|
136 |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CSAnimPluginCtrl::Plugin |
|
140 // |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 CSAnimPlugin& CSAnimPluginCtrl::Plugin() |
|
144 { |
|
145 return *iPlugin; |
|
146 } |
|
147 |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CSAnimPluginCtrl::DoCancel |
|
151 // |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CSAnimPluginCtrl::DoCancel() |
|
155 { |
|
156 FUNC_LOG; |
|
157 |
|
158 iPlugin->Cancel(); |
|
159 iSuccessCode = KErrCancel; |
|
160 iCallBack.CallBack(); |
|
161 } |
|
162 |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CSAnimPluginCtrl::RunL |
|
166 // |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void CSAnimPluginCtrl::RunL() |
|
170 { |
|
171 FUNC_LOG; |
|
172 INFO_1( "Plug-in command completed with %d", iStatus.Int() ); |
|
173 |
|
174 if ( !iReadyToStart && iStatus.Int() == KErrNone ) |
|
175 { |
|
176 TIMESTAMP( "Load - end" ); |
|
177 |
|
178 iReadyToStart = ETrue; |
|
179 } |
|
180 |
|
181 iSuccessCode = iStatus.Int(); |
|
182 iCallBack.CallBack(); |
|
183 } |
|
184 |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CSAnimPluginCtrl::CSAnimPluginCtrl |
|
188 // |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 CSAnimPluginCtrl::CSAnimPluginCtrl() |
|
192 : CActive( EPriorityStandard ), |
|
193 iReadyToStart( EFalse ) |
|
194 { |
|
195 FUNC_LOG; |
|
196 |
|
197 CActiveScheduler::Add( this ); |
|
198 } |
|
199 |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CSAnimPluginCtrl::ConstructL |
|
203 // |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void CSAnimPluginCtrl::ConstructL( |
|
207 const TDesC& aFileName, |
|
208 const TUint32 aIfUid, |
|
209 TAny* aConstructionParameters ) |
|
210 { |
|
211 FUNC_LOG; |
|
212 |
|
213 iFileName = aFileName.AllocL(); |
|
214 |
|
215 TFileNameExtension ext; |
|
216 GetExtension( aFileName, ext ); |
|
217 if ( ext.Length() > 0 ) |
|
218 { |
|
219 FindPluginByExtensionL( ext, aIfUid, aConstructionParameters ); |
|
220 } |
|
221 else |
|
222 { |
|
223 User::Leave( KErrNotFound ); |
|
224 } |
|
225 } |
|
226 |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // CSAnimPluginCtrl::GetExtension |
|
230 // |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void CSAnimPluginCtrl::GetExtension( const TDesC& aFileName, TDes& aExtension ) |
|
234 { |
|
235 FUNC_LOG; |
|
236 |
|
237 aExtension = KNullDesC; |
|
238 |
|
239 TInt pos = aFileName.LocateReverse( '.' ); |
|
240 if ( pos >= 0 && aFileName.Length() - pos - 1 <= aExtension.MaxLength() ) |
|
241 { |
|
242 aExtension = aFileName.Right( aFileName.Length() - pos - 1 ); |
|
243 } |
|
244 |
|
245 aExtension.LowerCase(); |
|
246 |
|
247 INFO_1( "File extension: '%S'", &aExtension ); |
|
248 } |
|
249 |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CSAnimPluginCtrl::FindPluginByExtensionL |
|
253 // |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CSAnimPluginCtrl::FindPluginByExtensionL( |
|
257 const TDesC& aExtension, |
|
258 const TUint32 aIfUid, |
|
259 TAny* aConstructionParameters ) |
|
260 { |
|
261 FUNC_LOG; |
|
262 ASSERT_TRACE( aExtension.Length() > 0, SAnimPanic::EInternalError ); |
|
263 |
|
264 TEComResolverParams params; |
|
265 params.SetGenericMatch( ETrue ); |
|
266 TFileNameExtension8 ext; |
|
267 ext.Copy( aExtension ); |
|
268 params.SetDataType( ext ); |
|
269 |
|
270 RImplInfoPtrArray implInfoArray; |
|
271 CleanupStack::PushL( |
|
272 TCleanupItem( CleanupRImplInfoPtrArray, &implInfoArray ) ); |
|
273 REComSession::ListImplementationsL( |
|
274 TUid::Uid( aIfUid ), |
|
275 params, |
|
276 implInfoArray ); |
|
277 if ( implInfoArray.Count() > 0 ) |
|
278 { |
|
279 TUid implUid = implInfoArray[ 0 ]->ImplementationUid(); |
|
280 INFO_2( "%d plug-ins found, using 0x%08x", implInfoArray.Count(), implUid ); |
|
281 |
|
282 iPlugin = static_cast<CSAnimPlugin*>( |
|
283 REComSession::CreateImplementationL( |
|
284 implUid, iDtorIDKey, aConstructionParameters ) ); |
|
285 } |
|
286 |
|
287 CleanupStack::PopAndDestroy( &implInfoArray ); |
|
288 if ( !iPlugin ) |
|
289 { |
|
290 User::Leave( KErrNotFound ); |
|
291 } |
|
292 } |