sl@0: // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: sl@0: #include sl@0: #include "uloggersession.h" sl@0: #include "uloggershared.h" sl@0: #include "uloggerclient.h" sl@0: #include "uloggershared.h" sl@0: #include "uloggertools.h" sl@0: sl@0: namespace Ulogger { sl@0: sl@0: sl@0: CULoggerSession* CULoggerSession::NewL(RThread& aClient, CULoggerServer& aServer) sl@0: { sl@0: CULoggerSession* self = CULoggerSession::NewLC(aClient, aServer); sl@0: CleanupStack::Pop(); //self sl@0: return self; sl@0: }// sl@0: sl@0: sl@0: sl@0: sl@0: CULoggerSession* CULoggerSession::NewLC(RThread& aClient, CULoggerServer& aServer) sl@0: { sl@0: CULoggerSession* self = new(ELeave) CULoggerSession( aClient, aServer ); sl@0: CleanupStack::PushL( self ); sl@0: self->ConstructL(); sl@0: return self; sl@0: }// sl@0: sl@0: sl@0: sl@0: sl@0: void CULoggerSession::ConstructL() sl@0: { sl@0: iServer.IncrementSessions(); sl@0: }// sl@0: sl@0: sl@0: sl@0: CULoggerSession::CULoggerSession(RThread& aClient, CULoggerServer& aServer) sl@0: : CSession2(), sl@0: iServer( aServer ), sl@0: iClient( aClient ) sl@0: { sl@0: sl@0: }// sl@0: sl@0: sl@0: sl@0: CULoggerSession::~CULoggerSession() sl@0: { sl@0: iServer.DecrementSessions(); sl@0: }// sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: /** Process message from 'client' (actually another instance of ourselves) sl@0: */ sl@0: void CULoggerSession::ServiceL(const RMessage2& aMessage) sl@0: { sl@0: TInt error = KErrNone; sl@0: switch(aMessage.Function()) sl@0: { sl@0: case ERunAsService: sl@0: { sl@0: iServer.RunAsService(ETrue); sl@0: error = KErrNone; sl@0: } sl@0: break; sl@0: sl@0: case EDontRunAsService: sl@0: { sl@0: iServer.RunAsService(EFalse); sl@0: error = KErrNone; sl@0: } sl@0: break; sl@0: sl@0: case EStart: sl@0: { sl@0: //Starts the BTrace sl@0: //r= iServer.Start(); sl@0: if(!iServer.ServerState()) sl@0: error = iServer.RestartOutputting(); sl@0: else sl@0: error = KErrInUse; sl@0: } sl@0: break; sl@0: sl@0: case EStop: sl@0: { sl@0: //Stops the BTrace sl@0: error = iServer.Stop(); sl@0: //iServer.UnconfigureCurrentChannel(); sl@0: } sl@0: break; sl@0: sl@0: case ERestart: sl@0: { sl@0: error = iServer.RestartOutputting(); sl@0: } sl@0: break; sl@0: sl@0: case ESetPrimaryFilter: sl@0: { sl@0: //Set filter 1 sl@0: RArray filterArray; sl@0: CleanupClosePushL(filterArray); sl@0: sl@0: TInt elementsCount = aMessage.Int1(); sl@0: if(elementsCount > 0) sl@0: { sl@0: HBufC8* desData = HBufC8::NewLC(elementsCount); sl@0: TPtr8 readPtr(desData->Des()); sl@0: aMessage.ReadL(0, readPtr); sl@0: sl@0: CArrayFixFlat *array = new (ELeave) CArrayFixFlat(1); sl@0: CleanupStack::PushL(array); sl@0: sl@0: TUint8 tmp(1); sl@0: InternalizeFromBufL(readPtr, *array, tmp); sl@0: sl@0: for(TInt i(0); i < array->Count(); ++i) sl@0: { sl@0: filterArray.AppendL((TUint32)array->At(i)); sl@0: } sl@0: sl@0: error = iServer.SetActiveFilterL(filterArray, EPrimaryFilter); sl@0: sl@0: CleanupStack::PopAndDestroy(3, &filterArray); // and array, desData sl@0: } sl@0: else sl@0: { sl@0: error = KErrArgument; sl@0: } sl@0: } sl@0: break; sl@0: sl@0: case ERemovePrimaryFilter: sl@0: { sl@0: //remove primaryfilters sl@0: TInt elementsCount = aMessage.Int1(); sl@0: if(elementsCount > 0) sl@0: { sl@0: RArray filterArray; sl@0: CleanupClosePushL(filterArray); sl@0: HBufC8* desData = HBufC8::NewLC(elementsCount); sl@0: TPtr8 readPtr(desData->Des()); sl@0: aMessage.ReadL(0, readPtr); sl@0: sl@0: CArrayFixFlat *array = new (ELeave) CArrayFixFlat(1); sl@0: CleanupStack::PushL(array); sl@0: sl@0: TUint8 tmp(1); sl@0: InternalizeFromBufL(readPtr, *array, tmp); sl@0: sl@0: for(TInt i(0); i < array->Count(); ++i) sl@0: { sl@0: filterArray.AppendL((TUint32)array->At(i)); sl@0: } sl@0: sl@0: error = iServer.RemoveActiveFilter(filterArray,EPrimaryFilter); sl@0: sl@0: CleanupStack::PopAndDestroy(3, &filterArray); // and array, desData sl@0: } sl@0: else sl@0: { sl@0: error = KErrArgument; sl@0: } sl@0: } sl@0: break; sl@0: sl@0: case EGetPrimaryFilters: sl@0: { sl@0: //Get primaryfilters sl@0: RArray listBuffer; sl@0: error = iServer.GetActiveFilters(listBuffer,EPrimaryFilter); sl@0: sl@0: CArrayFixFlat *fixArray = new (ELeave)CArrayFixFlat(1); sl@0: CleanupStack::PushL(fixArray); sl@0: sl@0: for(TInt i=0; iAppendL((TUint8)listBuffer[i]); sl@0: HBufC8* desData = ExternalizeToBufL((const CArrayFix&) *fixArray, sizeof(TUint8)); sl@0: CleanupStack::PopAndDestroy(); //fixArray sl@0: sl@0: aMessage.Write(0,*desData); sl@0: sl@0: delete desData; sl@0: desData = NULL; sl@0: listBuffer.Close(); sl@0: } sl@0: break; sl@0: case ESetSecondaryFilter: sl@0: { sl@0: //Set filter 2 sl@0: TInt elementsCount = aMessage.Int1(); sl@0: if(elementsCount > 0) sl@0: { sl@0: HBufC8* desData = HBufC8::NewLC(elementsCount*sizeof(TUint32)); sl@0: TPtr8 readPtr(desData->Des()); sl@0: aMessage.ReadL(0, readPtr); sl@0: sl@0: RArray filterArray; sl@0: TUint32 tmp=1; sl@0: InternalizeFromBufL(readPtr, filterArray, tmp); sl@0: sl@0: error = iServer.SetActiveFilterL(filterArray,ESecondaryFilter); sl@0: sl@0: CleanupStack::PopAndDestroy(); //desData sl@0: filterArray.Close(); sl@0: } sl@0: else sl@0: error = KErrArgument; sl@0: } sl@0: break; sl@0: sl@0: case ERemoveSecondaryFilter: sl@0: { sl@0: //remove secondaryfilters sl@0: TInt elementsCount = aMessage.Int1(); sl@0: if(elementsCount > 0) sl@0: { sl@0: HBufC8* desData = HBufC8::NewLC(elementsCount*sizeof(TUint32)); sl@0: TPtr8 readPtr(desData->Des()); sl@0: aMessage.ReadL(0, readPtr); sl@0: sl@0: RArray filterArray; sl@0: sl@0: TUint32 tmp=1; sl@0: InternalizeFromBufL(readPtr, filterArray, tmp); sl@0: sl@0: error = iServer.RemoveActiveFilter(filterArray,ESecondaryFilter); sl@0: sl@0: CleanupStack::PopAndDestroy(); //desData sl@0: filterArray.Close(); sl@0: } sl@0: else sl@0: error = KErrArgument; sl@0: } sl@0: break; sl@0: sl@0: case EGetSecondaryFilters: sl@0: { sl@0: //Get secondary filters sl@0: RArray listBuffer; sl@0: error=iServer.GetActiveFilters(listBuffer,ESecondaryFilter); sl@0: sl@0: HBufC8* desData = ExternalizeToBufL(listBuffer, sizeof(TUint32)); sl@0: TPtr8 readPtr2(desData->Des()); sl@0: aMessage.Write(0,readPtr2); sl@0: sl@0: delete desData; sl@0: desData = NULL; sl@0: listBuffer.Close(); sl@0: } sl@0: break; sl@0: sl@0: case EEnableSecondaryFiltering: sl@0: { sl@0: error = iServer.SetSecondaryFiltering(KEnable); sl@0: } sl@0: break; sl@0: sl@0: case EDisableSecondaryFiltering: sl@0: { sl@0: error = iServer.SetSecondaryFiltering(KDisable); sl@0: } sl@0: break; sl@0: sl@0: case EGetSecondaryFiltering: sl@0: { sl@0: TBool enabled = EFalse; sl@0: iServer.GetSecondaryFiltering(enabled); sl@0: SendIntegerL(aMessage, (TInt)enabled); sl@0: } sl@0: break; sl@0: sl@0: case ESetActivePlugin: sl@0: { sl@0: //Set the active plugin sl@0: HBufC8* pluginName = NULL; sl@0: TInt dataSize1 = aMessage.GetDesLength(0); sl@0: if(dataSize1 > 0) sl@0: { sl@0: pluginName = HBufC8::NewLC( dataSize1 ); sl@0: TPtr8 namePtr(pluginName->Des()); sl@0: aMessage.ReadL(0,namePtr); sl@0: error = iServer.SetActiveOutputPlugin(pluginName->Des()); sl@0: CleanupStack::PopAndDestroy(1); sl@0: } sl@0: else sl@0: error = KErrArgument; sl@0: } sl@0: break; sl@0: sl@0: case ESetActiveInputPlugin: sl@0: { sl@0: //Set the active control plugin sl@0: HBufC8* pluginName = NULL; sl@0: TInt dataSize1 = aMessage.GetDesLength(0); sl@0: if(dataSize1 > 0) sl@0: { sl@0: pluginName = HBufC8::NewLC( dataSize1 ); sl@0: TPtr8 namePtr(pluginName->Des()); sl@0: aMessage.ReadL(0,namePtr); sl@0: error = iServer.SetActiveInputPlugin(pluginName->Des()); sl@0: CleanupStack::PopAndDestroy(1); //pluginName sl@0: } sl@0: else sl@0: error = KErrArgument; sl@0: } sl@0: break; sl@0: sl@0: case ESetPluginSettings: sl@0: { sl@0: //Set the channel settings sl@0: HBufC8* pluginName = NULL; sl@0: HBufC8* setting = NULL; sl@0: sl@0: RArray value; sl@0: TInt dataSize1 = aMessage.GetDesLength(0); sl@0: TInt dataSize2 = aMessage.GetDesLength(1); sl@0: CArrayPtrFlat *ptrArray = new (ELeave) CArrayPtrFlat(1); sl@0: CleanupStack::PushL(ptrArray); sl@0: sl@0: if(dataSize1>0 && dataSize2>0) sl@0: { sl@0: pluginName = HBufC8::NewLC( dataSize1 ); sl@0: setting = HBufC8::NewLC( dataSize2 ); sl@0: TPtr8 data1Ptr(pluginName->Des()); sl@0: TPtr8 data2Ptr(setting->Des()); sl@0: sl@0: aMessage.ReadL(0,data1Ptr); sl@0: aMessage.ReadL(1,data2Ptr); sl@0: sl@0: _LIT8(KSeparator,";"); sl@0: TInt pos = KErrNone; sl@0: sl@0: while(pos != KErrNotFound) sl@0: { sl@0: pos = setting->Des().Find(KSeparator); sl@0: if(pos > 0) sl@0: { sl@0: TPtrC8 ptrVal(setting->Des().Left(pos)); sl@0: HBufC8 *bufDes = HBufC8::NewLC(ptrVal.Length()+8); sl@0: bufDes->Des().Copy(ptrVal); sl@0: CleanupStack::Pop(bufDes); sl@0: ptrArray->AppendL(bufDes); sl@0: setting->Des().Delete(0,pos+1); sl@0: } sl@0: } sl@0: sl@0: for(TInt i=0; iCount(); ++i) sl@0: value.AppendL(*(ptrArray->At(i))); sl@0: error = iServer.SetPluginSettings(pluginName->Des(), value); sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: else sl@0: error = KErrArgument; sl@0: sl@0: CleanupStack::PopAndDestroy(ptrArray); sl@0: } sl@0: break; sl@0: sl@0: case ERemovePluginSettings: sl@0: { sl@0: TInt dataSize = aMessage.GetDesLength(0); sl@0: TBuf8 pluginName; sl@0: if (dataSize > 0) sl@0: { sl@0: aMessage.ReadL(0, pluginName); sl@0: error = iServer.RemovePluginSettingsL(pluginName); sl@0: } sl@0: else sl@0: error = KErrArgument; sl@0: } sl@0: break; sl@0: sl@0: case EGetPluginSettings: sl@0: { sl@0: TInt dataSize1 = aMessage.GetDesLength(0); sl@0: TBuf8<128> mediaName; sl@0: sl@0: if(dataSize1 > 0) sl@0: { sl@0: aMessage.ReadL(0, mediaName); sl@0: RArray tmpArray; sl@0: error = iServer.GetOptionsSettingsL(mediaName,tmpArray); sl@0: sl@0: // sl@0: _LIT8(KFormatString,"%S;");//';' is a separator sl@0: RArray tmpArray2; sl@0: //count total_length + separators sl@0: TInt length = 1; sl@0: TInt i=0; sl@0: for(i=0; iDes().AppendFormat(KFormatString, &tmpArray[i]); sl@0: // sl@0: sl@0: aMessage.Write(1,*b); sl@0: CleanupStack::PopAndDestroy(); // b sl@0: } sl@0: else sl@0: error = KErrArgument; sl@0: } sl@0: break; sl@0: sl@0: case EGetInstalledPlugins: sl@0: { sl@0: //Get the installed plugins sl@0: RArray tmpArray; sl@0: iServer.GetInstalledOutputPlugins(tmpArray); sl@0: sl@0: // sl@0: _LIT8(KFormatString,"%S;");//';' is a separator sl@0: RArray tmpArray2; sl@0: //count total_length + separators sl@0: TInt length = 1; sl@0: TInt i=0; sl@0: for(i=0; iDes().AppendFormat(KFormatString, &tmpArray[i]); sl@0: // sl@0: sl@0: aMessage.Write(0,*b); sl@0: CleanupStack::PopAndDestroy(); // b sl@0: } sl@0: break; sl@0: sl@0: case EGetInputPlugins: sl@0: { sl@0: //Get the installed plugins sl@0: RArray tmpArray; sl@0: error = iServer.GetInstalledInputPluginsL(tmpArray); sl@0: if(!error) sl@0: { sl@0: // sl@0: _LIT8(KFormatString,"%S;");//';' is a separator sl@0: //count total_length + separators sl@0: TInt length = 1; sl@0: TInt i=0; sl@0: for(i=0; iDes().AppendFormat(KFormatString, &tmpArray[i]); sl@0: // sl@0: sl@0: aMessage.Write(0,*b); sl@0: CleanupStack::PopAndDestroy(); // b sl@0: } sl@0: } sl@0: break; sl@0: sl@0: case EGetActivePlugin: sl@0: { sl@0: //Reads the active plugin sl@0: RArray tmpArray; sl@0: error = iServer.GetActiveOutputPlugin(tmpArray); sl@0: if(!error) sl@0: { sl@0: // sl@0: _LIT8(KFormatString,"%S;");//';' is a separator sl@0: RArray tmpArray2; sl@0: //count total_length + separators sl@0: TInt length = 1; sl@0: TInt i=0; sl@0: for(i=0; iDes().AppendFormat(KFormatString, &tmpArray[i]); sl@0: // sl@0: sl@0: aMessage.Write(0,*b); sl@0: CleanupStack::PopAndDestroy(); // b sl@0: } sl@0: } sl@0: break; sl@0: sl@0: case EGetActiveInputPlugin: sl@0: { sl@0: RArray tmpArray; sl@0: error = iServer.GetActiveInputPlugin(tmpArray); sl@0: if(!error) sl@0: { sl@0: if(tmpArray.Count() == 0) sl@0: error = KErrNotFound; sl@0: // sl@0: _LIT8(KFormatString,"%S;");//';' is a separator sl@0: RArray tmpArray2; sl@0: //count total_length + separators sl@0: TInt length = 1; sl@0: TInt i=0; sl@0: for(i=0; iDes().AppendFormat(KFormatString, &tmpArray[i]); sl@0: // sl@0: sl@0: aMessage.Write(0,*b); sl@0: CleanupStack::PopAndDestroy(); // b sl@0: } sl@0: } sl@0: break; sl@0: sl@0: case EDeactivateInputPlugin: sl@0: { sl@0: HBufC8* pluginName = NULL; sl@0: TInt dataSize1 = aMessage.GetDesLength(0); sl@0: if(dataSize1 > 0) sl@0: { sl@0: pluginName = HBufC8::NewLC( dataSize1 ); sl@0: TPtr8 namePtr(pluginName->Des()); sl@0: aMessage.ReadL(0,namePtr); sl@0: error = iServer.DeActivateInputPlugin(pluginName->Des()); sl@0: CleanupStack::PopAndDestroy(); //pluginName sl@0: } sl@0: } sl@0: break; sl@0: case EResizeTraceBuffer: sl@0: { sl@0: //Resize buffer size sl@0: TInt bufferSize = aMessage.Int0(); sl@0: error = iServer.SetBufferSizeL(bufferSize); sl@0: } sl@0: break; sl@0: sl@0: case EGetTraceBufferSize: sl@0: { sl@0: //Get buffer size sl@0: TInt bufferSize = 0; sl@0: error = iServer.GetBufandDataNotifyValuesL(KBuffer,bufferSize); sl@0: SendIntegerL(aMessage, bufferSize); sl@0: } sl@0: break; sl@0: sl@0: case ESetBufferMode: sl@0: { sl@0: TInt bufferMode = aMessage.Int0(); sl@0: if(bufferMode == ECircularBuffer) sl@0: error = iServer.SetBufferMode(KCircular); sl@0: else if(bufferMode == EStraightBuffer) sl@0: error = iServer.SetBufferMode(KStraight); sl@0: else sl@0: error = KErrArgument; sl@0: } sl@0: break; sl@0: sl@0: case EGetBufferMode: sl@0: { sl@0: //Get buffer size sl@0: TInt bufferMode = 3; sl@0: error = iServer.GetBufandDataNotifyValuesL(KBufferMode,bufferMode); sl@0: SendIntegerL(aMessage, bufferMode); sl@0: } sl@0: break; sl@0: sl@0: case ESetDataNotificationSize: sl@0: { sl@0: //Set data notification size sl@0: TInt dataNotification = aMessage.Int0(); sl@0: error = iServer.SetDataNotificationSizeL(dataNotification); sl@0: } sl@0: break; sl@0: sl@0: case EGetDataNotificationSize: sl@0: { sl@0: //Get Data Notification size sl@0: TInt dataNotification = 0; sl@0: error = iServer.GetBufandDataNotifyValuesL(KDataNotification,dataNotification); sl@0: SendIntegerL(aMessage, dataNotification); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: { sl@0: error = KErrArgument; sl@0: } sl@0: break; sl@0: } sl@0: aMessage.Complete(error); sl@0: } sl@0: sl@0: void CULoggerSession::SendIntegerL(const RMessage2& aMessage, TUint32 aInt) sl@0: { sl@0: HBufC8* size = HBufC8::NewLC(32); sl@0: size->Des().Num(aInt); sl@0: TPtr8 ptr(size->Des()); sl@0: aMessage.Write(0,ptr); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: }//namespace