|
1 /* |
|
2 * Copyright (c) 2007-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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file CONFIGMANAGER.H |
|
21 @internalComponent |
|
22 @released |
|
23 */ |
|
24 #ifndef CONFIGMANAGER_H |
|
25 #define CONFIGMANAGER_H |
|
26 |
|
27 #pragma warning (disable: 4786) |
|
28 |
|
29 // System includes |
|
30 #include <istream> |
|
31 #include <list> |
|
32 #include <vector> |
|
33 #include <map> |
|
34 #include <exception> |
|
35 |
|
36 // User includes |
|
37 #include "symbiantypes.h" |
|
38 #include "parameterlist.h" |
|
39 |
|
40 |
|
41 // Structures referenced |
|
42 struct ConfigAttribute; |
|
43 |
|
44 const static int KVariableLanguage = 0x1000; |
|
45 const static int KVariableDrive = 0x1001; |
|
46 const static int KVariableDevSupLng = 0x1002; |
|
47 |
|
48 // Structures |
|
49 struct DriveAttributes |
|
50 { |
|
51 std::wstring iDir; |
|
52 bool iExternal; |
|
53 |
|
54 DriveAttributes() : iExternal(false) {}; |
|
55 }; |
|
56 |
|
57 typedef std::map< int /* drive letter */, DriveAttributes* > DrivesMap; |
|
58 |
|
59 /** |
|
60 * @publishedPartner |
|
61 * @released |
|
62 */ |
|
63 class ConfigManagerException |
|
64 { |
|
65 public: // Enumerations |
|
66 enum TType |
|
67 { |
|
68 ETypeKeywordNotSupported = 0, |
|
69 ETypeInvalidValueForKey, |
|
70 ETypeDuplicateDefinition, |
|
71 ETypeInvalidDirectory, |
|
72 ETypeDriveError |
|
73 }; |
|
74 |
|
75 public: |
|
76 inline ConfigManagerException( TType aType, const std::string& aKey, const std::string& aValue, int aLineNumber ) |
|
77 : iType( aType ), iKey( aKey ), iValue( aValue ), iLineNumber( aLineNumber ) |
|
78 { |
|
79 } |
|
80 |
|
81 inline ConfigManagerException( TType aType, const std::string& aValue ) |
|
82 : iType( aType ), iValue( aValue ), iLineNumber( 0 ) |
|
83 { |
|
84 } |
|
85 |
|
86 ~ConfigManagerException(); |
|
87 |
|
88 public: |
|
89 void Display() const; |
|
90 |
|
91 private: |
|
92 TType iType; |
|
93 std::string iKey; |
|
94 std::string iValue; |
|
95 int iLineNumber; |
|
96 }; |
|
97 |
|
98 /** |
|
99 * @internalComponent |
|
100 * @released |
|
101 */ |
|
102 class ConfigManager |
|
103 { |
|
104 public: // Constructors & destructor |
|
105 ConfigManager(const CParameterList& aParamList); |
|
106 ~ConfigManager(); |
|
107 |
|
108 public: // API |
|
109 void SetValue( TUint32 aKey, TUint32 aValue ); |
|
110 bool ValueExists( TUint32 aKey ) const; |
|
111 TUint32 ValueById( TUint32 aKey ) const; |
|
112 static std::string AttributeNameById( TUint32 aId ); |
|
113 std::wstring GetLocalDrivePath(int aDrive); |
|
114 bool IsTargetDrivePresent(int aDrive) const; |
|
115 bool IsTargetDriveExt(int aDrive) const; |
|
116 bool AddDrive(DriveAttributes* aDrive, const int aDriveLetter); |
|
117 std::vector<TInt>& GetDeviceSupportedLanguages(); |
|
118 void CheckAndAddDrive(const int aDriveLetter, const std::wstring& aDir, |
|
119 const bool aExternal = false); |
|
120 const DrivesMap& GetDrivesMap() const |
|
121 { return iDrives; } |
|
122 void AddMatchingSupportedLanguages(TInt aMatchingSupportedLangauges); |
|
123 std::vector<TInt>& GetMatchingSupportedLanguages(); |
|
124 |
|
125 private: // Internal methods |
|
126 void AddRomAndSystemDrives(const CParameterList& aParamList); |
|
127 void ReadFile( std::ifstream& aStream ); |
|
128 void ProcessLine( const std::string& aLine, int aLineNumber ); |
|
129 void ConvertLineData( const std::string& aKey, std::string& aValue, int aLineNumber ); |
|
130 bool AddDeviceSupportedLanguage (TInt langId); |
|
131 |
|
132 private: // Utility functions |
|
133 static const ConfigAttribute* AttributeByName( const std::string& aName ); |
|
134 static bool TryStringToNumeric( const std::string& aText, TUint32& aNumber ); |
|
135 static bool TryStringToBool( const std::string& aText, TUint32& aNumber ); |
|
136 static bool TryStringToYesNo( const std::string& aText, TUint32& aNumber ); |
|
137 static int ConvertToDriveAttributes( const std::string& aString, DriveAttributes* aDrive ); |
|
138 |
|
139 private: // Type definitions |
|
140 typedef std::map< TUint32 /* attribute id */, TUint32 /* attribute value */ > ConfigurationMap; |
|
141 std::vector<TInt> iDeviceSupportedLanguages; // Vector containing the list of device supported languages |
|
142 std::vector<TInt> iMatchingSupportedLanguages; // Vector containing the list of matching supported languages from the SIS files |
|
143 private: // Data members |
|
144 ConfigurationMap iValues; |
|
145 DrivesMap iDrives; |
|
146 }; |
|
147 |
|
148 #endif |