|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // BIF.CPP |
|
15 // |
|
16 #include "BIF.H" |
|
17 |
|
18 #include <s32file.h> // CFileStore |
|
19 #include <barsc.h> |
|
20 #include <barsread.h> |
|
21 |
|
22 #include "cbifentry.h" |
|
23 #include "BIFUPAN.H" |
|
24 |
|
25 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
26 #include "bifbase.h" |
|
27 #endif |
|
28 |
|
29 // |
|
30 // Defines and constants |
|
31 enum TBioInfoFileVersion // The order here is important, only ever APPEND to the list |
|
32 { |
|
33 EBifVersionOriginal=1, |
|
34 EBifVersionAddedAppCtrl, |
|
35 EBifVersionAddedFileExtension |
|
36 }; |
|
37 |
|
38 const TInt KIntDefaultArrayGranularity=4; |
|
39 |
|
40 /** 2nd UID of BIF file stores. */ |
|
41 const TUid KUidBioInfoFile={0x10005233}; // unicode Uid, used as 2nd Uid of file store |
|
42 |
|
43 /* |
|
44 * CBioInfoFile |
|
45 */ |
|
46 |
|
47 CBioInfoFile::CBioInfoFile(RFs& aFs) |
|
48 : iFs(aFs) |
|
49 { |
|
50 } |
|
51 |
|
52 void CBioInfoFile::ConstructL() |
|
53 { |
|
54 iIconZoomLevelArray=new(ELeave) CArrayFixFlat<TIconZoomLevel>(KIntDefaultArrayGranularity); |
|
55 iIdHeaderArray=new(ELeave) CArrayPtrFlat<CIdHeader>(KIntDefaultArrayGranularity); |
|
56 } |
|
57 |
|
58 CBioInfoFile::~CBioInfoFile() |
|
59 { |
|
60 delete iMessageParserName; |
|
61 delete iMessageAppCtrlName; |
|
62 delete iDescription; |
|
63 delete iFileExtension; |
|
64 delete iIconsFilename; |
|
65 |
|
66 if(iIdHeaderArray) |
|
67 { |
|
68 iIdHeaderArray->ResetAndDestroy(); |
|
69 delete iIdHeaderArray; |
|
70 } |
|
71 |
|
72 delete iIconZoomLevelArray; |
|
73 } |
|
74 |
|
75 /* |
|
76 * CIdHeader |
|
77 */ |
|
78 |
|
79 CBioInfoFile::CIdHeader::CIdHeader() |
|
80 { |
|
81 } |
|
82 |
|
83 CBioInfoFile::CIdHeader::~CIdHeader() |
|
84 { |
|
85 if (iText.IsPtr()) |
|
86 delete iText.AsPtr(); |
|
87 } |
|
88 |
|
89 void CBioInfoFile::CIdHeader::InternalizeL(RReadStream& aStream) |
|
90 { |
|
91 iType=(TBioMsgIdType)aStream.ReadInt16L(); |
|
92 iConfidence=(CApaDataRecognizerType::TRecognitionConfidence)aStream.ReadInt32L(); |
|
93 aStream>>iText; // is a TSwizzle |
|
94 iPort=(TUint16)aStream.ReadUint16L(); |
|
95 iCharacterSet.iUid=(TInt32)aStream.ReadInt32L(); |
|
96 iGeneralIdData=(TInt16)aStream.ReadInt16L(); |
|
97 } |
|
98 |
|
99 void CBioInfoFile::CIdHeader::ExternalizeL(RWriteStream& aStream) const |
|
100 { |
|
101 aStream.WriteInt16L(iType); |
|
102 aStream.WriteInt32L(iConfidence); |
|
103 aStream<<iText; // is a TSwizzle |
|
104 aStream.WriteUint16L(iPort); |
|
105 aStream.WriteInt32L(iCharacterSet.iUid); |
|
106 aStream.WriteInt16L(iGeneralIdData); |
|
107 } |
|
108 |
|
109 /* |
|
110 * TIconZoomLevel |
|
111 */ |
|
112 |
|
113 void CBioInfoFile::TIconZoomLevel::InternalizeL(RReadStream& aStream) |
|
114 { |
|
115 iZoomLevel=(TInt16)aStream.ReadInt16L(); |
|
116 } |
|
117 |
|
118 void CBioInfoFile::TIconZoomLevel::ExternalizeL(RWriteStream& aStream) const |
|
119 { |
|
120 aStream.WriteInt16L(iZoomLevel); |
|
121 } |
|
122 |
|
123 /* |
|
124 * CBioInfoFileReader |
|
125 */ |
|
126 |
|
127 /** Allocates and constructs a new BIF reader object, leaving the object on the |
|
128 cleanup stack. |
|
129 |
|
130 It loads the specified BIF file. |
|
131 |
|
132 @param aFs |
|
133 Connected file handle |
|
134 |
|
135 @param aFileName |
|
136 BIF file name |
|
137 |
|
138 @param aMsgTypeUid |
|
139 Optional message type UID. If this is specified, and the file does not does not |
|
140 describe this type, then it leaves with KErrCorrupt. |
|
141 |
|
142 @return |
|
143 New BIF reader object |
|
144 */ |
|
145 EXPORT_C CBioInfoFileReader* CBioInfoFileReader::NewLC(RFs& aFs,const TDesC& aFileName,TUid aMsgTypeUid) |
|
146 { |
|
147 CBioInfoFileReader* self=new(ELeave) CBioInfoFileReader(aFs); |
|
148 CleanupStack::PushL(self); |
|
149 self->ConstructL(aFileName,aMsgTypeUid); |
|
150 return self; |
|
151 } |
|
152 |
|
153 /** Allocates and constructs a new BIF reader object. |
|
154 |
|
155 It loads the specified BIF file. |
|
156 |
|
157 @param aFs |
|
158 Connected file handle |
|
159 |
|
160 @param aFileName |
|
161 BIF file name |
|
162 |
|
163 @param aMsgTypeUid |
|
164 Optional message type UID. If this is specified, and the file does not does not |
|
165 describe this type, then it leaves with KErrCorrupt. |
|
166 |
|
167 @return |
|
168 New BIF reader object |
|
169 */ |
|
170 EXPORT_C CBioInfoFileReader* CBioInfoFileReader::NewL(RFs& aFs,const TDesC& aFileName,TUid aMsgTypeUid) |
|
171 { |
|
172 CBioInfoFileReader* self=CBioInfoFileReader::NewLC(aFs,aFileName,aMsgTypeUid); |
|
173 CleanupStack::Pop(self); |
|
174 return self; |
|
175 } |
|
176 |
|
177 CBioInfoFileReader::CBioInfoFileReader(RFs& aFs) |
|
178 : CBioInfoFile(aFs) |
|
179 { |
|
180 } |
|
181 |
|
182 void CBioInfoFileReader::ConstructL(const TDesC& aFileName,TUid aMsgTypeUid) |
|
183 { |
|
184 CBioInfoFile::ConstructL(); |
|
185 |
|
186 iFileName = aFileName.AllocL(); |
|
187 TEntry entry; |
|
188 User::LeaveIfError(iFs.Entry(aFileName, entry)); |
|
189 |
|
190 iEntry = CBifEntry::NewL(entry); |
|
191 |
|
192 // Load the data |
|
193 if( IsResFileL() ) |
|
194 { |
|
195 LoadResourceL(aMsgTypeUid); |
|
196 } |
|
197 else if( IsDatFile(entry.iType) ) |
|
198 { |
|
199 LoadDataL(aMsgTypeUid); |
|
200 } |
|
201 else |
|
202 { |
|
203 User::Leave(KErrCorrupt); |
|
204 } |
|
205 } |
|
206 |
|
207 TBool CBioInfoFileReader::IsDatFile(const TUidType& aUidType) const |
|
208 { |
|
209 if( aUidType[0] == KDirectFileStoreLayoutUid && aUidType[1] == KUidBioInfoFile) |
|
210 { |
|
211 return ETrue; |
|
212 } |
|
213 else |
|
214 { |
|
215 return EFalse; |
|
216 } |
|
217 } |
|
218 |
|
219 void CBioInfoFileReader::LoadDataL(TUid aMsgTypeUid) |
|
220 { |
|
221 // Open file and validate its Uids (if Uid supplied as argument) |
|
222 CFileStore* store = CFileStore::OpenLC(iFs, *iFileName, EFileRead|EFileShareReadersOnly); |
|
223 |
|
224 const TUidType& type=store->Type(); |
|
225 if (aMsgTypeUid!=KNullUid && type[2]!=aMsgTypeUid) |
|
226 { |
|
227 User::Leave(KErrCorrupt); // it's the wrong file!!!!! |
|
228 } |
|
229 |
|
230 // Read from file into our data members |
|
231 RStoreReadStream inStream; |
|
232 inStream.OpenLC(*store,store->Root()); |
|
233 InternalizeL(inStream); |
|
234 |
|
235 CleanupStack::PopAndDestroy(2, store); // inStream, store |
|
236 } |
|
237 |
|
238 TBool CBioInfoFileReader::IsResFileL() const |
|
239 { |
|
240 // Check the extension to see if it's a resource file |
|
241 TParse parse; |
|
242 User::LeaveIfError(parse.Set(*iFileName, NULL, NULL)); |
|
243 |
|
244 // If first alpha character of extension is 'r' assume we're dealing with a resource file |
|
245 TPtrC ext(parse.Ext()); |
|
246 return ext.Length() > 1 && TCharF(ext[1]) == TCharF('r'); |
|
247 } |
|
248 |
|
249 |
|
250 void CBioInfoFileReader::LoadResourceL(TUid aMsgTypeUid) |
|
251 { |
|
252 // Open the resource file |
|
253 RResourceFile file; |
|
254 file.OpenL(iFs, *iFileName); |
|
255 CleanupClosePushL(file); |
|
256 |
|
257 // Read the resource |
|
258 HBufC8* resBuf = file.AllocReadLC(1); |
|
259 |
|
260 // interpret the resource buffer |
|
261 TResourceReader reader; |
|
262 reader.SetBuffer(resBuf); |
|
263 |
|
264 // Read message type uid, and check it's valid |
|
265 iMessageTypeUid = TUid::Uid(reader.ReadInt32()); |
|
266 if (aMsgTypeUid != KNullUid && iMessageTypeUid != aMsgTypeUid) |
|
267 { |
|
268 User::Leave(KErrCorrupt); |
|
269 } |
|
270 |
|
271 // Read message parser name |
|
272 delete iMessageParserName; |
|
273 iMessageParserName = NULL; |
|
274 iMessageParserName = reader.ReadHBufCL(); |
|
275 // Read message app uid |
|
276 iMessageAppUid = TUid::Uid(reader.ReadInt32()); |
|
277 |
|
278 // Read message appctrl uid |
|
279 delete iMessageAppCtrlName; |
|
280 iMessageAppCtrlName = NULL; |
|
281 iMessageAppCtrlName = reader.ReadHBufCL(); |
|
282 |
|
283 // Read description |
|
284 delete iDescription; |
|
285 iDescription = NULL; |
|
286 iDescription = reader.ReadHBufCL(); |
|
287 |
|
288 // Read file extension |
|
289 delete iFileExtension; |
|
290 iFileExtension = NULL; |
|
291 iFileExtension = reader.ReadHBufCL(); |
|
292 |
|
293 // Read general data[1..3] |
|
294 iGeneralData1 = (TInt16)reader.ReadInt16(); |
|
295 iGeneralData2 = (TInt16)reader.ReadInt16(); |
|
296 iGeneralData3 = (TInt16)reader.ReadInt16(); |
|
297 |
|
298 // Read in icon stuff |
|
299 delete iIconsFilename; |
|
300 iIconsFilename = NULL; |
|
301 iIconsFilename = reader.ReadHBufCL(); |
|
302 |
|
303 // Read in zoom levels |
|
304 TInt icons = reader.ReadInt16(); |
|
305 while(icons--) |
|
306 { |
|
307 TIconZoomLevel zoom; |
|
308 zoom.iZoomLevel = (TInt16)reader.ReadInt16(); |
|
309 iIconZoomLevelArray->AppendL(zoom); |
|
310 } |
|
311 |
|
312 // Read in IDs |
|
313 TInt ids = reader.ReadInt16(); |
|
314 while( ids-- > 0 ) |
|
315 { |
|
316 CIdHeader* header = new(ELeave)CIdHeader; |
|
317 CleanupStack::PushL(header); |
|
318 |
|
319 header->iType = (TBioMsgIdType)reader.ReadInt16(); |
|
320 header->iConfidence = (CApaDataRecognizerType::TRecognitionConfidence)reader.ReadInt32(); |
|
321 header->iCharacterSet = TUid::Uid(reader.ReadInt32()); |
|
322 |
|
323 // Don't ask me why it's like this! |
|
324 TPtrC text(reader.ReadTPtrC()); |
|
325 header->iText = HBufC::NewL(text.Length()); |
|
326 (*header->iText) = text; |
|
327 |
|
328 header->iPort = (TInt16)reader.ReadInt16(); |
|
329 header->iGeneralIdData = (TInt16)reader.ReadInt16(); |
|
330 |
|
331 iIdHeaderArray->AppendL(header); |
|
332 CleanupStack::Pop(header); |
|
333 } |
|
334 |
|
335 CleanupStack::PopAndDestroy(2, &file); // resBuf, file |
|
336 } |
|
337 |
|
338 /** |
|
339 Destructor. |
|
340 */ |
|
341 EXPORT_C CBioInfoFileReader::~CBioInfoFileReader() |
|
342 { |
|
343 delete iFileName; |
|
344 delete iEntry; |
|
345 } |
|
346 |
|
347 |
|
348 void CBioInfoFileReader::InternalizeL(RReadStream& aStream) |
|
349 { |
|
350 // |
|
351 // Get version number |
|
352 const TInt32 version(aStream.ReadInt32L()); |
|
353 __ASSERT_DEBUG(version==EBifVersionOriginal || |
|
354 version==EBifVersionAddedAppCtrl || |
|
355 version==EBifVersionAddedFileExtension, |
|
356 Panic(EBifUnknownVersion)); |
|
357 |
|
358 // Get data for BIF version EBifVersionOriginal |
|
359 iMessageTypeUid.iUid=(TInt32)aStream.ReadInt32L(); |
|
360 |
|
361 delete iMessageParserName; |
|
362 iMessageParserName = NULL; |
|
363 iMessageParserName = HBufC::NewL(aStream, KMaxFileName); |
|
364 |
|
365 iMessageAppUid.iUid=(TInt32)aStream.ReadInt32L(); |
|
366 |
|
367 delete iDescription; |
|
368 iDescription = NULL; |
|
369 iDescription = HBufC::NewL(aStream, KMaxFileName); |
|
370 |
|
371 iGeneralData1=(TInt16)aStream.ReadInt16L(); |
|
372 iGeneralData2=(TInt16)aStream.ReadInt16L(); |
|
373 iGeneralData3=(TInt16)aStream.ReadInt16L(); |
|
374 |
|
375 delete iIconsFilename; |
|
376 iIconsFilename = NULL; |
|
377 iIconsFilename = HBufC::NewL(aStream, KMaxFileName); |
|
378 |
|
379 aStream>>*iIconZoomLevelArray; |
|
380 |
|
381 const TInt32 numHeaders=(TInt32)aStream.ReadInt32L(); |
|
382 for (TInt32 cc=0; cc<numHeaders; ++cc) |
|
383 { |
|
384 CIdHeader* header=new(ELeave) CIdHeader; |
|
385 CleanupStack::PushL(header); |
|
386 aStream>>*header; |
|
387 iIdHeaderArray->AppendL(header); |
|
388 CleanupStack::Pop(header); |
|
389 } |
|
390 |
|
391 if(version==EBifVersionOriginal) |
|
392 return; |
|
393 |
|
394 // Get data for BIF version EBifVersionAddedAppCtrl |
|
395 delete iMessageAppCtrlName; |
|
396 iMessageAppCtrlName = NULL; |
|
397 iMessageAppCtrlName = HBufC::NewL(aStream, KMaxFileName); |
|
398 if(version==EBifVersionAddedAppCtrl) |
|
399 return; |
|
400 |
|
401 delete iFileExtension; |
|
402 iFileExtension = NULL; |
|
403 iFileExtension = HBufC::NewL(aStream, KMaxFileName); |
|
404 if(version==EBifVersionAddedFileExtension) |
|
405 return; |
|
406 |
|
407 // Put code here for reading data from newer versions of BIF |
|
408 } |
|
409 |
|
410 /** Gets the BIF's message type UID setting. |
|
411 |
|
412 @return |
|
413 Message type UID |
|
414 */ |
|
415 EXPORT_C TUid CBioInfoFileReader::MessageTypeUid() const |
|
416 { |
|
417 return iMessageTypeUid; |
|
418 } |
|
419 |
|
420 /** Gets the BIF's message parser name. |
|
421 |
|
422 @return |
|
423 BIF's message parser name |
|
424 */ |
|
425 EXPORT_C const TPtrC CBioInfoFileReader::MessageParserName() const |
|
426 { |
|
427 return (iMessageParserName!=NULL) ? iMessageParserName->Des() : TPtrC(); |
|
428 } |
|
429 |
|
430 |
|
431 /** Gets the BIF's application UID setting. |
|
432 |
|
433 @return |
|
434 Application UID setting |
|
435 */ |
|
436 EXPORT_C TUid CBioInfoFileReader::MessageAppUid() const |
|
437 { |
|
438 return iMessageAppUid; |
|
439 } |
|
440 |
|
441 /** Deprecated method. |
|
442 |
|
443 Use CBioInfoFileReader::MessageAppCtrlName |
|
444 |
|
445 @see CBioInfoFileReader::MessageAppCtrlName |
|
446 |
|
447 @return |
|
448 Invalid return. |
|
449 |
|
450 @deprecated |
|
451 */ |
|
452 EXPORT_C TUid CBioInfoFileReader::MessageAppCtrlUid() const |
|
453 { |
|
454 User::Invariant(); |
|
455 return TUid(); |
|
456 } |
|
457 |
|
458 /** Gets the BIF's control name. |
|
459 |
|
460 @return |
|
461 Control name |
|
462 */ |
|
463 EXPORT_C const TPtrC CBioInfoFileReader::MessageAppCtrlName() const |
|
464 { |
|
465 return (iMessageAppCtrlName != NULL) ? iMessageAppCtrlName->Des() : TPtrC(); |
|
466 } |
|
467 |
|
468 |
|
469 /** Gets the BIF's general data 1 setting. |
|
470 |
|
471 @return |
|
472 General data 1 setting |
|
473 */ |
|
474 EXPORT_C TInt16 CBioInfoFileReader::GeneralData1() const |
|
475 { |
|
476 return iGeneralData1; |
|
477 } |
|
478 |
|
479 /** Gets the BIF's general data 2 setting. |
|
480 |
|
481 @return |
|
482 General data 2 setting |
|
483 */ |
|
484 EXPORT_C TInt16 CBioInfoFileReader::GeneralData2() const |
|
485 { |
|
486 return iGeneralData2; |
|
487 } |
|
488 |
|
489 /** Gets the BIF's general data 3 setting. |
|
490 |
|
491 @return |
|
492 General data 3 setting |
|
493 */ |
|
494 EXPORT_C TInt16 CBioInfoFileReader::GeneralData3() const |
|
495 { |
|
496 return iGeneralData3; |
|
497 } |
|
498 |
|
499 /** Gets the BIF's description setting. |
|
500 |
|
501 @return |
|
502 BIF's description setting |
|
503 */ |
|
504 EXPORT_C const TPtrC CBioInfoFileReader::Description() const |
|
505 { |
|
506 return (iDescription!=NULL) ? iDescription->Des() : TPtrC(); |
|
507 } |
|
508 |
|
509 // |
|
510 // Data getter |
|
511 EXPORT_C const TPtrC CBioInfoFileReader::FileExtension() const |
|
512 /** Gets the BIF's file extension setting. |
|
513 |
|
514 @return BIF's file extension setting */ |
|
515 { |
|
516 return (iFileExtension!=NULL) ? iFileExtension->Des() : TPtrC(); |
|
517 } |
|
518 |
|
519 /** Gets the BIF's icons filename setting. |
|
520 |
|
521 @return |
|
522 BIF's icons filename setting |
|
523 */ |
|
524 EXPORT_C const TPtrC CBioInfoFileReader::IconsFilename() const |
|
525 { |
|
526 return (iIconsFilename!=NULL) ? iIconsFilename->Des() : TPtrC(); |
|
527 } |
|
528 |
|
529 /** Gets the BIF's icon zoom levels setting. |
|
530 |
|
531 The array of icon zoom level settings is left of the cleanup stack and ownership |
|
532 is returned to the caller. |
|
533 |
|
534 @return |
|
535 Icon zoom levels setting |
|
536 */ |
|
537 EXPORT_C const CArrayFixFlat<TInt16>* CBioInfoFileReader::ZoomLevelsLC() const |
|
538 { |
|
539 CArrayFixFlat<TInt16>* array=new(ELeave) CArrayFixFlat<TInt16>(KIntDefaultArrayGranularity); |
|
540 CleanupStack::PushL(array); |
|
541 |
|
542 const TInt count=iIconZoomLevelArray->Count(); |
|
543 |
|
544 for(TInt i=0;i<count;i++) |
|
545 { |
|
546 array->AppendL((*iIconZoomLevelArray)[i].iZoomLevel); |
|
547 } |
|
548 |
|
549 return array; |
|
550 } |
|
551 |
|
552 /** Gets the BIF's number of icon zoom levels. |
|
553 |
|
554 @return |
|
555 Number of icon zoom levels |
|
556 */ |
|
557 EXPORT_C TInt CBioInfoFileReader::ZoomLevelsCount() const |
|
558 { |
|
559 return iIconZoomLevelArray->Count(); |
|
560 } |
|
561 |
|
562 /** Gets the BIF's ID array. |
|
563 |
|
564 The of IDs is left of the cleanup stack and ownership is returned to the caller. |
|
565 |
|
566 @return |
|
567 ID array |
|
568 */ |
|
569 EXPORT_C const CArrayFixFlat<TBioMsgId>* CBioInfoFileReader::IdsLC() const |
|
570 { |
|
571 CArrayFixFlat<TBioMsgId>* array=new(ELeave) CArrayFixFlat<TBioMsgId>(KIntDefaultArrayGranularity); |
|
572 CleanupStack::PushL(array); |
|
573 |
|
574 TBioMsgId id; |
|
575 const TInt count=iIdHeaderArray->Count(); |
|
576 |
|
577 for(TInt i=0;i<count;++i) |
|
578 { |
|
579 // Get header for the Id |
|
580 CIdHeader* header=iIdHeaderArray->At(i); |
|
581 |
|
582 // Read in swizzle(s) of Id |
|
583 if (!header->iText.IsPtr()) |
|
584 { |
|
585 CFileStore* store = CFileStore::OpenLC(iFs,*iFileName,EFileRead|EFileShareReadersOnly); |
|
586 RStoreReadStream inStream; |
|
587 TStreamId streamId=header->iText.AsId(); |
|
588 inStream.OpenLC(*store,streamId); |
|
589 |
|
590 TBioMsgIdText idText; |
|
591 inStream>>idText; |
|
592 header->iText = idText.AllocL(); |
|
593 |
|
594 CleanupStack::PopAndDestroy(2, store); // inStream, store |
|
595 } |
|
596 |
|
597 // Fill object, ready for appending to array |
|
598 id.iType=header->iType; |
|
599 id.iConfidence=header->iConfidence; |
|
600 id.iText=*(header->iText); |
|
601 id.iPort=header->iPort; |
|
602 id.iCharacterSet=header->iCharacterSet; |
|
603 id.iGeneralIdData=header->iGeneralIdData; |
|
604 |
|
605 // Append object to array |
|
606 array->AppendL(id); |
|
607 } |
|
608 return array; |
|
609 } |
|
610 |
|
611 /** BIF entry. |
|
612 |
|
613 @return |
|
614 BIF entry |
|
615 |
|
616 @internalTechnology |
|
617 @released |
|
618 */ |
|
619 EXPORT_C const CBifEntry& CBioInfoFileReader::BifEntry() const |
|
620 { |
|
621 return *iEntry; |
|
622 } |