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