1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of the License "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 // |
7 // |
8 // Initial Contributors: |
8 // Initial Contributors: |
9 // Nokia Corporation - initial contribution. |
9 // Nokia Corporation - initial contribution. |
10 // |
10 // |
11 // Contributors: |
11 // Contributors: |
12 // |
12 // |
13 // Description: |
13 // Description: |
|
14 // apaflrec.cpp |
14 // |
15 // |
15 |
16 |
16 #include <f32file.h> |
17 #include <f32file.h> |
17 #include <apaflrec.h> |
18 #include <apaflrec.h> |
18 #include <apaid.h> |
19 #include <apaid.h> |
19 #include <apacmdln.h> |
20 #include <apacmdln.h> |
20 #include "APASTD.H" |
21 #include "APASTD.H" |
21 #include "APGCLI.H" |
22 #include "APGCLI.H" |
22 |
|
23 #ifdef USING_ECOM_RECOGS |
|
24 #include <ecom/ecom.h> |
23 #include <ecom/ecom.h> |
25 #endif |
|
26 |
|
27 // |
|
28 //CFileRecognizerExtension Class |
|
29 // |
|
30 //stores the destructor key to track the instance of ecom implementation class |
|
31 class CFileRecognizerExtension : public CBase |
|
32 { |
|
33 public: |
|
34 static CFileRecognizerExtension* NewL(TUid aDtorKey); |
|
35 ~CFileRecognizerExtension(); |
|
36 //returns the destructor key |
|
37 TUid DestructorUid()const; |
|
38 private: |
|
39 CFileRecognizerExtension(TUid aDtorKey); |
|
40 private: |
|
41 //destructor key to track the instance of ecom implementation class |
|
42 TUid iDtorKey; |
|
43 }; |
|
44 |
|
45 // |
|
46 // Class CApaFileRecognizer |
|
47 // |
|
48 |
|
49 EXPORT_C CApaFileRecognizer::CApaFileRecognizer(RFs& aFs) |
|
50 :iFs(aFs) |
|
51 {} |
|
52 |
|
53 |
|
54 EXPORT_C CApaFileRecognizer::~CApaFileRecognizer() |
|
55 { |
|
56 DestroyRecognizerList(); |
|
57 delete iAppLocator; |
|
58 //lint -esym(1740,CApaFileRecognizer::iFileRecognizerList) not directly freed - see DestroyRecognizerList() |
|
59 } |
|
60 |
|
61 |
|
62 EXPORT_C void CApaFileRecognizer::DestroyRecognizerList() |
|
63 // this method exists to allow subclassers to destroy the list earlier if they wish |
|
64 { |
|
65 CApaFileRecognizerType* rec=iFileRecognizerList; |
|
66 //delete one element after the other in the list |
|
67 while (rec!=NULL ) |
|
68 { |
|
69 CApaFileRecognizerType* prev=NULL; |
|
70 prev = rec; |
|
71 rec=rec->iNext; |
|
72 delete prev; |
|
73 } |
|
74 iFileRecognizerList=NULL; |
|
75 } |
|
76 |
|
77 |
|
78 EXPORT_C void CApaFileRecognizer::SetAppLocator(CApaAppLocator* aAppLocator) |
|
79 // takes ownership of the locator |
|
80 { |
|
81 iAppLocator = aAppLocator; |
|
82 } |
|
83 |
|
84 static TUidType UidTypeL(const TDesC& aFullFileName, const RFs& aFs) |
|
85 { |
|
86 _LIT(KSysBin, "\\sys\\bin\\"); |
|
87 if (TParsePtrC(aFullFileName).Path().CompareF(KSysBin)==0) |
|
88 { |
|
89 RLoader loader; |
|
90 User::LeaveIfError(loader.Connect()); |
|
91 CleanupClosePushL(loader); |
|
92 TPckgBuf<RLibrary::TInfo> dllInfo; |
|
93 User::LeaveIfError(loader.GetInfo(aFullFileName, dllInfo)); |
|
94 CleanupStack::PopAndDestroy(&loader); |
|
95 return dllInfo().iUids; |
|
96 } |
|
97 TEntry entry; |
|
98 User::LeaveIfError(aFs.Entry(aFullFileName,entry)); |
|
99 return entry.iType; |
|
100 } |
|
101 |
|
102 EXPORT_C CApaFileRecognizerType* CApaFileRecognizer::RecognizeFileL(const TDesC& aFullFileName,const TUidType* aUidType) |
|
103 // Returns the specific recognizer if the file is recogized as a runnable file. or NULL if not. |
|
104 // TUidType is optional, if not supplied it will be read from the file. |
|
105 // Leaves, if any files required cannot be found or if OOM. |
|
106 // Leaves with KErrNotSupported, if file cannot be recognized. |
|
107 { |
|
108 const TUidType uidType((aUidType!=NULL)? *aUidType: UidTypeL(aFullFileName, iFs)); |
|
109 CApaFileRecognizerType* rec=iFileRecognizerList; |
|
110 CApaFileRecognizerType::TRecognizedType type; |
|
111 while (rec!=NULL) |
|
112 { |
|
113 type=rec->RecognizeFileL(iFs,aFullFileName,uidType); |
|
114 if (type==CApaFileRecognizerType::EOtherFile) |
|
115 { |
|
116 rec=NULL; // Recognised but not runnable so stop search now |
|
117 break; |
|
118 } |
|
119 if (type!=CApaFileRecognizerType::ENotRecognized) |
|
120 { |
|
121 break; |
|
122 } |
|
123 rec=rec->iNext; |
|
124 } |
|
125 if (rec==NULL) |
|
126 { |
|
127 User::Leave(KErrNotSupported); |
|
128 } |
|
129 return rec; |
|
130 } |
|
131 |
|
132 EXPORT_C void CApaFileRecognizer::AddFileRecognizerType(CApaFileRecognizerType* aFileRecognizerType) |
|
133 // Add given RecognizerType to the end of the recognizer list. |
|
134 // Set's it's iFileRecognizer pointer to "this" - recognizers may call AppDataByUid |
|
135 { |
|
136 aFileRecognizerType->iNext=NULL; |
|
137 aFileRecognizerType->iFileRecognizer=this; |
|
138 CApaFileRecognizerType* rec=iFileRecognizerList; |
|
139 if (rec==NULL) |
|
140 iFileRecognizerList=aFileRecognizerType; |
|
141 else |
|
142 { |
|
143 while (rec->iNext!=NULL) |
|
144 rec=rec->iNext; |
|
145 rec->iNext=aFileRecognizerType; |
|
146 } |
|
147 } |
|
148 |
|
149 |
|
150 EXPORT_C TInt CApaFileRecognizer::RemoveFileRecognizerType(const CApaFileRecognizerType* aFileRecognizerType) |
|
151 // remove the given recognizer from the list if it is not locked |
|
152 // return an error code if removal failed |
|
153 { |
|
154 CApaFileRecognizerType* rec=iFileRecognizerList; |
|
155 CApaFileRecognizerType* prev=NULL; |
|
156 // find the recognizer in the list |
|
157 while (rec!=NULL && rec!=aFileRecognizerType) |
|
158 { |
|
159 prev = rec; |
|
160 rec=rec->iNext; |
|
161 } |
|
162 // did we find a match |
|
163 if (!rec) |
|
164 return KErrNotFound; |
|
165 // is the matching recognizer locked |
|
166 if (rec->Locked()) |
|
167 return KErrLocked; |
|
168 // remove the recognizer from the list, then delete it |
|
169 if (prev) |
|
170 prev->iNext = rec->iNext; |
|
171 else |
|
172 iFileRecognizerList = rec->iNext; |
|
173 rec->iNext = NULL; |
|
174 delete rec; |
|
175 return KErrNone; |
|
176 } |
|
177 |
|
178 |
|
179 EXPORT_C CApaAppLocator* CApaFileRecognizer::AppLocator() const |
|
180 { |
|
181 __ASSERT_ALWAYS(iAppLocator,Panic(EPanicNoAppLocator)); |
|
182 // |
|
183 return iAppLocator; |
|
184 } |
|
185 |
|
186 |
|
187 // |
|
188 // Class CApaFileRecognizerType |
|
189 // |
|
190 |
|
191 EXPORT_C CApaFileRecognizerType::CApaFileRecognizerType():iFileRecognizerExtn(NULL) |
|
192 { |
|
193 } |
|
194 |
|
195 |
|
196 EXPORT_C CApaFileRecognizerType::~CApaFileRecognizerType() |
|
197 { |
|
198 #ifdef USING_ECOM_RECOGS |
|
199 //if ecom plugin is used destroy its implementation |
|
200 if(iFileRecognizerExtn!=NULL) |
|
201 { |
|
202 REComSession::DestroyedImplementation(iFileRecognizerExtn->DestructorUid()); |
|
203 delete iFileRecognizerExtn; |
|
204 } |
|
205 #else |
|
206 iFileRecognizerExtn = NULL; |
|
207 #endif |
|
208 delete iCapabilityBuf; |
|
209 delete iFullFileName; |
|
210 iFileRecognizer = NULL; |
|
211 iAppStarter = NULL; |
|
212 iNext = NULL; |
|
213 } |
|
214 |
|
215 EXPORT_C TThreadId CApaFileRecognizerType::AppRunL(const CApaCommandLine& aCommandLine) const |
|
216 { |
|
217 __ASSERT_ALWAYS(iAppStarter,Panic(EPanicNoAppStarter)); |
|
218 // |
|
219 return iAppStarter->StartAppL(aCommandLine); |
|
220 } |
|
221 |
|
222 CApaFileRecognizerType::TRecognizedType CApaFileRecognizerType::RecognizeFileL(RFs& aFs,const TDesC& aFullFileName,TUidType aUidType) |
|
223 { |
|
224 // set the UID's and name |
|
225 iFileType = aUidType[1]; |
|
226 iAppUid = aUidType[2]; |
|
227 delete iFullFileName; |
|
228 iFullFileName = NULL; |
|
229 iFullFileName = aFullFileName.AllocL(); |
|
230 // |
|
231 // see if we recognize it |
|
232 iRecognizedType = ENotRecognized; |
|
233 TRecognizedType type=DoRecognizeFileL(aFs,aUidType); |
|
234 if (type==ENotRecognized) |
|
235 { |
|
236 delete iFullFileName; |
|
237 iFullFileName=NULL; |
|
238 } |
|
239 else |
|
240 { |
|
241 if(!iCapabilityBuf) |
|
242 { |
|
243 // Actually, iCapabilityBuf is not needed anymore, but in order not to break BC, |
|
244 // we must still support it (in case someone calls CApaFileRecognizerType::Capability). |
|
245 iCapabilityBuf = new(ELeave) TApaAppCapabilityBuf; |
|
246 iCapabilityBuf->FillZ(iCapabilityBuf->MaxLength()); |
|
247 } |
|
248 } |
|
249 return type; |
|
250 } |
|
251 |
|
252 |
|
253 EXPORT_C void CApaFileRecognizerType::Capability(TDes8& aCapabilityBuf)const |
|
254 { |
|
255 __ASSERT_ALWAYS(iCapabilityBuf,Panic(EPanicCapabilityNotSet)); // capability has been called when no file has been recognized |
|
256 // |
|
257 TApaAppCapability::CopyCapability(aCapabilityBuf,*iCapabilityBuf); |
|
258 } |
|
259 |
|
260 |
|
261 EXPORT_C void CApaFileRecognizerType::Lock() |
|
262 { |
|
263 iLock++; |
|
264 } |
|
265 |
|
266 |
|
267 EXPORT_C void CApaFileRecognizerType::Unlock() |
|
268 { |
|
269 if (iLock>0) |
|
270 iLock--; |
|
271 } |
|
272 |
|
273 |
|
274 TBool CApaFileRecognizerType::Locked()const |
|
275 { |
|
276 return (iLock>0); |
|
277 } |
|
278 |
|
279 EXPORT_C void CApaFileRecognizerType::Reserved_1() |
|
280 {} |
|
281 |
|
282 #ifdef USING_ECOM_RECOGS |
|
283 // instantiate the ecom implementation class |
|
284 EXPORT_C CApaFileRecognizerType* CApaFileRecognizerType::CreateFileRecognizerL(TUid aImplUid) |
|
285 { |
|
286 CApaFileRecognizerType* fileRecType = NULL; |
|
287 TUid tempDtorKey = KNullUid; |
|
288 fileRecType = static_cast<CApaFileRecognizerType*>(REComSession::CreateImplementationL(aImplUid, tempDtorKey)); |
|
289 CleanupStack::PushL(fileRecType); |
|
290 fileRecType->iFileRecognizerExtn=CFileRecognizerExtension::NewL(tempDtorKey); |
|
291 CleanupStack::Pop(fileRecType); |
|
292 return fileRecType; |
|
293 } |
|
294 #else |
|
295 EXPORT_C CApaFileRecognizerType* CApaFileRecognizerType::CreateFileRecognizerL(TUid) |
|
296 { |
|
297 return NULL; |
|
298 } |
|
299 #endif |
|
300 |
|
301 CFileRecognizerExtension::CFileRecognizerExtension(TUid aDtorKey) |
|
302 :iDtorKey(aDtorKey) |
|
303 { |
|
304 } |
|
305 |
|
306 CFileRecognizerExtension* CFileRecognizerExtension::NewL(TUid aDtorKey) |
|
307 { |
|
308 //instantiate CFileRecognizerExtension with the destructor key of the ecom implentation instance |
|
309 CFileRecognizerExtension* self=new(ELeave) CFileRecognizerExtension(aDtorKey); |
|
310 return self; |
|
311 } |
|
312 |
|
313 CFileRecognizerExtension::~CFileRecognizerExtension() |
|
314 { |
|
315 } |
|
316 |
|
317 //returns the destructor key of the ecom implentation instance |
|
318 TUid CFileRecognizerExtension::DestructorUid()const |
|
319 { |
|
320 return iDtorKey; |
|
321 } |
|
322 |
24 |
323 // |
25 // |
324 // MApaAppStarter |
26 // MApaAppStarter |
325 // |
27 // |
326 |
28 |