|
1 /* |
|
2 * Copyright (c) 2004 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: This class reads the resource file and provides access to the |
|
15 * information read from the resource file. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <f32file.h> |
|
22 #include <barsc.h> |
|
23 #include <bautils.h> |
|
24 #include <barsread.h> |
|
25 #include "devasrresourcehandler.h" |
|
26 #include <nssdevasr.rsg> |
|
27 #include "rubydebug.h" |
|
28 #include <data_caging_path_literals.hrh> |
|
29 |
|
30 // LOCAL CONSTANTS AND MACROS |
|
31 _LIT( KResourceFileName, "nssdevasr.rsc" ); |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CDevASRResourceHandler::CDevASRResourceHandler |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CDevASRResourceHandler::CDevASRResourceHandler() |
|
43 { |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CDevASRResourceHandler::ConstructL |
|
48 // Symbian 2nd phase constructor can leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CDevASRResourceHandler::ConstructL() |
|
52 { |
|
53 RUBY_DEBUG_BLOCK( "CDevASRResourceHandler::ConstructL()" ); |
|
54 |
|
55 ReadResourceFileL(); |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CDevASRResourceHandler::NewL |
|
60 // Two-phased constructor. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CDevASRResourceHandler* CDevASRResourceHandler::NewL() |
|
64 { |
|
65 CDevASRResourceHandler* self = new ( ELeave ) CDevASRResourceHandler(); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop(); // Self |
|
69 return self; |
|
70 } |
|
71 |
|
72 // Destructor |
|
73 CDevASRResourceHandler::~CDevASRResourceHandler() |
|
74 { |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CDevASRResourceHandler::ReadResourceFileL |
|
79 // Reads the data from the resource file. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CDevASRResourceHandler::ReadResourceFileL() |
|
83 { |
|
84 RUBY_DEBUG_BLOCK( "CDevASRResourceHandler::ReadResourceFileL()" ); |
|
85 |
|
86 // letters for drives in search order |
|
87 const TBuf<2> KResourceDrives = _L("cz"); |
|
88 |
|
89 // load resources |
|
90 RResourceFile resourceFile; |
|
91 RFs fs; |
|
92 User::LeaveIfError( fs.Connect() ); |
|
93 CleanupClosePushL( fs ); |
|
94 |
|
95 TFileName name; |
|
96 TInt i( 0 ); |
|
97 // try to find from the first driver |
|
98 name.Append( KResourceDrives[i] ); |
|
99 name.Append( ':' ); |
|
100 name.Append( KDC_RESOURCE_FILES_DIR ); |
|
101 name.Append( KResourceFileName ); |
|
102 |
|
103 TBool found( EFalse ); |
|
104 |
|
105 while ( !found && i < KResourceDrives.Length() ) |
|
106 { |
|
107 name[0] = KResourceDrives[i++]; |
|
108 |
|
109 if ( BaflUtils::FileExists(fs, name) ) |
|
110 { |
|
111 // open resource |
|
112 resourceFile.OpenL( fs, name ); |
|
113 CleanupClosePushL( resourceFile ); |
|
114 found = ETrue; |
|
115 } |
|
116 } |
|
117 |
|
118 if ( !found ) |
|
119 { |
|
120 User::Leave( KErrNotFound ); |
|
121 } |
|
122 |
|
123 |
|
124 HBufC8* res = resourceFile.AllocReadLC( DEVASRINFO ); |
|
125 |
|
126 TResourceReader theReader; |
|
127 theReader.SetBuffer( res ); |
|
128 |
|
129 iSamplingRate = theReader.ReadInt16(); |
|
130 iBitsPerSample = theReader.ReadInt16(); |
|
131 iMicrophoneGain = theReader.ReadInt16(); |
|
132 iSpeakerVolume = theReader.ReadInt16(); |
|
133 iSilenceFrames = theReader.ReadInt16(); |
|
134 iPadEndFrames = theReader.ReadInt16(); |
|
135 iPadStartFrames = theReader.ReadInt16(); |
|
136 iBufferSize = theReader.ReadInt16(); |
|
137 iBuffersInWins = theReader.ReadInt16(); |
|
138 iBuffersInThumb = theReader.ReadInt16(); |
|
139 |
|
140 // Cleanup res, fs, resourceFile |
|
141 CleanupStack::PopAndDestroy( 3 ); |
|
142 } |
|
143 |
|
144 // End of File |