traceservices/tracefw/ulogger/src/sysconfig/uloggersysconfig.cpp
changeset 0 08ec8eefde2f
child 23 26645d81f48d
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 "uloggersysconfig.h"
       
    18 #include "sysconfigimpl.h"
       
    19 #include "uloggershared.h"
       
    20 #include <e32base.h>		 
       
    21 
       
    22 
       
    23 namespace Ulogger
       
    24 {
       
    25 	
       
    26 /** Creates a sysconfig settings iterator object
       
    27 @return a pointer to the created object
       
    28 @leave KErrNoMemory if not enough memory available
       
    29 */
       
    30 EXPORT_C CConfigSettingsIter* CConfigSettingsIter::NewL()
       
    31 	{
       
    32 	CConfigSettingsIter* self=new (ELeave)CConfigSettingsIter();
       
    33 	CleanupStack::PushL(self);
       
    34 	self->iImpl=CConfigSettingsImpl::NewL();
       
    35 	CleanupStack::Pop();
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 /**
       
    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
       
    48 */	
       
    49 EXPORT_C TBool CConfigSettingsIter::Next(TPtrC8& aSetting,TPtrC8& aSettingValue)
       
    50 	{
       
    51 	return iImpl->Next(aSetting,aSettingValue);
       
    52 	}
       
    53 
       
    54 /**
       
    55 Reset the iterator to point to the first setting
       
    56 @post the iterator now points to the first setting
       
    57 */	
       
    58 EXPORT_C void CConfigSettingsIter::Reset()
       
    59 	{
       
    60 	return iImpl->Reset();
       
    61 	}
       
    62 
       
    63 /**
       
    64 Public Destructor
       
    65 */	
       
    66 EXPORT_C CConfigSettingsIter::~CConfigSettingsIter()
       
    67 	{
       
    68 	delete iImpl;
       
    69 	}
       
    70 
       
    71 CConfigSettingsIter::CConfigSettingsIter(){}
       
    72 
       
    73 ////////////////////////////////////////////////////////////////////////////
       
    74 
       
    75 /**
       
    76 Create a pointer to a CConfig object initialised with the current
       
    77 configuration settings for the system wide framework.
       
    78 
       
    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.
       
    86 
       
    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
       
    90 */
       
    91 EXPORT_C CConfig* CConfig::NewL(RHeap* aHeap,TFileName& aFilename)
       
    92 	{
       
    93 	CConfig* self= new(ELeave) CConfig();
       
    94 	CleanupStack::PushL(self);
       
    95 	self->iImpl=CConfigImpl::NewL(aHeap,aFilename);
       
    96 	CleanupStack::Pop();
       
    97 	return self;
       
    98 	}
       
    99 
       
   100 /**
       
   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.
       
   104 
       
   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.
       
   112 
       
   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
       
   116 */
       
   117 EXPORT_C CConfig* CConfig::NewLC(RHeap* aHeap,TFileName& aFilename)
       
   118 	{
       
   119 	CConfig* self=CConfig::NewL(aHeap,aFilename);
       
   120 	CleanupStack::PushL(self);
       
   121 	return self;
       
   122 	}
       
   123 
       
   124 
       
   125 /**
       
   126 Create and initialize a setting iterator to the list of output
       
   127 channels
       
   128 @param aIter reference to the setting iterator object
       
   129 @return KErrNone if no error
       
   130         Other system wide errors
       
   131 */
       
   132 EXPORT_C TInt CConfig::GetOutputPlugins(CConfigSettingsIter& aIter)
       
   133 	{
       
   134 	return iImpl->GetSection(KActiveSection,aIter);
       
   135 	}	
       
   136 
       
   137 
       
   138 EXPORT_C TInt CConfig::GetActivePlugins(CConfigSettingsIter& aIter)
       
   139 	{
       
   140 	return iImpl->GetSection(KActiveControlSection,aIter);
       
   141 	}	
       
   142 
       
   143 
       
   144 /**
       
   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
       
   149 */
       
   150 EXPORT_C TInt CConfig::GetActiveFilters(CConfigSettingsIter& aIter,TInt aFilter)
       
   151 	{
       
   152 	if(aFilter == 1)
       
   153 		return iImpl->GetSection(KPrimaryFilterSection,aIter);
       
   154 	else if(aFilter == 2)
       
   155 		return iImpl->GetSection(KSecondaryFilterSection,aIter);
       
   156 	else
       
   157 		return KErrNone;
       
   158 	}
       
   159 	
       
   160 EXPORT_C TInt CConfig::GetSectionValues(const TDesC8& aSectionName,CConfigSettingsIter& aIter)
       
   161 	{
       
   162 		return iImpl->GetSection(aSectionName,aIter);
       
   163 	}	
       
   164 	
       
   165 	
       
   166 /**
       
   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
       
   172 */
       
   173 EXPORT_C TInt CConfig::RemovePluginSettings(const TDesC8& aChanId)
       
   174 	{
       
   175 	//
       
   176 	// NEW CODE:
       
   177 	//
       
   178 
       
   179 	CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
       
   180 	CleanupStack::PushL(iter);
       
   181 
       
   182 	TInt ret = iImpl->GetSection(aChanId, *iter);
       
   183 
       
   184 	if (KErrNone == ret)
       
   185 		{
       
   186 		TPtrC8 key;
       
   187 		TPtrC8 dummy;
       
   188 
       
   189 		//remove all keys from section aChanId
       
   190 		while(iter->Next(key, dummy))
       
   191 			{
       
   192 			iImpl->RemoveKey(aChanId, key);
       
   193 			iter->Reset(); // otherwise we'd be skipping every 2nd element!
       
   194 			}
       
   195 
       
   196 		//remove section
       
   197 		iImpl->RemoveSection(aChanId);
       
   198 			//finally write into ini file
       
   199 			ret = iImpl->PersistIniFile();
       
   200 		}
       
   201 
       
   202 	CleanupStack::PopAndDestroy(iter);
       
   203 
       
   204 	return ret;
       
   205 	}
       
   206 
       
   207 /**
       
   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
       
   215 */
       
   216 EXPORT_C TInt CConfig::SetPluginSetting(const TDesC8& aChanId,const TDesC8& aSetting,const TDesC8& aValue)
       
   217 	{
       
   218 	TInt ret = iImpl->SetKeyValue(aChanId,aSetting,aValue);
       
   219 
       
   220 	if (KErrNone == ret)
       
   221 		{
       
   222 		//finally write into ini file
       
   223 		ret = iImpl->PersistIniFile();
       
   224 		}
       
   225 
       
   226 	return ret;
       
   227 	}
       
   228 
       
   229 /**
       
   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
       
   237 */
       
   238 EXPORT_C TInt CConfig::SetActiveOutputPlugin(const TDesC8& aMediaName)
       
   239 	{
       
   240 	//first check whether plugin already registered
       
   241 	TPtrC8 key;
       
   242 	TPtrC8 val;
       
   243 	TPtrC8 aMedia;
       
   244 	
       
   245 	TInt keyCount=0;
       
   246 	TInt ret=iImpl->CheckValueExist(KActiveSection,aMediaName,keyCount);
       
   247 	if(ret == KErrAlreadyExists)
       
   248 		return ret;
       
   249 	if ((ret==KErrNone && keyCount))
       
   250 	{			
       
   251 		CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
       
   252 		CleanupStack::PushL(iter);
       
   253 		GetOutputPlugins(*iter);
       
   254 		while(iter->Next(val,key))
       
   255 		{
       
   256 			ret=iImpl->RemoveKey(KActiveSection,val);	
       
   257 		}
       
   258 		CleanupStack::PopAndDestroy();		
       
   259 	}
       
   260 	
       
   261 	//get the internally generated name
       
   262 	TBuf8<15> internalName;
       
   263 	ret=iImpl->GenerateInternalKey(KActiveSection,internalName);
       
   264 	if (ret!=KErrNone)
       
   265 		return ret;		
       
   266 	
       
   267 	ret=iImpl->SetKeyValue(KActiveSection,internalName,aMediaName);
       
   268 	if (ret!=KErrNone)
       
   269 		return ret;
       
   270 	
       
   271 	ret= iImpl->GetPointerToKeyName(KActiveSection,internalName,aMedia);
       
   272 	if (ret!=KErrNone)
       
   273 		return ret;
       
   274 	
       
   275 	//finally write into ini file
       
   276 	return iImpl->PersistIniFile();
       
   277 	}
       
   278 
       
   279 
       
   280 EXPORT_C TInt CConfig::SetActiveInputPlugin(const TDesC8& aMediaName)
       
   281 	{
       
   282 	//first check whether plugin already registered
       
   283 	TPtrC8 key;
       
   284 	TPtrC8 val;
       
   285 	TPtrC8 aMedia;
       
   286 	
       
   287 	TInt keyCount=0;
       
   288 	TInt ret=iImpl->CheckValueExist(KActiveControlSection,aMediaName,keyCount);
       
   289 	if(ret == KErrAlreadyExists)
       
   290 		return ret;
       
   291 	if ((ret==KErrNone && keyCount))
       
   292 	{			
       
   293 		CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
       
   294 		CleanupStack::PushL(iter);
       
   295 		GetActivePlugins(*iter);
       
   296 		while(iter->Next(val,key))
       
   297 		{
       
   298 			ret=iImpl->RemoveKey(KActiveControlSection,val);	
       
   299 		}
       
   300 		CleanupStack::PopAndDestroy();		
       
   301 	}
       
   302 	
       
   303 	//get the internally generated name
       
   304 	TBuf8<15> internalName;
       
   305 	ret=iImpl->GenerateInternalKey(KActiveControlSection,internalName);
       
   306 	if (ret!=KErrNone)
       
   307 		return ret;		
       
   308 	
       
   309 	ret=iImpl->SetKeyValue(KActiveControlSection,internalName,aMediaName);
       
   310 	if (ret!=KErrNone)
       
   311 		return ret;
       
   312 	
       
   313 	ret= iImpl->GetPointerToKeyName(KActiveControlSection,internalName,aMedia);
       
   314 	if (ret!=KErrNone)
       
   315 		return ret;
       
   316 	
       
   317 	//finally write into ini file
       
   318 	return iImpl->PersistIniFile();
       
   319 	}
       
   320 
       
   321 
       
   322 EXPORT_C TInt CConfig::DeActivateOutputPlugin(const TDesC8& aMediaName)
       
   323 	{
       
   324 	TPtrC8 key;
       
   325 	TPtrC8 val;
       
   326 	TPtrC8 aMedia;
       
   327 	
       
   328 	TInt keyCount=0;
       
   329 	TInt ret=iImpl->CheckValueExist(KActiveSection,aMediaName,keyCount);
       
   330 	if(ret==KErrNone)
       
   331 		return KErrNotFound;
       
   332 	else if (ret==KErrAlreadyExists)
       
   333 		{			
       
   334 		CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
       
   335 		CleanupStack::PushL(iter);
       
   336 		User::LeaveIfError(GetOutputPlugins(*iter));
       
   337 		while(iter->Next(val,key))
       
   338 			{
       
   339 			ret=iImpl->RemoveKey(KActiveSection,val);	
       
   340 			}
       
   341 		CleanupStack::PopAndDestroy();		
       
   342 		}
       
   343 	if(ret!=KErrNone)
       
   344 		return ret;
       
   345 	return iImpl->PersistIniFile();
       
   346 	}
       
   347 
       
   348 
       
   349 EXPORT_C TInt CConfig::DeActivateInputPlugin(const TDesC8& aMediaName)
       
   350 	{
       
   351 	TPtrC8 key;
       
   352 	TPtrC8 val;
       
   353 	TPtrC8 aMedia;
       
   354 	
       
   355 	TInt keyCount=0;
       
   356 	TInt ret=iImpl->CheckValueExist(KActiveControlSection,aMediaName,keyCount);
       
   357 	if(ret==KErrNone)
       
   358 		return KErrNotFound;
       
   359 	else if (ret==KErrAlreadyExists)
       
   360 		{			
       
   361 		CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
       
   362 		CleanupStack::PushL(iter);
       
   363 		TInt a = GetActivePlugins(*iter);
       
   364 		if(a != KErrNone)
       
   365 			return a;
       
   366 		while(iter->Next(val,key))
       
   367 			{
       
   368 			ret=iImpl->RemoveKey(KActiveControlSection,val);	
       
   369 			}
       
   370 		CleanupStack::PopAndDestroy();		
       
   371 		}
       
   372 	if(ret!=KErrNone)
       
   373 		return ret;
       
   374 	return iImpl->PersistIniFile();
       
   375 	}
       
   376 
       
   377 
       
   378 EXPORT_C TInt CConfig::SetActiveFilter(const RArray<TUint32>&  aFilter, const TDesC8 &aSectionName)
       
   379 {
       
   380 	TInt error = KErrNone;  
       
   381 	
       
   382 	for(TInt i = 0; i < aFilter.Count(); i++)
       
   383 		{
       
   384 		//copy the filter as a string
       
   385 		HBufC8* filter = HBufC8::NewLC(32);
       
   386 		filter->Des().Num(aFilter[i]);
       
   387 		TPtr8 filterPtr(filter->Des());
       
   388 		TInt keycount = 0;
       
   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
       
   392 			{
       
   393 			TBuf8<15> internalName;
       
   394 			error = iImpl->GenerateInternalKey(aSectionName, internalName);
       
   395 			if(!error)
       
   396 				error = iImpl->SetKeyValue(aSectionName,internalName,filterPtr);
       
   397 			}
       
   398 		if(error == KErrAlreadyExists) //ignore these
       
   399 			error = KErrNone;
       
   400 		CleanupStack::PopAndDestroy();//filter			
       
   401 		if(error)
       
   402 			break;
       
   403 		}
       
   404 	//finally write into ini file
       
   405 	iImpl->PersistIniFile();
       
   406 	return error; 
       
   407 }
       
   408 
       
   409 EXPORT_C TInt CConfig:: SetTraceSettings(const TDesC8&  aValue, const TDesC8&  aSetting)
       
   410 {	
       
   411 	TPtrC8 aMedia;
       
   412 	TPtrC8 value;
       
   413 	//get the internally generated name
       
   414 	
       
   415 	TInt ret;
       
   416 	if(aSetting.Compare(KBuffer) == 0)	
       
   417 	{
       
   418 		ret=iImpl->SetKeyValue(KTrace,KBuffer,aValue);
       
   419 		if (ret!=KErrNone)
       
   420 			return ret;
       
   421 		
       
   422 		ret= iImpl->GetPointerToKeyName(KTrace,KBuffer,aMedia);
       
   423 		if (ret!=KErrNone)
       
   424 			return ret;	
       
   425 	}
       
   426 	else if(aSetting.Compare(KSecondaryGlobalFilter) == 0)		
       
   427 	{
       
   428 		iImpl->GetKeyValue(KTrace,KSecondaryGlobalFilter,value);
       
   429 		if(value.Compare(aValue)==0)
       
   430 			return KErrNone;
       
   431 		else
       
   432 			{
       
   433 			ret=iImpl->SetKeyValue(KTrace,KSecondaryGlobalFilter,aValue);
       
   434 			if (ret!=KErrNone)
       
   435 				return ret;
       
   436 		
       
   437 			ret= iImpl->GetPointerToKeyName(KTrace,KSecondaryGlobalFilter,aMedia);
       
   438 			if (ret!=KErrNone)
       
   439 				return ret;	
       
   440 			}
       
   441 	}
       
   442 	else if(aSetting.Compare(KDataNotification) == 0)		
       
   443 	{
       
   444 		ret=iImpl->SetKeyValue(KTrace,KDataNotification,aValue);
       
   445 		if (ret!=KErrNone)
       
   446 			return ret;
       
   447 		
       
   448 		ret= iImpl->GetPointerToKeyName(KTrace,KDataNotification,aMedia);
       
   449 		if (ret!=KErrNone)
       
   450 			return ret;	
       
   451 	}
       
   452 	else if(aSetting.Compare(KBufferMode) == 0)		
       
   453 	{
       
   454 		ret=iImpl->SetKeyValue(KTrace,KBufferMode,aValue);
       
   455 		if (ret!=KErrNone)
       
   456 			return ret;
       
   457 		
       
   458 		ret= iImpl->GetPointerToKeyName(KTrace,KBufferMode,aMedia);
       
   459 		if (ret!=KErrNone)
       
   460 			return ret;	
       
   461 	}
       
   462 	else 
       
   463 		return KErrNotFound;
       
   464 	
       
   465 	
       
   466 	//finally write into ini file
       
   467 	return iImpl->PersistIniFile();
       
   468 		
       
   469 }
       
   470 
       
   471 
       
   472 
       
   473 EXPORT_C TInt CConfig:: GetTraceSettings(CConfigSettingsIter& aIter)
       
   474 	{
       
   475 	return iImpl->GetSection(KTrace,aIter);
       
   476 	}	
       
   477 
       
   478 /**
       
   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
       
   485 */
       
   486 
       
   487 EXPORT_C TInt CConfig::RemoveActiveFilter(const RArray<TUint32>&  aFilter, const TInt &aFilterValue)
       
   488 {
       
   489 	TPtrC8 sectionName;
       
   490 	TPtrC8 val;
       
   491 	TPtrC8 key;
       
   492 	TInt ret = KErrNotFound;
       
   493 	
       
   494 	if(aFilterValue == 1)
       
   495 		sectionName.Set(KPrimaryFilterSection());
       
   496 	else if(aFilterValue == 2)
       
   497 		sectionName.Set(KSecondaryFilterSection());
       
   498 	
       
   499 	CConfigSettingsIter* iter = CConfigSettingsIter::NewL();
       
   500 	CleanupStack::PushL(iter);
       
   501 	GetActiveFilters(*iter, aFilterValue);
       
   502 	
       
   503 	for(TInt i=0; i<aFilter.Count();i++)
       
   504 		{
       
   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);
       
   510 		
       
   511 		while(iter->Next(val,key))
       
   512 		{
       
   513 			if (key.Compare(ptr)==0)
       
   514 				{
       
   515 				TInt tmpRet = iImpl->RemoveKey(sectionName,val);
       
   516 				if(ret != KErrNone)
       
   517 					ret = tmpRet;
       
   518 				break;
       
   519 				}				
       
   520 		}
       
   521 		iter->Reset();	
       
   522 				
       
   523 		}
       
   524 	CleanupStack::PopAndDestroy();	
       
   525 	//finally write into ini file
       
   526 	iImpl->PersistIniFile();
       
   527 	return ret;
       
   528 		
       
   529 }
       
   530 
       
   531 /**
       
   532 Public Destructor
       
   533 */
       
   534 EXPORT_C CConfig::~CConfig()
       
   535 	{
       
   536 	delete iImpl;	
       
   537 	}
       
   538 
       
   539 //default constructor
       
   540 CConfig::CConfig(){}
       
   541 
       
   542 }
       
   543