os/persistentdata/traceservices/tracefw/ulogger/src/uloggerserver/uloggerserver.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/traceservices/tracefw/ulogger/src/uloggerserver/uloggerserver.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2133 @@
     1.4 +// Copyright (c) 2007-2010 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 +#include <e32const.h>
    1.20 +#include <e32btrace.h>
    1.21 +#include <f32file.h>
    1.22 +#include "uloggerserver.h"
    1.23 +#include "uloggersession.h"
    1.24 +#include "uloggerclient.h"
    1.25 +#include "uloggerplugin.h"
    1.26 +#include "uloggershared.h"
    1.27 +#include "uloggerdatatypes.h"
    1.28 +#include "inputdata.h"
    1.29 +#include "uloggercommands.h"
    1.30 +
    1.31 +#if defined(__LIGHTLOGGER_ENABLED)
    1.32 +#include "lightlogger.h" 
    1.33 +#endif
    1.34 +
    1.35 +
    1.36 +namespace Ulogger {
    1.37 +
    1.38 +
    1.39 +/*Default constructor*/
    1.40 +CULoggerServer::CULoggerServer(TInt aPriority)
    1.41 +: CServer2( aPriority )
    1.42 +
    1.43 +{
    1.44 +	iIsBooting = ETrue;
    1.45 +	iConfigManager = NULL;
    1.46 +	iDataWatcher = NULL;
    1.47 +	iOutputFramework = NULL;
    1.48 +	iInputFramework = NULL;
    1.49 +	iPluginAllocator = NULL;
    1.50 +}
    1.51 +
    1.52 +
    1.53 +/** Destructor will be called before re-starting
    1.54 +*/
    1.55 +CULoggerServer::~CULoggerServer()
    1.56 +{
    1.57 +	delete iConfigManager;
    1.58 +	delete iOutputFramework;
    1.59 +	delete iInputFramework;
    1.60 +	delete iPluginAllocator;
    1.61 +	iPluginArray.ResetAndDestroy();
    1.62 +	iPluginArray.Close();
    1.63 +    if(iDataWatcher)
    1.64 +    	{
    1.65 +    	iDataWatcher->Cancel();
    1.66 +    	delete iDataWatcher; 
    1.67 +    	}
    1.68 +}
    1.69 +
    1.70 +/** Static Factory Construction 
    1.71 +@return a pointer to the created object
    1.72 +@leave KErrNoMemory if not enough memory available
    1.73 +*/
    1.74 +CULoggerServer* CULoggerServer::NewLC(TInt aPriority)
    1.75 +{
    1.76 +	CULoggerServer* self = new (ELeave) CULoggerServer( aPriority );
    1.77 +	CleanupStack::PushL( self );
    1.78 +	self->ConstructL();
    1.79 +
    1.80 +	return self;
    1.81 +}
    1.82 +
    1.83 +/**
    1.84 +Create and install new Framework & Active Scheduler
    1.85 +*/
    1.86 +void CULoggerServer::ConstructL()
    1.87 +{
    1.88 +	iRunAsService = EFalse; // Not used yet, to be used for run-as-service functionality
    1.89 +	iBufferSize = KMaxBufferSize;
    1.90 +	iBtraceOpen = EFalse;
    1.91 +	iDataNotification = 0;
    1.92 +
    1.93 +	StartL( KServerName );	
    1.94 +	iConfigManager = CConfigFileManager::NewL();
    1.95 +
    1.96 +}
    1.97 +
    1.98 +
    1.99 +/**
   1.100 +Create a new server session. 
   1.101 +@note Called by kernel after client's thread use any of the macros for the first time.
   1.102 +*/
   1.103 +CSession2* CULoggerServer::NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const
   1.104 +{
   1.105 + 	TVersion v(KULoggerSrvMajorVersionNumber,KULoggerSrvMinorVersionNumber,KULoggerSrvBuildVersionNumber);
   1.106 +    if (!User::QueryVersionSupported(v,aVersion))
   1.107 +         User::Leave(KErrNotSupported);
   1.108 +
   1.109 +	RThread client;
   1.110 +	aMessage.Client(client);
   1.111 +	return CULoggerSession::NewL( client, *const_cast<CULoggerServer*>(this) );
   1.112 +}
   1.113 +
   1.114 +
   1.115 +/*Increment session counter*/
   1.116 +void CULoggerServer::IncrementSessions()
   1.117 +{	
   1.118 +	++iSessionCounter;
   1.119 +}
   1.120 +
   1.121 +/*Decrement session counter*/
   1.122 +void CULoggerServer::DecrementSessions()
   1.123 +	{
   1.124 +	if(--iSessionCounter <= 0)
   1.125 +		{
   1.126 +		if (!iBtraceOpen)
   1.127 +			ShutDownServer();
   1.128 +
   1.129 +//
   1.130 +// // Replace above if-statement with following to implement run-as-service functionality
   1.131 +//
   1.132 +//		if((!iBtraceOpen) && (!iRunAsService))
   1.133 +//			ShutDownServer();
   1.134 +//
   1.135 +
   1.136 +		}
   1.137 +	}
   1.138 +
   1.139 +/*!
   1.140 +Shuts down the server
   1.141 +*/
   1.142 +void CULoggerServer::ShutDownServer()
   1.143 +{
   1.144 +	CActiveScheduler::Stop();
   1.145 +}//</ShutDownServer>
   1.146 +
   1.147 +
   1.148 +
   1.149 +
   1.150 +/*!
   1.151 +Return the error value
   1.152 +*/
   1.153 +TInt CULoggerServer::RunError(TInt aError)
   1.154 +{
   1.155 +	Message().Complete(aError);
   1.156 +	ReStart();
   1.157 +
   1.158 +	return KErrNone;
   1.159 +}
   1.160 +
   1.161 +
   1.162 +
   1.163 +
   1.164 +void CULoggerServer::PanicServer(TULoggerSrvPanics aPanic)
   1.165 +{
   1.166 +	User::Panic(KServerName, aPanic);
   1.167 +}//</PanicServer>
   1.168 +
   1.169 +
   1.170 +
   1.171 +/*!
   1.172 +*/
   1.173 +void CULoggerServer::PanicClient(const RMessage2& aMessage, TULoggerSrvPanics aPanic)
   1.174 +{
   1.175 +	aMessage.Panic( KServerName, aPanic );
   1.176 +}//</PanicClient>
   1.177 +
   1.178 +
   1.179 +
   1.180 +
   1.181 +////////////////////////////////////////////////////////////////////////////////////////////////////////////
   1.182 +/**
   1.183 +ServerL
   1.184 +@Installs the active scheduler
   1.185 +@Opens the semaphore
   1.186 +*/
   1.187 +TInt CULoggerServer::StartServerL()
   1.188 +{
   1.189 +	#if defined(__LIGHTLOGGER_ENABLED)
   1.190 +	__CREATE_LOG(EFalse)
   1.191 +	__HIRES_RESOLUTION
   1.192 +	#endif	
   1.193 +	
   1.194 +    CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler();
   1.195 +    CleanupStack::PushL(activeScheduler) ;
   1.196 +    CActiveScheduler::Install(activeScheduler);
   1.197 +    CULoggerServer* server = NULL;
   1.198 +	TInt servererr = KErrNone;
   1.199 +	TRAP(servererr,
   1.200 +		{
   1.201 +		server = CULoggerServer::NewLC((TProcessPriority)EPriorityHigh);
   1.202 +		CleanupStack::Pop();
   1.203 +		});
   1.204 +	
   1.205 +	if(servererr==KErrNone||servererr==KErrNotFound )
   1.206 +		{
   1.207 +		RProcess::Rendezvous(KErrNone);
   1.208 +		servererr=KErrNone;
   1.209 +		CActiveScheduler::Start();
   1.210 +		}
   1.211 +	else
   1.212 +		{
   1.213 +		RProcess::Rendezvous(servererr);		
   1.214 +		}
   1.215 +	delete server;
   1.216 +   	CleanupStack::PopAndDestroy();
   1.217 +	return servererr;
   1.218 +	
   1.219 +}//</StartingFunctionL>
   1.220 +
   1.221 +
   1.222 +/**
   1.223 +Function to to start the server 
   1.224 +This should leave with KErrNone 
   1.225 +*/
   1.226 +TInt CULoggerServer::StartServer()
   1.227 +{
   1.228 +	CTrapCleanup* cleanupStack = CTrapCleanup::New();
   1.229 +	if (!cleanupStack)
   1.230 +	{
   1.231 +        	return KErrNoMemory;
   1.232 +	}
   1.233 +	TInt err;
   1.234 +    TRAP(err, StartServerL());
   1.235 +   
   1.236 +    delete cleanupStack;
   1.237 +    cleanupStack = NULL;
   1.238 +
   1.239 +    return err;
   1.240 +}//</StartingFunction>
   1.241 +
   1.242 +
   1.243 +/**
   1.244 +Function to set the active output media 
   1.245 +This should leave with KErrNotFound if given plugin is not the correct one
   1.246 +or the file doesn't exists in the user and public path
   1.247 +*/
   1.248 +
   1.249 +TInt CULoggerServer::SetActiveOutputPlugin(const TDesC8 &aPluginname)
   1.250 +{
   1.251 +	RArray<TPtrC8> activePluginsArray;
   1.252 +	TInt error= KErrNone;
   1.253 +
   1.254 +	error = GetInstalledOutputPlugins(activePluginsArray);
   1.255 +	if(error==KErrNone)
   1.256 +		{
   1.257 +		for(TInt i=0;i<activePluginsArray.Count();i++)
   1.258 +			{
   1.259 +			if(aPluginname.Compare(activePluginsArray[i])==0)
   1.260 +				{
   1.261 +				error = iConfigManager->SetActiveOutputPlugin(aPluginname);
   1.262 +				break;
   1.263 +				}	
   1.264 +			else 
   1.265 +				error = KErrNotFound;
   1.266 +			}
   1.267 +		}
   1.268 +	if(error == KErrAlreadyExists)
   1.269 +		{
   1.270 +		error=KErrNone;
   1.271 +		}
   1.272 +	return error;
   1.273 +}
   1.274 +
   1.275 +
   1.276 +TInt CULoggerServer::SetActiveInputPlugin(const TDesC8 &aPluginname)
   1.277 +	{
   1.278 +	RArray<TPtrC8> activePluginsArray;
   1.279 +	TInt ret= KErrNone;
   1.280 +	//check configuration file in user path (\\ulogger\\uloggerconfig.ini)	
   1.281 +
   1.282 +	ret = GetInstalledInputPluginsL(activePluginsArray);
   1.283 +	if(ret==KErrNone)
   1.284 +		{
   1.285 +		ret = KErrNotFound;
   1.286 +		for(TInt i=0;i<activePluginsArray.Count();i++)
   1.287 +			{
   1.288 +			if(aPluginname.Compare(activePluginsArray[i])==0)
   1.289 +				{
   1.290 +				ret = iConfigManager->SetActiveInputPlugin(aPluginname);
   1.291 +				break;	
   1.292 +				}
   1.293 +			}
   1.294 +		}
   1.295 +	return ret;
   1.296 +	}
   1.297 +
   1.298 +
   1.299 +/**
   1.300 +Function to set the plugin settings
   1.301 +This should leave with KErrNotFound if cannot file doesn't exist
   1.302 +*/
   1.303 +TInt CULoggerServer::SetPluginSettings(const TDesC8 &aPluginname, RArray<TPtrC8>& aListBuffer)
   1.304 +{	
   1.305 +	TInt i = 0;
   1.306 +	TInt ret=KErrNone;
   1.307 +
   1.308 +	//if plug-in doesn't exists
   1.309 +	TPtrC8 pluginName(aPluginname);
   1.310 +	if(!CheckPluginExists(pluginName, EOutputPluginFilter) && !CheckPluginExists(pluginName, EInputPluginFilter))
   1.311 +		return KErrNotFound;
   1.312 +	
   1.313 +	while(i<aListBuffer.Count())
   1.314 +		{
   1.315 +		TPtrC8 key(aListBuffer[i]);
   1.316 +		TPtrC8 val(aListBuffer[++i]);
   1.317 +		ret = iConfigManager->SetPluginSetting(aPluginname, key, val);
   1.318 +		if(ret!=KErrNone)
   1.319 +			break;
   1.320 +		i++;		
   1.321 +		}					
   1.322 +	return ret;
   1.323 +}
   1.324 +
   1.325 +
   1.326 +
   1.327 +
   1.328 +/**
   1.329 +Function to get the plugin settings
   1.330 +This should leave with KErrNotFound if cannot find one
   1.331 +*/
   1.332 +TInt CULoggerServer::GetOptionsSettingsL(const TDesC8 &aMediaName, RArray<TPtrC8>& aListBuffer)
   1.333 +{
   1.334 +	//if plug-in doesn't exists
   1.335 +	TPtrC8 pluginName(aMediaName);
   1.336 +	if(!CheckPluginExists(pluginName, EOutputPluginFilter) && !CheckPluginExists(pluginName, EInputPluginFilter))
   1.337 +		return KErrNotFound;
   1.338 +	else
   1.339 +		{
   1.340 +		TInt ret = GetValuesL(aMediaName,aListBuffer);
   1.341 +		if(ret == KErrNotFound) //this error indicate that there is no section in config file, plug-in exists
   1.342 +			ret = KErrNone;
   1.343 +		return ret;
   1.344 +		}
   1.345 +}
   1.346 +
   1.347 +
   1.348 +
   1.349 +/**
   1.350 +Function to get values from the configuration file (i.e. for filters,plugin settings)
   1.351 +This should leave with KErrNotFound if it cannot find the configuration file
   1.352 +*/
   1.353 +TInt CULoggerServer::GetValuesL(const TDesC8 &aSectionName, RArray<TPtrC8>& aListBuffer)
   1.354 +{	
   1.355 +	TPtrC8 key;
   1.356 +	TPtrC8 val;
   1.357 +	TInt err = KErrNotFound;	
   1.358 +
   1.359 +	Ulogger::CConfigSettingsIter* iter = Ulogger::CConfigSettingsIter::NewL();
   1.360 +	CleanupStack::PushL(iter);
   1.361 +	
   1.362 +	//check User configuration file if exists
   1.363 +	//check values for given section in the configuration file 
   1.364 +	//if value exists copy it to array 
   1.365 +	err = iConfigManager->GetSectionValues(aSectionName,*iter);
   1.366 +	if(err == KErrNone)
   1.367 +		{
   1.368 +		TBool found =EFalse;
   1.369 +		while(iter->Next(key,val))
   1.370 +			{
   1.371 +			aListBuffer.AppendL(key);
   1.372 +			aListBuffer.AppendL(val);
   1.373 +			found = ETrue;
   1.374 +			}
   1.375 +		if(!found)
   1.376 +			err = KErrNotFound;
   1.377 +		}
   1.378 +	CleanupStack::PopAndDestroy(); // list
   1.379 +	return err;
   1.380 +	
   1.381 +}
   1.382 +
   1.383 +
   1.384 +/**
   1.385 +Sets the Active Filter in the configuration file (primary and secondary filters)
   1.386 +@aCategory filters to be set
   1.387 +@aDupCategory duplicate filters which are not set
   1.388 +@aFilter value that describes primary or secondary filter
   1.389 +@return KErrNone, if successful, otherwise one of the other system-wide
   1.390 +        error codes.
   1.391 +*/
   1.392 +TInt CULoggerServer::SetActiveFilterL(RArray<TUint32> aCategory, TInt aFilterType)
   1.393 +{
   1.394 +	TInt error = KErrNone;
   1.395 +	if(aFilterType == 1)
   1.396 +		{
   1.397 +		if(aCategory.Count()==0 || aCategory.Count()>KMaxPrimaryFiltersLimit)
   1.398 +			error = KErrArgument;
   1.399 +		else
   1.400 +			{
   1.401 +			error = iConfigManager->SetActiveFilter(aCategory,KPrimaryFilterSection);
   1.402 +			if(error == KErrAlreadyExists)
   1.403 +				error = KErrNone;
   1.404 +			}
   1.405 +		}
   1.406 +	if(aFilterType == 2)
   1.407 +		{
   1.408 +		//we don't want to set more secondary filters than KMaxSecondaryFiltersLimit
   1.409 +		RArray<TUint32> tmpArray;
   1.410 +		CleanupClosePushL(tmpArray);
   1.411 +		error = GetActiveFilters(tmpArray, ESecondaryFilter);
   1.412 +		if(!error || error == KErrNotFound)
   1.413 +			{
   1.414 +			error = KErrNone; //in case it was KErrNotFound as it doesn't matter we didn't have any set already
   1.415 +			if(aCategory.Count()==0 ||tmpArray.Count() > KMaxSecondaryFiltersLimit ||
   1.416 +					(tmpArray.Count()+ aCategory.Count()) > KMaxSecondaryFiltersLimit)
   1.417 +				error = KErrArgument;
   1.418 +				
   1.419 +			}
   1.420 +		CleanupStack::PopAndDestroy(); //tmpArray
   1.421 +		if(!error)
   1.422 +			error = iConfigManager->SetActiveFilter(aCategory,KSecondaryFilterSection);
   1.423 +		}
   1.424 +	return error;
   1.425 +}
   1.426 +	
   1.427 +
   1.428 +/**
   1.429 +Function to remove the Filter from config file
   1.430 +@aFilter  Filter to be removed
   1.431 +@aValue primary or secondary filter to be removed
   1.432 +This should leave with KErrNotFound if cannot find one or any system wide error codes
   1.433 +*/
   1.434 +TInt CULoggerServer::RemoveActiveFilter(RArray<TUint32>& aValue, const TInt aFilter)
   1.435 +{
   1.436 +	TInt ret = KErrNone;
   1.437 +	//remove filter (primary or secondary) from BTrace current configuration
   1.438 +	if(aFilter == EPrimaryFilter && (aValue.Count()==0 || aValue.Count()>KMaxPrimaryFiltersLimit))
   1.439 +		return KErrArgument;
   1.440 +	else if(aFilter == ESecondaryFilter && (aValue.Count()==0 || aValue.Count()>KMaxSecondaryFiltersLimit))
   1.441 +		return KErrArgument;
   1.442 +		
   1.443 +	ret = iConfigManager->RemoveActiveFilter(aValue,aFilter);
   1.444 +	if(ret == KErrNotFound) //remove operation should succeed in this situation
   1.445 +		ret = KErrNone;
   1.446 +		
   1.447 +	return ret;
   1.448 +}
   1.449 +
   1.450 +
   1.451 +/**
   1.452 +Function to set Trace settings to the configuration file
   1.453 +@aValue  value to be set
   1.454 +@aSetting setting to which value to be set
   1.455 +This should leave with KErrNotFound if cannot find one or any system wide error codes
   1.456 +*/
   1.457 +TInt CULoggerServer::SetTraceSettings(const TDesC8&  aValue, const TDesC8& aSetting)
   1.458 +	{
   1.459 +	TInt r = iConfigManager->SetTraceSettings(aValue, aSetting);
   1.460 +	return r;
   1.461 +
   1.462 +	}
   1.463 +
   1.464 +/**
   1.465 +Function to remove plugin settings from the configuration file
   1.466 +@aPluginName  Plugin name whose settings has to be removed
   1.467 +@return will return KErrNone or else leave with KErrNotFound  
   1.468 +	or any system wide error codes 
   1.469 +*/
   1.470 +
   1.471 +TInt CULoggerServer::RemovePluginSettingsL(const TDesC8 &aPluginName)
   1.472 +	{
   1.473 +	if(aPluginName.Length() == 0)
   1.474 +		return KErrArgument;
   1.475 +	
   1.476 +	TInt ret = KErrNone;
   1.477 +	RArray<TPtrC8> settings;
   1.478 +	ret = GetOptionsSettingsL(aPluginName, settings);
   1.479 +	if(ret != KErrNone || settings.Count()==0)
   1.480 +		ret = KErrNotFound;
   1.481 +	settings.Close();
   1.482 +		
   1.483 +	if(ret == KErrNone)
   1.484 +		return iConfigManager->RemovePluginSettings(aPluginName);
   1.485 +	else
   1.486 +		return ret;
   1.487 +	}
   1.488 +
   1.489 +/**
   1.490 +Resize the BTrace buffer size
   1.491 +
   1.492 +@aSize The size to be set for the BTrace buffer.
   1.493 +@return KErrNone, if successful, otherwise one of the other system-wide
   1.494 +        error codes.
   1.495 +*/
   1.496 +TInt CULoggerServer::SetBufferSizeL(TInt aSize)
   1.497 +	{
   1.498 +	if(aSize > KMaxBufferSize || aSize < 1)
   1.499 +		return KErrArgument;
   1.500 +
   1.501 +	
   1.502 +	//get dns to check
   1.503 +	GetBufandDataNotifyValuesL(KDataNotification,iDataNotification);
   1.504 +	if(aSize < iDataNotification)
   1.505 +		return KErrGeneral;
   1.506 +	
   1.507 +	iBufferSize = aSize;
   1.508 +	HBufC8* Size = HBufC8::NewLC(32);
   1.509 +	Size->Des().Num(iBufferSize);
   1.510 +	CleanupStack::Pop(1);
   1.511 +	TPtr8 ptr(Size->Des());
   1.512 +	TInt r = iConfigManager->SetTraceSettings((const TDesC8&)ptr, KBuffer);
   1.513 +	return r;
   1.514 +	}
   1.515 +
   1.516 +
   1.517 +/**
   1.518 +Change the mode of the BTrace Buffer
   1.519 +
   1.520 +@aValue The mode to be set for the BTrace buffer.
   1.521 +@return KErrNone, if successful, otherwise one of the other system-wide
   1.522 +        error codes.
   1.523 +*/
   1.524 +TInt CULoggerServer::SetBufferMode(const TDesC8& aValue)
   1.525 +	{
   1.526 +	
   1.527 +	TInt r = SetTraceSettings(aValue, KBufferMode);
   1.528 +	return r;
   1.529 +	}
   1.530 +
   1.531 +/**
   1.532 +Resize the Data Notification size
   1.533 +
   1.534 +@aSize The size to be set for the Data Notification size.
   1.535 +@return KErrNone, if successful, otherwise one of the other system-wide
   1.536 +        error codes.
   1.537 +*/
   1.538 +TInt CULoggerServer::SetDataNotificationSizeL(TInt aSize)
   1.539 +	{
   1.540 +	if(aSize > KMaxDnsSize || aSize < 0)
   1.541 +		return KErrArgument;
   1.542 +	TInt size, r;
   1.543 +	TRAP_IGNORE((r=GetBufandDataNotifyValuesL(KBuffer,size)));
   1.544 +	if(aSize > size)
   1.545 +		return KErrGeneral;
   1.546 +	
   1.547 +	iDataNotification = aSize;
   1.548 +	HBufC8* Size = HBufC8::NewLC(32);
   1.549 +	Size->Des().Num(aSize);
   1.550 +	TPtr8 ptr(Size->Des());
   1.551 +	r = SetTraceSettings((const TDesC8&)ptr, KDataNotification);
   1.552 +	CleanupStack::PopAndDestroy();
   1.553 +	return r;
   1.554 +	}
   1.555 +	
   1.556 +/**
   1.557 +Function to retrieve the Trace Section Values
   1.558 +This should leave with KErrNotFound if cannot find one
   1.559 +as this should be treated as a corrupt config file
   1.560 +*/
   1.561 +void CULoggerServer::GetOptionsSettingsL(RArray<TPtrC8>& aListBuffer,const TDesC8& aSetting)
   1.562 +{
   1.563 +	TPtrC8 key;
   1.564 +	TPtrC8 val;	
   1.565 +	TInt err=0;
   1.566 +	
   1.567 +	Ulogger::CConfigSettingsIter* iter = Ulogger::CConfigSettingsIter::NewL();
   1.568 +	CleanupStack::PushL(iter);
   1.569 +	err=iConfigManager->GetPluginSettings(*iter);
   1.570 +	
   1.571 +	if(err==KErrNone)
   1.572 +		{
   1.573 +		while(iter->Next(key,val))
   1.574 +			{
   1.575 +			if(key.Compare(aSetting)==0)
   1.576 +				{
   1.577 +				aListBuffer.AppendL(key);
   1.578 +				aListBuffer.AppendL(val);					
   1.579 +				}
   1.580 +			}
   1.581 +		}
   1.582 +	CleanupStack::PopAndDestroy(); // list
   1.583 +}
   1.584 +
   1.585 +/**
   1.586 +Function to retrieve the active primary filters
   1.587 +This should leave with KErrNotFound if cannot find one
   1.588 +as this should be treated as a corrupt config file
   1.589 +*/
   1.590 +TInt CULoggerServer::GetBufandDataNotifyValuesL(const TDesC8& aSetting,TInt& value)
   1.591 +	{
   1.592 +	TInt err = KErrNotFound;
   1.593 +	RArray<TPtrC8> traceValues;
   1.594 +	TFileName filepath;
   1.595 +	
   1.596 +	GetOptionsSettingsL(traceValues,aSetting);
   1.597 +		
   1.598 +	value =-1;
   1.599 +	//if values exists for the given trace settings	
   1.600 +	if(traceValues.Count()>1)
   1.601 +		{// get values for buffer mode
   1.602 +		if(aSetting.Compare(KBufferMode)==0)	
   1.603 +			{
   1.604 +			err=KErrNone;
   1.605 +			if(traceValues[1].Compare(KCircular) == 0)
   1.606 +				value = ECircularBuffer;
   1.607 +			else if(traceValues[1].Compare(KStraight) == 0)
   1.608 +				value = EStraightBuffer;
   1.609 +			else
   1.610 +				err=KErrNotFound;
   1.611 +			}
   1.612 +		else
   1.613 +			{// get values for data notification and buffer size
   1.614 +			TLex8 lex_val(traceValues[1]);	
   1.615 +			err = lex_val.Val(value);
   1.616 +			}
   1.617 +		}
   1.618 +	return err;
   1.619 +	}
   1.620 +	
   1.621 +
   1.622 +
   1.623 +/**
   1.624 +Set the enable/disable secondary filters
   1.625 +
   1.626 +@aSize The size to be set for the BTrace buffer.
   1.627 +@return KErrNone, if successful, otherwise one of the other system-wide
   1.628 +        error codes.
   1.629 +*/
   1.630 +TInt CULoggerServer::SetSecondaryFiltering(const TDesC8& aEnabled)
   1.631 +	{
   1.632 +	TInt error = iConfigManager->SetTraceSettings(aEnabled, KSecondaryGlobalFilter);
   1.633 +	if(error == KErrAlreadyExists)
   1.634 +		error = KErrNone;
   1.635 +	return error;
   1.636 +
   1.637 +	}	
   1.638 +
   1.639 +
   1.640 +/**
   1.641 +Function to retrieve the active primary and secondary filters
   1.642 +This should return KErrNotFound if cannot find one or return any of the system wide error codes
   1.643 +*/
   1.644 +TInt CULoggerServer::GetActiveFilters(RArray<TUint32>& aListBuffer,TInt aFilterType)
   1.645 +	{
   1.646 +	TInt ret = KErrNotFound;
   1.647 +	RArray<TPtrC8> aValues;
   1.648 +	if(aFilterType == 1)
   1.649 +		{
   1.650 +		TRAPD(err, ret = GetValuesL(KPrimaryFilterSection,aValues));
   1.651 +		if (err != KErrNone)
   1.652 +			{
   1.653 +			return err;
   1.654 +			}
   1.655 +		
   1.656 +		if(ret==KErrNone)	
   1.657 +			{
   1.658 +			TInt i =0;
   1.659 +			TPtrC8 val;	
   1.660 +			TUint8 int_val;
   1.661 +			while(i<aValues.Count())
   1.662 +				{
   1.663 +				TLex8 lex_val(aValues[++i]);	
   1.664 +				ret = lex_val.Val(int_val,EDecimal);	
   1.665 +				if(ret == KErrNone)
   1.666 +					{
   1.667 +					ret = aListBuffer.Append(int_val);
   1.668 +					if (ret != KErrNone)
   1.669 +						{
   1.670 +						return ret;
   1.671 +						}
   1.672 +					}
   1.673 +				else
   1.674 +					{
   1.675 +					return KErrCorrupt;
   1.676 +					}
   1.677 +				i++;		
   1.678 +				}					
   1.679 +			}
   1.680 +		}
   1.681 +	else if(aFilterType == 2)
   1.682 +		{
   1.683 +		TRAPD(err, ret = GetValuesL(KSecondaryFilterSection,aValues));
   1.684 +		if (err != KErrNone)
   1.685 +			{
   1.686 +			return err;
   1.687 +			}
   1.688 +		if(ret==KErrNone)	
   1.689 +			{
   1.690 +			TInt i =0;
   1.691 +			TPtrC8 val;	
   1.692 +			TUint int_val;
   1.693 +			while(i<aValues.Count())
   1.694 +				{
   1.695 +				TLex8 lex_val(aValues[++i]);	
   1.696 +				ret = lex_val.Val(int_val,EDecimal);	
   1.697 +				if(ret == KErrNone)
   1.698 +					{
   1.699 +					ret = aListBuffer.Append(int_val);
   1.700 +					if (ret != KErrNone)
   1.701 +						{
   1.702 +						return ret;
   1.703 +						}
   1.704 +					}
   1.705 +				else
   1.706 +					{
   1.707 +					return KErrCorrupt;
   1.708 +					}
   1.709 +				i++;		
   1.710 +				}					
   1.711 +			}
   1.712 +		else
   1.713 +			{
   1.714 +			if(ret==KErrNotFound)//i.e. if there are no values in the array --> change to if(filters.Count = 0)?
   1.715 +				{
   1.716 +				ret=KErrNone;
   1.717 +				}
   1.718 +			}
   1.719 +		}
   1.720 +	return ret;
   1.721 +	}
   1.722 +
   1.723 +/**
   1.724 +Function to retrieve the active secondary global filter
   1.725 +This should leave with KErrNotFound if cannot find one
   1.726 +*/
   1.727 +
   1.728 +TInt CULoggerServer::GetSecondaryFiltering(TBool& aEnabled)
   1.729 +{
   1.730 +	RArray<TPtrC8> configSettings;			
   1.731 +	TRAPD(error, GetOptionsSettingsL(configSettings,KSecondaryGlobalFilter));
   1.732 +	if(configSettings[1]==KEnable) //First element contains KSecondaryGlobalFilter, second the value
   1.733 +		aEnabled = ETrue;
   1.734 +	if(configSettings[1]==KDisable)
   1.735 +		aEnabled = EFalse;
   1.736 +	return error; 
   1.737 +}
   1.738 +
   1.739 +/**
   1.740 +Function to retrieve the plugin names from the ECOM framework
   1.741 +This should leave with KErrNotFound if cannot find one
   1.742 +*/
   1.743 +TInt CULoggerServer::GetInstalledOutputPlugins(RArray<TPtrC8>& aListBuffer)
   1.744 +	{
   1.745 +	// Read info about all implementations into infoArray
   1.746 +	// Note that a special cleanup function is required to reset and destroy
   1.747 +	// all items in the array, and then close it.
   1.748 +	if(iPluginArray.Count()>0)
   1.749 +	{
   1.750 +     iPluginArray.ResetAndDestroy();
   1.751 +     iPluginArray.Close();
   1.752 +	}
   1.753 +	
   1.754 +	TRAPD(error,CPluginAllocator::ListAllImplementationsL(iPluginArray));
   1.755 +
   1.756 +	if(iPluginArray.Count()>0)
   1.757 +	{
   1.758 +		for (TInt i=0; i< iPluginArray.Count(); i++)
   1.759 +			{
   1.760 +			TRAP(error,aListBuffer.AppendL(iPluginArray[i]->DataType()));
   1.761 +			}
   1.762 +	
   1.763 +		//filter plugins and to use only output plugins
   1.764 +		FilterPlugins(EOutputPluginFilter, aListBuffer);
   1.765 +	}
   1.766 +	
   1.767 +	return error;
   1.768 +	}
   1.769 +	
   1.770 +
   1.771 +
   1.772 +TInt CULoggerServer::GetInstalledInputPluginsL(RArray<TPtrC8>& aListBuffer)
   1.773 +	{
   1.774 +	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
   1.775 +	__MARK_METHOD("CULoggerServer::GetInstalledControlPlugins")
   1.776 +	#endif
   1.777 +	
   1.778 +	if(iPluginArray.Count()>0)
   1.779 +		{
   1.780 +	     iPluginArray.ResetAndDestroy();
   1.781 +	     iPluginArray.Close();
   1.782 +		}
   1.783 +	// Read info about all implementations into infoArray
   1.784 +	// Note that a special cleanup function is required to reset and destroy
   1.785 +	// all items in the array, and then close it.
   1.786 +	CPluginAllocator::ListAllImplementationsL(iPluginArray);
   1.787 +		
   1.788 +	if(iPluginArray.Count() > 0)
   1.789 +		{	
   1.790 +		for (TInt i=0; i< iPluginArray.Count(); i++)
   1.791 +			aListBuffer.AppendL(iPluginArray[i]->DataType());
   1.792 +		
   1.793 +		//filter plugins and to use only output plugins
   1.794 +		FilterPlugins(EInputPluginFilter, aListBuffer);
   1.795 +		}
   1.796 +	return KErrNone;
   1.797 +	}
   1.798 +
   1.799 +
   1.800 +/**
   1.801 +Function to retrieve the Active plugin name 
   1.802 +This should leave with KErrNotFound if cannot find one or any system wide error codes
   1.803 +*/
   1.804 +TInt CULoggerServer::GetActiveOutputPlugin(RArray<TPtrC8>& aListBuffer)
   1.805 +	{
   1.806 +	TInt errCode = GetValuesL(KActiveSection,aListBuffer);
   1.807 +	//plugins are received as, e.g. '1 uloggerfileplugin' (.ini file syntax)
   1.808 +	//we have to remove number from array
   1.809 +	for(TInt i=0; i<aListBuffer.Count(); ++i)
   1.810 +		{
   1.811 +		TInt v;
   1.812 +		TLex8 lex(aListBuffer[i]);
   1.813 +		if(lex.Val(v) == KErrNone)
   1.814 +			{
   1.815 +			aListBuffer.Remove(i);
   1.816 +			i=-1; //start from begin, i will be incremented in loop
   1.817 +			}
   1.818 +		}
   1.819 +	return errCode;
   1.820 +	}
   1.821 +
   1.822 +
   1.823 +/**
   1.824 +Function to Deactivate or remove active output plugin 
   1.825 +This should leave with KErrNotFound if cannot find one or any system wide error codes
   1.826 +*/
   1.827 +
   1.828 +TInt CULoggerServer::DeActivateOutputPlugin(const TDesC8 &aPluginname)
   1.829 +{	
   1.830 +	if(iBtraceOpen != EFalse)
   1.831 +		{
   1.832 +		Stop();
   1.833 +		iBtraceOpen = EFalse;
   1.834 +		}
   1.835 +	
   1.836 +	TInt ret = iConfigManager->DeActivateOutputPlugin(aPluginname);
   1.837 +	return ret;
   1.838 +}
   1.839 +
   1.840 +/**
   1.841 +Function to retrieve the Active control plugin name 
   1.842 +This should leave with KErrNotFound if cannot find one or any system wide error codes
   1.843 +*/
   1.844 +TInt CULoggerServer::GetActiveInputPlugin(RArray<TPtrC8>& aListBuffer)
   1.845 +	{
   1.846 +	return GetValuesL(KActiveControlSection,aListBuffer);
   1.847 +	}
   1.848 +
   1.849 +/**
   1.850 +Function to Deactivate active control plugin 
   1.851 +This should leave with KErrNotFound if cannot find one or any system wide error codes
   1.852 +*/
   1.853 +TInt CULoggerServer::DeActivateInputPlugin(const TDesC8& aPluginname)
   1.854 +	{
   1.855 +	return iConfigManager->DeActivateInputPlugin(aPluginname);
   1.856 +	}
   1.857 +
   1.858 +/**
   1.859 +Function to run ULogger server as service, i.e. to keep it constantly running
   1.860 +(but not necessarily logging) in the background, or to stop it being run as a
   1.861 +service (if EFalse is passed).
   1.862 +
   1.863 +@param aRunAsService ETrue to start, EFalse to stop running as service
   1.864 +*/
   1.865 +void CULoggerServer::RunAsService(TBool /*aRunAsService*/)
   1.866 +	{
   1.867 +//
   1.868 +// // Uncomment following to implement run-as-service functionality
   1.869 +//
   1.870 +//	iRunAsService = aRunAsService;
   1.871 +//
   1.872 +//	if (!aRunAsService)
   1.873 +//		{
   1.874 +//		//make sure server is stopped if there are no sessions
   1.875 +//		IncrementSessions();
   1.876 +//		DecrementSessions();
   1.877 +//		}
   1.878 +	}
   1.879 +
   1.880 +/**
   1.881 +Function to cd.. ulogger server
   1.882 +This should leave with KErrNotFound if cannot find one or any system wide error codes
   1.883 +*/
   1.884 +TInt CULoggerServer::Start()
   1.885 +	{
   1.886 +	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
   1.887 +	__MARK_METHOD("CULoggerServer::Start")
   1.888 +	#endif
   1.889 +
   1.890 +	TRAPD(error, InitializeFrameworksL());
   1.891 +	
   1.892 +	//check errors
   1.893 +	if(error != KErrNone)
   1.894 +		return error;
   1.895 +	if(!iOutputFramework)
   1.896 +		return KErrNotReady;
   1.897 +	if(iBtraceOpen)
   1.898 +		return KErrInUse;
   1.899 +
   1.900 +	TPtrC8 key;
   1.901 +	TPtrC8 val;
   1.902 +	TInt buffermode=0;
   1.903 +	RArray<TPtrC8> settings;
   1.904 +	RArray<TUint32> activefilters;
   1.905 +	//checking if there is at least one active channel
   1.906 +	error = GetActiveOutputPlugin(settings);
   1.907 +	if(error != KErrNone)
   1.908 +		return error;
   1.909 +	if(settings.Count()==0)
   1.910 +		{
   1.911 +		return KErrNotFound; //active output plug-in not found
   1.912 +		}
   1.913 +
   1.914 +	if(iBtraceOpen == EFalse)
   1.915 +		{
   1.916 +		if(iIsBooting)
   1.917 +			error = TraceSettingsOnBootL();
   1.918 +		else
   1.919 +			error = iTrace.Open();
   1.920 +
   1.921 +		if(error == KErrNone)
   1.922 +			{
   1.923 +			//----Reset the notification size
   1.924 +			TRAP_IGNORE(error=GetBufandDataNotifyValuesL(KDataNotification,iDataNotification));
   1.925 +			if(error!=KErrNone)
   1.926 +				return error;
   1.927 +			TRAP_IGNORE(error=GetBufandDataNotifyValuesL(KBuffer,iBufferSize));
   1.928 +			if(error!=KErrNone)
   1.929 +				return error;
   1.930 +
   1.931 +			//----Reset BTrace filters
   1.932 +			ResetBtracePrimaryFilters(iTrace);
   1.933 +
   1.934 +			//----Resize the trace buffer
   1.935 +			error = iTrace.ResizeBuffer(iBufferSize*1024);
   1.936 +			if(error == KErrNoMemory)
   1.937 +			{
   1.938 +				error = iTrace.ResizeBuffer(KMinBufferMTPLE*1024);
   1.939 +			}
   1.940 +			if(error != KErrNone)
   1.941 +				return error;
   1.942 +			//----Reset the buffer mode
   1.943 +			TRAP_IGNORE(GetBufandDataNotifyValuesL(KBufferMode,buffermode));
   1.944 +			if(buffermode==ECircularBuffer)
   1.945 +			{
   1.946 +				iTrace.SetMode(RBTrace::EFreeRunning|RBTrace::EEnable);	
   1.947 +			}
   1.948 +			else
   1.949 +			{
   1.950 +				iTrace.SetMode(RBTrace::EEnable);
   1.951 +			}
   1.952 +		
   1.953 +			//----Enable/disable primary filter
   1.954 +			error = GetActiveFilters(activefilters,EPrimaryFilter);
   1.955 +			if(error != KErrNone)
   1.956 +				return error;
   1.957 +			for(TInt i=0; i<activefilters.Count(); ++i)
   1.958 +				{
   1.959 +				TUint filter;
   1.960 +				filter= (TUint8)activefilters[i];
   1.961 +				iTrace.SetFilter(filter,ETrue);
   1.962 +				}
   1.963 +
   1.964 +			//----Enable/disable secondary filter
   1.965 +			settings.Reset();
   1.966 +			TBool enabled = EFalse;
   1.967 +			error = GetSecondaryFiltering(enabled);
   1.968 +			if(!error)
   1.969 +				{
   1.970 +				if (enabled)//enable secondary filter, only traces with certain value will pass
   1.971 +					{
   1.972 +					iTrace.SetFilter2(0);
   1.973 +
   1.974 +					//enable secondary filters chosen by user
   1.975 +					activefilters.Reset();
   1.976 +					if((error = GetActiveFilters(activefilters,ESecondaryFilter)) == KErrNone)
   1.977 +						for(TInt i=0; i<activefilters.Count(); ++i)
   1.978 +							iTrace.SetFilter2(activefilters[i], ETrue);
   1.979 +					else
   1.980 +						{
   1.981 +						if(error == KErrNotFound)
   1.982 +							{
   1.983 +							error = KErrNone;
   1.984 +							}
   1.985 +						else
   1.986 +							return error;
   1.987 +						}
   1.988 +					}
   1.989 +				else//disable secondary filter, all traces will pass
   1.990 +					{
   1.991 +					iTrace.SetFilter2(1);
   1.992 +					}				
   1.993 +				}
   1.994 +			
   1.995 +			//set flag to idicate that btrace is open
   1.996 +			iBtraceOpen = ETrue;
   1.997 +
   1.998 +			//start input and output frameworks
   1.999 +			iInputFramework->StartReading(); //start waiting for remote commands
  1.1000 +			AsynchDataRequest();
  1.1001 +			}
  1.1002 +		}
  1.1003 +	else
  1.1004 +		error = KErrInUse;
  1.1005 +
  1.1006 +	return error;
  1.1007 +	}
  1.1008 +
  1.1009 +/**
  1.1010 +Close the BTrace handle to the buffer
  1.1011 +@return none
  1.1012 +*/
  1.1013 +TInt CULoggerServer::Stop()
  1.1014 +{
  1.1015 +	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1016 +	__MARK_METHOD("CULoggerServer::Stop")
  1.1017 +	#endif
  1.1018 +	
  1.1019 +	if(iBtraceOpen)
  1.1020 +	{	
  1.1021 +		TInt errCode = KErrNone;
  1.1022 +		TRAP(errCode, ReadBufferL());	//flush the BTrace buffer
  1.1023 +		
  1.1024 +		ResetBtracePrimaryFilters(iTrace);//reset BTrace filters
  1.1025 +		
  1.1026 +		iTrace.CancelRequestData();	
  1.1027 +		iTrace.Empty();
  1.1028 +		iTrace.Close();
  1.1029 +		iBtraceOpen = EFalse;
  1.1030 +		iDataWatcher->Cancel();
  1.1031 +		
  1.1032 +		//stop waiting/reading for remote commands
  1.1033 +		iInputFramework->StopReading();
  1.1034 +		iOutputFramework->ReleaseOutputResources();
  1.1035 +		return KErrNone;
  1.1036 +		}
  1.1037 +	else
  1.1038 +		{
  1.1039 +		return KErrNotReady;	
  1.1040 +		}
  1.1041 +		
  1.1042 +}
  1.1043 +
  1.1044 +/**
  1.1045 +Gets the Trace settings on boot
  1.1046 +@return none
  1.1047 +*/
  1.1048 +TInt CULoggerServer::TraceSettingsOnBootL()
  1.1049 +{
  1.1050 +	TInt trace = FALSE;
  1.1051 +	
  1.1052 +	RArray<TUint32> category;
  1.1053 +	TInt error = iTrace.Open();
  1.1054 +	if(error != KErrNone)
  1.1055 +		return error;
  1.1056 +	
  1.1057 +	TInt bufferSize = iTrace.BufferSize(); //To get the buffer size set at boot	
  1.1058 +	if(bufferSize <= 0 && bufferSize > KMaxBufferSize)
  1.1059 +		SetBufferSizeL(KMaxBufferSize); //Update config
  1.1060 +	else
  1.1061 +		SetBufferSizeL(bufferSize); //Update config
  1.1062 +	for(TUint i=0; i<KMaxPrimaryFiltersLimit; i++)
  1.1063 +	{
  1.1064 +		trace = iTrace.Filter(i);
  1.1065 +		if(trace == 1)         
  1.1066 +			category.AppendL((TUint32)i);				
  1.1067 +	}
  1.1068 +	error = iConfigManager->SetActiveFilter(category,KPrimaryFilterSection);
  1.1069 +	category.Close();
  1.1070 +	iIsBooting=0;
  1.1071 +	return error;
  1.1072 +}
  1.1073 +
  1.1074 +
  1.1075 +
  1.1076 +/**
  1.1077 +Reads the BTrace buffer and transfers the collected logs to
  1.1078 +the ACTIVE channel
  1.1079 +*/
  1.1080 +void CULoggerServer::ReadBufferL()
  1.1081 +    {
  1.1082 +    if(iBtraceOpen)
  1.1083 +    	{   	
  1.1084 +    	TUint8* data;
  1.1085 +		TInt dataSize;
  1.1086 +		//TUint oldMode = iTrace.Mode();
  1.1087 +		//iTrace.SetMode(0); // turn off trace capture while we dump
  1.1088 +		dataSize = iTrace.GetData(data);
  1.1089 +		if(dataSize > 0)
  1.1090 +			{
  1.1091 +
  1.1092 +	 		TPtrC8 dataPtr(data, dataSize);
  1.1093 +			
  1.1094 +	 		#if defined(__LIGHTLOGGER_ENABLED) && defined(__PERFORMANCE_TEST)
  1.1095 + 			__LOGTIMESTAMP_HIRES("Passing data to output framework - t2") //performance test
  1.1096 +			#endif
  1.1097 + 			
  1.1098 + 			//send data through output channel
  1.1099 + 			TInt error = KErrNone;
  1.1100 + 			if((error = iOutputFramework->SendData(dataPtr)) == KErrNone)
  1.1101 + 				iTrace.DataUsed(); //only if data was really sent via output plugin
  1.1102 + 			else
  1.1103 + 				User::Leave(error);
  1.1104 +	 		
  1.1105 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__PERFORMANCE_TEST)
  1.1106 +	 		__LOGTIMESTAMP_HIRES("Data logged - t3")	//performance test
  1.1107 +			#endif
  1.1108 +			}
  1.1109 +		//iTrace.SetMode(oldMode);
  1.1110 +			
  1.1111 +		AsynchDataRequest();
  1.1112 +	    } 
  1.1113 +    }
  1.1114 +
  1.1115 +
  1.1116 +void CULoggerServer::AsynchDataRequest()
  1.1117 +	{
  1.1118 +	if(!iDataWatcher->IsActive())
  1.1119 +		{
  1.1120 +		iTrace.RequestData(iDataWatcher->GetStatus(), iDataNotification*1024); 
  1.1121 +		iDataWatcher->StartWatching(this);
  1.1122 +		}
  1.1123 +	}
  1.1124 +
  1.1125 +
  1.1126 +void CULoggerServer::DataNotification()
  1.1127 +{
  1.1128 +	TRAPD(e, ReadBufferL());
  1.1129 +	if(e != KErrNone)
  1.1130 +		AsynchDataRequest();
  1.1131 +}
  1.1132 +
  1.1133 +
  1.1134 +void CULoggerServer::GetPluginAndSettingsL(TDes8& aPluginName, RPointerArray<TPluginConfiguration>* aSettings, TPluginFilter aPluginFilter)
  1.1135 +	{	
  1.1136 +	TPtrC8 key;
  1.1137 +	TPtrC8 val;
  1.1138 +	RArray<TPtrC8> activePluginsArray;
  1.1139 +	RArray<TPtrC8> pluginsArray;
  1.1140 +	RArray<TPtrC8> pluginSettings;
  1.1141 +	TInt i,j;
  1.1142 +	
  1.1143 +	if(aPluginFilter == EOutputPluginFilter)
  1.1144 +		GetActiveOutputPlugin(activePluginsArray); //get output plugin
  1.1145 +	else
  1.1146 +		GetActiveInputPlugin(activePluginsArray); //get control plugin
  1.1147 +	
  1.1148 +	for(i=0; i<activePluginsArray.Count(); ++i)
  1.1149 +		{
  1.1150 +		TBuf8<256> activeplugin;
  1.1151 +		activeplugin.Copy(activePluginsArray[i]);
  1.1152 +		activeplugin.LowerCase();
  1.1153 +		
  1.1154 +		GetInstalledOutputPlugins(pluginsArray);
  1.1155 +		for(j=0;j<pluginsArray.Count();j++)
  1.1156 +			{
  1.1157 +			TBuf8<256> plugin;
  1.1158 +			plugin.Copy(pluginsArray[j]);
  1.1159 +			plugin.LowerCase();
  1.1160 +			
  1.1161 +			if(activeplugin.Compare(plugin)==0)
  1.1162 +				{
  1.1163 +				break;
  1.1164 +				}
  1.1165 +			}
  1.1166 +		aPluginName.Copy(activePluginsArray[i]);
  1.1167 +		GetOptionsSettingsL(aPluginName,pluginSettings);
  1.1168 +		j=0;
  1.1169 +		while(j < pluginSettings.Count())
  1.1170 +			{
  1.1171 +			TPluginConfiguration* keyAndVal = new TPluginConfiguration();
  1.1172 +			keyAndVal->SetKey(pluginSettings[j]);
  1.1173 +			keyAndVal->SetValue(pluginSettings[j+1]);
  1.1174 +			aSettings->AppendL(keyAndVal);
  1.1175 +			j=j+2;
  1.1176 +			}
  1.1177 +		}
  1.1178 +	}
  1.1179 +
  1.1180 +
  1.1181 +/*
  1.1182 + * Cleanup RPointerArray<TPluginConfiguration>* object by calling ResetAndDestroy to delete memory
  1.1183 + * allocated as TPluginConfigurations whose ownership has been passed to the RPointerArray.
  1.1184 + *
  1.1185 + */
  1.1186 +void CULoggerServer::CleanupTPluginConfigArray(TAny* aPtr)
  1.1187 +	{
  1.1188 +	RPointerArray<TPluginConfiguration>* ptrArray = reinterpret_cast<RPointerArray<TPluginConfiguration>*>(aPtr);
  1.1189 +	ptrArray->ResetAndDestroy();
  1.1190 +	ptrArray->Close();
  1.1191 +	}
  1.1192 +
  1.1193 +
  1.1194 +void CULoggerServer::InitializeFrameworksL()
  1.1195 +	{
  1.1196 +	//<create plugin allocator (plugins)>
  1.1197 +	//output settings
  1.1198 +	RBuf8 outPluginName;
  1.1199 +	outPluginName.CreateL(KMaxPluginName);
  1.1200 +	CleanupClosePushL(outPluginName);
  1.1201 +	RPointerArray<TPluginConfiguration> outputPluginSettings;
  1.1202 +	CleanupStack::PushL(TCleanupItem(CleanupTPluginConfigArray, &outputPluginSettings));
  1.1203 +	GetPluginAndSettingsL(outPluginName, &outputPluginSettings, EOutputPluginFilter);
  1.1204 +
  1.1205 +	//control settings
  1.1206 +	RBuf8 inputPluginName;
  1.1207 +	inputPluginName.CreateL(KMaxPluginName);
  1.1208 +	CleanupClosePushL(inputPluginName);
  1.1209 +	RPointerArray<TPluginConfiguration> inputPluginSettings;
  1.1210 +	CleanupStack::PushL(TCleanupItem(CleanupTPluginConfigArray, &inputPluginSettings));
  1.1211 +	GetPluginAndSettingsL(inputPluginName, &inputPluginSettings, EInputPluginFilter);
  1.1212 +
  1.1213 +	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1214 +	__LOG("before creating CPluginAllocator")
  1.1215 +	#endif
  1.1216 +	
  1.1217 +	//create plugin allocator (plugins)
  1.1218 +	if(!iPluginAllocator)
  1.1219 +		{
  1.1220 +		iPluginAllocator = CPluginAllocator::NewL(outPluginName, inputPluginName);
  1.1221 +		}
  1.1222 +
  1.1223 +	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1224 +	__LOG("before creating COutputFramework")
  1.1225 +	#endif
  1.1226 +	//Initialize output framework
  1.1227 +	if(!iOutputFramework)
  1.1228 +		{
  1.1229 +		iOutputFramework = COutputFramework::NewL(*(iPluginAllocator->GetOutputPlugin()), outputPluginSettings);
  1.1230 +		}
  1.1231 +
  1.1232 +	//Initialize Control Framework
  1.1233 +	if(!iInputFramework)
  1.1234 +		{
  1.1235 +		iInputFramework = CInputFramework::NewL(iPluginAllocator->GetInputPlugin(), inputPluginSettings, this);
  1.1236 +		}
  1.1237 +
  1.1238 +	//cleanup
  1.1239 +	CleanupStack::PopAndDestroy(4, &outPluginName); // and outputPluginSettings, inputPluginName and inputPluginSettings
  1.1240 +
  1.1241 +	iDataWatcher = CULoggerWatcher::NewL();	
  1.1242 +	}
  1.1243 +
  1.1244 +
  1.1245 +void CULoggerServer::PrepareControlDataPayloadL(RBuf8& aPayloadBuf, const RArray<TPtrC8>& aArray)
  1.1246 +	{
  1.1247 +	aPayloadBuf.CreateL(aArray.Count()*32);
  1.1248 +	for(TInt i=0; i<aArray.Count(); i++)
  1.1249 +		{
  1.1250 +		if(aPayloadBuf.MaxSize() < aPayloadBuf.Length()+aArray[i].Length())
  1.1251 +			{
  1.1252 +			aPayloadBuf.ReAllocL(aPayloadBuf.Length()+(aArray[i].Length()*10));
  1.1253 +			}
  1.1254 +		aPayloadBuf.Append(aArray[i]);
  1.1255 +		if(i < aArray.Count()-1) //skip last sparator as it will be added automatically
  1.1256 +			{
  1.1257 +			aPayloadBuf.Append(DATA_SEPARATOR);
  1.1258 +			}
  1.1259 +		}
  1.1260 +	}
  1.1261 +
  1.1262 +
  1.1263 +void CULoggerServer::PrepareControlDataPayloadL(RBuf8& aPayloadBuf, const RArray<TUint32>& aArray)
  1.1264 +	{
  1.1265 +	aPayloadBuf.CreateL(aArray.Count()*4);
  1.1266 +	for(TInt i=0; i<aArray.Count(); i++)
  1.1267 +		{
  1.1268 +		TBuf8<64> b;
  1.1269 +		b.Num(aArray[i]);
  1.1270 +		if(aPayloadBuf.MaxSize() < aPayloadBuf.Length()+b.Length())
  1.1271 +			{
  1.1272 +			aPayloadBuf.ReAllocL(aPayloadBuf.Length()+(b.Length()*10));
  1.1273 +			}
  1.1274 +		aPayloadBuf.Append(b);
  1.1275 +		if(i < aArray.Count()-1) //skip last sparator as it will be added automatically
  1.1276 +			{
  1.1277 +			aPayloadBuf.Append(DATA_SEPARATOR);
  1.1278 +			}
  1.1279 +		}
  1.1280 +	}
  1.1281 +
  1.1282 +
  1.1283 +TInt CULoggerServer::RestartOutputting()
  1.1284 +	{
  1.1285 +	TInt err=KErrNone;
  1.1286 +	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1287 +	__MARK_METHOD("CULoggerServer::ForceRefreshSettingsL")
  1.1288 +	#endif
  1.1289 +	if(iBtraceOpen != EFalse)
  1.1290 +		{
  1.1291 +		err = Stop();
  1.1292 +		iBtraceOpen = EFalse;
  1.1293 +		}
  1.1294 +
  1.1295 +	 if(iDataWatcher)
  1.1296 +		 {
  1.1297 +		 iDataWatcher->Cancel();
  1.1298 +		 delete iDataWatcher;
  1.1299 +		 iDataWatcher = NULL;
  1.1300 +		 }
  1.1301 +	 if(iOutputFramework)
  1.1302 +		 {
  1.1303 +		 delete iOutputFramework;
  1.1304 +		 iOutputFramework = NULL;
  1.1305 +		 }
  1.1306 +	 if(iInputFramework)
  1.1307 +		 {
  1.1308 +		 delete iInputFramework;
  1.1309 +		 iInputFramework = NULL;
  1.1310 +		 }
  1.1311 +	 if(iPluginAllocator)
  1.1312 +		 {
  1.1313 +		 delete iPluginAllocator;
  1.1314 +		 iPluginAllocator = NULL;
  1.1315 +		 }
  1.1316 +	if(iConfigManager)
  1.1317 +		{
  1.1318 +		iConfigManager->RefreshConfigFiles();
  1.1319 +		}
  1.1320 +
  1.1321 +	err = Start(); //always start
  1.1322 +	return err;
  1.1323 +	}
  1.1324 +
  1.1325 +
  1.1326 +TInt CULoggerServer::ResetBtracePrimaryFilters(RBTrace	&aBTrace)
  1.1327 +	{
  1.1328 +	for(TUint i=0; i<256; i++)
  1.1329 +		aBTrace.SetFilter(i, EFalse);
  1.1330 +	aBTrace.SetFilter2(0); 
  1.1331 +	return KErrNone;
  1.1332 +	}
  1.1333 +
  1.1334 +//This bit should be part of the input framework, or it should reuse the other methods better
  1.1335 +ControlData* CULoggerServer::ProcessCommandL(TCommand aOpCode, RArray<TPtrC8> &aArguments)
  1.1336 +	{
  1.1337 +	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1338 +	__MARK_METHOD("CULoggerServer::ProcessCommand")
  1.1339 +	#endif	
  1.1340 +	
  1.1341 +	TInt errCode = KErrNone;
  1.1342 +	TInt minSize = 8;
  1.1343 +	CInputData *inputData = new (ELeave) CInputData(minSize);
  1.1344 +	ControlData* data = NULL;
  1.1345 +	RBuf8 payloadBuf;
  1.1346 +	TBuf8<32> result;
  1.1347 +
  1.1348 +	switch(aOpCode)
  1.1349 +		{
  1.1350 +		case EStart:
  1.1351 +			{
  1.1352 +			if(!ServerState())
  1.1353 +				errCode = this->Start();
  1.1354 +			else
  1.1355 +				errCode = KErrInUse;
  1.1356 +			result.Num(errCode);
  1.1357 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1358 +			}
  1.1359 +		break;
  1.1360 +
  1.1361 +		case EStop:
  1.1362 +			{
  1.1363 +			//ulogger shouldn't be restarted here as we must send acknowledgment back to PC
  1.1364 +			//Stop will be done in DoPostProcessing method after sending ack.
  1.1365 +			result.Num(errCode);
  1.1366 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1367 +			}
  1.1368 +		break;
  1.1369 +			
  1.1370 +		case ESetPrimaryFilter:
  1.1371 +			{
  1.1372 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1373 +			__LOG("ESetPrimaryFilter")
  1.1374 +			#endif
  1.1375 +			
  1.1376 +			RArray<TUint32> filterArray;
  1.1377 +			
  1.1378 +			errCode = KErrNone;
  1.1379 +			//process parameters
  1.1380 +			TInt i;
  1.1381 +			for(i=0; i<aArguments.Count(); i++)
  1.1382 +				{
  1.1383 +				TUint8 val;
  1.1384 +				TLex8 lex(aArguments[i]);
  1.1385 +				if((errCode=lex.Val(val, EDecimal)) != KErrNone)
  1.1386 +					{
  1.1387 +					//report bad values, don't set anything
  1.1388 +					if(errCode == KErrGeneral)
  1.1389 +						errCode = KErrArgument;
  1.1390 +					result.Num(errCode);
  1.1391 +					data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1392 +					/*
  1.1393 +					payloadBuf.Create(128);
  1.1394 +					payloadBuf.Copy(aArguments[i]);
  1.1395 +					inputData->AppendNewData(ack, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1396 +					*/
  1.1397 +					filterArray.Close();
  1.1398 +					break;
  1.1399 +					}
  1.1400 +				filterArray.AppendL(val);
  1.1401 +				}
  1.1402 +			
  1.1403 +			if(errCode == KErrNone)
  1.1404 +				{
  1.1405 +				errCode = SetActiveFilterL(filterArray, EPrimaryFilter);
  1.1406 +				result.Num(errCode);
  1.1407 +			
  1.1408 +				//create acknowledment
  1.1409 +				result.Num(errCode);
  1.1410 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1411 +			
  1.1412 +				//create string as a payload
  1.1413 +				/*
  1.1414 +				payloadBuf.CreateL(dupfilterArray.Count()*4);
  1.1415 +				for(i=0; i<dupfilterArray.Count(); i++)
  1.1416 +					{
  1.1417 +					TBuf8<32> b;
  1.1418 +					b.Num(dupfilterArray[i]);
  1.1419 +					if(payloadBuf.MaxSize() < payloadBuf.Length()+b.Length())
  1.1420 +						payloadBuf.ReAllocL(payloadBuf.Length()+(b.Length()*10));
  1.1421 +					payloadBuf.Append(b);
  1.1422 +					if(i < dupfilterArray.Count()-1) //skip last sparator as it will be added automatically
  1.1423 +						payloadBuf.Append(DATA_SEPARATOR);
  1.1424 +					}
  1.1425 +				if(payloadBuf.Length() > 0)
  1.1426 +					inputData->AppendNewData(ack, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1427 +				*/
  1.1428 +				filterArray.Close();
  1.1429 +				}
  1.1430 +			}
  1.1431 +		break; //ESetPrimaryFilter
  1.1432 +		
  1.1433 +		case ESetSecondaryFilter:
  1.1434 +			{
  1.1435 +			RArray<TUint32> filterArray;
  1.1436 +			//process parameters
  1.1437 +			TInt i;
  1.1438 +			for(i=0; i<aArguments.Count(); i++)
  1.1439 +				{
  1.1440 +				TUint32 val;
  1.1441 +				TLex8 lex(aArguments[i]);
  1.1442 +				if((errCode=lex.Val(val,EDecimal)) != KErrNone)
  1.1443 +					{
  1.1444 +					//report bad values, don't set anything
  1.1445 +					if(errCode == KErrGeneral)
  1.1446 +						errCode = KErrArgument;
  1.1447 +					result.Num(errCode);
  1.1448 +					data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1449 +					/*
  1.1450 +					payloadBuf.CreateL(128);
  1.1451 +					payloadBuf.Copy(aArguments[i]);
  1.1452 +					man->AppendNewData(ack, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1453 +					*/
  1.1454 +					filterArray.Close();
  1.1455 +					break;
  1.1456 +					}
  1.1457 +				filterArray.AppendL(val);
  1.1458 +				}
  1.1459 +			if(errCode != KErrNone)
  1.1460 +				break;
  1.1461 +			
  1.1462 +			//create ack
  1.1463 +			errCode = SetActiveFilterL(filterArray, ESecondaryFilter);
  1.1464 +			result.Num(errCode);
  1.1465 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1466 +		
  1.1467 +			filterArray.Close();
  1.1468 +			}
  1.1469 +		break; //ESetSecondaryFilter
  1.1470 +
  1.1471 +		case EEnableSecondaryFiltering:
  1.1472 +			{
  1.1473 +			errCode = SetSecondaryFiltering(KEnable);
  1.1474 +			result.Num(errCode);
  1.1475 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1476 +			}
  1.1477 +		break;
  1.1478 +
  1.1479 +		case EDisableSecondaryFiltering:
  1.1480 +			{
  1.1481 +			errCode = SetSecondaryFiltering(KDisable);
  1.1482 +			result.Num(errCode);
  1.1483 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1484 +			}
  1.1485 +		break;
  1.1486 +
  1.1487 +		case EResizeTraceBuffer:
  1.1488 +			{
  1.1489 +			if(aArguments.Count() > 0)
  1.1490 +				{
  1.1491 +				TInt bufSize;
  1.1492 +				TLex8 lex(aArguments[0]);
  1.1493 +				if((errCode = lex.Val(bufSize)) == KErrNone)
  1.1494 +					errCode = SetBufferSizeL(bufSize);
  1.1495 +				}
  1.1496 +			else
  1.1497 +				errCode = KErrArgument;
  1.1498 +
  1.1499 +			result.Num(errCode);
  1.1500 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1501 +			}
  1.1502 +		break;
  1.1503 +
  1.1504 +		case ESetBufferMode:
  1.1505 +			{
  1.1506 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1507 +			__LOG("ESetBufferMode")
  1.1508 +			#endif
  1.1509 +
  1.1510 +			if(aArguments.Count() > 0)
  1.1511 +				{
  1.1512 +				if(aArguments[0].Compare(KCircular)==0)
  1.1513 +					errCode  = SetBufferMode(KCircular);
  1.1514 +					else if(aArguments[0].Compare(KStraight)==0)
  1.1515 +						errCode  = SetBufferMode(KStraight);
  1.1516 +						else
  1.1517 +							errCode = KErrArgument;
  1.1518 +				}
  1.1519 +			else
  1.1520 +				errCode = KErrArgument;
  1.1521 +
  1.1522 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1523 +			__LOG("errCode")
  1.1524 +			__LOGNUM(errCode)
  1.1525 +			#endif
  1.1526 +
  1.1527 +			result.Num(errCode);
  1.1528 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1529 +			}
  1.1530 +		break;
  1.1531 +
  1.1532 +		case ESetDataNotificationSize:
  1.1533 +			{
  1.1534 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1535 +			__LOG("ESetDataNotificationSize")
  1.1536 +			#endif
  1.1537 +
  1.1538 +			if(aArguments.Count() > 0)
  1.1539 +				{
  1.1540 +				TInt dns;
  1.1541 +				TLex8 lex(aArguments[0]);
  1.1542 +				if((errCode = lex.Val(dns)) == KErrNone)
  1.1543 +					errCode = SetDataNotificationSizeL(dns);
  1.1544 +					else
  1.1545 +						errCode = KErrArgument;
  1.1546 +				}
  1.1547 +			else
  1.1548 +				errCode = KErrArgument;
  1.1549 +
  1.1550 +			result.Num(errCode);
  1.1551 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1552 +			}
  1.1553 +		break;
  1.1554 +
  1.1555 +		case ERemovePluginSettings:
  1.1556 +			{
  1.1557 +			if(aArguments.Count() > 0)
  1.1558 +				errCode = RemovePluginSettingsL(aArguments[0]);
  1.1559 +			else
  1.1560 +				errCode = KErrArgument;
  1.1561 +			result.Num(errCode);
  1.1562 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1563 +			}
  1.1564 +		break;
  1.1565 +
  1.1566 +		case EGetInstalledPlugins:
  1.1567 +			{
  1.1568 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1569 +			__LOG("EGetInstalledOutputPlugins")
  1.1570 +			#endif
  1.1571 +
  1.1572 +			RArray<TPtrC8> tmpArray;
  1.1573 +			errCode = GetInstalledOutputPlugins(tmpArray);
  1.1574 +			result.Num(errCode);
  1.1575 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1576 +
  1.1577 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1578 +			for(TInt p=0; p<tmpArray.Count(); p++) __LOGBUF(tmpArray[p])
  1.1579 +			#endif
  1.1580 +
  1.1581 +			//create payload
  1.1582 +			PrepareControlDataPayloadL(payloadBuf, tmpArray);
  1.1583 +			//add playload in control data chunk
  1.1584 +			if(payloadBuf.Length() > 0)
  1.1585 +				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1586 +			}
  1.1587 +		break; //EGetInstalledOutputPlugins
  1.1588 +
  1.1589 +		case EGetActivePlugin: //output
  1.1590 +			{
  1.1591 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1592 +			__LOG("EGetActivePlugin")
  1.1593 +			#endif
  1.1594 +
  1.1595 +			RArray<TPtrC8> tmpArray;
  1.1596 +			errCode = GetActiveOutputPlugin(tmpArray);
  1.1597 +			result.Num(errCode);
  1.1598 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1599 +
  1.1600 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1601 +			for(TInt p=0; p<tmpArray.Count(); p++) __LOGBUF(tmpArray[p])
  1.1602 +			#endif
  1.1603 +
  1.1604 +			//create payload
  1.1605 +			PrepareControlDataPayloadL(payloadBuf, tmpArray);
  1.1606 +			//add playload in control data chunk
  1.1607 +			if(payloadBuf.Length() > 0)
  1.1608 +				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1609 +			}
  1.1610 +		break; //EGetActivePlugin
  1.1611 +
  1.1612 +		case EGetPluginSettings:
  1.1613 +			{
  1.1614 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1615 +			__LOG("EGetPluginSettings")
  1.1616 +			#endif
  1.1617 +			RArray<TPtrC8> tmpArray;
  1.1618 +			if(aArguments.Count() > 0)
  1.1619 +				{	
  1.1620 +				errCode = GetOptionsSettingsL(aArguments[0],tmpArray);
  1.1621 +
  1.1622 +				#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1623 +				for(TInt p=0; p<tmpArray.Count(); p++) __LOGBUF(tmpArray[p])
  1.1624 +				#endif
  1.1625 +				}
  1.1626 +			else
  1.1627 +				errCode = KErrArgument;
  1.1628 +
  1.1629 +			result.Num(errCode);
  1.1630 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1631 +			//create payload
  1.1632 +			PrepareControlDataPayloadL(payloadBuf, tmpArray);
  1.1633 +			//add playload in control data chunk
  1.1634 +			if(payloadBuf.Length() > 0)
  1.1635 +				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1636 +			}
  1.1637 +		break; //EGetPluginSettings
  1.1638 +
  1.1639 +		case EGetPrimaryFilters:
  1.1640 +			{
  1.1641 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1642 +			__LOG("EGetPluginSettings")
  1.1643 +			#endif
  1.1644 +
  1.1645 +			RArray<TUint32> tmpArray;
  1.1646 +			errCode = GetActiveFilters(tmpArray,EPrimaryFilter);
  1.1647 +
  1.1648 +			result.Num(errCode);
  1.1649 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1650 +
  1.1651 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1652 +			for(TInt p=0; p<tmpArray.Count(); p++) __LOGNUM(tmpArray[p])
  1.1653 +			#endif
  1.1654 +
  1.1655 +			//create payload
  1.1656 +			PrepareControlDataPayloadL(payloadBuf, tmpArray);
  1.1657 +
  1.1658 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1659 +			__LOG("EGetPluginSettings - test 1")
  1.1660 +			#endif
  1.1661 +
  1.1662 +			
  1.1663 +			if(payloadBuf.Length() > 0)
  1.1664 +				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1665 +			tmpArray.Close();
  1.1666 +			
  1.1667 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1668 +			__LOG("EGetPluginSettings - test 2")
  1.1669 +			#endif
  1.1670 +			}
  1.1671 +		break; //EGetPrimaryFilters
  1.1672 +		
  1.1673 +		case EGetSecondaryFilters:
  1.1674 +			{
  1.1675 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1676 +			__LOG("EGetSecondaryFilters")
  1.1677 +			#endif
  1.1678 +			
  1.1679 +			TBool skipReadingFilters = EFalse;
  1.1680 +			RArray<TPtrC8> tmpArrayTxt;
  1.1681 +			TBool enabled = EFalse;
  1.1682 +			errCode = errCode = this->GetSecondaryFiltering(enabled);
  1.1683 +			if(errCode == KErrNone)
  1.1684 +				{
  1.1685 +				if(EFalse == enabled)
  1.1686 +						{
  1.1687 +						result.Num(errCode);
  1.1688 +					data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1689 +						skipReadingFilters = ETrue;
  1.1690 +						//create payload
  1.1691 +					PrepareControlDataPayloadL(payloadBuf, tmpArrayTxt);
  1.1692 +						if(payloadBuf.Length() > 0)
  1.1693 +						inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1694 +						}
  1.1695 +				}
  1.1696 +
  1.1697 +			RArray<TUint32> tmpArray;
  1.1698 +			if(!skipReadingFilters)
  1.1699 +				{
  1.1700 +				errCode = this->GetActiveFilters(tmpArray,ESecondaryFilter);
  1.1701 +				result.Num(errCode);
  1.1702 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1703 +				//create payload
  1.1704 +				PrepareControlDataPayloadL(payloadBuf, tmpArray);
  1.1705 +				if(payloadBuf.Length() > 0)
  1.1706 +					inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1707 +				}
  1.1708 +			
  1.1709 +			tmpArrayTxt.Close();
  1.1710 +			tmpArray.Close();
  1.1711 +			}
  1.1712 +		break; //EGetSecondaryFilters
  1.1713 +		
  1.1714 +		case EGetSecondaryFiltering:
  1.1715 +			{
  1.1716 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1717 +			__LOG("EGetSecondaryFiltering")
  1.1718 +			#endif
  1.1719 +			
  1.1720 +			TBool enabled = EFalse;
  1.1721 +			errCode = GetSecondaryFiltering(enabled);
  1.1722 +			if(errCode == KErrNone)
  1.1723 +				{
  1.1724 +			result.Num(errCode);
  1.1725 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1726 +				
  1.1727 +				//create payload
  1.1728 +				TBuf8<32> b;
  1.1729 +				b.Num(enabled);
  1.1730 +				inputData->AppendNewData(data, (const void*)b.Ptr(), b.Length());
  1.1731 +				}
  1.1732 +			else
  1.1733 +				{
  1.1734 +				result.Num(errCode);
  1.1735 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1736 +				}
  1.1737 +			}
  1.1738 +		break; //EGetSecondaryFiltering
  1.1739 +		
  1.1740 +		//this functionality is removed now
  1.1741 +		/*
  1.1742 +		case ESetSecondaryFilterCurrent:
  1.1743 +			{
  1.1744 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1745 +			__LOG("ESetSecondaryFilterCurrent")
  1.1746 +			#endif
  1.1747 +			
  1.1748 +			errCode = this->SetSecondaryFiltering(KCurrent);
  1.1749 +			result.Num(errCode);
  1.1750 +			ack = man->CreatePackage((void*)result.Ptr(), result.Length());
  1.1751 +			}
  1.1752 +		break; //ESetSecondaryFilterCurrent
  1.1753 +		*/
  1.1754 +		case EGetTraceBufferSize:
  1.1755 +			{
  1.1756 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1757 +			__LOG("EGetTraceBufferSize")
  1.1758 +			#endif
  1.1759 +			
  1.1760 +			TInt bufferSize = 0;	
  1.1761 +			errCode = GetBufandDataNotifyValuesL(KBuffer,bufferSize);
  1.1762 +			if(errCode == KErrNone)
  1.1763 +				{
  1.1764 +				result.Num(errCode);
  1.1765 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1766 +				TBuf8<32> b;
  1.1767 +				b.Num(bufferSize);
  1.1768 +				inputData->AppendNewData(data, (const void*)b.Ptr(), b.Length());
  1.1769 +				}
  1.1770 +			else
  1.1771 +				{
  1.1772 +				result.Num(errCode);
  1.1773 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1774 +				}
  1.1775 +			}
  1.1776 +		break; //EGetTraceBufferSize
  1.1777 +		
  1.1778 +		case EGetBufferMode:
  1.1779 +			{
  1.1780 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1781 +			__LOG("EGetBufferMode")
  1.1782 +			#endif
  1.1783 +			
  1.1784 +			TInt bufferMode = 3;	
  1.1785 +			errCode = GetBufandDataNotifyValuesL(KBufferMode,bufferMode);
  1.1786 +			if(errCode == KErrNone)
  1.1787 +				{
  1.1788 +				result.Num(errCode);
  1.1789 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1790 +
  1.1791 +				result.Zero();
  1.1792 +				if(bufferMode == 0)
  1.1793 +					result.Append(KCircular);
  1.1794 +				else if(bufferMode == 1)
  1.1795 +					result.Append(KStraight);
  1.1796 +					else
  1.1797 +						result.Append(_L8("Invalid mode"));
  1.1798 +
  1.1799 +				inputData->AppendNewData(data, (const void*)result.Ptr(), result.Length());
  1.1800 +				}
  1.1801 +			else
  1.1802 +				{
  1.1803 +				result.Num(errCode);
  1.1804 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1805 +				}
  1.1806 +			}
  1.1807 +		break; //EGetBufferMode
  1.1808 +		
  1.1809 +		case EGetDataNotificationSize:
  1.1810 +			{
  1.1811 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1812 +			__LOG("EGetDataNotificationSize")
  1.1813 +			#endif
  1.1814 +			
  1.1815 +			TInt dataNotification = 0;	
  1.1816 +			errCode = GetBufandDataNotifyValuesL(KDataNotification,dataNotification);
  1.1817 +			if(errCode == KErrNone)
  1.1818 +				{
  1.1819 +				result.Num(errCode);
  1.1820 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1821 +				TBuf8<32> b;
  1.1822 +				b.Num(dataNotification);
  1.1823 +				inputData->AppendNewData(data, (const void*)b.Ptr(), b.Length());
  1.1824 +				}
  1.1825 +			else
  1.1826 +				{
  1.1827 +				result.Num(errCode);
  1.1828 +				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1829 +				}
  1.1830 +			}
  1.1831 +		break; //EGetDataNotificationSize
  1.1832 +		
  1.1833 +		case ERemovePrimaryFilter:
  1.1834 +			{
  1.1835 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1836 +			__LOG("ERemovePrimaryFilter")
  1.1837 +			for(TInt k=0; k<aArguments.Count(); k++)
  1.1838 +				{
  1.1839 +				__LOGBUF(aArguments[k])
  1.1840 +				}
  1.1841 +			#endif
  1.1842 +			
  1.1843 +			if(aArguments.Count() > 0)
  1.1844 +				{
  1.1845 +				RArray<TUint32> filterArray;
  1.1846 +				for(TInt i=0; i<aArguments.Count(); i++)
  1.1847 +					{
  1.1848 +					TUint32 val;
  1.1849 +					TLex8 lex(aArguments[i]);
  1.1850 +					if(lex.Val(val, EDecimal) == KErrNone)
  1.1851 +						filterArray.AppendL(val);
  1.1852 +					}
  1.1853 +				errCode = RemoveActiveFilter(filterArray,EPrimaryFilter);
  1.1854 +				filterArray.Close();
  1.1855 +				}
  1.1856 +			else
  1.1857 +				errCode = KErrArgument;
  1.1858 +			
  1.1859 +			result.Num(errCode);
  1.1860 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1861 +			}
  1.1862 +		break; //ERemovePrimaryFilter
  1.1863 +		
  1.1864 +		case ERemoveSecondaryFilter:
  1.1865 +			{
  1.1866 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1867 +			__LOG("EDisableMultipleModuleUids")
  1.1868 +			for(TInt k=0; k<aArguments.Count(); k++)
  1.1869 +				{
  1.1870 +				__LOGBUF(aArguments[k])
  1.1871 +				}
  1.1872 +			#endif
  1.1873 +			
  1.1874 +			if(aArguments.Count() > 0)
  1.1875 +				{
  1.1876 +				RArray<TUint32> filterArray;
  1.1877 +				for(TInt i=0; i<aArguments.Count(); i++)
  1.1878 +					{
  1.1879 +					TUint32 val;
  1.1880 +					TLex8 lex(aArguments[i]);
  1.1881 +					if(lex.Val(val, EDecimal) == KErrNone)
  1.1882 +						filterArray.AppendL(val);
  1.1883 +					}
  1.1884 +				errCode = RemoveActiveFilter(filterArray,ESecondaryFilter);
  1.1885 +				filterArray.Close();
  1.1886 +				}
  1.1887 +			else
  1.1888 +				errCode = KErrArgument;
  1.1889 +			
  1.1890 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1891 +			__LOG("errCode:")
  1.1892 +			__LOGNUM(errCode)
  1.1893 +			#endif
  1.1894 +			
  1.1895 +			result.Num(errCode);
  1.1896 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1897 +			}
  1.1898 +		break; //ERemoveSecondaryFilter
  1.1899 +		
  1.1900 +		case ESetPluginSettings:
  1.1901 +			{
  1.1902 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1903 +			__LOG("ESetPluginSettings")
  1.1904 +			#endif
  1.1905 +				
  1.1906 +			if(aArguments.Count() > 2)
  1.1907 +				{
  1.1908 +				TBuf8<128> plugin;
  1.1909 +				plugin.Copy(aArguments[0]);
  1.1910 +				aArguments.Remove(0);
  1.1911 +				errCode = SetPluginSettings(plugin, aArguments);
  1.1912 +				}
  1.1913 +			else
  1.1914 +				errCode = KErrArgument;
  1.1915 +						
  1.1916 +			result.Num(errCode);
  1.1917 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1918 +			}
  1.1919 +		break; //ESetChannelSettings
  1.1920 +		
  1.1921 +		case ESetActivePlugin:
  1.1922 +			{
  1.1923 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1924 +			__LOG("ESetActiveOutputPlugin")
  1.1925 +			#endif
  1.1926 +
  1.1927 +			if(aArguments.Count() > 0)
  1.1928 +				errCode = SetActiveOutputPlugin(aArguments[0]);
  1.1929 +			else
  1.1930 +				errCode = KErrArgument;
  1.1931 +
  1.1932 +			result.Num(errCode);
  1.1933 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1934 +			}
  1.1935 +		break; //ESetActiveOutputPlugin
  1.1936 +
  1.1937 +		case ESetActiveInputPlugin:
  1.1938 +			{
  1.1939 +			if(aArguments.Count() > 0)
  1.1940 +				errCode = SetActiveInputPlugin(aArguments[0]);
  1.1941 +			else
  1.1942 +				errCode = KErrArgument;
  1.1943 +
  1.1944 +			result.Num(errCode);
  1.1945 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1946 +			}
  1.1947 +		break;
  1.1948 +		
  1.1949 +		case EDeactivateInputPlugin:
  1.1950 +			{
  1.1951 +			if(aArguments.Count() > 0)
  1.1952 +				errCode = DeActivateInputPlugin(aArguments[0]);
  1.1953 +			else
  1.1954 +				errCode = KErrArgument;
  1.1955 +
  1.1956 +			result.Num(errCode);
  1.1957 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1958 +			}
  1.1959 +		break;
  1.1960 +
  1.1961 +		case EGetActiveInputPlugin:
  1.1962 +			{
  1.1963 +			RArray<TPtrC8> tmpArray;
  1.1964 +			errCode = GetActiveInputPlugin(tmpArray);
  1.1965 +			result.Num(errCode);
  1.1966 +
  1.1967 +			//remove ini specific data (number)
  1.1968 +			//example (1 uloggerusbplugin) must look like (uloggerusbplugin)
  1.1969 +			TInt i=0;
  1.1970 +			while(i<tmpArray.Count())
  1.1971 +				{
  1.1972 +				TInt v = 0;
  1.1973 +				TLex8 l(tmpArray[i]);
  1.1974 +				if(l.Val(v) == KErrNone)
  1.1975 +					tmpArray.Remove(i);
  1.1976 +				else
  1.1977 +					++i;
  1.1978 +				}
  1.1979 +
  1.1980 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1981 +			PrepareControlDataPayloadL(payloadBuf, tmpArray);
  1.1982 +			if(payloadBuf.Length() > 0)
  1.1983 +				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.1984 +			tmpArray.Close();
  1.1985 +			}
  1.1986 +		break;
  1.1987 +		
  1.1988 +		case EGetInputPlugins:
  1.1989 +			{
  1.1990 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.1991 +			__LOG("EGetControlPlugins")
  1.1992 +			#endif
  1.1993 +			
  1.1994 +			RArray<TPtrC8> tmpArray;
  1.1995 +			errCode = GetInstalledInputPluginsL(tmpArray);
  1.1996 +
  1.1997 +			result.Num(errCode);
  1.1998 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.1999 +
  1.2000 +			//create payload
  1.2001 +			PrepareControlDataPayloadL(payloadBuf, tmpArray);
  1.2002 +			//add playload to control data chunk
  1.2003 +			if(payloadBuf.Length() > 0)
  1.2004 +				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
  1.2005 +			tmpArray.Close();
  1.2006 +			}
  1.2007 +		break;
  1.2008 +
  1.2009 +		case ERestart:
  1.2010 +			{
  1.2011 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.2012 +			__LOG("ERestartOutputting")
  1.2013 +			#endif
  1.2014 +
  1.2015 +			//ulogger shouldn't be restarted here as we must send acknowledgment back to PC
  1.2016 +			//restart will be done in DoPostProcessing method after sending ack.
  1.2017 +			result.Num(errCode);
  1.2018 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.2019 +			}
  1.2020 +		break;
  1.2021 +		
  1.2022 +		default:
  1.2023 +			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
  1.2024 +			__LOG("input command not supported")
  1.2025 +			#endif
  1.2026 +		
  1.2027 +			result.Num(KErrNotSupported);
  1.2028 +			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
  1.2029 +		break;
  1.2030 +	}//end of switch
  1.2031 +
  1.2032 +	
  1.2033 +	//cleanup
  1.2034 +	if(inputData)
  1.2035 +		{
  1.2036 +		delete inputData;
  1.2037 +		inputData = NULL;
  1.2038 +		}
  1.2039 +	payloadBuf.Close();
  1.2040 +
  1.2041 +	return data;
  1.2042 +	}
  1.2043 +
  1.2044 +
  1.2045 +
  1.2046 +void CULoggerServer::DoPostProcessing(TCommand aCmd)
  1.2047 +	{
  1.2048 +	switch(aCmd)
  1.2049 +		{
  1.2050 +		case EStop:
  1.2051 +			Stop();
  1.2052 +			break;
  1.2053 +		case ERestart:
  1.2054 +			RestartOutputting();
  1.2055 +			break;
  1.2056 +		default:
  1.2057 +			break;
  1.2058 +		}
  1.2059 +	}
  1.2060 +
  1.2061 +/**
  1.2062 +This function checks if array of given names contains any of real plugin names (either output of input).
  1.2063 +After call aPluginList will be filtered to contain only proper plugin names (strings that really could be used 
  1.2064 +to refer to a real plugin.
  1.2065 +@param aFilter Either EOutputPluginFilter or EInputPluginFilter.
  1.2066 +@param aPluginList Reference to an array which contain list of names that function has to check.
  1.2067 + */
  1.2068 +void CULoggerServer::FilterPlugins(TPluginFilter aFilter, RArray<TPtrC8>& aPluginList)
  1.2069 +	{
  1.2070 +	TInt errCode = 0;
  1.2071 +	CPlugin::TPluginInterface interfaceId;
  1.2072 +	//assign filter value
  1.2073 +	interfaceId = (aFilter == EOutputPluginFilter ? MOutputPlugin::iInterfaceId : MInputPlugin::iInterfaceId);
  1.2074 +	
  1.2075 +	//filter plugins
  1.2076 +	TInt i=0;
  1.2077 +	while(i<aPluginList.Count())
  1.2078 +		{
  1.2079 +		CPlugin *plugin = NULL;
  1.2080 +		TRAP(errCode, plugin=CPlugin::NewL(aPluginList[i]));
  1.2081 +		if(plugin && errCode==KErrNone)
  1.2082 +			{
  1.2083 +			TAny *ptr = NULL;
  1.2084 +			TRAP(errCode, ptr=plugin->GetInterfaceL(interfaceId));
  1.2085 +			if(!ptr || errCode!=KErrNone)
  1.2086 +				{
  1.2087 +				aPluginList.Remove(i--);
  1.2088 +				}
  1.2089 +			//cleanup
  1.2090 +			if(plugin)
  1.2091 +				{	
  1.2092 +				delete plugin;
  1.2093 +				plugin = NULL;
  1.2094 +				}
  1.2095 +			}
  1.2096 +		++i;
  1.2097 +		}
  1.2098 +	}
  1.2099 +
  1.2100 +
  1.2101 +
  1.2102 +TBool CULoggerServer::ServerState()
  1.2103 +	{
  1.2104 +	return iBtraceOpen;
  1.2105 +	}
  1.2106 +
  1.2107 +
  1.2108 +TBool CULoggerServer::CheckPluginExists(TPtrC8& aPluginName, TPluginFilter aPluginFilter)
  1.2109 +	{
  1.2110 +	RArray<TPtrC8> pluginsArray;
  1.2111 +	if(aPluginFilter == EOutputPluginFilter)
  1.2112 +		GetInstalledOutputPlugins(pluginsArray);
  1.2113 +	else if(aPluginFilter == EInputPluginFilter)
  1.2114 +		GetInstalledInputPluginsL(pluginsArray);
  1.2115 +
  1.2116 +	for(TInt i=0; i<pluginsArray.Count(); ++i)
  1.2117 +		if(aPluginName.Compare(pluginsArray[i])==0)
  1.2118 +			{
  1.2119 +			pluginsArray.Close();
  1.2120 +			return ETrue;
  1.2121 +			}
  1.2122 +		
  1.2123 +	pluginsArray.Close();
  1.2124 +	return EFalse;
  1.2125 +	}
  1.2126 +
  1.2127 +
  1.2128 +}//end of namespace
  1.2129 +
  1.2130 +#ifndef __ULOGGER_SERVER_UNIT_TEST
  1.2131 +//Main Entry
  1.2132 +TInt E32Main()
  1.2133 +{
  1.2134 +	return Ulogger::CULoggerServer::StartServer();
  1.2135 +}
  1.2136 +#endif //__ULOGGER_SERVER_UNIT_TEST