perfsrv/memspy/Engine/Source/EventHandlers/MemSpyEngineUndertaker.cpp
author hgs
Mon, 06 Sep 2010 15:00:47 +0300
changeset 51 98307c651589
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <memspy/engine/memspyengineundertaker.h>
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
// Driver includes
hgs
parents:
diff changeset
    21
#include <memspy/driver/memspydriverclient.h>
hgs
parents:
diff changeset
    22
#include <memspy/driver/memspydriverenumerationsshared.h>
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
CMemSpyEngineUndertaker::CMemSpyEngineUndertaker( RMemSpyDriverClient& aDriver, TInt aPriority )
hgs
parents:
diff changeset
    27
:	CActive( aPriority ), iDriver( aDriver )
hgs
parents:
diff changeset
    28
	{
hgs
parents:
diff changeset
    29
	CActiveScheduler::Add( this );
hgs
parents:
diff changeset
    30
	}
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
CMemSpyEngineUndertaker::~CMemSpyEngineUndertaker()
hgs
parents:
diff changeset
    34
	{
hgs
parents:
diff changeset
    35
	Cancel();
hgs
parents:
diff changeset
    36
    //
hgs
parents:
diff changeset
    37
    if ( iEventMonitorHandle != KNullHandle )
hgs
parents:
diff changeset
    38
        {
hgs
parents:
diff changeset
    39
        iDriver.EventMonitorClose( iEventMonitorHandle );
hgs
parents:
diff changeset
    40
        }
hgs
parents:
diff changeset
    41
    //
hgs
parents:
diff changeset
    42
    iObservers.Close();
hgs
parents:
diff changeset
    43
	}
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
void CMemSpyEngineUndertaker::ConstructL()
hgs
parents:
diff changeset
    47
	{
hgs
parents:
diff changeset
    48
    const TInt error = iDriver.EventMonitorOpen( iEventMonitorHandle );
hgs
parents:
diff changeset
    49
    User::LeaveIfError( error );
hgs
parents:
diff changeset
    50
    //
hgs
parents:
diff changeset
    51
	Request();
hgs
parents:
diff changeset
    52
	}
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
CMemSpyEngineUndertaker* CMemSpyEngineUndertaker::NewL( RMemSpyDriverClient& aDriver, TInt aPriority )
hgs
parents:
diff changeset
    56
	{
hgs
parents:
diff changeset
    57
	CMemSpyEngineUndertaker* self = new(ELeave) CMemSpyEngineUndertaker( aDriver, aPriority );
hgs
parents:
diff changeset
    58
	CleanupStack::PushL( self );
hgs
parents:
diff changeset
    59
	self->ConstructL();
hgs
parents:
diff changeset
    60
	CleanupStack::Pop( self );
hgs
parents:
diff changeset
    61
	return self;
hgs
parents:
diff changeset
    62
	}
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
void CMemSpyEngineUndertaker::AddObserverL( MMemSpyEngineUndertakerObserver& aObserver )
hgs
parents:
diff changeset
    66
    {
hgs
parents:
diff changeset
    67
    RemoveObserver( aObserver );
hgs
parents:
diff changeset
    68
    iObservers.AppendL( &aObserver );
hgs
parents:
diff changeset
    69
    }
hgs
parents:
diff changeset
    70
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
void CMemSpyEngineUndertaker::RemoveObserver( MMemSpyEngineUndertakerObserver& aObserver )
hgs
parents:
diff changeset
    73
    {
hgs
parents:
diff changeset
    74
    const TInt count = iObservers.Count();
hgs
parents:
diff changeset
    75
    for( TInt i=count-1; i>=0; i-- )
hgs
parents:
diff changeset
    76
        {
hgs
parents:
diff changeset
    77
        MMemSpyEngineUndertakerObserver* obs = iObservers[ i ];
hgs
parents:
diff changeset
    78
        if ( obs == &aObserver )
hgs
parents:
diff changeset
    79
            {
hgs
parents:
diff changeset
    80
            iObservers.Remove( i );
hgs
parents:
diff changeset
    81
            }
hgs
parents:
diff changeset
    82
        }
hgs
parents:
diff changeset
    83
    }
