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