24
|
1 |
// Copyright (c) 2008-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 |
//
|
|
15 |
|
|
16 |
#include "config.h"
|
|
17 |
|
|
18 |
TConfig::TConfig()
|
|
19 |
{
|
|
20 |
}
|
|
21 |
|
|
22 |
TBool TConfig::IsSupported(TInt aIpc)
|
|
23 |
{
|
|
24 |
TBool ret= ETrue;
|
|
25 |
|
|
26 |
RFs fs;
|
|
27 |
RFile file;
|
|
28 |
|
|
29 |
if( fs.Connect() == KErrNone)
|
|
30 |
{
|
|
31 |
if( file.Open(fs, KConfigFile, EFileRead) == KErrNone)
|
|
32 |
{
|
|
33 |
TBuf8<1000> buf;
|
|
34 |
TBuf<100> temp;
|
|
35 |
TInt bufLength=1000;
|
|
36 |
TBuf<100> ipc;
|
|
37 |
ipc.Num(aIpc);
|
|
38 |
|
|
39 |
TBool commentFlag=EFalse;
|
|
40 |
TBool valueFlag=EFalse;
|
|
41 |
TBool storeFlag=EFalse;
|
|
42 |
TBool valueRetrieved=EFalse;
|
|
43 |
|
|
44 |
|
|
45 |
while (bufLength==1000)
|
|
46 |
{
|
|
47 |
file.Read(buf,1000);
|
|
48 |
bufLength=buf.Length();
|
|
49 |
|
|
50 |
for (TInt i=0; i<bufLength; ++i)
|
|
51 |
{
|
|
52 |
if(buf[i]=='#')
|
|
53 |
{
|
|
54 |
commentFlag=ETrue;
|
|
55 |
}
|
|
56 |
else
|
|
57 |
{
|
|
58 |
if(!commentFlag)
|
|
59 |
{//read the content
|
|
60 |
if(buf[i]!=' ' && buf[i]!='\n' && buf[i]!='\r' && buf[i]!='=' && buf[i]!='\t')
|
|
61 |
{
|
|
62 |
temp.Append(buf[i]);
|
|
63 |
//end of the file and the file doesn't have a new line at the end
|
|
64 |
if((i==bufLength-1 && bufLength<1000) && (valueFlag))
|
|
65 |
valueRetrieved=ETrue;
|
|
66 |
}
|
|
67 |
else if ((valueFlag)&& buf[i]=='\r')
|
|
68 |
{
|
|
69 |
valueRetrieved=ETrue;
|
|
70 |
}
|
|
71 |
else
|
|
72 |
{
|
|
73 |
storeFlag=ETrue;
|
|
74 |
}
|
|
75 |
|
|
76 |
//storing a port names
|
|
77 |
if (storeFlag)
|
|
78 |
{
|
|
79 |
if(temp.CompareC(ipc) == 0) valueFlag = ETrue;
|
|
80 |
temp.Zero();
|
|
81 |
storeFlag=EFalse;
|
|
82 |
}
|
|
83 |
else
|
|
84 |
if(valueRetrieved)
|
|
85 |
{
|
|
86 |
temp.LowerCase();
|
|
87 |
if (temp.CompareC(_L("notsupported")) == 0)
|
|
88 |
{
|
|
89 |
file.Close();
|
|
90 |
fs.Close();
|
|
91 |
return EFalse;
|
|
92 |
}
|
|
93 |
else
|
|
94 |
{
|
|
95 |
file.Close();
|
|
96 |
fs.Close();
|
|
97 |
return ETrue;
|
|
98 |
}
|
|
99 |
}
|
|
100 |
}
|
|
101 |
else //skip the comment until \n
|
|
102 |
if(buf[i]=='\n')
|
|
103 |
{
|
|
104 |
commentFlag=EFalse;
|
|
105 |
}
|
|
106 |
}
|
|
107 |
}//for
|
|
108 |
}//while
|
|
109 |
}
|
|
110 |
}
|
|
111 |
|
|
112 |
file.Close();
|
|
113 |
fs.Close();
|
|
114 |
return ret;
|
|
115 |
}
|
|
116 |
|
|
117 |
TInt TConfig::SetSupportedValue(TInt aIpc, TBool aSupported)
|
|
118 |
{
|
|
119 |
TInt ret=KErrGeneral;
|
|
120 |
|
|
121 |
RFs fs;
|
|
122 |
RFile file;
|
|
123 |
|
|
124 |
if(fs.Connect() == KErrNone)
|
|
125 |
{
|
|
126 |
if( file.Replace(fs, KConfigFile, EFileWrite) == KErrNone)
|
|
127 |
{
|
|
128 |
// write the content
|
|
129 |
TBuf8<1000> buf;
|
|
130 |
_LIT8(KTemp, "%d ");
|
|
131 |
_LIT8(KSupported, "supported");
|
|
132 |
_LIT8(KNotSupported, "notsupported");
|
|
133 |
|
|
134 |
buf.Format(KTemp,aIpc);
|
|
135 |
if (aSupported)
|
|
136 |
{
|
|
137 |
buf.Append(KSupported);
|
|
138 |
}
|
|
139 |
else
|
|
140 |
{
|
|
141 |
buf.Append(KNotSupported);
|
|
142 |
}
|
|
143 |
ret = file.Write(buf);
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
file.Close();
|
|
148 |
fs.Close();
|
|
149 |
return ret;
|
|
150 |
}
|
|
151 |
|
|
152 |
TInt TConfig::Reset()
|
|
153 |
{
|
|
154 |
TInt ret=KErrGeneral;
|
|
155 |
RFs fs;
|
|
156 |
|
|
157 |
if(fs.Connect() == KErrNone)
|
|
158 |
{
|
|
159 |
ret = fs.Delete(KConfigFile);
|
|
160 |
}
|
|
161 |
|
|
162 |
fs.Close();
|
|
163 |
return ret;
|
|
164 |
}
|
|
165 |
|
|
166 |
/* static */
|
|
167 |
void TConfig::ResetThis(TAny* aThis)
|
|
168 |
{
|
|
169 |
(void)(static_cast<TConfig*>(aThis))->Reset();
|
|
170 |
}
|
|
171 |
|
|
172 |
void TConfig::PushL()
|
|
173 |
{
|
|
174 |
CleanupStack::PushL(TCleanupItem(ResetThis, this));
|
|
175 |
}
|
|
176 |
|