|
1 /* |
|
2 * Copyright (c) 2009 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: Utility library for reading simple configuration |
|
15 * property files containing Key=Value lines. |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef __HTICFG_H__ |
|
20 #define __HTICFG_H__ |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 // Parameter lengths |
|
28 const static TInt KMaxParameterNameLength = 64; |
|
29 const static TInt KMaxParameterValueLength = 64; |
|
30 const static TInt KMaxParameterLength = KMaxParameterNameLength + 1 + KMaxParameterValueLength; |
|
31 |
|
32 // Configuration file constants |
|
33 #define KCfgNewLine (TChar)'\n' |
|
34 #define KCfgSeparator (TChar)'=' |
|
35 #define KCfgComment (TChar)'#' |
|
36 |
|
37 // FORWARD DECLARATIONS |
|
38 class CDesC8ArrayFlat; |
|
39 |
|
40 // CLASS DECLARATION |
|
41 class CHtiCfg: public CBase |
|
42 { |
|
43 public: |
|
44 |
|
45 /** |
|
46 * Create instance of configuration class. |
|
47 * @return Configuration class instance. |
|
48 */ |
|
49 IMPORT_C static CHtiCfg* NewL(); |
|
50 |
|
51 /** |
|
52 * Create instance of configuration class leaving it to cleanup stack. |
|
53 * @return Configuration class instance. |
|
54 */ |
|
55 IMPORT_C static CHtiCfg* NewLC(); |
|
56 |
|
57 /** |
|
58 * Destructor. |
|
59 */ |
|
60 IMPORT_C virtual ~CHtiCfg(); |
|
61 |
|
62 /** |
|
63 * Loads the configuration file and reads the values to iCfgParameters. |
|
64 * Drive letter is not specified. File will be searched from all drives. |
|
65 * @param aCfgFilePath absolute path (without drive letter) to the directory |
|
66 * from where to search the configuration file |
|
67 * @param aCfgFileName configuration filename. |
|
68 */ |
|
69 IMPORT_C void LoadCfgL( const TDesC& aCfgFilePath, |
|
70 const TDesC& aCfgFileName ); |
|
71 |
|
72 /** |
|
73 * Reads the values from iCfgParameters and saves them to configuration file. |
|
74 * Drive letter is not specified. File will be searched from all drives and |
|
75 * if not found file will be crated to c-drive. |
|
76 * @param aCfgFilePath directory from where to search the configuration file |
|
77 * @param aCfgFileName configuration filename. |
|
78 */ |
|
79 IMPORT_C void SaveCfgL( const TDesC& aCfgFilePath, |
|
80 const TDesC& aCfgFileName ); |
|
81 |
|
82 /** |
|
83 * Gets a parameter value as descriptor. |
|
84 * @param aName name of the parameter whose value to get |
|
85 * @return Parameter value. |
|
86 */ |
|
87 IMPORT_C TPtrC8 GetParameterL( const TDesC8& aName ); |
|
88 |
|
89 /** |
|
90 * Gets a numerical parameter value as integer. |
|
91 * @param aName name of the parameter whose value to get |
|
92 * @return Parameter value. |
|
93 */ |
|
94 IMPORT_C TInt GetParameterIntL( const TDesC8& aName ); |
|
95 |
|
96 /** |
|
97 * Sets a parameter |
|
98 * @param aName name of the parameter whose value to set |
|
99 * @param aValue parameter value to set |
|
100 * @return error code. |
|
101 */ |
|
102 IMPORT_C TInt SetParameterL( const TDesC8& aName, const TDesC8& aValue ); |
|
103 |
|
104 /** |
|
105 * Removes a parameter |
|
106 * @param aName name of the parameter to remove |
|
107 * @return error code. |
|
108 */ |
|
109 IMPORT_C TInt RemoveParameterL( const TDesC8& aName ); |
|
110 |
|
111 private: |
|
112 |
|
113 /** |
|
114 * Constructor. |
|
115 */ |
|
116 CHtiCfg(); |
|
117 |
|
118 /** |
|
119 * Second phase construction. |
|
120 */ |
|
121 void ConstructL(); |
|
122 |
|
123 |
|
124 private: // data |
|
125 |
|
126 // array of key=value lines |
|
127 CDesC8ArrayFlat* iCfgParameters; |
|
128 |
|
129 }; |
|
130 |
|
131 #endif // __HTICFG_H__ |