traceservices/tracefw/ulogger/src/uloggerserver/uloggerserver.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 #include <e32const.h>
       
    17 #include <e32btrace.h>
       
    18 #include <f32file.h>
       
    19 #include "uloggerserver.h"
       
    20 #include "uloggersession.h"
       
    21 #include "uloggerclient.h"
       
    22 #include "uloggerplugin.h"
       
    23 #include "uloggershared.h"
       
    24 #include "uloggerdatatypes.h"
       
    25 #include "inputdata.h"
       
    26 #include "uloggercommands.h"
       
    27 
       
    28 #if defined(__LIGHTLOGGER_ENABLED)
       
    29 #include "lightlogger.h" 
       
    30 #endif
       
    31 
       
    32 
       
    33 namespace Ulogger {
       
    34 
       
    35 
       
    36 /*Default constructor*/
       
    37 CULoggerServer::CULoggerServer(TInt aPriority)
       
    38 : CServer2( aPriority )
       
    39 
       
    40 {
       
    41 	iIsBooting = ETrue;
       
    42 	iConfigManager = NULL;
       
    43 	iDataWatcher = NULL;
       
    44 	iOutputFramework = NULL;
       
    45 	iInputFramework = NULL;
       
    46 	iPluginAllocator = NULL;
       
    47 }
       
    48 
       
    49 
       
    50 /** Destructor will be called before re-starting
       
    51 */
       
    52 CULoggerServer::~CULoggerServer()
       
    53 {
       
    54 	delete iConfigManager;
       
    55 	delete iOutputFramework;
       
    56 	delete iInputFramework;
       
    57 	delete iPluginAllocator;
       
    58 	iPluginArray.ResetAndDestroy();
       
    59 	iPluginArray.Close();
       
    60     if(iDataWatcher)
       
    61     	{
       
    62     	iDataWatcher->Cancel();
       
    63     	delete iDataWatcher; 
       
    64     	}
       
    65 }
       
    66 
       
    67 /** Static Factory Construction 
       
    68 @return a pointer to the created object
       
    69 @leave KErrNoMemory if not enough memory available
       
    70 */
       
    71 CULoggerServer* CULoggerServer::NewLC(TInt aPriority)
       
    72 {
       
    73 	CULoggerServer* self = new (ELeave) CULoggerServer( aPriority );
       
    74 	CleanupStack::PushL( self );
       
    75 	self->ConstructL();
       
    76 
       
    77 	return self;
       
    78 }
       
    79 
       
    80 /**
       
    81 Create and install new Framework & Active Scheduler
       
    82 */
       
    83 void CULoggerServer::ConstructL()
       
    84 {
       
    85 	iRunAsService = EFalse; // Not used yet, to be used for run-as-service functionality
       
    86 	iBufferSize = KMaxBufferSize;
       
    87 	iBtraceOpen = EFalse;
       
    88 	iDataNotification = 0;
       
    89 
       
    90 	StartL( KServerName );	
       
    91 	iConfigManager = CConfigFileManager::NewL();
       
    92 
       
    93 }
       
    94 
       
    95 
       
    96 /**
       
    97 Create a new server session. 
       
    98 @note Called by kernel after client's thread use any of the macros for the first time.
       
    99 */
       
   100 CSession2* CULoggerServer::NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const
       
   101 {
       
   102  	TVersion v(KULoggerSrvMajorVersionNumber,KULoggerSrvMinorVersionNumber,KULoggerSrvBuildVersionNumber);
       
   103     if (!User::QueryVersionSupported(v,aVersion))
       
   104          User::Leave(KErrNotSupported);
       
   105 
       
   106 	RThread client;
       
   107 	aMessage.Client(client);
       
   108 	return CULoggerSession::NewL( client, *const_cast<CULoggerServer*>(this) );
       
   109 }
       
   110 
       
   111 
       
   112 /*Increment session counter*/
       
   113 void CULoggerServer::IncrementSessions()
       
   114 {	
       
   115 	++iSessionCounter;
       
   116 }
       
   117 
       
   118 /*Decrement session counter*/
       
   119 void CULoggerServer::DecrementSessions()
       
   120 	{
       
   121 	if(--iSessionCounter <= 0)
       
   122 		{
       
   123 		if (!iBtraceOpen)
       
   124 			ShutDownServer();
       
   125 
       
   126 //
       
   127 // // Replace above if-statement with following to implement run-as-service functionality
       
   128 //
       
   129 //		if((!iBtraceOpen) && (!iRunAsService))
       
   130 //			ShutDownServer();
       
   131 //
       
   132 
       
   133 		}
       
   134 	}
       
   135 
       
   136 /*!
       
   137 Shuts down the server
       
   138 */
       
   139 void CULoggerServer::ShutDownServer()
       
   140 {
       
   141 	CActiveScheduler::Stop();
       
   142 }//</ShutDownServer>
       
   143 
       
   144 
       
   145 
       
   146 
       
   147 /*!
       
   148 Return the error value
       
   149 */
       
   150 TInt CULoggerServer::RunError(TInt aError)
       
   151 {
       
   152 	Message().Complete(aError);
       
   153 	ReStart();
       
   154 
       
   155 	return KErrNone;
       
   156 }
       
   157 
       
   158 
       
   159 
       
   160 
       
   161 void CULoggerServer::PanicServer(TULoggerSrvPanics aPanic)
       
   162 {
       
   163 	User::Panic(KServerName, aPanic);
       
   164 }//</PanicServer>
       
   165 
       
   166 
       
   167 
       
   168 /*!
       
   169 */
       
   170 void CULoggerServer::PanicClient(const RMessage2& aMessage, TULoggerSrvPanics aPanic)
       
   171 {
       
   172 	aMessage.Panic( KServerName, aPanic );
       
   173 }//</PanicClient>
       
   174 
       
   175 
       
   176 
       
   177 
       
   178 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   179 /**
       
   180 ServerL
       
   181 @Installs the active scheduler
       
   182 @Opens the semaphore
       
   183 */
       
   184 TInt CULoggerServer::StartServerL()
       
   185 {
       
   186 	#if defined(__LIGHTLOGGER_ENABLED)
       
   187 	__CREATE_LOG(EFalse)
       
   188 	__HIRES_RESOLUTION
       
   189 	#endif	
       
   190 	
       
   191     CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler();
       
   192     CleanupStack::PushL(activeScheduler) ;
       
   193     CActiveScheduler::Install(activeScheduler);
       
   194     CULoggerServer* server = NULL;
       
   195 	TInt servererr = KErrNone;
       
   196 	TRAP(servererr,
       
   197 		{
       
   198 		server = CULoggerServer::NewLC((TProcessPriority)EPriorityHigh);
       
   199 		CleanupStack::Pop();
       
   200 		});
       
   201 	
       
   202 	if(servererr==KErrNone||servererr==KErrNotFound )
       
   203 		{
       
   204 		RProcess::Rendezvous(KErrNone);
       
   205 		servererr=KErrNone;
       
   206 		CActiveScheduler::Start();
       
   207 		}
       
   208 	else
       
   209 		{
       
   210 		RProcess::Rendezvous(servererr);		
       
   211 		}
       
   212 	delete server;
       
   213    	CleanupStack::PopAndDestroy();
       
   214 	return servererr;
       
   215 	
       
   216 }//</StartingFunctionL>
       
   217 
       
   218 
       
   219 /**
       
   220 Function to to start the server 
       
   221 This should leave with KErrNone 
       
   222 */
       
   223 TInt CULoggerServer::StartServer()
       
   224 {
       
   225 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
   226 	if (!cleanupStack)
       
   227 	{
       
   228         	return KErrNoMemory;
       
   229 	}
       
   230 	TInt err;
       
   231     TRAP(err, StartServerL());
       
   232    
       
   233     delete cleanupStack;
       
   234     cleanupStack = NULL;
       
   235 
       
   236     return err;
       
   237 }//</StartingFunction>
       
   238 
       
   239 
       
   240 /**
       
   241 Function to set the active output media 
       
   242 This should leave with KErrNotFound if given plugin is not the correct one
       
   243 or the file doesn't exists in the user and public path
       
   244 */
       
   245 
       
   246 TInt CULoggerServer::SetActiveOutputPlugin(const TDesC8 &aPluginname)
       
   247 {
       
   248 	RArray<TPtrC8> activePluginsArray;
       
   249 	TInt error= KErrNone;
       
   250 
       
   251 	error = GetInstalledOutputPlugins(activePluginsArray);
       
   252 	if(error==KErrNone)
       
   253 		{
       
   254 		for(TInt i=0;i<activePluginsArray.Count();i++)
       
   255 			{
       
   256 			if(aPluginname.Compare(activePluginsArray[i])==0)
       
   257 				{
       
   258 				error = iConfigManager->SetActiveOutputPlugin(aPluginname);
       
   259 				break;
       
   260 				}	
       
   261 			else 
       
   262 				error = KErrNotFound;
       
   263 			}
       
   264 		}
       
   265 	if(error == KErrAlreadyExists)
       
   266 		{
       
   267 		error=KErrNone;
       
   268 		}
       
   269 	return error;
       
   270 }
       
   271 
       
   272 
       
   273 TInt CULoggerServer::SetActiveInputPlugin(const TDesC8 &aPluginname)
       
   274 	{
       
   275 	RArray<TPtrC8> activePluginsArray;
       
   276 	TInt ret= KErrNone;
       
   277 	//check configuration file in user path (\\ulogger\\uloggerconfig.ini)	
       
   278 
       
   279 	ret = GetInstalledInputPlugins(activePluginsArray);
       
   280 	if(ret==KErrNone)
       
   281 		{
       
   282 		ret = KErrNotFound;
       
   283 		for(TInt i=0;i<activePluginsArray.Count();i++)
       
   284 			{
       
   285 			if(aPluginname.Compare(activePluginsArray[i])==0)
       
   286 				{
       
   287 				ret = iConfigManager->SetActiveInputPlugin(aPluginname);
       
   288 				break;	
       
   289 				}
       
   290 			}
       
   291 		}
       
   292 	return ret;
       
   293 	}
       
   294 
       
   295 
       
   296 /**
       
   297 Function to set the plugin settings
       
   298 This should leave with KErrNotFound if cannot file doesn't exist
       
   299 */
       
   300 TInt CULoggerServer::SetPluginSettings(const TDesC8 &aPluginname, RArray<TPtrC8>& aListBuffer)
       
   301 {	
       
   302 	TInt i = 0;
       
   303 	TInt ret=KErrNone;
       
   304 
       
   305 	//if plug-in doesn't exists
       
   306 	TPtrC8 pluginName(aPluginname);
       
   307 	if(!CheckPluginExists(pluginName, EOutputPluginFilter) && !CheckPluginExists(pluginName, EInputPluginFilter))
       
   308 		return KErrNotFound;
       
   309 	
       
   310 	while(i<aListBuffer.Count())
       
   311 		{
       
   312 		TPtrC8 key(aListBuffer[i]);
       
   313 		TPtrC8 val(aListBuffer[++i]);
       
   314 		ret = iConfigManager->SetPluginSetting(aPluginname, key, val);
       
   315 		if(ret!=KErrNone)
       
   316 			break;
       
   317 		i++;		
       
   318 		}					
       
   319 	return ret;
       
   320 }
       
   321 
       
   322 
       
   323 
       
   324 
       
   325 /**
       
   326 Function to get the plugin settings
       
   327 This should leave with KErrNotFound if cannot find one
       
   328 */
       
   329 TInt CULoggerServer::GetOptionsSettingsL(const TDesC8 &aMediaName, RArray<TPtrC8>& aListBuffer)
       
   330 {
       
   331 	//if plug-in doesn't exists
       
   332 	TPtrC8 pluginName(aMediaName);
       
   333 	if(!CheckPluginExists(pluginName, EOutputPluginFilter) && !CheckPluginExists(pluginName, EInputPluginFilter))
       
   334 		return KErrNotFound;
       
   335 	else
       
   336 		{
       
   337 		TInt ret = GetValues(aMediaName,aListBuffer);
       
   338 		if(ret == KErrNotFound) //this error indicate that there is no section in config file, plug-in exists
       
   339 			ret = KErrNone;
       
   340 		return ret;
       
   341 		}
       
   342 }
       
   343 
       
   344 
       
   345 
       
   346 /**
       
   347 Function to get values from the configuration file (i.e. for filters,plugin settings)
       
   348 This should leave with KErrNotFound if it cannot find the configuration file
       
   349 */
       
   350 TInt CULoggerServer::GetValues(const TDesC8 &aSectionName, RArray<TPtrC8>& aListBuffer)
       
   351 {	
       
   352 	TPtrC8 key;
       
   353 	TPtrC8 val;
       
   354 	TInt err = KErrNotFound;	
       
   355 
       
   356 	Ulogger::CConfigSettingsIter* iter = Ulogger::CConfigSettingsIter::NewL();
       
   357 	CleanupStack::PushL(iter);
       
   358 	
       
   359 	//check User configuration file if exists
       
   360 	//check values for given section in the configuration file 
       
   361 	//if value exists copy it to array 
       
   362 	err = iConfigManager->GetSectionValues(aSectionName,*iter);
       
   363 	if(err == KErrNone)
       
   364 		{
       
   365 		TBool found =EFalse;
       
   366 		while(iter->Next(key,val))
       
   367 			{
       
   368 			aListBuffer.AppendL(key);
       
   369 			aListBuffer.AppendL(val);
       
   370 			found = ETrue;
       
   371 			}
       
   372 		if(!found)
       
   373 			err = KErrNotFound;
       
   374 		}
       
   375 	CleanupStack::PopAndDestroy(); // list
       
   376 	return err;
       
   377 	
       
   378 }
       
   379 
       
   380 
       
   381 /**
       
   382 Sets the Active Filter in the configuration file (primary and secondary filters)
       
   383 @aCategory filters to be set
       
   384 @aDupCategory duplicate filters which are not set
       
   385 @aFilter value that describes primary or secondary filter
       
   386 @return KErrNone, if successful, otherwise one of the other system-wide
       
   387         error codes.
       
   388 */
       
   389 TInt CULoggerServer::SetActiveFilter(RArray<TUint32> aCategory, TInt aFilterType)
       
   390 {
       
   391 	TInt error = KErrNone;
       
   392 	if(aFilterType == 1)
       
   393 		{
       
   394 		if(aCategory.Count()==0 || aCategory.Count()>KMaxPrimaryFiltersLimit)
       
   395 			error = KErrArgument;
       
   396 		else
       
   397 			{
       
   398 			error = iConfigManager->SetActiveFilter(aCategory,KPrimaryFilterSection);
       
   399 			if(error == KErrAlreadyExists)
       
   400 				error = KErrNone;
       
   401 			}
       
   402 		}
       
   403 	if(aFilterType == 2)
       
   404 		{
       
   405 		//we don't want to set more secondary filters than KMaxSecondaryFiltersLimit
       
   406 		RArray<TUint32> tmpArray;
       
   407 		CleanupClosePushL(tmpArray);
       
   408 		error = GetActiveFilters(tmpArray, ESecondaryFilter);
       
   409 		if(!error || error == KErrNotFound)
       
   410 			{
       
   411 			error = KErrNone; //in case it was KErrNotFound as it doesn't matter we didn't have any set already
       
   412 			if(aCategory.Count()==0 ||tmpArray.Count() > KMaxSecondaryFiltersLimit ||
       
   413 					(tmpArray.Count()+ aCategory.Count()) > KMaxSecondaryFiltersLimit)
       
   414 				error = KErrArgument;
       
   415 				
       
   416 			}
       
   417 		CleanupStack::PopAndDestroy(); //tmpArray
       
   418 		if(!error)
       
   419 			error = iConfigManager->SetActiveFilter(aCategory,KSecondaryFilterSection);
       
   420 		}
       
   421 	return error;
       
   422 }
       
   423 	
       
   424 
       
   425 /**
       
   426 Function to remove the Filter from config file
       
   427 @aFilter  Filter to be removed
       
   428 @aValue primary or secondary filter to be removed
       
   429 This should leave with KErrNotFound if cannot find one or any system wide error codes
       
   430 */
       
   431 TInt CULoggerServer::RemoveActiveFilter(RArray<TUint32>& aValue, const TInt aFilter)
       
   432 {
       
   433 	TInt ret = KErrNone;
       
   434 	//remove filter (primary or secondary) from BTrace current configuration
       
   435 	if(aFilter == EPrimaryFilter && (aValue.Count()==0 || aValue.Count()>KMaxPrimaryFiltersLimit))
       
   436 		return KErrArgument;
       
   437 	else if(aFilter == ESecondaryFilter && (aValue.Count()==0 || aValue.Count()>KMaxSecondaryFiltersLimit))
       
   438 		return KErrArgument;
       
   439 		
       
   440 	ret = iConfigManager->RemoveActiveFilter(aValue,aFilter);
       
   441 	if(ret == KErrNotFound) //remove operation should succeed in this situation
       
   442 		ret = KErrNone;
       
   443 		
       
   444 	return ret;
       
   445 }
       
   446 
       
   447 
       
   448 /**
       
   449 Function to set Trace settings to the configuration file
       
   450 @aValue  value to be set
       
   451 @aSetting setting to which value to be set
       
   452 This should leave with KErrNotFound if cannot find one or any system wide error codes
       
   453 */
       
   454 TInt CULoggerServer::SetTraceSettings(const TDesC8&  aValue, const TDesC8& aSetting)
       
   455 	{
       
   456 	TInt r = iConfigManager->SetTraceSettings(aValue, aSetting);
       
   457 	return r;
       
   458 
       
   459 	}
       
   460 
       
   461 /**
       
   462 Function to remove plugin settings from the configuration file
       
   463 @aPluginName  Plugin name whose settings has to be removed
       
   464 @return will return KErrNone or else leave with KErrNotFound  
       
   465 	or any system wide error codes 
       
   466 */
       
   467 
       
   468 TInt CULoggerServer::RemovePluginSettingsL(const TDesC8 &aPluginName)
       
   469 	{
       
   470 	if(aPluginName.Length() == 0)
       
   471 		return KErrArgument;
       
   472 	
       
   473 	TInt ret = KErrNone;
       
   474 	RArray<TPtrC8> settings;
       
   475 	ret = GetOptionsSettingsL(aPluginName, settings);
       
   476 	if(ret != KErrNone || settings.Count()==0)
       
   477 		ret = KErrNotFound;
       
   478 	settings.Close();
       
   479 		
       
   480 	if(ret == KErrNone)
       
   481 		return iConfigManager->RemovePluginSettings(aPluginName);
       
   482 	else
       
   483 		return ret;
       
   484 	}
       
   485 
       
   486 /**
       
   487 Resize the BTrace buffer size
       
   488 
       
   489 @aSize The size to be set for the BTrace buffer.
       
   490 @return KErrNone, if successful, otherwise one of the other system-wide
       
   491         error codes.
       
   492 */
       
   493 TInt CULoggerServer::SetBufferSize(TInt aSize)
       
   494 	{
       
   495 	if(aSize > KMaxBufferSize || aSize < 1)
       
   496 		return KErrArgument;
       
   497 
       
   498 	
       
   499 	//get dns to check
       
   500 	GetBufandDataNotifyValuesL(KDataNotification,iDataNotification);
       
   501 	if(aSize < iDataNotification)
       
   502 		return KErrGeneral;
       
   503 	
       
   504 	iBufferSize = aSize;
       
   505 	HBufC8* Size = HBufC8::NewLC(32);
       
   506 	Size->Des().Num(iBufferSize);
       
   507 	CleanupStack::Pop(1);
       
   508 	TPtr8 ptr(Size->Des());
       
   509 	TInt r = iConfigManager->SetTraceSettings((const TDesC8&)ptr, KBuffer);
       
   510 	return r;
       
   511 	}
       
   512 
       
   513 
       
   514 /**
       
   515 Change the mode of the BTrace Buffer
       
   516 
       
   517 @aValue The mode to be set for the BTrace buffer.
       
   518 @return KErrNone, if successful, otherwise one of the other system-wide
       
   519         error codes.
       
   520 */
       
   521 TInt CULoggerServer::SetBufferMode(const TDesC8& aValue)
       
   522 	{
       
   523 	
       
   524 	TInt r = SetTraceSettings(aValue, KBufferMode);
       
   525 	return r;
       
   526 	}
       
   527 
       
   528 /**
       
   529 Resize the Data Notification size
       
   530 
       
   531 @aSize The size to be set for the Data Notification size.
       
   532 @return KErrNone, if successful, otherwise one of the other system-wide
       
   533         error codes.
       
   534 */
       
   535 TInt CULoggerServer::SetDataNotificationSize(TInt aSize)
       
   536 	{
       
   537 	if(aSize > KMaxDnsSize || aSize < 0)
       
   538 		return KErrArgument;
       
   539 	TInt size, r;
       
   540 	TRAP_IGNORE((r=GetBufandDataNotifyValuesL(KBuffer,size)));
       
   541 	if(aSize > size)
       
   542 		return KErrGeneral;
       
   543 	
       
   544 	iDataNotification = aSize;
       
   545 	HBufC8* Size = HBufC8::NewLC(32);
       
   546 	Size->Des().Num(aSize);
       
   547 	TPtr8 ptr(Size->Des());
       
   548 	r = SetTraceSettings((const TDesC8&)ptr, KDataNotification);
       
   549 	CleanupStack::PopAndDestroy();
       
   550 	return r;
       
   551 	}
       
   552 	
       
   553 /**
       
   554 Function to retrieve the Trace Section Values
       
   555 This should leave with KErrNotFound if cannot find one
       
   556 as this should be treated as a corrupt config file
       
   557 */
       
   558 void CULoggerServer::GetOptionsSettingsL(RArray<TPtrC8>& aListBuffer,const TDesC8& aSetting)
       
   559 {
       
   560 	TPtrC8 key;
       
   561 	TPtrC8 val;	
       
   562 	TInt err=0;
       
   563 	
       
   564 	Ulogger::CConfigSettingsIter* iter = Ulogger::CConfigSettingsIter::NewL();
       
   565 	CleanupStack::PushL(iter);
       
   566 	err=iConfigManager->GetPluginSettings(*iter);
       
   567 	
       
   568 	if(err==KErrNone)
       
   569 		{
       
   570 		while(iter->Next(key,val))
       
   571 			{
       
   572 			if(key.Compare(aSetting)==0)
       
   573 				{
       
   574 				aListBuffer.AppendL(key);
       
   575 				aListBuffer.AppendL(val);					
       
   576 				}
       
   577 			}
       
   578 		}
       
   579 	CleanupStack::PopAndDestroy(); // list
       
   580 }
       
   581 
       
   582 /**
       
   583 Function to retrieve the active primary filters
       
   584 This should leave with KErrNotFound if cannot find one
       
   585 as this should be treated as a corrupt config file
       
   586 */
       
   587 TInt CULoggerServer::GetBufandDataNotifyValuesL(const TDesC8& aSetting,TInt& value)
       
   588 	{
       
   589 	TInt err = KErrNotFound;
       
   590 	RArray<TPtrC8> traceValues;
       
   591 	TFileName filepath;
       
   592 	
       
   593 	GetOptionsSettingsL(traceValues,aSetting);
       
   594 		
       
   595 	value =-1;
       
   596 	//if values exists for the given trace settings	
       
   597 	if(traceValues.Count()>1)
       
   598 		{// get values for buffer mode
       
   599 		if(aSetting.Compare(KBufferMode)==0)	
       
   600 			{
       
   601 			err=KErrNone;
       
   602 			if(traceValues[1].Compare(KCircular) == 0)
       
   603 				value = ECircularBuffer;
       
   604 			else if(traceValues[1].Compare(KStraight) == 0)
       
   605 				value = EStraightBuffer;
       
   606 			else
       
   607 				err=KErrNotFound;
       
   608 			}
       
   609 		else
       
   610 			{// get values for data notification and buffer size
       
   611 			TLex8 lex_val(traceValues[1]);	
       
   612 			err = lex_val.Val(value);
       
   613 			}
       
   614 		}
       
   615 	return err;
       
   616 	}
       
   617 	
       
   618 
       
   619 
       
   620 /**
       
   621 Set the enable/disable secondary filters
       
   622 
       
   623 @aSize The size to be set for the BTrace buffer.
       
   624 @return KErrNone, if successful, otherwise one of the other system-wide
       
   625         error codes.
       
   626 */
       
   627 TInt CULoggerServer::SetSecondaryFiltering(const TDesC8& aEnabled)
       
   628 	{
       
   629 	TInt error = iConfigManager->SetTraceSettings(aEnabled, KSecondaryGlobalFilter);
       
   630 	if(error == KErrAlreadyExists)
       
   631 		error = KErrNone;
       
   632 	return error;
       
   633 
       
   634 	}	
       
   635 
       
   636 
       
   637 /**
       
   638 Function to retrieve the active primary and secondary filters
       
   639 This should leave with KErrNotFound if cannot find one or any system wide error codes
       
   640 */
       
   641 TInt CULoggerServer::GetActiveFilters(RArray<TUint32>& aListBuffer,TInt aFilterType)
       
   642 	{
       
   643 	TInt ret = KErrNotFound;
       
   644 	RArray<TPtrC8> aValues;
       
   645 	if(aFilterType == 1)
       
   646 		{
       
   647 		ret = GetValues(KPrimaryFilterSection,aValues);
       
   648 		if(ret==KErrNone)	
       
   649 			{
       
   650 			TInt i =0;
       
   651 			TPtrC8 val;	
       
   652 			TUint8 int_val;
       
   653 			while(i<aValues.Count())
       
   654 				{
       
   655 				TLex8 lex_val(aValues[++i]);	
       
   656 				ret = lex_val.Val(int_val,EDecimal);	
       
   657 				if(ret==KErrNone)
       
   658 					aListBuffer.Append(int_val);
       
   659 				else
       
   660 					return KErrCorrupt;
       
   661 				i++;		
       
   662 				}					
       
   663 			}
       
   664 		}
       
   665 	else if(aFilterType == 2)
       
   666 		{
       
   667 		ret = GetValues(KSecondaryFilterSection,aValues);
       
   668 		if(ret==KErrNone)	
       
   669 			{
       
   670 			TInt i =0;
       
   671 			TPtrC8 val;	
       
   672 			TUint int_val;
       
   673 			while(i<aValues.Count())
       
   674 				{
       
   675 				TLex8 lex_val(aValues[++i]);	
       
   676 				ret = lex_val.Val(int_val,EDecimal);	
       
   677 				if(ret==KErrNone)
       
   678 					aListBuffer.Append(int_val);
       
   679 				else
       
   680 					return KErrCorrupt;
       
   681 				i++;		
       
   682 				}					
       
   683 			}
       
   684 		else
       
   685 			{
       
   686 			if(ret==KErrNotFound)//i.e. if there are no values in the array --> change to if(filters.Count = 0)?
       
   687 				ret=KErrNone;
       
   688 			}
       
   689 		}
       
   690 	return ret;
       
   691 	}
       
   692 
       
   693 /**
       
   694 Function to retrieve the active secondary global filter
       
   695 This should leave with KErrNotFound if cannot find one
       
   696 */
       
   697 
       
   698 TInt CULoggerServer::GetSecondaryFiltering(TBool& aEnabled)
       
   699 {
       
   700 	RArray<TPtrC8> configSettings;			
       
   701 	TRAPD(error, GetOptionsSettingsL(configSettings,KSecondaryGlobalFilter));
       
   702 	if(configSettings[1]==KEnable) //First element contains KSecondaryGlobalFilter, second the value
       
   703 		aEnabled = ETrue;
       
   704 	if(configSettings[1]==KDisable)
       
   705 		aEnabled = EFalse;
       
   706 	return error; 
       
   707 }
       
   708 
       
   709 /**
       
   710 Function to retrieve the plugin names from the ECOM framework
       
   711 This should leave with KErrNotFound if cannot find one
       
   712 */
       
   713 TInt CULoggerServer::GetInstalledOutputPlugins(RArray<TPtrC8>& aListBuffer)
       
   714 	{
       
   715 	// Read info about all implementations into infoArray
       
   716 	// Note that a special cleanup function is required to reset and destroy
       
   717 	// all items in the array, and then close it.
       
   718 	if(iPluginArray.Count()>0)
       
   719 	{
       
   720      iPluginArray.ResetAndDestroy();
       
   721      iPluginArray.Close();
       
   722 	}
       
   723 	
       
   724 	TRAPD(error,CPluginAllocator::ListAllImplementationsL(iPluginArray));
       
   725 
       
   726 	if(iPluginArray.Count()>0)
       
   727 	{
       
   728 		for (TInt i=0; i< iPluginArray.Count(); i++)
       
   729 			{
       
   730 			TRAP(error,aListBuffer.AppendL(iPluginArray[i]->DataType()));
       
   731 			}
       
   732 	
       
   733 		//filter plugins and to use only output plugins
       
   734 		FilterPlugins(EOutputPluginFilter, aListBuffer);
       
   735 	}
       
   736 	
       
   737 	return error;
       
   738 	}
       
   739 	
       
   740 
       
   741 
       
   742 TInt CULoggerServer::GetInstalledInputPlugins(RArray<TPtrC8>& aListBuffer)
       
   743 	{
       
   744 	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
   745 	__MARK_METHOD("CULoggerServer::GetInstalledControlPlugins")
       
   746 	#endif
       
   747 	
       
   748 	if(iPluginArray.Count()>0)
       
   749 		{
       
   750 	     iPluginArray.ResetAndDestroy();
       
   751 	     iPluginArray.Close();
       
   752 		}
       
   753 	// Read info about all implementations into infoArray
       
   754 	// Note that a special cleanup function is required to reset and destroy
       
   755 	// all items in the array, and then close it.
       
   756 	CPluginAllocator::ListAllImplementationsL(iPluginArray);
       
   757 		
       
   758 	if(iPluginArray.Count() > 0)
       
   759 		{	
       
   760 		for (TInt i=0; i< iPluginArray.Count(); i++)
       
   761 			aListBuffer.AppendL(iPluginArray[i]->DataType());
       
   762 		
       
   763 		//filter plugins and to use only output plugins
       
   764 		FilterPlugins(EInputPluginFilter, aListBuffer);
       
   765 		}
       
   766 	return KErrNone;
       
   767 	}
       
   768 
       
   769 
       
   770 /**
       
   771 Function to retrieve the Active plugin name 
       
   772 This should leave with KErrNotFound if cannot find one or any system wide error codes
       
   773 */
       
   774 TInt CULoggerServer::GetActiveOutputPlugin(RArray<TPtrC8>& aListBuffer)
       
   775 	{
       
   776 	TInt errCode = GetValues(KActiveSection,aListBuffer);
       
   777 	//plugins are received as, e.g. '1 uloggerfileplugin' (.ini file syntax)
       
   778 	//we have to remove number from array
       
   779 	for(TInt i=0; i<aListBuffer.Count(); ++i)
       
   780 		{
       
   781 		TInt v;
       
   782 		TLex8 lex(aListBuffer[i]);
       
   783 		if(lex.Val(v) == KErrNone)
       
   784 			{
       
   785 			aListBuffer.Remove(i);
       
   786 			i=-1; //start from begin, i will be incremented in loop
       
   787 			}
       
   788 		}
       
   789 	return errCode;
       
   790 	}
       
   791 
       
   792 
       
   793 /**
       
   794 Function to Deactivate or remove active output plugin 
       
   795 This should leave with KErrNotFound if cannot find one or any system wide error codes
       
   796 */
       
   797 
       
   798 TInt CULoggerServer::DeActivateOutputPlugin(const TDesC8 &aPluginname)
       
   799 {	
       
   800 	if(iBtraceOpen != EFalse)
       
   801 		{
       
   802 		Stop();
       
   803 		iBtraceOpen = EFalse;
       
   804 		}
       
   805 	
       
   806 	TInt ret = iConfigManager->DeActivateOutputPlugin(aPluginname);
       
   807 	return ret;
       
   808 }
       
   809 
       
   810 /**
       
   811 Function to retrieve the Active control plugin name 
       
   812 This should leave with KErrNotFound if cannot find one or any system wide error codes
       
   813 */
       
   814 TInt CULoggerServer::GetActiveInputPlugin(RArray<TPtrC8>& aListBuffer)
       
   815 	{
       
   816 	return GetValues(KActiveControlSection,aListBuffer);
       
   817 	}
       
   818 
       
   819 /**
       
   820 Function to Deactivate active control plugin 
       
   821 This should leave with KErrNotFound if cannot find one or any system wide error codes
       
   822 */
       
   823 TInt CULoggerServer::DeActivateInputPlugin(const TDesC8& aPluginname)
       
   824 	{
       
   825 	return iConfigManager->DeActivateInputPlugin(aPluginname);
       
   826 	}
       
   827 
       
   828 /**
       
   829 Function to run ULogger server as service, i.e. to keep it constantly running
       
   830 (but not necessarily logging) in the background, or to stop it being run as a
       
   831 service (if EFalse is passed).
       
   832 
       
   833 @param aRunAsService ETrue to start, EFalse to stop running as service
       
   834 */
       
   835 void CULoggerServer::RunAsService(TBool /*aRunAsService*/)
       
   836 	{
       
   837 //
       
   838 // // Uncomment following to implement run-as-service functionality
       
   839 //
       
   840 //	iRunAsService = aRunAsService;
       
   841 //
       
   842 //	if (!aRunAsService)
       
   843 //		{
       
   844 //		//make sure server is stopped if there are no sessions
       
   845 //		IncrementSessions();
       
   846 //		DecrementSessions();
       
   847 //		}
       
   848 	}
       
   849 
       
   850 /**
       
   851 Function to cd.. ulogger server
       
   852 This should leave with KErrNotFound if cannot find one or any system wide error codes
       
   853 */
       
   854 TInt CULoggerServer::Start()
       
   855 	{
       
   856 	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
   857 	__MARK_METHOD("CULoggerServer::Start")
       
   858 	#endif
       
   859 
       
   860 	TRAPD(error, InitializeFrameworksL());
       
   861 	
       
   862 	//check errors
       
   863 	if(error != KErrNone)
       
   864 		return error;
       
   865 	if(!iOutputFramework)
       
   866 		return KErrNotReady;
       
   867 	if(iBtraceOpen)
       
   868 		return KErrInUse;
       
   869 
       
   870 	TPtrC8 key;
       
   871 	TPtrC8 val;
       
   872 	TInt buffermode=0;
       
   873 	RArray<TPtrC8> settings;
       
   874 	RArray<TUint32> activefilters;
       
   875 	//checking if there is at least one active channel
       
   876 	error = GetActiveOutputPlugin(settings);
       
   877 	if(error != KErrNone)
       
   878 		return error;
       
   879 	if(settings.Count()==0)
       
   880 		{
       
   881 		return KErrNotFound; //active output plug-in not found
       
   882 		}
       
   883 
       
   884 	if(iBtraceOpen == EFalse)
       
   885 		{
       
   886 		if(iIsBooting)
       
   887 			error = TraceSettingsOnBoot();
       
   888 		else
       
   889 			error = iTrace.Open();
       
   890 
       
   891 		if(error == KErrNone)
       
   892 			{
       
   893 			//----Reset the notification size
       
   894 			TRAP_IGNORE(error=GetBufandDataNotifyValuesL(KDataNotification,iDataNotification));
       
   895 			if(error!=KErrNone)
       
   896 				return error;
       
   897 			TRAP_IGNORE(error=GetBufandDataNotifyValuesL(KBuffer,iBufferSize));
       
   898 			if(error!=KErrNone)
       
   899 				return error;
       
   900 
       
   901 			//----Reset BTrace filters
       
   902 			ResetBtracePrimaryFilters(iTrace);
       
   903 
       
   904 			//----Resize the trace buffer
       
   905 			error = iTrace.ResizeBuffer(iBufferSize*1024);
       
   906 			if(error == KErrNoMemory)
       
   907 			{
       
   908 				error = iTrace.ResizeBuffer(KMinBufferMTPLE*1024);
       
   909 			}
       
   910 			if(error != KErrNone)
       
   911 				return error;
       
   912 			//----Reset the buffer mode
       
   913 			TRAP_IGNORE(GetBufandDataNotifyValuesL(KBufferMode,buffermode));
       
   914 			if(buffermode==ECircularBuffer)
       
   915 			{
       
   916 				iTrace.SetMode(RBTrace::EFreeRunning|RBTrace::EEnable);	
       
   917 			}
       
   918 			else
       
   919 			{
       
   920 				iTrace.SetMode(RBTrace::EEnable);
       
   921 			}
       
   922 		
       
   923 			//----Enable/disable primary filter
       
   924 			error = GetActiveFilters(activefilters,EPrimaryFilter);
       
   925 			if(error != KErrNone)
       
   926 				return error;
       
   927 			for(TInt i=0; i<activefilters.Count(); ++i)
       
   928 				{
       
   929 				TUint filter;
       
   930 				filter= (TUint8)activefilters[i];
       
   931 				iTrace.SetFilter(filter,ETrue);
       
   932 				}
       
   933 
       
   934 			//----Enable/disable secondary filter
       
   935 			settings.Reset();
       
   936 			TBool enabled = EFalse;
       
   937 			error = GetSecondaryFiltering(enabled);
       
   938 			if(!error)
       
   939 				{
       
   940 				if (enabled)//enable secondary filter, only traces with certain value will pass
       
   941 					{
       
   942 					iTrace.SetFilter2(0);
       
   943 
       
   944 					//enable secondary filters chosen by user
       
   945 					activefilters.Reset();
       
   946 					if((error = GetActiveFilters(activefilters,ESecondaryFilter)) == KErrNone)
       
   947 						for(TInt i=0; i<activefilters.Count(); ++i)
       
   948 							iTrace.SetFilter2(activefilters[i], ETrue);
       
   949 					else
       
   950 						{
       
   951 						if(error == KErrNotFound)
       
   952 							{
       
   953 							error = KErrNone;
       
   954 							}
       
   955 						else
       
   956 							return error;
       
   957 						}
       
   958 					}
       
   959 				else//disable secondary filter, all traces will pass
       
   960 					{
       
   961 					iTrace.SetFilter2(1);
       
   962 					}				
       
   963 				}
       
   964 			
       
   965 			//set flag to idicate that btrace is open
       
   966 			iBtraceOpen = ETrue;
       
   967 
       
   968 			//start input and output frameworks
       
   969 			iInputFramework->StartReading(); //start waiting for remote commands
       
   970 			AsynchDataRequest();
       
   971 			}
       
   972 		}
       
   973 	else
       
   974 		error = KErrInUse;
       
   975 
       
   976 	return error;
       
   977 	}
       
   978 
       
   979 /**
       
   980 Close the BTrace handle to the buffer
       
   981 @return none
       
   982 */
       
   983 TInt CULoggerServer::Stop()
       
   984 {
       
   985 	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
   986 	__MARK_METHOD("CULoggerServer::Stop")
       
   987 	#endif
       
   988 	
       
   989 	if(iBtraceOpen)
       
   990 	{	
       
   991 		TInt errCode = KErrNone;
       
   992 		TRAP(errCode, ReadBufferL());	//flush the BTrace buffer
       
   993 		
       
   994 		ResetBtracePrimaryFilters(iTrace);//reset BTrace filters
       
   995 		
       
   996 		iTrace.CancelRequestData();	
       
   997 		iTrace.Empty();
       
   998 		iTrace.Close();
       
   999 		iBtraceOpen = EFalse;
       
  1000 		iDataWatcher->Cancel();
       
  1001 		
       
  1002 		//stop waiting/reading for remote commands
       
  1003 		iInputFramework->StopReading();
       
  1004 		iOutputFramework->ReleaseOutputResources();
       
  1005 		return KErrNone;
       
  1006 		}
       
  1007 	else
       
  1008 		{
       
  1009 		return KErrNotReady;	
       
  1010 		}
       
  1011 		
       
  1012 }
       
  1013 
       
  1014 /**
       
  1015 Gets the Trace settings on boot
       
  1016 @return none
       
  1017 */
       
  1018 TInt CULoggerServer::TraceSettingsOnBoot()
       
  1019 {
       
  1020 
       
  1021 	TInt trace = FALSE;
       
  1022 	
       
  1023 	RArray<TUint32> category;
       
  1024 	TInt error = iTrace.Open();
       
  1025 	if(error != KErrNone)
       
  1026 		return error;
       
  1027 	
       
  1028 	TInt bufferSize = iTrace.BufferSize(); //To get the buffer size set at boot	
       
  1029 	if(bufferSize <= 0 && bufferSize > KMaxBufferSize)
       
  1030 		SetBufferSize(KMaxBufferSize); //Update config
       
  1031 	else
       
  1032 		SetBufferSize(bufferSize); //Update config
       
  1033 	for(TUint i=0; i<KMaxPrimaryFiltersLimit; i++)
       
  1034 	{
       
  1035 		trace = iTrace.Filter(i);
       
  1036 		if(trace == 1)         
       
  1037 			category.AppendL((TUint32)i);				
       
  1038 	}
       
  1039 	error = iConfigManager->SetActiveFilter(category,KPrimaryFilterSection);
       
  1040 	category.Close();
       
  1041 	iIsBooting=0;
       
  1042 	return error;
       
  1043 }
       
  1044 
       
  1045 
       
  1046 
       
  1047 /**
       
  1048 Reads the BTrace buffer and transfers the collected logs to
       
  1049 the ACTIVE channel
       
  1050 */
       
  1051 void CULoggerServer::ReadBufferL()
       
  1052     {
       
  1053     if(iBtraceOpen)
       
  1054     	{   	
       
  1055     	TUint8* data;
       
  1056 		TInt dataSize;
       
  1057 		//TUint oldMode = iTrace.Mode();
       
  1058 		//iTrace.SetMode(0); // turn off trace capture while we dump
       
  1059 		dataSize = iTrace.GetData(data);
       
  1060 		if(dataSize > 0)
       
  1061 			{
       
  1062 
       
  1063 	 		TPtrC8 dataPtr(data, dataSize);
       
  1064 			
       
  1065 	 		#if defined(__LIGHTLOGGER_ENABLED) && defined(__PERFORMANCE_TEST)
       
  1066  			__LOGTIMESTAMP_HIRES("Passing data to output framework - t2") //performance test
       
  1067 			#endif
       
  1068  			
       
  1069  			//send data through output channel
       
  1070  			TInt error = KErrNone;
       
  1071  			if((error = iOutputFramework->SendData(dataPtr)) == KErrNone)
       
  1072  				iTrace.DataUsed(); //only if data was really sent via output plugin
       
  1073  			else
       
  1074  				User::Leave(error);
       
  1075 	 		
       
  1076 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__PERFORMANCE_TEST)
       
  1077 	 		__LOGTIMESTAMP_HIRES("Data logged - t3")	//performance test
       
  1078 			#endif
       
  1079 			}
       
  1080 		//iTrace.SetMode(oldMode);
       
  1081 			
       
  1082 		AsynchDataRequest();
       
  1083 	    } 
       
  1084     }
       
  1085 
       
  1086 
       
  1087 void CULoggerServer::AsynchDataRequest()
       
  1088 	{
       
  1089 	if(!iDataWatcher->IsActive())
       
  1090 		{
       
  1091 		iTrace.RequestData(iDataWatcher->GetStatus(), iDataNotification*1024); 
       
  1092 		iDataWatcher->StartWatching(this);
       
  1093 		}
       
  1094 	}
       
  1095 
       
  1096 
       
  1097 void CULoggerServer::DataNotification()
       
  1098 {
       
  1099 	TRAPD(e, ReadBufferL());
       
  1100 	if(e != KErrNone)
       
  1101 		AsynchDataRequest();
       
  1102 }
       
  1103 
       
  1104 
       
  1105 void CULoggerServer::GetPluginAndSettingsL(TDes8& aPluginName, RPointerArray<TPluginConfiguration>* aSettings, TPluginFilter aPluginFilter)
       
  1106 	{	
       
  1107 	TPtrC8 key;
       
  1108 	TPtrC8 val;
       
  1109 	RArray<TPtrC8> activePluginsArray;
       
  1110 	RArray<TPtrC8> pluginsArray;
       
  1111 	RArray<TPtrC8> pluginSettings;
       
  1112 	TInt i,j;
       
  1113 	
       
  1114 	if(aPluginFilter == EOutputPluginFilter)
       
  1115 		GetActiveOutputPlugin(activePluginsArray); //get output plugin
       
  1116 	else
       
  1117 		GetActiveInputPlugin(activePluginsArray); //get control plugin
       
  1118 	
       
  1119 	for(i=0; i<activePluginsArray.Count(); ++i)
       
  1120 		{
       
  1121 		TBuf8<256> activeplugin;
       
  1122 		activeplugin.Copy(activePluginsArray[i]);
       
  1123 		activeplugin.LowerCase();
       
  1124 		
       
  1125 		GetInstalledOutputPlugins(pluginsArray);
       
  1126 		for(j=0;j<pluginsArray.Count();j++)
       
  1127 			{
       
  1128 			TBuf8<256> plugin;
       
  1129 			plugin.Copy(pluginsArray[j]);
       
  1130 			plugin.LowerCase();
       
  1131 			
       
  1132 			if(activeplugin.Compare(plugin)==0)
       
  1133 				{
       
  1134 				break;
       
  1135 				}
       
  1136 			}
       
  1137 		aPluginName.Copy(activePluginsArray[i]);
       
  1138 		GetOptionsSettingsL(aPluginName,pluginSettings);
       
  1139 		j=0;
       
  1140 		while(j < pluginSettings.Count())
       
  1141 			{
       
  1142 			TPluginConfiguration* keyAndVal = new TPluginConfiguration();
       
  1143 			keyAndVal->SetKey(pluginSettings[j]);
       
  1144 			keyAndVal->SetValue(pluginSettings[j+1]);
       
  1145 			aSettings->AppendL(keyAndVal);
       
  1146 			j=j+2;
       
  1147 			}
       
  1148 		}
       
  1149 	}
       
  1150 
       
  1151 
       
  1152 void CULoggerServer::InitializeFrameworksL()
       
  1153 	{
       
  1154 	//<create plugin allocator (plugins)>
       
  1155 	//output settings
       
  1156 	RBuf8 outPluginName;
       
  1157 	outPluginName.Create(KMaxPluginName);
       
  1158 	RPointerArray<TPluginConfiguration> outputPluginSettings;
       
  1159 	GetPluginAndSettingsL(outPluginName, &outputPluginSettings, EOutputPluginFilter);
       
  1160 
       
  1161 	//control settings
       
  1162 	RBuf8 inputPluginName;
       
  1163 	inputPluginName.Create(KMaxPluginName);
       
  1164 	RPointerArray<TPluginConfiguration> inputPluginSettings;
       
  1165 	this->GetPluginAndSettingsL(inputPluginName, &inputPluginSettings, EInputPluginFilter);
       
  1166 
       
  1167 	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1168 	__LOG("before creating CPluginAllocator")
       
  1169 	#endif
       
  1170 	
       
  1171 	//create plugin allocator (plugins)
       
  1172 	if(!iPluginAllocator)
       
  1173 		iPluginAllocator = CPluginAllocator::NewL(outPluginName, inputPluginName);
       
  1174 
       
  1175 	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1176 	__LOG("before creating COutputFramework")
       
  1177 	#endif
       
  1178 	//Initialize output framework
       
  1179 	if(!iOutputFramework)
       
  1180 		iOutputFramework = COutputFramework::NewL(*(iPluginAllocator->GetOutputPlugin()), outputPluginSettings);
       
  1181 
       
  1182 	//Initialize Control Framework
       
  1183 	if(!iInputFramework)
       
  1184 		iInputFramework = CInputFramework::NewL(iPluginAllocator->GetInputPlugin(), inputPluginSettings, this);
       
  1185 
       
  1186 	//cleanup
       
  1187 	outPluginName.Close();
       
  1188 	outputPluginSettings.ResetAndDestroy();
       
  1189 	outputPluginSettings.Close();
       
  1190 	inputPluginName.Close();
       
  1191 	inputPluginSettings.ResetAndDestroy();
       
  1192 	inputPluginSettings.Close();
       
  1193 
       
  1194 	iDataWatcher = CULoggerWatcher::NewL();	
       
  1195 	}
       
  1196 
       
  1197 
       
  1198 void CULoggerServer::PrepareControlDataPayloadL(RBuf8& aPayloadBuf, const RArray<TPtrC8>& aArray)
       
  1199 	{
       
  1200 	aPayloadBuf.Create(aArray.Count()*32);
       
  1201 	for(TInt i=0; i<aArray.Count(); i++)
       
  1202 		{
       
  1203 		if(aPayloadBuf.MaxSize() < aPayloadBuf.Length()+aArray[i].Length())
       
  1204 			aPayloadBuf.ReAllocL(aPayloadBuf.Length()+(aArray[i].Length()*10));
       
  1205 		aPayloadBuf.Append(aArray[i]);
       
  1206 		if(i < aArray.Count()-1) //skip last sparator as it will be added automatically
       
  1207 			aPayloadBuf.Append(DATA_SEPARATOR);
       
  1208 		}
       
  1209 	}
       
  1210 
       
  1211 
       
  1212 void CULoggerServer::PrepareControlDataPayloadL(RBuf8& aPayloadBuf, const RArray<TUint32>& aArray)
       
  1213 	{
       
  1214 	aPayloadBuf.Create(aArray.Count()*4);
       
  1215 	for(TInt i=0; i<aArray.Count(); i++)
       
  1216 		{
       
  1217 		TBuf8<64> b;
       
  1218 		b.Num(aArray[i]);
       
  1219 		if(aPayloadBuf.MaxSize() < aPayloadBuf.Length()+b.Length())
       
  1220 			aPayloadBuf.ReAllocL(aPayloadBuf.Length()+(b.Length()*10));
       
  1221 		aPayloadBuf.Append(b);
       
  1222 		if(i < aArray.Count()-1) //skip last sparator as it will be added automatically
       
  1223 			aPayloadBuf.Append(DATA_SEPARATOR);
       
  1224 		}
       
  1225 	}
       
  1226 
       
  1227 
       
  1228 TInt CULoggerServer::RestartOutputting()
       
  1229 	{
       
  1230 	TInt err=KErrNone;
       
  1231 	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1232 	__MARK_METHOD("CULoggerServer::ForceRefreshSettingsL")
       
  1233 	#endif
       
  1234 	if(iBtraceOpen != EFalse)
       
  1235 		{
       
  1236 		err = Stop();
       
  1237 		iBtraceOpen = EFalse;
       
  1238 		}
       
  1239 
       
  1240 	 if(iDataWatcher)
       
  1241 		 {
       
  1242 		 iDataWatcher->Cancel();
       
  1243 		 delete iDataWatcher;
       
  1244 		 iDataWatcher = NULL;
       
  1245 		 }
       
  1246 	 if(iOutputFramework)
       
  1247 		 {
       
  1248 		 delete iOutputFramework;
       
  1249 		 iOutputFramework = NULL;
       
  1250 		 }
       
  1251 	 if(iInputFramework)
       
  1252 		 {
       
  1253 		 delete iInputFramework;
       
  1254 		 iInputFramework = NULL;
       
  1255 		 }
       
  1256 	 if(iPluginAllocator)
       
  1257 		 {
       
  1258 		 delete iPluginAllocator;
       
  1259 		 iPluginAllocator = NULL;
       
  1260 		 }
       
  1261 	if(iConfigManager)
       
  1262 		{
       
  1263 		iConfigManager->RefreshConfigFiles();
       
  1264 		}
       
  1265 
       
  1266 	err = Start(); //always start
       
  1267 	return err;
       
  1268 	}
       
  1269 
       
  1270 
       
  1271 TInt CULoggerServer::ResetBtracePrimaryFilters(RBTrace	&aBTrace)
       
  1272 	{
       
  1273 	for(TUint i=0; i<256; i++)
       
  1274 		aBTrace.SetFilter(i, EFalse);
       
  1275 	aBTrace.SetFilter2(0); 
       
  1276 	return KErrNone;
       
  1277 	}
       
  1278 
       
  1279 //This bit should be part of the input framework, or it should reuse the other methods better
       
  1280 ControlData* CULoggerServer::ProcessCommandL(TCommand aOpCode, RArray<TPtrC8> &aArguments)
       
  1281 	{
       
  1282 	#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1283 	__MARK_METHOD("CULoggerServer::ProcessCommand")
       
  1284 	#endif	
       
  1285 	
       
  1286 	TInt errCode = KErrNone;
       
  1287 	TInt minSize = 8;
       
  1288 	CInputData *inputData = new (ELeave) CInputData(minSize);
       
  1289 	ControlData* data = NULL;
       
  1290 	RBuf8 payloadBuf;
       
  1291 	TBuf8<32> result;
       
  1292 
       
  1293 	switch(aOpCode)
       
  1294 		{
       
  1295 		case EStart:
       
  1296 			{
       
  1297 			if(!ServerState())
       
  1298 				errCode = this->Start();
       
  1299 			else
       
  1300 				errCode = KErrInUse;
       
  1301 			result.Num(errCode);
       
  1302 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1303 			}
       
  1304 		break;
       
  1305 
       
  1306 		case EStop:
       
  1307 			{
       
  1308 			//ulogger shouldn't be restarted here as we must send acknowledgment back to PC
       
  1309 			//Stop will be done in DoPostProcessing method after sending ack.
       
  1310 			result.Num(errCode);
       
  1311 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1312 			}
       
  1313 		break;
       
  1314 			
       
  1315 		case ESetPrimaryFilter:
       
  1316 			{
       
  1317 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1318 			__LOG("ESetPrimaryFilter")
       
  1319 			#endif
       
  1320 			
       
  1321 			RArray<TUint32> filterArray;
       
  1322 			
       
  1323 			errCode = KErrNone;
       
  1324 			//process parameters
       
  1325 			TInt i;
       
  1326 			for(i=0; i<aArguments.Count(); i++)
       
  1327 				{
       
  1328 				TUint8 val;
       
  1329 				TLex8 lex(aArguments[i]);
       
  1330 				if((errCode=lex.Val(val, EDecimal)) != KErrNone)
       
  1331 					{
       
  1332 					//report bad values, don't set anything
       
  1333 					if(errCode == KErrGeneral)
       
  1334 						errCode = KErrArgument;
       
  1335 					result.Num(errCode);
       
  1336 					data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1337 					/*
       
  1338 					payloadBuf.Create(128);
       
  1339 					payloadBuf.Copy(aArguments[i]);
       
  1340 					inputData->AppendNewData(ack, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1341 					*/
       
  1342 					filterArray.Close();
       
  1343 					break;
       
  1344 					}
       
  1345 				filterArray.AppendL(val);
       
  1346 				}
       
  1347 			
       
  1348 			if(errCode == KErrNone)
       
  1349 				{
       
  1350 				errCode = SetActiveFilter(filterArray, EPrimaryFilter);
       
  1351 				result.Num(errCode);
       
  1352 			
       
  1353 				//create acknowledment
       
  1354 				result.Num(errCode);
       
  1355 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1356 			
       
  1357 				//create string as a payload
       
  1358 				/*
       
  1359 				payloadBuf.Create(dupfilterArray.Count()*4);
       
  1360 				for(i=0; i<dupfilterArray.Count(); i++)
       
  1361 					{
       
  1362 					TBuf8<32> b;
       
  1363 					b.Num(dupfilterArray[i]);
       
  1364 					if(payloadBuf.MaxSize() < payloadBuf.Length()+b.Length())
       
  1365 						payloadBuf.ReAllocL(payloadBuf.Length()+(b.Length()*10));
       
  1366 					payloadBuf.Append(b);
       
  1367 					if(i < dupfilterArray.Count()-1) //skip last sparator as it will be added automatically
       
  1368 						payloadBuf.Append(DATA_SEPARATOR);
       
  1369 					}
       
  1370 				if(payloadBuf.Length() > 0)
       
  1371 					inputData->AppendNewData(ack, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1372 				*/
       
  1373 				filterArray.Close();
       
  1374 				}
       
  1375 			}
       
  1376 		break; //ESetPrimaryFilter
       
  1377 		
       
  1378 		case ESetSecondaryFilter:
       
  1379 			{
       
  1380 			RArray<TUint32> filterArray;
       
  1381 			//process parameters
       
  1382 			TInt i;
       
  1383 			for(i=0; i<aArguments.Count(); i++)
       
  1384 				{
       
  1385 				TUint32 val;
       
  1386 				TLex8 lex(aArguments[i]);
       
  1387 				if((errCode=lex.Val(val,EDecimal)) != KErrNone)
       
  1388 					{
       
  1389 					//report bad values, don't set anything
       
  1390 					if(errCode == KErrGeneral)
       
  1391 						errCode = KErrArgument;
       
  1392 					result.Num(errCode);
       
  1393 					data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1394 					/*
       
  1395 					payloadBuf.Create(128);
       
  1396 					payloadBuf.Copy(aArguments[i]);
       
  1397 					man->AppendNewData(ack, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1398 					*/
       
  1399 					filterArray.Close();
       
  1400 					break;
       
  1401 					}
       
  1402 				filterArray.AppendL(val);
       
  1403 				}
       
  1404 			if(errCode != KErrNone)
       
  1405 				break;
       
  1406 			
       
  1407 			//create ack
       
  1408 			errCode = SetActiveFilter(filterArray, ESecondaryFilter);
       
  1409 			result.Num(errCode);
       
  1410 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1411 		
       
  1412 			filterArray.Close();
       
  1413 			}
       
  1414 		break; //ESetSecondaryFilter
       
  1415 
       
  1416 		case EEnableSecondaryFiltering:
       
  1417 			{
       
  1418 			errCode = SetSecondaryFiltering(KEnable);
       
  1419 			result.Num(errCode);
       
  1420 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1421 			}
       
  1422 		break;
       
  1423 
       
  1424 		case EDisableSecondaryFiltering:
       
  1425 			{
       
  1426 			errCode = SetSecondaryFiltering(KDisable);
       
  1427 			result.Num(errCode);
       
  1428 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1429 			}
       
  1430 		break;
       
  1431 
       
  1432 		case EResizeTraceBuffer:
       
  1433 			{
       
  1434 			if(aArguments.Count() > 0)
       
  1435 				{
       
  1436 				TInt bufSize;
       
  1437 				TLex8 lex(aArguments[0]);
       
  1438 				if((errCode = lex.Val(bufSize)) == KErrNone)
       
  1439 					errCode = SetBufferSize(bufSize);
       
  1440 				}
       
  1441 			else
       
  1442 				errCode = KErrArgument;
       
  1443 
       
  1444 			result.Num(errCode);
       
  1445 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1446 			}
       
  1447 		break;
       
  1448 
       
  1449 		case ESetBufferMode:
       
  1450 			{
       
  1451 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1452 			__LOG("ESetBufferMode")
       
  1453 			#endif
       
  1454 
       
  1455 			if(aArguments.Count() > 0)
       
  1456 				{
       
  1457 				if(aArguments[0].Compare(KCircular)==0)
       
  1458 					errCode  = SetBufferMode(KCircular);
       
  1459 					else if(aArguments[0].Compare(KStraight)==0)
       
  1460 						errCode  = SetBufferMode(KStraight);
       
  1461 						else
       
  1462 							errCode = KErrArgument;
       
  1463 				}
       
  1464 			else
       
  1465 				errCode = KErrArgument;
       
  1466 
       
  1467 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1468 			__LOG("errCode")
       
  1469 			__LOGNUM(errCode)
       
  1470 			#endif
       
  1471 
       
  1472 			result.Num(errCode);
       
  1473 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1474 			}
       
  1475 		break;
       
  1476 
       
  1477 		case ESetDataNotificationSize:
       
  1478 			{
       
  1479 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1480 			__LOG("ESetDataNotificationSize")
       
  1481 			#endif
       
  1482 
       
  1483 			if(aArguments.Count() > 0)
       
  1484 				{
       
  1485 				TInt dns;
       
  1486 				TLex8 lex(aArguments[0]);
       
  1487 				if((errCode = lex.Val(dns)) == KErrNone)
       
  1488 					errCode = SetDataNotificationSize(dns);
       
  1489 					else
       
  1490 						errCode = KErrArgument;
       
  1491 				}
       
  1492 			else
       
  1493 				errCode = KErrArgument;
       
  1494 
       
  1495 			result.Num(errCode);
       
  1496 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1497 			}
       
  1498 		break;
       
  1499 
       
  1500 		case ERemovePluginSettings:
       
  1501 			{
       
  1502 			if(aArguments.Count() > 0)
       
  1503 				errCode = RemovePluginSettingsL(aArguments[0]);
       
  1504 			else
       
  1505 				errCode = KErrArgument;
       
  1506 			result.Num(errCode);
       
  1507 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1508 			}
       
  1509 		break;
       
  1510 
       
  1511 		case EGetInstalledPlugins:
       
  1512 			{
       
  1513 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1514 			__LOG("EGetInstalledOutputPlugins")
       
  1515 			#endif
       
  1516 
       
  1517 			RArray<TPtrC8> tmpArray;
       
  1518 			errCode = GetInstalledOutputPlugins(tmpArray);
       
  1519 			result.Num(errCode);
       
  1520 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1521 
       
  1522 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1523 			for(TInt p=0; p<tmpArray.Count(); p++) __LOGBUF(tmpArray[p])
       
  1524 			#endif
       
  1525 
       
  1526 			//create payload
       
  1527 			PrepareControlDataPayloadL(payloadBuf, tmpArray);
       
  1528 			//add playload in control data chunk
       
  1529 			if(payloadBuf.Length() > 0)
       
  1530 				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1531 			}
       
  1532 		break; //EGetInstalledOutputPlugins
       
  1533 
       
  1534 		case EGetActivePlugin: //output
       
  1535 			{
       
  1536 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1537 			__LOG("EGetActivePlugin")
       
  1538 			#endif
       
  1539 
       
  1540 			RArray<TPtrC8> tmpArray;
       
  1541 			errCode = GetActiveOutputPlugin(tmpArray);
       
  1542 			result.Num(errCode);
       
  1543 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1544 
       
  1545 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1546 			for(TInt p=0; p<tmpArray.Count(); p++) __LOGBUF(tmpArray[p])
       
  1547 			#endif
       
  1548 
       
  1549 			//create payload
       
  1550 			PrepareControlDataPayloadL(payloadBuf, tmpArray);
       
  1551 			//add playload in control data chunk
       
  1552 			if(payloadBuf.Length() > 0)
       
  1553 				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1554 			}
       
  1555 		break; //EGetActivePlugin
       
  1556 
       
  1557 		case EGetPluginSettings:
       
  1558 			{
       
  1559 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1560 			__LOG("EGetPluginSettings")
       
  1561 			#endif
       
  1562 			RArray<TPtrC8> tmpArray;
       
  1563 			if(aArguments.Count() > 0)
       
  1564 				{	
       
  1565 				errCode = GetOptionsSettingsL(aArguments[0],tmpArray);
       
  1566 
       
  1567 				#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1568 				for(TInt p=0; p<tmpArray.Count(); p++) __LOGBUF(tmpArray[p])
       
  1569 				#endif
       
  1570 				}
       
  1571 			else
       
  1572 				errCode = KErrArgument;
       
  1573 
       
  1574 			result.Num(errCode);
       
  1575 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1576 			//create payload
       
  1577 			PrepareControlDataPayloadL(payloadBuf, tmpArray);
       
  1578 			//add playload in control data chunk
       
  1579 			if(payloadBuf.Length() > 0)
       
  1580 				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1581 			}
       
  1582 		break; //EGetPluginSettings
       
  1583 
       
  1584 		case EGetPrimaryFilters:
       
  1585 			{
       
  1586 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1587 			__LOG("EGetPluginSettings")
       
  1588 			#endif
       
  1589 
       
  1590 			RArray<TUint32> tmpArray;
       
  1591 			errCode = GetActiveFilters(tmpArray,EPrimaryFilter);
       
  1592 
       
  1593 			result.Num(errCode);
       
  1594 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1595 
       
  1596 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1597 			for(TInt p=0; p<tmpArray.Count(); p++) __LOGNUM(tmpArray[p])
       
  1598 			#endif
       
  1599 
       
  1600 			//create payload
       
  1601 			PrepareControlDataPayloadL(payloadBuf, tmpArray);
       
  1602 
       
  1603 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1604 			__LOG("EGetPluginSettings - test 1")
       
  1605 			#endif
       
  1606 
       
  1607 			
       
  1608 			if(payloadBuf.Length() > 0)
       
  1609 				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1610 			tmpArray.Close();
       
  1611 			
       
  1612 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1613 			__LOG("EGetPluginSettings - test 2")
       
  1614 			#endif
       
  1615 			}
       
  1616 		break; //EGetPrimaryFilters
       
  1617 		
       
  1618 		case EGetSecondaryFilters:
       
  1619 			{
       
  1620 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1621 			__LOG("EGetSecondaryFilters")
       
  1622 			#endif
       
  1623 			
       
  1624 			TBool skipReadingFilters = EFalse;
       
  1625 			RArray<TPtrC8> tmpArrayTxt;
       
  1626 			TBool enabled = EFalse;
       
  1627 			errCode = errCode = this->GetSecondaryFiltering(enabled);
       
  1628 			if(errCode == KErrNone)
       
  1629 				{
       
  1630 				if(EFalse == enabled)
       
  1631 						{
       
  1632 						result.Num(errCode);
       
  1633 					data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1634 						skipReadingFilters = ETrue;
       
  1635 						//create payload
       
  1636 					PrepareControlDataPayloadL(payloadBuf, tmpArrayTxt);
       
  1637 						if(payloadBuf.Length() > 0)
       
  1638 						inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1639 						}
       
  1640 				}
       
  1641 
       
  1642 			RArray<TUint32> tmpArray;
       
  1643 			if(!skipReadingFilters)
       
  1644 				{
       
  1645 				errCode = this->GetActiveFilters(tmpArray,ESecondaryFilter);
       
  1646 				result.Num(errCode);
       
  1647 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1648 				//create payload
       
  1649 				PrepareControlDataPayloadL(payloadBuf, tmpArray);
       
  1650 				if(payloadBuf.Length() > 0)
       
  1651 					inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1652 				}
       
  1653 			
       
  1654 			tmpArrayTxt.Close();
       
  1655 			tmpArray.Close();
       
  1656 			}
       
  1657 		break; //EGetSecondaryFilters
       
  1658 		
       
  1659 		case EGetSecondaryFiltering:
       
  1660 			{
       
  1661 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1662 			__LOG("EGetSecondaryFiltering")
       
  1663 			#endif
       
  1664 			
       
  1665 			TBool enabled = EFalse;
       
  1666 			errCode = GetSecondaryFiltering(enabled);
       
  1667 			if(errCode == KErrNone)
       
  1668 				{
       
  1669 			result.Num(errCode);
       
  1670 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1671 				
       
  1672 				//create payload
       
  1673 				TBuf8<32> b;
       
  1674 				b.Num(enabled);
       
  1675 				inputData->AppendNewData(data, (const void*)b.Ptr(), b.Length());
       
  1676 				}
       
  1677 			else
       
  1678 				{
       
  1679 				result.Num(errCode);
       
  1680 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1681 				}
       
  1682 			}
       
  1683 		break; //EGetSecondaryFiltering
       
  1684 		
       
  1685 		//this functionality is removed now
       
  1686 		/*
       
  1687 		case ESetSecondaryFilterCurrent:
       
  1688 			{
       
  1689 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1690 			__LOG("ESetSecondaryFilterCurrent")
       
  1691 			#endif
       
  1692 			
       
  1693 			errCode = this->SetSecondaryFiltering(KCurrent);
       
  1694 			result.Num(errCode);
       
  1695 			ack = man->CreatePackage((void*)result.Ptr(), result.Length());
       
  1696 			}
       
  1697 		break; //ESetSecondaryFilterCurrent
       
  1698 		*/
       
  1699 		case EGetTraceBufferSize:
       
  1700 			{
       
  1701 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1702 			__LOG("EGetTraceBufferSize")
       
  1703 			#endif
       
  1704 			
       
  1705 			TInt bufferSize = 0;	
       
  1706 			errCode = GetBufandDataNotifyValuesL(KBuffer,bufferSize);
       
  1707 			if(errCode == KErrNone)
       
  1708 				{
       
  1709 				result.Num(errCode);
       
  1710 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1711 				TBuf8<32> b;
       
  1712 				b.Num(bufferSize);
       
  1713 				inputData->AppendNewData(data, (const void*)b.Ptr(), b.Length());
       
  1714 				}
       
  1715 			else
       
  1716 				{
       
  1717 				result.Num(errCode);
       
  1718 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1719 				}
       
  1720 			}
       
  1721 		break; //EGetTraceBufferSize
       
  1722 		
       
  1723 		case EGetBufferMode:
       
  1724 			{
       
  1725 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1726 			__LOG("EGetBufferMode")
       
  1727 			#endif
       
  1728 			
       
  1729 			TInt bufferMode = 3;	
       
  1730 			errCode = GetBufandDataNotifyValuesL(KBufferMode,bufferMode);
       
  1731 			if(errCode == KErrNone)
       
  1732 				{
       
  1733 				result.Num(errCode);
       
  1734 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1735 
       
  1736 				result.Zero();
       
  1737 				if(bufferMode == 0)
       
  1738 					result.Append(KCircular);
       
  1739 				else if(bufferMode == 1)
       
  1740 					result.Append(KStraight);
       
  1741 					else
       
  1742 						result.Append(_L8("Invalid mode"));
       
  1743 
       
  1744 				inputData->AppendNewData(data, (const void*)result.Ptr(), result.Length());
       
  1745 				}
       
  1746 			else
       
  1747 				{
       
  1748 				result.Num(errCode);
       
  1749 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1750 				}
       
  1751 			}
       
  1752 		break; //EGetBufferMode
       
  1753 		
       
  1754 		case EGetDataNotificationSize:
       
  1755 			{
       
  1756 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1757 			__LOG("EGetDataNotificationSize")
       
  1758 			#endif
       
  1759 			
       
  1760 			TInt dataNotification = 0;	
       
  1761 			errCode = GetBufandDataNotifyValuesL(KDataNotification,dataNotification);
       
  1762 			if(errCode == KErrNone)
       
  1763 				{
       
  1764 				result.Num(errCode);
       
  1765 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1766 				TBuf8<32> b;
       
  1767 				b.Num(dataNotification);
       
  1768 				inputData->AppendNewData(data, (const void*)b.Ptr(), b.Length());
       
  1769 				}
       
  1770 			else
       
  1771 				{
       
  1772 				result.Num(errCode);
       
  1773 				data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1774 				}
       
  1775 			}
       
  1776 		break; //EGetDataNotificationSize
       
  1777 		
       
  1778 		case ERemovePrimaryFilter:
       
  1779 			{
       
  1780 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1781 			__LOG("ERemovePrimaryFilter")
       
  1782 			for(TInt k=0; k<aArguments.Count(); k++)
       
  1783 				{
       
  1784 				__LOGBUF(aArguments[k])
       
  1785 				}
       
  1786 			#endif
       
  1787 			
       
  1788 			if(aArguments.Count() > 0)
       
  1789 				{
       
  1790 				RArray<TUint32> filterArray;
       
  1791 				for(TInt i=0; i<aArguments.Count(); i++)
       
  1792 					{
       
  1793 					TUint32 val;
       
  1794 					TLex8 lex(aArguments[i]);
       
  1795 					if(lex.Val(val, EDecimal) == KErrNone)
       
  1796 						filterArray.AppendL(val);
       
  1797 					}
       
  1798 				errCode = RemoveActiveFilter(filterArray,EPrimaryFilter);
       
  1799 				filterArray.Close();
       
  1800 				}
       
  1801 			else
       
  1802 				errCode = KErrArgument;
       
  1803 			
       
  1804 			result.Num(errCode);
       
  1805 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1806 			}
       
  1807 		break; //ERemovePrimaryFilter
       
  1808 		
       
  1809 		case ERemoveSecondaryFilter:
       
  1810 			{
       
  1811 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1812 			__LOG("EDisableMultipleModuleUids")
       
  1813 			for(TInt k=0; k<aArguments.Count(); k++)
       
  1814 				{
       
  1815 				__LOGBUF(aArguments[k])
       
  1816 				}
       
  1817 			#endif
       
  1818 			
       
  1819 			if(aArguments.Count() > 0)
       
  1820 				{
       
  1821 				RArray<TUint32> filterArray;
       
  1822 				for(TInt i=0; i<aArguments.Count(); i++)
       
  1823 					{
       
  1824 					TUint32 val;
       
  1825 					TLex8 lex(aArguments[i]);
       
  1826 					if(lex.Val(val, EDecimal) == KErrNone)
       
  1827 						filterArray.AppendL(val);
       
  1828 					}
       
  1829 				errCode = RemoveActiveFilter(filterArray,ESecondaryFilter);
       
  1830 				filterArray.Close();
       
  1831 				}
       
  1832 			else
       
  1833 				errCode = KErrArgument;
       
  1834 			
       
  1835 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1836 			__LOG("errCode:")
       
  1837 			__LOGNUM(errCode)
       
  1838 			#endif
       
  1839 			
       
  1840 			result.Num(errCode);
       
  1841 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1842 			}
       
  1843 		break; //ERemoveSecondaryFilter
       
  1844 		
       
  1845 		case ESetPluginSettings:
       
  1846 			{
       
  1847 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1848 			__LOG("ESetPluginSettings")
       
  1849 			#endif
       
  1850 				
       
  1851 			if(aArguments.Count() > 2)
       
  1852 				{
       
  1853 				TBuf8<128> plugin;
       
  1854 				plugin.Copy(aArguments[0]);
       
  1855 				aArguments.Remove(0);
       
  1856 				errCode = SetPluginSettings(plugin, aArguments);
       
  1857 				}
       
  1858 			else
       
  1859 				errCode = KErrArgument;
       
  1860 						
       
  1861 			result.Num(errCode);
       
  1862 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1863 			}
       
  1864 		break; //ESetChannelSettings
       
  1865 		
       
  1866 		case ESetActivePlugin:
       
  1867 			{
       
  1868 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1869 			__LOG("ESetActiveOutputPlugin")
       
  1870 			#endif
       
  1871 
       
  1872 			if(aArguments.Count() > 0)
       
  1873 				errCode = SetActiveOutputPlugin(aArguments[0]);
       
  1874 			else
       
  1875 				errCode = KErrArgument;
       
  1876 
       
  1877 			result.Num(errCode);
       
  1878 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1879 			}
       
  1880 		break; //ESetActiveOutputPlugin
       
  1881 
       
  1882 		case ESetActiveInputPlugin:
       
  1883 			{
       
  1884 			if(aArguments.Count() > 0)
       
  1885 				errCode = SetActiveInputPlugin(aArguments[0]);
       
  1886 			else
       
  1887 				errCode = KErrArgument;
       
  1888 
       
  1889 			result.Num(errCode);
       
  1890 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1891 			}
       
  1892 		break;
       
  1893 		
       
  1894 		case EDeactivateInputPlugin:
       
  1895 			{
       
  1896 			if(aArguments.Count() > 0)
       
  1897 				errCode = DeActivateInputPlugin(aArguments[0]);
       
  1898 			else
       
  1899 				errCode = KErrArgument;
       
  1900 
       
  1901 			result.Num(errCode);
       
  1902 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1903 			}
       
  1904 		break;
       
  1905 
       
  1906 		case EGetActiveInputPlugin:
       
  1907 			{
       
  1908 			RArray<TPtrC8> tmpArray;
       
  1909 			errCode = GetActiveInputPlugin(tmpArray);
       
  1910 			result.Num(errCode);
       
  1911 
       
  1912 			//remove ini specific data (number)
       
  1913 			//example (1 uloggerusbplugin) must look like (uloggerusbplugin)
       
  1914 			TInt i=0;
       
  1915 			while(i<tmpArray.Count())
       
  1916 				{
       
  1917 				TInt v = 0;
       
  1918 				TLex8 l(tmpArray[i]);
       
  1919 				if(l.Val(v) == KErrNone)
       
  1920 					tmpArray.Remove(i);
       
  1921 				else
       
  1922 					++i;
       
  1923 				}
       
  1924 
       
  1925 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1926 			PrepareControlDataPayloadL(payloadBuf, tmpArray);
       
  1927 			if(payloadBuf.Length() > 0)
       
  1928 				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1929 			tmpArray.Close();
       
  1930 			}
       
  1931 		break;
       
  1932 		
       
  1933 		case EGetInputPlugins:
       
  1934 			{
       
  1935 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1936 			__LOG("EGetControlPlugins")
       
  1937 			#endif
       
  1938 			
       
  1939 			RArray<TPtrC8> tmpArray;
       
  1940 			errCode = GetInstalledInputPlugins(tmpArray);
       
  1941 
       
  1942 			result.Num(errCode);
       
  1943 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1944 
       
  1945 			//create payload
       
  1946 			PrepareControlDataPayloadL(payloadBuf, tmpArray);
       
  1947 			//add playload to control data chunk
       
  1948 			if(payloadBuf.Length() > 0)
       
  1949 				inputData->AppendNewData(data, (const void*)payloadBuf.Ptr(), payloadBuf.Length());
       
  1950 			tmpArray.Close();
       
  1951 			}
       
  1952 		break;
       
  1953 
       
  1954 		case ERestart:
       
  1955 			{
       
  1956 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1957 			__LOG("ERestartOutputting")
       
  1958 			#endif
       
  1959 
       
  1960 			//ulogger shouldn't be restarted here as we must send acknowledgment back to PC
       
  1961 			//restart will be done in DoPostProcessing method after sending ack.
       
  1962 			result.Num(errCode);
       
  1963 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1964 			}
       
  1965 		break;
       
  1966 		
       
  1967 		default:
       
  1968 			#if defined(__LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE)
       
  1969 			__LOG("input command not supported")
       
  1970 			#endif
       
  1971 		
       
  1972 			result.Num(KErrNotSupported);
       
  1973 			data = inputData->CreatePackage((void*)result.Ptr(), result.Length());
       
  1974 		break;
       
  1975 	}//end of switch
       
  1976 
       
  1977 	
       
  1978 	//cleanup
       
  1979 	if(inputData)
       
  1980 		{
       
  1981 		delete inputData;
       
  1982 		inputData = NULL;
       
  1983 		}
       
  1984 	payloadBuf.Close();
       
  1985 
       
  1986 	return data;
       
  1987 	}
       
  1988 
       
  1989 
       
  1990 
       
  1991 void CULoggerServer::DoPostProcessing(TCommand aCmd)
       
  1992 	{
       
  1993 	switch(aCmd)
       
  1994 		{
       
  1995 		case EStop:
       
  1996 			Stop();
       
  1997 			break;
       
  1998 		case ERestart:
       
  1999 			RestartOutputting();
       
  2000 			break;
       
  2001 		default:
       
  2002 			break;
       
  2003 		}
       
  2004 	}
       
  2005 
       
  2006 /**
       
  2007 This function checks if array of given names contains any of real plugin names (either output of input).
       
  2008 After call aPluginList will be filtered to contain only proper plugin names (strings that really could be used 
       
  2009 to refer to a real plugin.
       
  2010 @param aFilter Either EOutputPluginFilter or EInputPluginFilter.
       
  2011 @param aPluginList Reference to an array which contain list of names that function has to check.
       
  2012  */
       
  2013 void CULoggerServer::FilterPlugins(TPluginFilter aFilter, RArray<TPtrC8>& aPluginList)
       
  2014 	{
       
  2015 	TInt errCode = 0;
       
  2016 	CPlugin::TPluginInterface interfaceId;
       
  2017 	//assign filter value
       
  2018 	aFilter==EOutputPluginFilter ? interfaceId=MOutputPlugin::iInterfaceId : interfaceId=MInputPlugin::iInterfaceId;
       
  2019 	
       
  2020 	//filter plugins
       
  2021 	TInt i=0;
       
  2022 	while(i<aPluginList.Count())
       
  2023 		{
       
  2024 		CPlugin *plugin = NULL;
       
  2025 		TRAP(errCode, plugin=CPlugin::NewL(aPluginList[i]));
       
  2026 		if(plugin && errCode==KErrNone)
       
  2027 			{
       
  2028 			TAny *ptr = NULL;
       
  2029 			TRAP(errCode, ptr=plugin->GetInterfaceL(interfaceId));
       
  2030 			if(!ptr || errCode!=KErrNone)
       
  2031 				{
       
  2032 				aPluginList.Remove(i--);
       
  2033 				}
       
  2034 			//cleanup
       
  2035 			if(plugin)
       
  2036 				{	
       
  2037 				delete plugin;
       
  2038 				plugin = NULL;
       
  2039 				}
       
  2040 			}
       
  2041 		++i;
       
  2042 		}
       
  2043 	}
       
  2044 
       
  2045 
       
  2046 
       
  2047 TBool CULoggerServer::ServerState()
       
  2048 	{
       
  2049 	return iBtraceOpen;
       
  2050 	}
       
  2051 
       
  2052 
       
  2053 TBool CULoggerServer::CheckPluginExists(TPtrC8& aPluginName, TPluginFilter aPluginFilter)
       
  2054 	{
       
  2055 	RArray<TPtrC8> pluginsArray;
       
  2056 	if(aPluginFilter == EOutputPluginFilter)
       
  2057 		GetInstalledOutputPlugins(pluginsArray);
       
  2058 	else if(aPluginFilter == EInputPluginFilter)
       
  2059 		GetInstalledInputPlugins(pluginsArray);
       
  2060 
       
  2061 	for(TInt i=0; i<pluginsArray.Count(); ++i)
       
  2062 		if(aPluginName.Compare(pluginsArray[i])==0)
       
  2063 			{
       
  2064 			pluginsArray.Close();
       
  2065 			return ETrue;
       
  2066 			}
       
  2067 		
       
  2068 	pluginsArray.Close();
       
  2069 	return EFalse;
       
  2070 	}
       
  2071 
       
  2072 
       
  2073 }//end of namespace
       
  2074 
       
  2075 #ifndef __ULOGGER_SERVER_UNIT_TEST
       
  2076 //Main Entry
       
  2077 TInt E32Main()
       
  2078 {
       
  2079 	return Ulogger::CULoggerServer::StartServer();
       
  2080 }
       
  2081 #endif //__ULOGGER_SERVER_UNIT_TEST