os/persistentdata/traceservices/tracefw/ulogger/src/sysconfig/uloggersysconfig.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include "uloggersysconfig.h"
18 #include "sysconfigimpl.h"
19 #include "uloggershared.h"
26 /** Creates a sysconfig settings iterator object
27 @return a pointer to the created object
28 @leave KErrNoMemory if not enough memory available
30 EXPORT_C CConfigSettingsIter* CConfigSettingsIter::NewL()
32 CConfigSettingsIter* self=new (ELeave)CConfigSettingsIter();
33 CleanupStack::PushL(self);
34 self->iImpl=CConfigSettingsImpl::NewL();
40 A function to loop through the settings in the system config
41 and return the setting and its value through the passed in pointer
42 @param aSetting a pointer to the buffered setting name
43 @param aSettingValue a pointer to the buffered setting value
44 @return ETrue if there are more setting
45 EFalse if the iterator is at end of settings
46 Other system wide errors
47 @post the iterator now points to the next setting
49 EXPORT_C TBool CConfigSettingsIter::Next(TPtrC8& aSetting,TPtrC8& aSettingValue)
51 return iImpl->Next(aSetting,aSettingValue);
55 Reset the iterator to point to the first setting
56 @post the iterator now points to the first setting
58 EXPORT_C void CConfigSettingsIter::Reset()
66 EXPORT_C CConfigSettingsIter::~CConfigSettingsIter()
71 CConfigSettingsIter::CConfigSettingsIter(){}
73 ////////////////////////////////////////////////////////////////////////////
76 Create a pointer to a CConfig object initialised with the current
77 configuration settings for the system wide framework.
79 Therefore it allocates and manages memory to store these settings.
80 If the client has a requirement to use a private heap then a reference to it
81 must be supplied should the notification funtionality be required
82 as this will result in the settings being reloaded and hence memory
83 will need to be reallocated.
84 Clients with this requirement will need to ensure heaps are switch to ensure
85 the CConfig object is itself allocated on the correct heap.
87 @param aHeap a pointer to a private heap location
88 @param aFilename name of the configuration file with full path
89 @return a pointer to the new CConfig object
91 EXPORT_C CConfig* CConfig::NewL(RHeap* aHeap,TFileName& aFilename)
93 CConfig* self= new(ELeave) CConfig();
94 CleanupStack::PushL(self);
95 self->iImpl=CConfigImpl::NewL(aHeap,aFilename);
101 Create a pointer to a CConfig object initialised with the current
102 configuration settings for the system wide framework. Places object
103 on the Cleanup stack.
105 Therefore it allocates and manages memory to store these settings.
106 If the client has a requirement to use a private heap then a reference to it
107 must be supplied should the notification funtionality be required
108 as this will result in the settings being reloaded and hence memory
109 will need to be reallocated.
110 Clients with this requirement will need to ensure heaps are switch to ensure
111 the CConfig object is itself allocated on the correct heap.
113 @param aHeap a pointer to a private heap location
114 @param aFilename name of the configuration file with full path
115 @return a pointer to the new CConfig object
117 EXPORT_C CConfig* CConfig::NewLC(RHeap* aHeap,TFileName& aFilename)
119 CConfig* self=CConfig::NewL(aHeap,aFilename);
120 CleanupStack::PushL(self);
126 Create and initialize a setting iterator to the list of output
128 @param aIter reference to the setting iterator object
129 @return KErrNone if no error
130 Other system wide errors
132 EXPORT_C TInt CConfig::GetOutputPlugins(CConfigSettingsIter& aIter)
134 return iImpl->GetSection(KActiveSection,aIter);
138 EXPORT_C TInt CConfig::GetActivePlugins(CConfigSettingsIter& aIter)
140 return iImpl->GetSection(KActiveControlSection,aIter);
145 Create and initialize a setting iterator to the list filters
146 @param aIter reference to the setting iterator object
147 @return KErrNone if no error
148 Other system wide errors
150 EXPORT_C TInt CConfig::GetActiveFilters(CConfigSettingsIter& aIter,TInt aFilter)
153 return iImpl->GetSection(KPrimaryFilterSection,aIter);
154 else if(aFilter == 2)
155 return iImpl->GetSection(KSecondaryFilterSection,aIter);
160 EXPORT_C TInt CConfig::GetSectionValues(const TDesC8& aSectionName,CConfigSettingsIter& aIter)
162 return iImpl->GetSection(aSectionName,aIter);
167 Removes output channel setting section from the configuration file
168 @param aOutputChanId the plugin name which has to be removed
169 @return KErrNone if no error,
170 KErrNotFound if output channel setting section does not exist
171 Other System wide errors
173 EXPORT_C TInt CConfig::RemovePluginSettings(const TDesC8& aChanId)
179 CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
180 CleanupStack::PushL(iter);
182 TInt ret = iImpl->GetSection(aChanId, *iter);
189 //remove all keys from section aChanId
190 while(iter->Next(key, dummy))
192 iImpl->RemoveKey(aChanId, key);
193 iter->Reset(); // otherwise we'd be skipping every 2nd element!
197 iImpl->RemoveSection(aChanId);
198 //finally write into ini file
199 ret = iImpl->PersistIniFile();
202 CleanupStack::PopAndDestroy(iter);
208 Set a particular channel id settings, create one if settings does not exist yet
209 @param aOutputChanId the channel id
210 @param aSetting the channel setting to modify or add
211 @param aValue the value to assign to this setting
212 @return KErrNone if no error,
213 KErrNotFound if no matching output id
214 Other System wide errors
216 EXPORT_C TInt CConfig::SetPluginSetting(const TDesC8& aChanId,const TDesC8& aSetting,const TDesC8& aValue)
218 TInt ret = iImpl->SetKeyValue(aChanId,aSetting,aValue);
222 //finally write into ini file
223 ret = iImpl->PersistIniFile();
230 Register Active Plugin
231 An internal active name that maps to this plugin is generated internally
232 @param aPluginName the plugin to be added to the system.
233 @param aMediaName pointer to the internal media name
234 @return KErrNone if no error
235 KErrAlreadyExists if the plugin name already exists
236 Other system wide errors
238 EXPORT_C TInt CConfig::SetActiveOutputPlugin(const TDesC8& aMediaName)
240 //first check whether plugin already registered
246 TInt ret=iImpl->CheckValueExist(KActiveSection,aMediaName,keyCount);
247 if(ret == KErrAlreadyExists)
249 if ((ret==KErrNone && keyCount))
251 CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
252 CleanupStack::PushL(iter);
253 GetOutputPlugins(*iter);
254 while(iter->Next(val,key))
256 ret=iImpl->RemoveKey(KActiveSection,val);
258 CleanupStack::PopAndDestroy();
261 //get the internally generated name
262 TBuf8<15> internalName;
263 ret=iImpl->GenerateInternalKey(KActiveSection,internalName);
267 ret=iImpl->SetKeyValue(KActiveSection,internalName,aMediaName);
271 ret= iImpl->GetPointerToKeyName(KActiveSection,internalName,aMedia);
275 //finally write into ini file
276 return iImpl->PersistIniFile();
280 EXPORT_C TInt CConfig::SetActiveInputPlugin(const TDesC8& aMediaName)
282 //first check whether plugin already registered
288 TInt ret=iImpl->CheckValueExist(KActiveControlSection,aMediaName,keyCount);
289 if(ret == KErrAlreadyExists)
291 if ((ret==KErrNone && keyCount))
293 CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
294 CleanupStack::PushL(iter);
295 GetActivePlugins(*iter);
296 while(iter->Next(val,key))
298 ret=iImpl->RemoveKey(KActiveControlSection,val);
300 CleanupStack::PopAndDestroy();
303 //get the internally generated name
304 TBuf8<15> internalName;
305 ret=iImpl->GenerateInternalKey(KActiveControlSection,internalName);
309 ret=iImpl->SetKeyValue(KActiveControlSection,internalName,aMediaName);
313 ret= iImpl->GetPointerToKeyName(KActiveControlSection,internalName,aMedia);
317 //finally write into ini file
318 return iImpl->PersistIniFile();
322 EXPORT_C TInt CConfig::DeActivateOutputPlugin(const TDesC8& aMediaName)
329 TInt ret=iImpl->CheckValueExist(KActiveSection,aMediaName,keyCount);
332 else if (ret==KErrAlreadyExists)
334 CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
335 CleanupStack::PushL(iter);
336 User::LeaveIfError(GetOutputPlugins(*iter));
337 while(iter->Next(val,key))
339 ret=iImpl->RemoveKey(KActiveSection,val);
341 CleanupStack::PopAndDestroy();
345 return iImpl->PersistIniFile();
349 EXPORT_C TInt CConfig::DeActivateInputPlugin(const TDesC8& aMediaName)
356 TInt ret=iImpl->CheckValueExist(KActiveControlSection,aMediaName,keyCount);
359 else if (ret==KErrAlreadyExists)
361 CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
362 CleanupStack::PushL(iter);
363 TInt a = GetActivePlugins(*iter);
366 while(iter->Next(val,key))
368 ret=iImpl->RemoveKey(KActiveControlSection,val);
370 CleanupStack::PopAndDestroy();
374 return iImpl->PersistIniFile();
378 EXPORT_C TInt CConfig::SetActiveFilter(const RArray<TUint32>& aFilter, const TDesC8 &aSectionName)
380 TInt error = KErrNone;
382 for(TInt i = 0; i < aFilter.Count(); i++)
384 //copy the filter as a string
385 HBufC8* filter = HBufC8::NewLC(32);
386 filter->Des().Num(aFilter[i]);
387 TPtr8 filterPtr(filter->Des());
389 //check if the section exists
390 error = iImpl->CheckValueExist(aSectionName, filterPtr, keycount);
391 if (!error)//either the section or the value didn't exist
393 TBuf8<15> internalName;
394 error = iImpl->GenerateInternalKey(aSectionName, internalName);
396 error = iImpl->SetKeyValue(aSectionName,internalName,filterPtr);
398 if(error == KErrAlreadyExists) //ignore these
400 CleanupStack::PopAndDestroy();//filter
404 //finally write into ini file
405 iImpl->PersistIniFile();
409 EXPORT_C TInt CConfig:: SetTraceSettings(const TDesC8& aValue, const TDesC8& aSetting)
413 //get the internally generated name
416 if(aSetting.Compare(KBuffer) == 0)
418 ret=iImpl->SetKeyValue(KTrace,KBuffer,aValue);
422 ret= iImpl->GetPointerToKeyName(KTrace,KBuffer,aMedia);
426 else if(aSetting.Compare(KSecondaryGlobalFilter) == 0)
428 iImpl->GetKeyValue(KTrace,KSecondaryGlobalFilter,value);
429 if(value.Compare(aValue)==0)
433 ret=iImpl->SetKeyValue(KTrace,KSecondaryGlobalFilter,aValue);
437 ret= iImpl->GetPointerToKeyName(KTrace,KSecondaryGlobalFilter,aMedia);
442 else if(aSetting.Compare(KDataNotification) == 0)
444 ret=iImpl->SetKeyValue(KTrace,KDataNotification,aValue);
448 ret= iImpl->GetPointerToKeyName(KTrace,KDataNotification,aMedia);
452 else if(aSetting.Compare(KBufferMode) == 0)
454 ret=iImpl->SetKeyValue(KTrace,KBufferMode,aValue);
458 ret= iImpl->GetPointerToKeyName(KTrace,KBufferMode,aMedia);
466 //finally write into ini file
467 return iImpl->PersistIniFile();
473 EXPORT_C TInt CConfig:: GetTraceSettings(CConfigSettingsIter& aIter)
475 return iImpl->GetSection(KTrace,aIter);
479 Remove a Filter based on its internal media name. It will fail if
480 any of this media is still referenced by one of the output channel
481 @param aMediaName the internal media name of the plugin to be removed
482 @return KErrNone if no error
483 KErrNotFound if no matching media name
484 KErrAccessDenied if still referenced by one of the output channel
487 EXPORT_C TInt CConfig::RemoveActiveFilter(const RArray<TUint32>& aFilter, const TInt &aFilterValue)
492 TInt ret = KErrNotFound;
494 if(aFilterValue == 1)
495 sectionName.Set(KPrimaryFilterSection());
496 else if(aFilterValue == 2)
497 sectionName.Set(KSecondaryFilterSection());
499 CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
500 CleanupStack::PushL(iter);
501 GetActiveFilters(*iter, aFilterValue);
503 for(TInt i=0; i<aFilter.Count();i++)
505 //ret = iImpl->GetSection(aSectionName,iter);
506 HBufC8* filter = HBufC8::NewLC(32);
507 filter->Des().Num(aFilter[i]);
508 TPtr8 ptr(filter->Des());
509 CleanupStack::Pop(1);
511 while(iter->Next(val,key))
513 if (key.Compare(ptr)==0)
515 TInt tmpRet = iImpl->RemoveKey(sectionName,val);
524 CleanupStack::PopAndDestroy();
525 //finally write into ini file
526 iImpl->PersistIniFile();
534 EXPORT_C CConfig::~CConfig()
539 //default constructor