os/persistentdata/traceservices/tracefw/ulogger/src/sysconfig/configfilemanager.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/traceservices/tracefw/ulogger/src/sysconfig/configfilemanager.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,256 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +
1.20 +#include "uloggerconfigmanager.h"
1.21 +#include "uloggershared.h"
1.22 +#include <e32base.h>
1.23 +#include <f32file.h>
1.24 +
1.25 +namespace Ulogger
1.26 +{
1.27 +
1.28 +EXPORT_C CConfigFileManager* CConfigFileManager::NewL()
1.29 + {
1.30 + CConfigFileManager* self = new (ELeave) CConfigFileManager;
1.31 + CleanupStack::PushL(self);
1.32 + self->iConfig = NULL;
1.33 + TInt error = self->ConstructL();
1.34 + CleanupStack::Pop();
1.35 + if(error)
1.36 + {
1.37 + delete self;
1.38 + self = NULL;
1.39 + }
1.40 + return self;
1.41 + }
1.42 +
1.43 +TInt CConfigFileManager::ConstructL()
1.44 + {
1.45 + return InitializeFilesL();
1.46 + }
1.47 +
1.48 +EXPORT_C TInt CConfigFileManager::RefreshConfigFiles()
1.49 + {
1.50 + return InitializeFilesL();
1.51 + }
1.52 +
1.53 +TInt CConfigFileManager::InitializeFilesL()
1.54 + {
1.55 + //Load the respective configuration file
1.56 + TInt error = CheckIfFileExistsInPathL(KConfigFilename, KPublicConfigFilePath, iFilename);
1.57 + if (error == KErrNotFound || error == KErrPathNotFound)
1.58 + {
1.59 + error = CheckIfFileExistsInPathL(KConfigFilename, KPrivateConfigFilePath, iFilename);
1.60 + if((error != KErrNotFound) && (iFilename == KDefaultConfigFilePath))
1.61 + {
1.62 + error = CopyFileToSystemDriveL(iFilename);
1.63 + }
1.64 + }
1.65 + if(!error)
1.66 + {
1.67 + if(iConfig)
1.68 + delete iConfig;
1.69 + iConfig = CConfig::NewL(NULL, iFilename);
1.70 + }
1.71 + if(iConfig == NULL)
1.72 + error = KErrNotFound;
1.73 + return error;
1.74 + }
1.75 +
1.76 +TInt CConfigFileManager::CheckIfFileExistsInPathL(const TDesC& aFilename, const TDesC& aPath, TFileName& aFullFilePath)
1.77 + {
1.78 + RFs fs;
1.79 + TParse fileParse;
1.80 + User::LeaveIfError(fs.Connect());
1.81 + TFindFile findfile(fs);
1.82 + TInt error = findfile.FindByDir(aFilename,aPath);
1.83 + if(error == KErrNone) //file is found, now set the aFullFilePath to the full path including drive
1.84 + {
1.85 + fileParse.Set(findfile.File(),NULL,NULL);
1.86 + aFullFilePath.Zero();
1.87 + aFullFilePath.Append(fileParse.FullName());
1.88 + }
1.89 + fs.Close();
1.90 + return error;
1.91 + }
1.92 +
1.93 +/* Copy file to the System drives private path
1.94 + * if the drive exists otherwise
1.95 + * create the drive and copy the file*/
1.96 +TInt CConfigFileManager::CopyFileToSystemDriveL(TFileName &aFilePath)
1.97 + {
1.98 + TFileName fileName;
1.99 + TDriveName aSystemDrive;
1.100 + TDriveUnit driveunit(RFs::GetSystemDrive());
1.101 + aSystemDrive.Zero();
1.102 + aSystemDrive=driveunit.Name();
1.103 + fileName.Zero();
1.104 + fileName.Append(aSystemDrive);
1.105 + fileName.Append(KPrivateConfigFilePath);
1.106 +
1.107 + RFs fs;
1.108 + User::LeaveIfError(fs.Connect());
1.109 +
1.110 + TInt error= fs.MkDir(fileName);
1.111 + if(error==KErrNone || error== KErrAlreadyExists)
1.112 + {
1.113 + CFileMan* fMan = CFileMan::NewL(fs);
1.114 + CleanupStack::PushL(fMan);
1.115 + fileName.Append(KConfigFilename);
1.116 + User::LeaveIfError(fMan->Copy(KDefaultConfigFilePath, fileName, CFileMan::EOverWrite) );
1.117 + CleanupStack::PopAndDestroy(fMan);
1.118 + User::LeaveIfError(fs.SetAtt(fileName,0, KEntryAttReadOnly));
1.119 + }
1.120 + fs.Close();
1.121 + aFilePath.Zero();
1.122 + aFilePath.Append(fileName);
1.123 + return error;
1.124 + }
1.125 +
1.126 +
1.127 +EXPORT_C TInt CConfigFileManager::GetSectionValues(const TDesC8& aSectionName,CConfigSettingsIter& aIter)
1.128 + {
1.129 + TInt error = RefreshConfigFiles();
1.130 + if(!error)
1.131 + {
1.132 + error = iConfig->GetSectionValues(aSectionName, aIter);
1.133 + }
1.134 + return error;
1.135 + }
1.136 +
1.137 +EXPORT_C TInt CConfigFileManager::GetOutputPlugins(CConfigSettingsIter& aIter)
1.138 + {
1.139 + TInt error = RefreshConfigFiles();
1.140 + if(!error)
1.141 + {
1.142 + error = iConfig->GetOutputPlugins(aIter);
1.143 + }
1.144 + return error;
1.145 + }
1.146 +
1.147 +EXPORT_C TInt CConfigFileManager::RemovePluginSettings(const TDesC8& aOutputChanId)
1.148 + {
1.149 + TInt error = RefreshConfigFiles();
1.150 + if(!error)
1.151 + {
1.152 + error = iConfig->RemovePluginSettings(aOutputChanId);
1.153 + }
1.154 + return error;
1.155 + }
1.156 +EXPORT_C TInt CConfigFileManager::GetActiveFilters(CConfigSettingsIter& aIter,TInt aFilter)
1.157 + {
1.158 + TInt error = RefreshConfigFiles();
1.159 + if(!error)
1.160 + {
1.161 + error = iConfig->GetActiveFilters(aIter, aFilter);
1.162 + }
1.163 + return error;
1.164 + }
1.165 +
1.166 +EXPORT_C TInt CConfigFileManager::RemoveActiveFilter(const RArray<TUint32>& aFilter, const TInt &aFilterValue)
1.167 + {
1.168 + TInt error = RefreshConfigFiles();
1.169 + if(!error)
1.170 + {
1.171 + error = iConfig->RemoveActiveFilter(aFilter, aFilterValue);
1.172 + }
1.173 + return error;
1.174 + }
1.175 +//Get direct setting's value API
1.176 +EXPORT_C TInt CConfigFileManager::SetActiveFilter(const RArray<TUint32>& aFilter, const TDesC8 &aSectionName)
1.177 + {
1.178 + TInt error = RefreshConfigFiles();
1.179 + if(!error)
1.180 + {
1.181 + error = iConfig->SetActiveFilter(aFilter, aSectionName);
1.182 + }
1.183 + return error;
1.184 + }
1.185 +EXPORT_C TInt CConfigFileManager::SetTraceSettings(const TDesC8& aValue, const TDesC8& aSetting)
1.186 + {
1.187 + TInt error = RefreshConfigFiles();
1.188 + if(!error)
1.189 + {
1.190 + error = iConfig->SetTraceSettings(aValue, aSetting);
1.191 + }
1.192 + return error;
1.193 + }
1.194 +EXPORT_C TInt CConfigFileManager::SetPluginSetting(const TDesC8& aOutputChanId,
1.195 + const TDesC8& aSetting,
1.196 + const TDesC8& aValue)
1.197 + {
1.198 + TInt error = RefreshConfigFiles();
1.199 + if(!error)
1.200 + {
1.201 + error = iConfig->SetPluginSetting(aOutputChanId, aSetting, aValue);
1.202 + }
1.203 + return error;
1.204 + }
1.205 +EXPORT_C TInt CConfigFileManager::SetActiveOutputPlugin(const TDesC8& aMediaName)
1.206 + {
1.207 + TInt error = RefreshConfigFiles();
1.208 + if(!error)
1.209 + {
1.210 + error = iConfig->SetActiveOutputPlugin(aMediaName);
1.211 + }
1.212 + return error;
1.213 + }
1.214 +EXPORT_C TInt CConfigFileManager::SetActiveInputPlugin(const TDesC8& aMediaName)
1.215 + {
1.216 + TInt error = RefreshConfigFiles();
1.217 + if(!error)
1.218 + {
1.219 + error = iConfig->SetActiveInputPlugin(aMediaName);
1.220 + }
1.221 + return error;
1.222 + }
1.223 +EXPORT_C TInt CConfigFileManager::GetActiveInputPlugins(CConfigSettingsIter& aIter)
1.224 + {
1.225 + TInt error = RefreshConfigFiles();
1.226 + if(!error)
1.227 + {
1.228 + error = iConfig->GetActivePlugins(aIter);
1.229 + }
1.230 + return error;
1.231 + }
1.232 +EXPORT_C TInt CConfigFileManager::GetPluginSettings(CConfigSettingsIter& aIter)
1.233 + {
1.234 + TInt error = RefreshConfigFiles();
1.235 + if(!error)
1.236 + {
1.237 + error = iConfig->GetTraceSettings(aIter);
1.238 + }
1.239 + return error;
1.240 + }
1.241 +EXPORT_C TInt CConfigFileManager::DeActivateOutputPlugin(const TDesC8& aMediaName)
1.242 + {
1.243 + TInt error = RefreshConfigFiles();
1.244 + if(!error)
1.245 + {
1.246 + error = iConfig->DeActivateOutputPlugin(aMediaName);
1.247 + }
1.248 + return error;
1.249 + }
1.250 +EXPORT_C TInt CConfigFileManager::DeActivateInputPlugin(const TDesC8& aMediaName)
1.251 + {
1.252 + TInt error = RefreshConfigFiles();
1.253 + if(!error)
1.254 + {
1.255 + error = iConfig->DeActivateInputPlugin(aMediaName);
1.256 + }
1.257 + return error;
1.258 + }
1.259 +}//namespace