|
1 // Copyright (c) 2004-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 // This file handles retrieving settings from the config file for the loopback test driver |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <e32std.h> |
|
25 #include <e32property.h> |
|
26 |
|
27 #include <cs_port.h> |
|
28 #include "SLOGGER.H" |
|
29 #include <d32comm.h> |
|
30 #include <c32comm.h> |
|
31 #include <e32hal.h> |
|
32 |
|
33 #include "LoopbackConfig.h" |
|
34 |
|
35 const TUint KStdDelimiter=','; // < Standard Delimiter for config file (a comma) |
|
36 // config element indicies for elements common to both packet and serial mode |
|
37 const TUint KFirstPortConfigElementIndex = 0; |
|
38 const TUint KSecondPortConfigElementIndex = 1; |
|
39 const TUint KDelayConfigElementIndex = 2; |
|
40 // config element indicies for packet mode |
|
41 const TUint KQueueLengthConfigElementIndex = 3; |
|
42 const TUint KPacketLengthConfigElementIndex = 4; |
|
43 // config element indicies for serial mode |
|
44 const TUint KTotalBufferSizeConfigElementIndex = 3; |
|
45 |
|
46 CLoopbackConfig* CLoopbackConfig::NewL() |
|
47 { |
|
48 CLoopbackConfig* me = new(ELeave) CLoopbackConfig(); |
|
49 CleanupStack::PushL(me); |
|
50 me->ConstructL(); |
|
51 CleanupStack::Pop(me); |
|
52 return me; |
|
53 } |
|
54 |
|
55 CLoopbackConfig::CLoopbackConfig() : iConfigItems(NULL) |
|
56 {} |
|
57 |
|
58 CLoopbackConfig::~CLoopbackConfig() |
|
59 { |
|
60 delete iConfigItems; |
|
61 } |
|
62 |
|
63 void CLoopbackConfig::ConstructL() |
|
64 { |
|
65 RFs fs; |
|
66 User::LeaveIfError(fs.Connect()); |
|
67 CTestConfig* configFile = CTestConfig::NewLC(fs, KConfigFileDir, KLoopbackConfigFilename); |
|
68 |
|
69 TBuf8<KMaxName> sectionName; |
|
70 TInt testNum = 0; |
|
71 CTestConfigSection* configSection = NULL; |
|
72 TBool foundSection = EFalse; |
|
73 if (KErrNone == GetTestNumber(testNum)) |
|
74 { |
|
75 sectionName.Format(KSectionNameFormat, testNum); |
|
76 configSection = configFile->Section(sectionName); |
|
77 if(configSection != NULL) |
|
78 { |
|
79 foundSection = ETrue; |
|
80 } |
|
81 } |
|
82 if (!foundSection) |
|
83 { |
|
84 // use the [Defaults] section |
|
85 configSection = configFile->Section(KScriptDefaults); |
|
86 } |
|
87 if(configSection == NULL) |
|
88 { |
|
89 CleanupStack::PopAndDestroy(configFile); |
|
90 return; |
|
91 } |
|
92 |
|
93 // if retrieving the port type fails, we leave it at the default |
|
94 iPortType = EPacketLoopbackPortType; |
|
95 const CTestConfigItem* item = NULL; |
|
96 item = configSection->Item(KSerialLoopbackPortType); |
|
97 if (item != NULL) |
|
98 { |
|
99 iPortType = ESerialLoopbackPortType; |
|
100 } |
|
101 |
|
102 TUint portCount = configSection->ItemCount(KPort); |
|
103 // CArrayFixFlat doesn't like a count of 0 for some reason |
|
104 if (portCount == 0) |
|
105 portCount = 1; |
|
106 iConfigItems = new(ELeave) CArrayFixFlat<TLoopbackConfigItem>(portCount); |
|
107 for (TInt i = 0; i < configSection->ItemCount(KPort); i++) |
|
108 { |
|
109 TLoopbackConfigItem newItem; |
|
110 const CTestConfigItem* item = configSection->Item(KPort, i); |
|
111 if(item == NULL) |
|
112 continue; |
|
113 else |
|
114 { |
|
115 TInt elementValue = 0; |
|
116 TInt ret = CTestConfig::GetElement(item->Value(), KStdDelimiter, |
|
117 KFirstPortConfigElementIndex, elementValue); |
|
118 if(ret == KErrNone) |
|
119 { |
|
120 newItem.iPortA = elementValue; |
|
121 } |
|
122 |
|
123 ret = CTestConfig::GetElement(item->Value(), KStdDelimiter, |
|
124 KSecondPortConfigElementIndex, elementValue); |
|
125 if(ret == KErrNone) |
|
126 { |
|
127 newItem.iPortB = elementValue; |
|
128 } |
|
129 |
|
130 ret = CTestConfig::GetElement(item->Value(), KStdDelimiter, KDelayConfigElementIndex, |
|
131 elementValue); |
|
132 if(ret == KErrNone) |
|
133 { |
|
134 newItem.iDelay = elementValue; |
|
135 } |
|
136 |
|
137 if (ESerialLoopbackPortType == iPortType) |
|
138 { |
|
139 ret = CTestConfig::GetElement(item->Value(), KStdDelimiter, |
|
140 KTotalBufferSizeConfigElementIndex, elementValue); |
|
141 if(ret == KErrNone) |
|
142 { |
|
143 newItem.iBufferSize = elementValue; |
|
144 } |
|
145 } |
|
146 else |
|
147 { |
|
148 ret = CTestConfig::GetElement(item->Value(), KStdDelimiter, |
|
149 KQueueLengthConfigElementIndex, elementValue); |
|
150 if(ret == KErrNone) |
|
151 { |
|
152 newItem.iQueueLength = elementValue; |
|
153 } |
|
154 |
|
155 ret = CTestConfig::GetElement(item->Value(),KStdDelimiter, |
|
156 KPacketLengthConfigElementIndex, elementValue); |
|
157 if(ret == KErrNone) |
|
158 { |
|
159 newItem.iPacketLength = elementValue; |
|
160 } |
|
161 } |
|
162 } |
|
163 iConfigItems->AppendL(newItem); |
|
164 } |
|
165 |
|
166 CleanupStack::PopAndDestroy(configFile); |
|
167 } |
|
168 |
|
169 /** |
|
170 @return The number of config items found |
|
171 */ |
|
172 TUint CLoopbackConfig::Count() const |
|
173 { |
|
174 return iConfigItems->Count(); |
|
175 } |
|
176 |
|
177 /** |
|
178 @return The configured port type - either packet or serial |
|
179 */ |
|
180 TPortType CLoopbackConfig::PortType() const |
|
181 { |
|
182 return iPortType; |
|
183 } |
|
184 |
|
185 /** |
|
186 Retrieves the settings from the config file for the given port |
|
187 |
|
188 @param aUnit The port number to retrieve the settings for |
|
189 @param aPort This method assigns the settings to this object |
|
190 |
|
191 @return KErrNone if the port corresponding to aUnit is found, KErrNotFound otherwise |
|
192 */ |
|
193 TInt CLoopbackConfig::GetPortSettings(TUint aUnit, TLoopbackConfigItem& aPortSettings) const |
|
194 { |
|
195 for (TInt i = 0; i < iConfigItems->Count(); i++) |
|
196 { |
|
197 if ((iConfigItems->At(i).iPortA == aUnit) || (iConfigItems->At(i).iPortB == aUnit)) |
|
198 { |
|
199 LOGTEXT2(_L8("Found port settings for unit = %d"), aUnit); |
|
200 aPortSettings = iConfigItems->At(i); |
|
201 return KErrNone; |
|
202 } |
|
203 } |
|
204 LOGTEXT2(_L8("Could not find port settings for unit = %d"), aUnit); |
|
205 return KErrNotFound; |
|
206 } |
|
207 |
|
208 TInt CLoopbackConfig::GetTestNumber(TInt& aTestNumber) |
|
209 /** |
|
210 * Retrieve the test number. |
|
211 * Use the test number corresonding the the publish and subsciber property KPSLoopbackCsyTestNumber |
|
212 */ |
|
213 { |
|
214 TInt ret0 = RProperty::Get(KUidPSPacketLoopbackCsyCategory, KPSLoopbackCsyTestNumber, |
|
215 aTestNumber); |
|
216 if (ret0 == KErrNone && aTestNumber >= 0) |
|
217 { |
|
218 LOGTEXT2(_L8("Got system property KPSLoopbackCsyTestNumber. testNumber=%d"), aTestNumber); |
|
219 return KErrNone; |
|
220 } |
|
221 return KErrNotFound; |
|
222 } |
|
223 |