hgs
parents:
diff changeset
    84
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
void CMemSpyEngineUndertaker::RunL()
hgs
parents:
diff changeset
    87
	{
hgs
parents:
diff changeset
    88
    const TUint notifiedId = iId;
hgs
parents:
diff changeset
    89
    const TInt typeAsInt = iStatus.Int();
hgs
parents:
diff changeset
    90
    User::LeaveIfError( typeAsInt );
hgs
parents:
diff changeset
    91
	Request();
hgs
parents:
diff changeset
    92
    //
hgs
parents:
diff changeset
    93
    const TMemSpyDriverEventType type = static_cast< TMemSpyDriverEventType >( typeAsInt );
hgs
parents:
diff changeset
    94
    switch( type )
hgs
parents:
diff changeset
    95
        {
hgs
parents:
diff changeset
    96
    case EMemSpyDriverEventTypeProcessRemove:
hgs
parents:
diff changeset
    97
        {
hgs
parents:
diff changeset
    98
        const TProcessId id( notifiedId );
hgs
parents:
diff changeset
    99
        NotifyProcessDeadL( id );
hgs
parents:
diff changeset
   100
        break;
hgs
parents:
diff changeset
   101
        }
hgs
parents:
diff changeset
   102
    case EMemSpyDriverEventTypeThreadKill:
hgs
parents:
diff changeset
   103
        {
hgs
parents:
diff changeset
   104
        const TThreadId id( notifiedId );
hgs
parents:
diff changeset
   105
        NotifyThreadDeadL( id );
hgs
parents:
diff changeset
   106
        break;
hgs
parents:
diff changeset
   107
        }
hgs
parents:
diff changeset
   108
    default:
hgs
parents:
diff changeset
   109
        // Process removal not handled as not relevant
hgs
parents:
diff changeset
   110
        break;
hgs
parents:
diff changeset
   111
        }
hgs
parents:
diff changeset
   112
	}
hgs
parents:
diff changeset
   113
hgs
parents:
diff changeset
   114
hgs
parents:
diff changeset
   115
void CMemSpyEngineUndertaker::DoCancel()
hgs
parents:
diff changeset
   116
	{
hgs
parents:
diff changeset
   117
	iDriver.EventMonitorNotifyCancel( iEventMonitorHandle );
hgs
parents:
diff changeset
   118
	}
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
void CMemSpyEngineUndertaker::Request()
hgs
parents:
diff changeset
   122
	{
hgs
parents:
diff changeset
   123
    Cancel();
hgs
parents:
diff changeset
   124
    iDriver.EventMonitorNotify( iEventMonitorHandle, iStatus, iId );
hgs
parents:
diff changeset
   125
	SetActive();
hgs
parents:
diff changeset
   126
	}
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
hgs
parents:
diff changeset
   129
void CMemSpyEngineUndertaker::NotifyProcessDeadL( const TProcessId& aId )
hgs
parents:
diff changeset
   130
    {
hgs
parents:
diff changeset
   131
    // NB: opening may fail - client's must tolerate this
hgs
parents:
diff changeset
   132
    RProcess process;
hgs
parents:
diff changeset
   133
    iDriver.OpenProcess( aId, process );
hgs
parents:
diff changeset
   134
    CleanupClosePushL( process );
hgs
parents:
diff changeset
   135
    //
hgs
parents:
diff changeset
   136
    const TInt count = iObservers.Count();
hgs
parents:
diff changeset
   137
    for( TInt i=0; i<count; i++ )
hgs
parents:
diff changeset
   138
        {
hgs
parents:
diff changeset
   139
        MMemSpyEngineUndertakerObserver* obs = iObservers[ i ];
hgs
parents:
diff changeset
   140
        TRAP_IGNORE( obs->ProcessIsDeadL( aId, process ) );
hgs
parents:
diff changeset
   141
        }
hgs
parents:
diff changeset
   142
    //
hgs
parents:
diff changeset
   143
    CleanupStack::PopAndDestroy( &process );
hgs
parents:
diff changeset
   144
    }
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
hgs
parents:
diff changeset
   147
void CMemSpyEngineUndertaker::NotifyThreadDeadL( const TThreadId& aId )
hgs
parents:
diff changeset
   148
    {
hgs
parents:
diff changeset
   149
    // NB: opening may fail - client's must tolerate this
hgs
parents:
diff changeset
   150
    RThread thread;
hgs
parents:
diff changeset
   151
    iDriver.OpenThread( aId, thread );
hgs
parents:
diff changeset
   152
    CleanupClosePushL( thread );
hgs
parents:
diff changeset
   153
    //
hgs
parents:
diff changeset
   154
    const TInt count = iObservers.Count();
hgs
parents:
diff changeset
   155
    for( TInt i=0; i<count; i++ )
hgs
parents:
diff changeset
   156
        {
hgs
parents:
diff changeset
   157
        MMemSpyEngineUndertakerObserver* obs = iObservers[ i ];
hgs
parents:
diff changeset
   158
        TRAP_IGNORE( obs->ThreadIsDeadL( aId, thread ) );
hgs
parents:
diff changeset
   159
        }
hgs
parents:
diff changeset
   160
    //
hgs
parents:
diff changeset
   161
    CleanupStack::PopAndDestroy( &thread );
hgs
parents:
diff changeset
   162
    }
hgs
parents:
diff changeset
   163