sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
|
sl@0
|
17 |
#include "uloggerconfigmanager.h"
|
sl@0
|
18 |
#include "uloggershared.h"
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include <f32file.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
namespace Ulogger
|
sl@0
|
23 |
{
|
sl@0
|
24 |
|
sl@0
|
25 |
EXPORT_C CConfigFileManager* CConfigFileManager::NewL()
|
sl@0
|
26 |
{
|
sl@0
|
27 |
CConfigFileManager* self = new (ELeave) CConfigFileManager;
|
sl@0
|
28 |
CleanupStack::PushL(self);
|
sl@0
|
29 |
self->iConfig = NULL;
|
sl@0
|
30 |
TInt error = self->ConstructL();
|
sl@0
|
31 |
CleanupStack::Pop();
|
sl@0
|
32 |
if(error)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
delete self;
|
sl@0
|
35 |
self = NULL;
|
sl@0
|
36 |
}
|
sl@0
|
37 |
return self;
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
TInt CConfigFileManager::ConstructL()
|
sl@0
|
41 |
{
|
sl@0
|
42 |
return InitializeFilesL();
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
EXPORT_C TInt CConfigFileManager::RefreshConfigFiles()
|
sl@0
|
46 |
{
|
sl@0
|
47 |
return InitializeFilesL();
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
TInt CConfigFileManager::InitializeFilesL()
|
sl@0
|
51 |
{
|
sl@0
|
52 |
//Load the respective configuration file
|
sl@0
|
53 |
TInt error = CheckIfFileExistsInPathL(KConfigFilename, KPublicConfigFilePath, iFilename);
|
sl@0
|
54 |
if (error == KErrNotFound || error == KErrPathNotFound)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
error = CheckIfFileExistsInPathL(KConfigFilename, KPrivateConfigFilePath, iFilename);
|
sl@0
|
57 |
if((error != KErrNotFound) && (iFilename == KDefaultConfigFilePath))
|
sl@0
|
58 |
{
|
sl@0
|
59 |
error = CopyFileToSystemDriveL(iFilename);
|
sl@0
|
60 |
}
|
sl@0
|
61 |
}
|
sl@0
|
62 |
if(!error)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
if(iConfig)
|
sl@0
|
65 |
delete iConfig;
|
sl@0
|
66 |
iConfig = CConfig::NewL(NULL, iFilename);
|
sl@0
|
67 |
}
|
sl@0
|
68 |
if(iConfig == NULL)
|
sl@0
|
69 |
error = KErrNotFound;
|
sl@0
|
70 |
return error;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
TInt CConfigFileManager::CheckIfFileExistsInPathL(const TDesC& aFilename, const TDesC& aPath, TFileName& aFullFilePath)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
RFs fs;
|
sl@0
|
76 |
TParse fileParse;
|
sl@0
|
77 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
78 |
TFindFile findfile(fs);
|
sl@0
|
79 |
TInt error = findfile.FindByDir(aFilename,aPath);
|
sl@0
|
80 |
if(error == KErrNone) //file is found, now set the aFullFilePath to the full path including drive
|
sl@0
|
81 |
{
|
sl@0
|
82 |
fileParse.Set(findfile.File(),NULL,NULL);
|
sl@0
|
83 |
aFullFilePath.Zero();
|
sl@0
|
84 |
aFullFilePath.Append(fileParse.FullName());
|
sl@0
|
85 |
}
|
sl@0
|
86 |
fs.Close();
|
sl@0
|
87 |
return error;
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
/* Copy file to the System drives private path
|
sl@0
|
91 |
* if the drive exists otherwise
|
sl@0
|
92 |
* create the drive and copy the file*/
|
sl@0
|
93 |
TInt CConfigFileManager::CopyFileToSystemDriveL(TFileName &aFilePath)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
TFileName fileName;
|
sl@0
|
96 |
TDriveName aSystemDrive;
|
sl@0
|
97 |
TDriveUnit driveunit(RFs::GetSystemDrive());
|
sl@0
|
98 |
aSystemDrive.Zero();
|
sl@0
|
99 |
aSystemDrive=driveunit.Name();
|
sl@0
|
100 |
fileName.Zero();
|
sl@0
|
101 |
fileName.Append(aSystemDrive);
|
sl@0
|
102 |
fileName.Append(KPrivateConfigFilePath);
|
sl@0
|
103 |
|
sl@0
|
104 |
RFs fs;
|
sl@0
|
105 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
106 |
|
sl@0
|
107 |
TInt error= fs.MkDir(fileName);
|
sl@0
|
108 |
if(error==KErrNone || error== KErrAlreadyExists)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
CFileMan* fMan = CFileMan::NewL(fs);
|
sl@0
|
111 |
CleanupStack::PushL(fMan);
|
sl@0
|
112 |
fileName.Append(KConfigFilename);
|
sl@0
|
113 |
User::LeaveIfError(fMan->Copy(KDefaultConfigFilePath, fileName, CFileMan::EOverWrite) );
|
sl@0
|
114 |
CleanupStack::PopAndDestroy(fMan);
|
sl@0
|
115 |
User::LeaveIfError(fs.SetAtt(fileName,0, KEntryAttReadOnly));
|
sl@0
|
116 |
}
|
sl@0
|
117 |
fs.Close();
|
sl@0
|
118 |
aFilePath.Zero();
|
sl@0
|
119 |
aFilePath.Append(fileName);
|
sl@0
|
120 |
return error;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
|
sl@0
|
124 |
EXPORT_C TInt CConfigFileManager::GetSectionValues(const TDesC8& aSectionName,CConfigSettingsIter& aIter)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
TInt error = RefreshConfigFiles();
|
sl@0
|
127 |
if(!error)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
error = iConfig->GetSectionValues(aSectionName, aIter);
|
sl@0
|
130 |
}
|
sl@0
|
131 |
return error;
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
EXPORT_C TInt CConfigFileManager::GetOutputPlugins(CConfigSettingsIter& aIter)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
TInt error = RefreshConfigFiles();
|
sl@0
|
137 |
if(!error)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
error = iConfig->GetOutputPlugins(aIter);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
return error;
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
EXPORT_C TInt CConfigFileManager::RemovePluginSettings(const TDesC8& aOutputChanId)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
TInt error = RefreshConfigFiles();
|
sl@0
|
147 |
if(!error)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
error = iConfig->RemovePluginSettings(aOutputChanId);
|
sl@0
|
150 |
}
|
sl@0
|
151 |
return error;
|
sl@0
|
152 |
}
|
sl@0
|
153 |
EXPORT_C TInt CConfigFileManager::GetActiveFilters(CConfigSettingsIter& aIter,TInt aFilter)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
TInt error = RefreshConfigFiles();
|
sl@0
|
156 |
if(!error)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
error = iConfig->GetActiveFilters(aIter, aFilter);
|
sl@0
|
159 |
}
|
sl@0
|
160 |
return error;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
EXPORT_C TInt CConfigFileManager::RemoveActiveFilter(const RArray<TUint32>& aFilter, const TInt &aFilterValue)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
TInt error = RefreshConfigFiles();
|
sl@0
|
166 |
if(!error)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
error = iConfig->RemoveActiveFilter(aFilter, aFilterValue);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
return error;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
//Get direct setting's value API
|
sl@0
|
173 |
EXPORT_C TInt CConfigFileManager::SetActiveFilter(const RArray<TUint32>& aFilter, const TDesC8 &aSectionName)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
TInt error = RefreshConfigFiles();
|
sl@0
|
176 |
if(!error)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
error = iConfig->SetActiveFilter(aFilter, aSectionName);
|
sl@0
|
179 |
}
|
sl@0
|
180 |
return error;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
EXPORT_C TInt CConfigFileManager::SetTraceSettings(const TDesC8& aValue, const TDesC8& aSetting)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
TInt error = RefreshConfigFiles();
|
sl@0
|
185 |
if(!error)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
error = iConfig->SetTraceSettings(aValue, aSetting);
|
sl@0
|
188 |
}
|
sl@0
|
189 |
return error;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
EXPORT_C TInt CConfigFileManager::SetPluginSetting(const TDesC8& aOutputChanId,
|
sl@0
|
192 |
const TDesC8& aSetting,
|
sl@0
|
193 |
const TDesC8& aValue)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
TInt error = RefreshConfigFiles();
|
sl@0
|
196 |
if(!error)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
error = iConfig->SetPluginSetting(aOutputChanId, aSetting, aValue);
|
sl@0
|
199 |
}
|
sl@0
|
200 |
return error;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
EXPORT_C TInt CConfigFileManager::SetActiveOutputPlugin(const TDesC8& aMediaName)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
TInt error = RefreshConfigFiles();
|
sl@0
|
205 |
if(!error)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
error = iConfig->SetActiveOutputPlugin(aMediaName);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
return error;
|
sl@0
|
210 |
}
|
sl@0
|
211 |
EXPORT_C TInt CConfigFileManager::SetActiveInputPlugin(const TDesC8& aMediaName)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
TInt error = RefreshConfigFiles();
|
sl@0
|
214 |
if(!error)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
error = iConfig->SetActiveInputPlugin(aMediaName);
|
sl@0
|
217 |
}
|
sl@0
|
218 |
return error;
|
sl@0
|
219 |
}
|
sl@0
|
220 |
EXPORT_C TInt CConfigFileManager::GetActiveInputPlugins(CConfigSettingsIter& aIter)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
TInt error = RefreshConfigFiles();
|
sl@0
|
223 |
if(!error)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
error = iConfig->GetActivePlugins(aIter);
|
sl@0
|
226 |
}
|
sl@0
|
227 |
return error;
|
sl@0
|
228 |
}
|
sl@0
|
229 |
EXPORT_C TInt CConfigFileManager::GetPluginSettings(CConfigSettingsIter& aIter)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
TInt error = RefreshConfigFiles();
|
sl@0
|
232 |
if(!error)
|
sl@0
|
233 |
{
|
sl@0
|
234 |
error = iConfig->GetTraceSettings(aIter);
|
sl@0
|
235 |
}
|
sl@0
|
236 |
return error;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
EXPORT_C TInt CConfigFileManager::DeActivateOutputPlugin(const TDesC8& aMediaName)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
TInt error = RefreshConfigFiles();
|
sl@0
|
241 |
if(!error)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
error = iConfig->DeActivateOutputPlugin(aMediaName);
|
sl@0
|
244 |
}
|
sl@0
|
245 |
return error;
|
sl@0
|
246 |
}
|
sl@0
|
247 |
EXPORT_C TInt CConfigFileManager::DeActivateInputPlugin(const TDesC8& aMediaName)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
TInt error = RefreshConfigFiles();
|
sl@0
|
250 |
if(!error)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
error = iConfig->DeActivateInputPlugin(aMediaName);
|
sl@0
|
253 |
}
|
sl@0
|
254 |
return error;
|
sl@0
|
255 |
}
|
sl@0
|
256 |
}//namespace
|