49 @leave KErrEof No valid config string found in the configuration file; |
44 @leave KErrEof No valid config string found in the configuration file; |
50 Note that the function may also leave with some other system-wide error codes. |
45 Note that the function may also leave with some other system-wide error codes. |
51 */ |
46 */ |
52 void TSqlSrvConfig::InitL(RFs& aFs, const TDesC& aFileName) |
47 void TSqlSrvConfig::InitL(RFs& aFs, const TDesC& aFileName) |
53 { |
48 { |
54 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL_ENTRY, "Entry;0;TSqlSrvConfig::InitL;aFs.Handle()=0x%X;aFileName=%S", (TUint)aFs.Handle(), __SQLPRNSTR(aFileName))); |
|
55 if(::FileExists(aFs, aFileName)) |
49 if(::FileExists(aFs, aFileName)) |
56 { |
50 { |
57 SQL_TRACE_INTERNALS(OstTrace0(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL1, "0;TSqlSrvConfig::InitL;Config file found")); |
|
58 TBuf8<KSqlSrvMaxConfigStrLen> configFileStr; |
51 TBuf8<KSqlSrvMaxConfigStrLen> configFileStr; |
59 //Step 1: get the config string from the config file and store the string in configFileStr |
52 //Step 1: get the config string from the config file and store the string in configFileStr |
60 TSqlSrvConfig::GetConfigStringFromFileL(aFs, aFileName, configFileStr); |
53 TSqlSrvConfig::GetConfigStringFromFileL(aFs, aFileName, configFileStr); |
61 __SQLTRACE_INTERNALSVAR(TBuf<100> des16prnbuf); |
|
62 SQL_TRACE_INTERNALS(OstTraceExt1(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL2, "0;TSqlSrvConfig::InitL;Config file string=%s", __SQLPRNSTR8(configFileStr, des16prnbuf))); |
|
63 //Step 2: extract config file parameters from the string (configFileStr) and store them in iConfigFileParams |
54 //Step 2: extract config file parameters from the string (configFileStr) and store them in iConfigFileParams |
64 TSqlSrvConfig::ExtractConfigParamsFromStringL(configFileStr, iConfigFileParams); |
55 TSqlSrvConfig::ExtractConfigParamsFromStringL(configFileStr, iConfigFileParams); |
65 } |
56 } |
66 //If the soft heap limit is not set from the file or the file does not exist - then set the soft heap limit with the default value |
57 //If the soft heap limit is not set from the file or the file does not exist - then set the soft heap limit with the default value |
67 if(iConfigFileParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
58 if(iConfigFileParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
71 //If the free page threshold is not set from the file or the file does not exist - then set the free page threshold with the default value |
62 //If the free page threshold is not set from the file or the file does not exist - then set the free page threshold with the default value |
72 if(iConfigFileParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
63 if(iConfigFileParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
73 { |
64 { |
74 iConfigFileParams.iFreePageThresholdKb = KSqlCompactFreePageThresholdKb; |
65 iConfigFileParams.iFreePageThresholdKb = KSqlCompactFreePageThresholdKb; |
75 } |
66 } |
76 |
|
77 #ifdef _SQL_RDEBUG_PRINT |
|
78 SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL_EXIT1, "Exit;0;TSqlSrvConfig::InitL;iCacheSize=%d;iPageSize=%d;iDbEncoding=%d;iSoftHeapLimit=%d", iConfigFileParams.iCacheSize, iConfigFileParams.iPageSize, iConfigFileParams.iDbEncoding, iConfigFileParams.iSoftHeapLimitKb)); |
|
79 #else |
|
80 SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL_EXIT2, "Exit;0;TSqlSrvConfig::InitL;iCacheSize=%d;iPageSize=%d;iDbEncoding=%{TSqlSrvConfig_TDbEncoding};iSoftHeapLimit=%d", iConfigFileParams.iCacheSize, iConfigFileParams.iPageSize, iConfigFileParams.iDbEncoding, iConfigFileParams.iSoftHeapLimitKb)); |
|
81 #endif |
|
82 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLSRVCONFIGFILE_INITL_EXIT3, "Exit;0;TSqlSrvConfig::InitL;iCompactionMode=%d;iFreePageThresholdKb=%d", iConfigFileParams.iCompactionMode, iConfigFileParams.iFreePageThresholdKb)); |
|
83 } |
67 } |
84 |
68 |
85 /** |
69 /** |
86 Parses the config string parameter (aConfigStr), extracts configuration parameters values and |
70 Parses the config string parameter (aConfigStr), extracts configuration parameters values and |
87 and initialises with them aConfigParams data members. |
71 and initialises with them aConfigParams data members. |
96 @leave KErrArgument if the config is not good or the config string contains "soft heap limit" parameter/value pair. |
80 @leave KErrArgument if the config is not good or the config string contains "soft heap limit" parameter/value pair. |
97 @leave KErrArgument if the config is not good or the config string contains "free page threshold" parameter/value pair. |
81 @leave KErrArgument if the config is not good or the config string contains "free page threshold" parameter/value pair. |
98 */ |
82 */ |
99 void TSqlSrvConfig::GetConfigParamsL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams) const |
83 void TSqlSrvConfig::GetConfigParamsL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams) const |
100 { |
84 { |
101 __SQLTRACE_INTERNALSVAR(TBuf<100> des16prnbuf); |
|
102 SQL_TRACE_INTERNALS(OstTraceExt1(TRACE_INTERNALS, TSQLSRVCONFIGFILE_GETCONFIGPARAMSL_ENTRY, "Entry;0;TSqlSrvConfig::GetConfigParamsL;aConfigStr=%s", __SQLPRNSTR8(aConfigStr, des16prnbuf))); |
|
103 TSqlSrvConfigParams tmpConfigParams; |
85 TSqlSrvConfigParams tmpConfigParams; |
104 //Step 1: extract configuration parameters from aConfigStr, store them in tmpConfigParams. |
86 //Step 1: extract configuration parameters from aConfigStr, store them in tmpConfigParams. |
105 TSqlSrvConfig::ExtractConfigParamsFromStringL(aConfigStr, tmpConfigParams); |
87 TSqlSrvConfig::ExtractConfigParamsFromStringL(aConfigStr, tmpConfigParams); |
106 if(tmpConfigParams.iSoftHeapLimitKb != TSqlSrvConfigParams::KConfigPrmValueNotSet || |
88 if(tmpConfigParams.iSoftHeapLimitKb != TSqlSrvConfigParams::KConfigPrmValueNotSet || |
107 tmpConfigParams.iFreePageThresholdKb != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
89 tmpConfigParams.iFreePageThresholdKb != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
127 //Step 4: set the soft heap limit. |
109 //Step 4: set the soft heap limit. |
128 aConfigParams.iSoftHeapLimitKb = iConfigFileParams.iSoftHeapLimitKb; |
110 aConfigParams.iSoftHeapLimitKb = iConfigFileParams.iSoftHeapLimitKb; |
129 //Step 5: set the free page threshold. |
111 //Step 5: set the free page threshold. |
130 aConfigParams.iFreePageThresholdKb = iConfigFileParams.iFreePageThresholdKb; |
112 aConfigParams.iFreePageThresholdKb = iConfigFileParams.iFreePageThresholdKb; |
131 //Step 6: assert the parameter values. |
113 //Step 6: assert the parameter values. |
132 __ASSERT_DEBUG(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, __SQLPANIC(ESqlPanicInternalError)); |
114 __SQLASSERT(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, ESqlPanicInternalError); |
133 __ASSERT_DEBUG(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, __SQLPANIC(ESqlPanicInternalError)); |
115 __SQLASSERT(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, ESqlPanicInternalError); |
134 __ASSERT_DEBUG(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet || |
116 __SQLASSERT(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet || |
135 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf8 || |
117 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf8 || |
136 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf16, __SQLPANIC(ESqlPanicInternalError)); |
118 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf16, ESqlPanicInternalError); |
137 __ASSERT_DEBUG(aConfigParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
119 __SQLASSERT(aConfigParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
138 (aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
120 (aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
139 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb), __SQLPANIC(ESqlPanicInternalError)); |
121 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb), ESqlPanicInternalError); |
140 __ASSERT_DEBUG(aConfigParams.iCompactionMode == ESqlCompactionNotSet || aConfigParams.iCompactionMode == ESqlCompactionManual || |
122 __SQLASSERT(aConfigParams.iCompactionMode == ESqlCompactionNotSet || aConfigParams.iCompactionMode == ESqlCompactionManual || |
141 aConfigParams.iCompactionMode == ESqlCompactionBackground || aConfigParams.iCompactionMode == ESqlCompactionAuto, __SQLPANIC(ESqlPanicInternalError)); |
123 aConfigParams.iCompactionMode == ESqlCompactionBackground || aConfigParams.iCompactionMode == ESqlCompactionAuto, ESqlPanicInternalError); |
142 __ASSERT_DEBUG(aConfigParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
124 __SQLASSERT(aConfigParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
143 aConfigParams.iFreePageThresholdKb >= 0, __SQLPANIC(ESqlPanicInternalError)); |
125 aConfigParams.iFreePageThresholdKb >= 0, ESqlPanicInternalError); |
144 #ifdef _SQL_RDEBUG_PRINT |
|
145 SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, TSQLSRVCONFIGFILE_GETCONFIGPARAMSL_EXIT1, "Exit;0;TSqlSrvConfig::GetConfigParamsL;cacheSize=%d;pageSize=%d;dbEncoding=%d;softHeapLimit=%d", aConfigParams.iCacheSize, aConfigParams.iPageSize, aConfigParams.iDbEncoding, aConfigParams.iSoftHeapLimitKb)); |
|
146 #else |
|
147 SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, TSQLSRVCONFIGFILE_GETCONFIGPARAMSL_EXIT2, "Exit;0;TSqlSrvConfig::GetConfigParamsL;cacheSize=%d;pageSize=%d;dbEncoding=%{TSqlSrvConfig_TDbEncoding};softHeapLimit=%d", aConfigParams.iCacheSize, aConfigParams.iPageSize, aConfigParams.iDbEncoding, aConfigParams.iSoftHeapLimitKb)); |
|
148 #endif |
|
149 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, TSQLSRVCONFIGFILE_GETCONFIGPARAMSL_EXIT3, "Exit;0;TSqlSrvConfig::GetConfigParamsL;compactionMode=%d;freePageThresholdKb=%d", aConfigParams.iCompactionMode, aConfigParams.iFreePageThresholdKb)); |
|
150 } |
126 } |
151 |
127 |
152 //The function opeans the aFileName config file and reads the config string, storring it in aConfigStr argument. |
128 //The function opeans the aFileName config file and reads the config string, storring it in aConfigStr argument. |
153 //Preconditions: |
129 //Preconditions: |
154 // - The config file does exist; |
130 // - The config file does exist; |
155 // - It is a file, containing 16-bit strings; |
131 // - It is a file, containing 16-bit strings; |
156 // - aConfigStr max size is at least KSqlSrvMaxConfigStrLen bytes; |
132 // - aConfigStr max size is at least KSqlSrvMaxConfigStrLen bytes; |
157 //The function may leave if some of the file I/O operations (open file, read file) fails. |
133 //The function may leave if some of the file I/O operations (open file, read file) fails. |
158 void TSqlSrvConfig::GetConfigStringFromFileL(RFs& aFs, const TDesC& aFileName, TDes8& aConfigStr) |
134 void TSqlSrvConfig::GetConfigStringFromFileL(RFs& aFs, const TDesC& aFileName, TDes8& aConfigStr) |
159 { |
135 { |
160 __ASSERT_DEBUG(aConfigStr.MaxLength() >= KSqlSrvMaxConfigStrLen, __SQLPANIC2(ESqlPanicBadArgument)); |
136 __SQLASSERT(aConfigStr.MaxLength() >= KSqlSrvMaxConfigStrLen, ESqlPanicBadArgument); |
161 RFile64 cfgFile; |
137 RFile64 cfgFile; |
162 CleanupClosePushL(cfgFile); |
138 CleanupClosePushL(cfgFile); |
163 __SQLLEAVE_IF_ERROR2(cfgFile.Open(aFs, aFileName, EFileRead)); |
139 __SQLLEAVE_IF_ERROR(cfgFile.Open(aFs, aFileName, EFileRead)); |
164 TFileText cfgFileReader; |
140 TFileText cfgFileReader; |
165 cfgFileReader.Set(cfgFile); |
141 cfgFileReader.Set(cfgFile); |
166 TBuf<KSqlSrvMaxConfigStrLen> buf; |
142 TBuf<KSqlSrvMaxConfigStrLen> buf; |
167 TBool cfgLineFound = EFalse; |
143 TBool cfgLineFound = EFalse; |
168 TInt err = KErrNone; |
144 TInt err = KErrNone; |
206 { |
182 { |
207 TSqlSrvConfig::ExtractParamValueL(prmName, prmValue, aConfigParams); |
183 TSqlSrvConfig::ExtractParamValueL(prmName, prmValue, aConfigParams); |
208 } |
184 } |
209 } |
185 } |
210 //Assert the extracted parameter values. |
186 //Assert the extracted parameter values. |
211 __ASSERT_DEBUG(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, __SQLPANIC2(ESqlPanicInternalError)); |
187 __SQLASSERT(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, ESqlPanicInternalError); |
212 __ASSERT_DEBUG(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, __SQLPANIC2(ESqlPanicInternalError)); |
188 __SQLASSERT(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, ESqlPanicInternalError); |
213 __ASSERT_DEBUG(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet || |
189 __SQLASSERT(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet || |
214 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf8 || |
190 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf8 || |
215 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf16, __SQLPANIC2(ESqlPanicInternalError)); |
191 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf16, ESqlPanicInternalError); |
216 __ASSERT_DEBUG(aConfigParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
192 __SQLASSERT(aConfigParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
217 (aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
193 (aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
218 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb), __SQLPANIC2(ESqlPanicInternalError)); |
194 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb), ESqlPanicInternalError); |
219 __ASSERT_DEBUG(aConfigParams.iCompactionMode == ESqlCompactionNotSet || aConfigParams.iCompactionMode == ESqlCompactionManual || |
195 __SQLASSERT(aConfigParams.iCompactionMode == ESqlCompactionNotSet || aConfigParams.iCompactionMode == ESqlCompactionManual || |
220 aConfigParams.iCompactionMode == ESqlCompactionBackground || aConfigParams.iCompactionMode == ESqlCompactionAuto, __SQLPANIC2(ESqlPanicInternalError)); |
196 aConfigParams.iCompactionMode == ESqlCompactionBackground || aConfigParams.iCompactionMode == ESqlCompactionAuto, ESqlPanicInternalError); |
221 __ASSERT_DEBUG(aConfigParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
197 __SQLASSERT(aConfigParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
222 aConfigParams.iFreePageThresholdKb >= 0, __SQLPANIC2(ESqlPanicInternalError)); |
198 aConfigParams.iFreePageThresholdKb >= 0, ESqlPanicInternalError); |
223 } |
199 } |
224 |
200 |
225 //The function searches aConfigStr arguments for "PARAM=VALUE;" pair. If such pair is found, then |
201 //The function searches aConfigStr arguments for "PARAM=VALUE;" pair. If such pair is found, then |
226 //aParamName is set to point to the parameter name, aParamValue is set to point to the parameter value, |
202 //aParamName is set to point to the parameter name, aParamValue is set to point to the parameter value, |
227 //aConfigStr is set to point to the rest of the config string (skipping the just found "param=value;" pair). |
203 //aConfigStr is set to point to the rest of the config string (skipping the just found "param=value;" pair). |
394 TLex8 lex(aParamValue); |
370 TLex8 lex(aParamValue); |
395 TInt freePageThreshold = 0; |
371 TInt freePageThreshold = 0; |
396 TInt err = lex.Val(freePageThreshold); |
372 TInt err = lex.Val(freePageThreshold); |
397 if(err != KErrNone || freePageThreshold < 0) |
373 if(err != KErrNone || freePageThreshold < 0) |
398 { |
374 { |
399 __SQLLEAVE2(KErrArgument); |
375 __SQLLEAVE(KErrArgument); |
400 } |
376 } |
401 return freePageThreshold; |
377 return freePageThreshold; |
402 } |
378 } |
403 |
379 |
404 |
380 |
405 //The function searches aStr for leading and trailing whitespace |
381 //The function searches aStr for leading and trailing whitespace |
406 //characters, then creates and returns TPtrC object which points to the |
382 //characters, then creates and returns TPtrC object which points to the |
407 //aStr content without leading and trailing whitespace characters. |
383 //aStr content without leading and trailing whitespace characters. |
408 TPtrC8 TSqlSrvConfig::TrimAndConstructPtr(const TUint8* aStr, TInt aLength) |
384 TPtrC8 TSqlSrvConfig::TrimAndConstructPtr(const TUint8* aStr, TInt aLength) |
409 { |
385 { |
410 __ASSERT_DEBUG(aStr != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
386 __SQLASSERT(aStr != NULL, ESqlPanicBadArgument); |
411 __ASSERT_DEBUG(aLength >= 0, __SQLPANIC2(ESqlPanicBadArgument)); |
387 __SQLASSERT(aLength >= 0, ESqlPanicBadArgument); |
412 //Trim left |
388 //Trim left |
413 for(;aLength>0;--aLength,++aStr) |
389 for(;aLength>0;--aLength,++aStr) |
414 { |
390 { |
415 if(!TChar(*aStr).IsSpace()) |
391 if(!TChar(*aStr).IsSpace()) |
416 { |
392 { |