diff -r 185201be11b0 -r 516af714ebb4 perfsrv/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanClientServer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/perfsrv/memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanClientServer.cpp Fri Sep 17 08:38:31 2010 +0300 @@ -0,0 +1,228 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "MemSpyDriverLogChanClientServer.h" + +// System includes +#include + +// Shared includes +#include "MemSpyDriverOpCodes.h" +#include "MemSpyDriverObjectsInternal.h" + +// User includes +#include "MemSpyDriverUtils.h" +#include "MemSpyDriverOSAdaption.h" + + + +DMemSpyDriverLogChanClientServer::DMemSpyDriverLogChanClientServer( DMemSpyDriverDevice& aDevice, DThread& aThread ) +: DMemSpyDriverLogChanContainerBase( aDevice, aThread ) + { + TRACE( Kern::Printf("DMemSpyDriverLogChanChunks::DMemSpyDriverLogChanChunks() - this: 0x%08x", this )); + } + + +DMemSpyDriverLogChanClientServer::~DMemSpyDriverLogChanClientServer() + { + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::~DMemSpyDriverLogChanClientServer() - START - this: 0x%08x", this )); + + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::~DMemSpyDriverLogChanClientServer() - END - this: 0x%08x", this )); + } + + + +TInt DMemSpyDriverLogChanClientServer::Request( TInt aFunction, TAny* a1, TAny* a2 ) + { + TInt r = DMemSpyDriverLogChanContainerBase::Request( aFunction, a1, a2 ); + if ( r == KErrNone ) + { + switch( aFunction ) + { + case EMemSpyDriverOpCodeClientServerGetServerSessionHandles: + r = GetServerSessionHandles( (TMemSpyDriverInternalServerSessionHandleParams*) a1 ); + break; + case EMemSpyDriverOpCodeClientServerGetServerSessionInfo: + r = GetServerSessionInfo( a1, (TMemSpyDriverServerSessionInfo*) a2 ); + break; + + default: + r = KErrNotSupported; + break; + } + } + // + return r; + } + + +TBool DMemSpyDriverLogChanClientServer::IsHandler( TInt aFunction ) const + { + return ( aFunction > EMemSpyDriverOpCodeClientServerBase && aFunction < EMemSpyDriverOpCodeClientServerEnd ); + } + + + + + + +TInt DMemSpyDriverLogChanClientServer::GetServerSessionHandles( TMemSpyDriverInternalServerSessionHandleParams* aParams ) + { + TMemSpyDriverInternalServerSessionHandleParams params; + TInt r = Kern::ThreadRawRead( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverInternalServerSessionHandleParams) ); + if ( r != KErrNone ) + { + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - params read error: %d", r)); + return r; + } + + DMemSpyDriverOSAdaptionDServer& serverAdaption = OSAdaption().DServer(); + + const TInt maxCount = params.iMaxCount; + NKern::ThreadEnterCS(); + + DObject* serverHandle = (DObject*) params.iServerHandle; + DServer* server = static_cast(CheckedOpen(EMemSpyDriverContainerTypeServer, serverHandle)); + if (server == NULL) + { + Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - server not found"); + NKern::ThreadLeaveCS(); + return KErrNotFound; + } + + ResetTempHandles(); + + NKern::LockSystem(); // Iterating session queue requires system lock + // Iterate through this server's sessions, writing back session pointer (handle) + // to client + SDblQue& serverQueue = serverAdaption.GetSessionQueue( *server ); + SDblQueLink* anchor = &serverQueue.iA; + SDblQueLink* link = serverQueue.First(); + while( link != anchor ) + { + DSession* session = serverAdaption.GetSession( link ); + + // Found a match in the specified container. Write the object's handle (aka the object address) + // back to the client address space + if ( session ) + { + AddTempHandle( session ); + } + + // Get next item + link = link->iNext; + } + NKern::UnlockSystem(); + server->Close(NULL); + NKern::ThreadLeaveCS(); + + // This variable holds the number of handles that we have already + // written to the client-side. + TInt currentWriteIndex = 0; + const TInt handleCount = TempHandleCount(); + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles - writing %d handles to client...", handleCount ) ); + for( ; currentWriteIndexFullName( params.iName ); + + // Get owner type and id + DObject* sessionOwner = sessionAdaption.GetOwner( *session ); + if ( sessionOwner ) + { + const TObjectType objectType = sessionAdaption.GetObjectType( *sessionOwner ); + if ( objectType == EProcess ) + { + DProcess* sessionProcess = (DProcess*) sessionOwner; + // + params.iOwnerId = processAdaption.GetId( *sessionProcess ); + params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerProcess; + } + else if ( objectType == EThread ) + { + DThread* sessionThread = (DThread*) sessionOwner; + // + params.iOwnerId = threadAdaption.GetId( *sessionThread ); + params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerThread; + } + } + else + { + params.iOwnerId = -1; + params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerNone; + } + + // Other attributes + params.iSessionType = sessionAdaption.GetSessionType( *session ); + params.iAddress = (TUint8*)session; + session->Close(NULL); + NKern::ThreadLeaveCS(); + r = Kern::ThreadRawWrite( &ClientThread(), aParams, ¶ms, sizeof(TMemSpyDriverServerSessionInfo) ); + + TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - r: %d", r)); + return r; + }