sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: sl@0: #include "uloggersysconfig.h" sl@0: #include "sysconfigimpl.h" sl@0: #include "uloggershared.h" sl@0: #include sl@0: sl@0: sl@0: namespace Ulogger sl@0: { sl@0: sl@0: /** Creates a sysconfig settings iterator object sl@0: @return a pointer to the created object sl@0: @leave KErrNoMemory if not enough memory available sl@0: */ sl@0: EXPORT_C CConfigSettingsIter* CConfigSettingsIter::NewL() sl@0: { sl@0: CConfigSettingsIter* self=new (ELeave)CConfigSettingsIter(); sl@0: CleanupStack::PushL(self); sl@0: self->iImpl=CConfigSettingsImpl::NewL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: A function to loop through the settings in the system config sl@0: and return the setting and its value through the passed in pointer sl@0: @param aSetting a pointer to the buffered setting name sl@0: @param aSettingValue a pointer to the buffered setting value sl@0: @return ETrue if there are more setting sl@0: EFalse if the iterator is at end of settings sl@0: Other system wide errors sl@0: @post the iterator now points to the next setting sl@0: */ sl@0: EXPORT_C TBool CConfigSettingsIter::Next(TPtrC8& aSetting,TPtrC8& aSettingValue) sl@0: { sl@0: return iImpl->Next(aSetting,aSettingValue); sl@0: } sl@0: sl@0: /** sl@0: Reset the iterator to point to the first setting sl@0: @post the iterator now points to the first setting sl@0: */ sl@0: EXPORT_C void CConfigSettingsIter::Reset() sl@0: { sl@0: iImpl->Reset(); sl@0: } sl@0: sl@0: /** sl@0: Public Destructor sl@0: */ sl@0: EXPORT_C CConfigSettingsIter::~CConfigSettingsIter() sl@0: { sl@0: delete iImpl; sl@0: } sl@0: sl@0: CConfigSettingsIter::CConfigSettingsIter(){} sl@0: sl@0: //////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: Create a pointer to a CConfig object initialised with the current sl@0: configuration settings for the system wide framework. sl@0: sl@0: Therefore it allocates and manages memory to store these settings. sl@0: If the client has a requirement to use a private heap then a reference to it sl@0: must be supplied should the notification funtionality be required sl@0: as this will result in the settings being reloaded and hence memory sl@0: will need to be reallocated. sl@0: Clients with this requirement will need to ensure heaps are switch to ensure sl@0: the CConfig object is itself allocated on the correct heap. sl@0: sl@0: @param aHeap a pointer to a private heap location sl@0: @param aFilename name of the configuration file with full path sl@0: @return a pointer to the new CConfig object sl@0: */ sl@0: EXPORT_C CConfig* CConfig::NewL(RHeap* aHeap,TFileName& aFilename) sl@0: { sl@0: CConfig* self= new(ELeave) CConfig(); sl@0: CleanupStack::PushL(self); sl@0: self->iImpl=CConfigImpl::NewL(aHeap,aFilename); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Create a pointer to a CConfig object initialised with the current sl@0: configuration settings for the system wide framework. Places object sl@0: on the Cleanup stack. sl@0: sl@0: Therefore it allocates and manages memory to store these settings. sl@0: If the client has a requirement to use a private heap then a reference to it sl@0: must be supplied should the notification funtionality be required sl@0: as this will result in the settings being reloaded and hence memory sl@0: will need to be reallocated. sl@0: Clients with this requirement will need to ensure heaps are switch to ensure sl@0: the CConfig object is itself allocated on the correct heap. sl@0: sl@0: @param aHeap a pointer to a private heap location sl@0: @param aFilename name of the configuration file with full path sl@0: @return a pointer to the new CConfig object sl@0: */ sl@0: EXPORT_C CConfig* CConfig::NewLC(RHeap* aHeap,TFileName& aFilename) sl@0: { sl@0: CConfig* self=CConfig::NewL(aHeap,aFilename); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Create and initialize a setting iterator to the list of output sl@0: channels sl@0: @param aIter reference to the setting iterator object sl@0: @return KErrNone if no error sl@0: Other system wide errors sl@0: */ sl@0: EXPORT_C TInt CConfig::GetOutputPlugins(CConfigSettingsIter& aIter) sl@0: { sl@0: return iImpl->GetSection(KActiveSection,aIter); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CConfig::GetActivePlugins(CConfigSettingsIter& aIter) sl@0: { sl@0: return iImpl->GetSection(KActiveControlSection,aIter); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Create and initialize a setting iterator to the list filters sl@0: @param aIter reference to the setting iterator object sl@0: @return KErrNone if no error sl@0: Other system wide errors sl@0: */ sl@0: EXPORT_C TInt CConfig::GetActiveFilters(CConfigSettingsIter& aIter,TInt aFilter) sl@0: { sl@0: if(aFilter == 1) sl@0: return iImpl->GetSection(KPrimaryFilterSection,aIter); sl@0: else if(aFilter == 2) sl@0: return iImpl->GetSection(KSecondaryFilterSection,aIter); sl@0: else sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C TInt CConfig::GetSectionValues(const TDesC8& aSectionName,CConfigSettingsIter& aIter) sl@0: { sl@0: return iImpl->GetSection(aSectionName,aIter); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Removes output channel setting section from the configuration file sl@0: @param aOutputChanId the plugin name which has to be removed sl@0: @return KErrNone if no error, sl@0: KErrNotFound if output channel setting section does not exist sl@0: Other System wide errors sl@0: */ sl@0: EXPORT_C TInt CConfig::RemovePluginSettings(const TDesC8& aChanId) sl@0: { sl@0: // sl@0: // NEW CODE: sl@0: // sl@0: sl@0: CConfigSettingsIter* iter = CConfigSettingsIter::NewL(); sl@0: CleanupStack::PushL(iter); sl@0: sl@0: TInt ret = iImpl->GetSection(aChanId, *iter); sl@0: sl@0: if (KErrNone == ret) sl@0: { sl@0: TPtrC8 key; sl@0: TPtrC8 dummy; sl@0: sl@0: //remove all keys from section aChanId sl@0: while(iter->Next(key, dummy)) sl@0: { sl@0: iImpl->RemoveKey(aChanId, key); sl@0: iter->Reset(); // otherwise we'd be skipping every 2nd element! sl@0: } sl@0: sl@0: //remove section sl@0: iImpl->RemoveSection(aChanId); sl@0: //finally write into ini file sl@0: ret = iImpl->PersistIniFile(); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(iter); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: Set a particular channel id settings, create one if settings does not exist yet sl@0: @param aOutputChanId the channel id sl@0: @param aSetting the channel setting to modify or add sl@0: @param aValue the value to assign to this setting sl@0: @return KErrNone if no error, sl@0: KErrNotFound if no matching output id sl@0: Other System wide errors sl@0: */ sl@0: EXPORT_C TInt CConfig::SetPluginSetting(const TDesC8& aChanId,const TDesC8& aSetting,const TDesC8& aValue) sl@0: { sl@0: TInt ret = iImpl->SetKeyValue(aChanId,aSetting,aValue); sl@0: sl@0: if (KErrNone == ret) sl@0: { sl@0: //finally write into ini file sl@0: ret = iImpl->PersistIniFile(); sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: Register Active Plugin sl@0: An internal active name that maps to this plugin is generated internally sl@0: @param aPluginName the plugin to be added to the system. sl@0: @param aMediaName pointer to the internal media name sl@0: @return KErrNone if no error sl@0: KErrAlreadyExists if the plugin name already exists sl@0: Other system wide errors sl@0: */ sl@0: EXPORT_C TInt CConfig::SetActiveOutputPlugin(const TDesC8& aMediaName) sl@0: { sl@0: //first check whether plugin already registered sl@0: TPtrC8 key; sl@0: TPtrC8 val; sl@0: TPtrC8 aMedia; sl@0: sl@0: TInt keyCount=0; sl@0: TInt ret=iImpl->CheckValueExist(KActiveSection,aMediaName,keyCount); sl@0: if(ret == KErrAlreadyExists) sl@0: return ret; sl@0: if ((ret==KErrNone && keyCount)) sl@0: { sl@0: CConfigSettingsIter* iter = CConfigSettingsIter::NewL(); sl@0: CleanupStack::PushL(iter); sl@0: GetOutputPlugins(*iter); sl@0: while(iter->Next(val,key)) sl@0: { sl@0: ret=iImpl->RemoveKey(KActiveSection,val); sl@0: } sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: //get the internally generated name sl@0: TBuf8<15> internalName; sl@0: ret=iImpl->GenerateInternalKey(KActiveSection,internalName); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: ret=iImpl->SetKeyValue(KActiveSection,internalName,aMediaName); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: ret= iImpl->GetPointerToKeyName(KActiveSection,internalName,aMedia); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: //finally write into ini file sl@0: return iImpl->PersistIniFile(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CConfig::SetActiveInputPlugin(const TDesC8& aMediaName) sl@0: { sl@0: //first check whether plugin already registered sl@0: TPtrC8 key; sl@0: TPtrC8 val; sl@0: TPtrC8 aMedia; sl@0: sl@0: TInt keyCount=0; sl@0: TInt ret=iImpl->CheckValueExist(KActiveControlSection,aMediaName,keyCount); sl@0: if(ret == KErrAlreadyExists) sl@0: return ret; sl@0: if ((ret==KErrNone && keyCount)) sl@0: { sl@0: CConfigSettingsIter* iter = CConfigSettingsIter::NewL(); sl@0: CleanupStack::PushL(iter); sl@0: GetActivePlugins(*iter); sl@0: while(iter->Next(val,key)) sl@0: { sl@0: ret=iImpl->RemoveKey(KActiveControlSection,val); sl@0: } sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: //get the internally generated name sl@0: TBuf8<15> internalName; sl@0: ret=iImpl->GenerateInternalKey(KActiveControlSection,internalName); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: ret=iImpl->SetKeyValue(KActiveControlSection,internalName,aMediaName); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: ret= iImpl->GetPointerToKeyName(KActiveControlSection,internalName,aMedia); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: //finally write into ini file sl@0: return iImpl->PersistIniFile(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CConfig::DeActivateOutputPlugin(const TDesC8& aMediaName) sl@0: { sl@0: TPtrC8 key; sl@0: TPtrC8 val; sl@0: TPtrC8 aMedia; sl@0: sl@0: TInt keyCount=0; sl@0: TInt ret=iImpl->CheckValueExist(KActiveSection,aMediaName,keyCount); sl@0: if(ret==KErrNone) sl@0: return KErrNotFound; sl@0: else if (ret==KErrAlreadyExists) sl@0: { sl@0: CConfigSettingsIter* iter = CConfigSettingsIter::NewL(); sl@0: CleanupStack::PushL(iter); sl@0: User::LeaveIfError(GetOutputPlugins(*iter)); sl@0: while(iter->Next(val,key)) sl@0: { sl@0: ret=iImpl->RemoveKey(KActiveSection,val); sl@0: } sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: if(ret!=KErrNone) sl@0: return ret; sl@0: return iImpl->PersistIniFile(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CConfig::DeActivateInputPlugin(const TDesC8& aMediaName) sl@0: { sl@0: TPtrC8 key; sl@0: TPtrC8 val; sl@0: TPtrC8 aMedia; sl@0: sl@0: TInt keyCount=0; sl@0: TInt ret=iImpl->CheckValueExist(KActiveControlSection,aMediaName,keyCount); sl@0: if(ret==KErrNone) sl@0: return KErrNotFound; sl@0: else if (ret==KErrAlreadyExists) sl@0: { sl@0: CConfigSettingsIter* iter = CConfigSettingsIter::NewL(); sl@0: CleanupStack::PushL(iter); sl@0: TInt a = GetActivePlugins(*iter); sl@0: if(a != KErrNone) sl@0: return a; sl@0: while(iter->Next(val,key)) sl@0: { sl@0: ret=iImpl->RemoveKey(KActiveControlSection,val); sl@0: } sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: if(ret!=KErrNone) sl@0: return ret; sl@0: return iImpl->PersistIniFile(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CConfig::SetActiveFilter(const RArray& aFilter, const TDesC8 &aSectionName) sl@0: { sl@0: TInt error = KErrNone; sl@0: sl@0: for(TInt i = 0; i < aFilter.Count(); i++) sl@0: { sl@0: //copy the filter as a string sl@0: HBufC8* filter = HBufC8::NewLC(32); sl@0: filter->Des().Num(aFilter[i]); sl@0: TPtr8 filterPtr(filter->Des()); sl@0: TInt keycount = 0; sl@0: //check if the section exists sl@0: error = iImpl->CheckValueExist(aSectionName, filterPtr, keycount); sl@0: if (!error)//either the section or the value didn't exist sl@0: { sl@0: TBuf8<15> internalName; sl@0: error = iImpl->GenerateInternalKey(aSectionName, internalName); sl@0: if(!error) sl@0: error = iImpl->SetKeyValue(aSectionName,internalName,filterPtr); sl@0: } sl@0: if(error == KErrAlreadyExists) //ignore these sl@0: error = KErrNone; sl@0: CleanupStack::PopAndDestroy();//filter sl@0: if(error) sl@0: break; sl@0: } sl@0: //finally write into ini file sl@0: iImpl->PersistIniFile(); sl@0: return error; sl@0: } sl@0: sl@0: EXPORT_C TInt CConfig:: SetTraceSettings(const TDesC8& aValue, const TDesC8& aSetting) sl@0: { sl@0: TPtrC8 aMedia; sl@0: TPtrC8 value; sl@0: //get the internally generated name sl@0: sl@0: TInt ret; sl@0: if(aSetting.Compare(KBuffer) == 0) sl@0: { sl@0: ret=iImpl->SetKeyValue(KTrace,KBuffer,aValue); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: ret= iImpl->GetPointerToKeyName(KTrace,KBuffer,aMedia); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: } sl@0: else if(aSetting.Compare(KSecondaryGlobalFilter) == 0) sl@0: { sl@0: iImpl->GetKeyValue(KTrace,KSecondaryGlobalFilter,value); sl@0: if(value.Compare(aValue)==0) sl@0: return KErrNone; sl@0: else sl@0: { sl@0: ret=iImpl->SetKeyValue(KTrace,KSecondaryGlobalFilter,aValue); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: ret= iImpl->GetPointerToKeyName(KTrace,KSecondaryGlobalFilter,aMedia); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: } sl@0: } sl@0: else if(aSetting.Compare(KDataNotification) == 0) sl@0: { sl@0: ret=iImpl->SetKeyValue(KTrace,KDataNotification,aValue); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: ret= iImpl->GetPointerToKeyName(KTrace,KDataNotification,aMedia); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: } sl@0: else if(aSetting.Compare(KBufferMode) == 0) sl@0: { sl@0: ret=iImpl->SetKeyValue(KTrace,KBufferMode,aValue); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: sl@0: ret= iImpl->GetPointerToKeyName(KTrace,KBufferMode,aMedia); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: } sl@0: else sl@0: return KErrNotFound; sl@0: sl@0: sl@0: //finally write into ini file sl@0: return iImpl->PersistIniFile(); sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt CConfig:: GetTraceSettings(CConfigSettingsIter& aIter) sl@0: { sl@0: return iImpl->GetSection(KTrace,aIter); sl@0: } sl@0: sl@0: /** sl@0: Remove a Filter based on its internal media name. It will fail if sl@0: any of this media is still referenced by one of the output channel sl@0: @param aMediaName the internal media name of the plugin to be removed sl@0: @return KErrNone if no error sl@0: KErrNotFound if no matching media name sl@0: KErrAccessDenied if still referenced by one of the output channel sl@0: */ sl@0: sl@0: EXPORT_C TInt CConfig::RemoveActiveFilter(const RArray& aFilter, const TInt &aFilterValue) sl@0: { sl@0: TPtrC8 sectionName; sl@0: TPtrC8 val; sl@0: TPtrC8 key; sl@0: TInt ret = KErrNotFound; sl@0: sl@0: if(aFilterValue == 1) sl@0: sectionName.Set(KPrimaryFilterSection()); sl@0: else if(aFilterValue == 2) sl@0: sectionName.Set(KSecondaryFilterSection()); sl@0: sl@0: CConfigSettingsIter* iter = CConfigSettingsIter::NewL(); sl@0: CleanupStack::PushL(iter); sl@0: GetActiveFilters(*iter, aFilterValue); sl@0: sl@0: for(TInt i=0; iGetSection(aSectionName,iter); sl@0: HBufC8* filter = HBufC8::NewLC(32); sl@0: filter->Des().Num(aFilter[i]); sl@0: TPtr8 ptr(filter->Des()); sl@0: CleanupStack::Pop(1); sl@0: sl@0: while(iter->Next(val,key)) sl@0: { sl@0: if (key.Compare(ptr)==0) sl@0: { sl@0: TInt tmpRet = iImpl->RemoveKey(sectionName,val); sl@0: if(ret != KErrNone) sl@0: ret = tmpRet; sl@0: break; sl@0: } sl@0: } sl@0: iter->Reset(); sl@0: sl@0: } sl@0: CleanupStack::PopAndDestroy(); sl@0: //finally write into ini file sl@0: iImpl->PersistIniFile(); sl@0: return ret; sl@0: sl@0: } sl@0: sl@0: /** sl@0: Public Destructor sl@0: */ sl@0: EXPORT_C CConfig::~CConfig() sl@0: { sl@0: delete iImpl; sl@0: } sl@0: sl@0: //default constructor sl@0: CConfig::CConfig(){} sl@0: sl@0: } sl@0: