|
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 "MemSpyEngineChunkWatcher.h" |
|
19 |
|
20 // Driver includes |
|
21 #include <memspy/driver/memspydriverclient.h> |
|
22 #include <memspy/driver/memspydriverenumerationsshared.h> |
|
23 |
|
24 |
|
25 |
|
26 CMemSpyEngineChunkWatcher::CMemSpyEngineChunkWatcher( RMemSpyDriverClient& aDriver, TInt aPriority ) |
|
27 : CActive( aPriority ), iDriver( aDriver ) |
|
28 { |
|
29 CActiveScheduler::Add( this ); |
|
30 } |
|
31 |
|
32 |
|
33 CMemSpyEngineChunkWatcher::~CMemSpyEngineChunkWatcher() |
|
34 { |
|
35 Cancel(); |
|
36 // |
|
37 if ( iEventMonitorHandle != KNullHandle ) |
|
38 { |
|
39 iDriver.EventMonitorClose( iEventMonitorHandle ); |
|
40 } |
|
41 // |
|
42 iObservers.Close(); |
|
43 } |
|
44 |
|
45 |
|
46 void CMemSpyEngineChunkWatcher::ConstructL() |
|
47 { |
|
48 const TInt error = iDriver.EventMonitorOpen( iEventMonitorHandle ); |
|
49 User::LeaveIfError( error ); |
|
50 // |
|
51 Request(); |
|
52 } |
|
53 |
|
54 |
|
55 CMemSpyEngineChunkWatcher* CMemSpyEngineChunkWatcher::NewL( RMemSpyDriverClient& aDriver, TInt aPriority ) |
|
56 { |
|
57 CMemSpyEngineChunkWatcher* self = new(ELeave) CMemSpyEngineChunkWatcher( aDriver, aPriority ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 void CMemSpyEngineChunkWatcher::AddObserverL( MMemSpyEngineChunkWatcherObserver& aObserver ) |
|
66 { |
|
67 RemoveObserver( aObserver ); |
|
68 iObservers.AppendL( &aObserver ); |
|
69 } |
|
70 |
|
71 |
|
72 void CMemSpyEngineChunkWatcher::RemoveObserver( MMemSpyEngineChunkWatcherObserver& aObserver ) |
|
73 { |
|
74 const TInt count = iObservers.Count(); |
|
75 for( TInt i=count-1; i>=0; i-- ) |
|
76 { |
|
77 MMemSpyEngineChunkWatcherObserver* obs = iObservers[ i ]; |
|
78 if ( obs == &aObserver ) |
|
79 { |
|
80 iObservers.Remove( i ); |
|
81 } |
|
82 } |
|
83 } |
|
84 |
|
85 |
|
86 void CMemSpyEngineChunkWatcher::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 EMemSpyDriverEventTypeChunkAdd: |
|
97 { |
|
98 NotifyChunkAddL( notifiedId ); |
|
99 break; |
|
100 } |
|
101 case EMemSpyDriverEventTypeChunkDestroy: |
|
102 { |
|
103 NotifyChunkDestroyL( notifiedId ); |
|
104 break; |
|
105 } |
|
106 default: |
|
107 break; |
|
108 } |
|
109 } |
|
110 |
|
111 |
|
112 void CMemSpyEngineChunkWatcher::DoCancel() |
|
113 { |
|
114 iDriver.EventMonitorNotifyCancel( iEventMonitorHandle ); |
|
115 } |
|
116 |
|
117 |
|
118 void CMemSpyEngineChunkWatcher::Request() |
|
119 { |
|
120 Cancel(); |
|
121 iDriver.EventMonitorNotify( iEventMonitorHandle, iStatus, iId ); |
|
122 SetActive(); |
|
123 } |
|
124 |
|
125 |
|
126 void CMemSpyEngineChunkWatcher::NotifyChunkAddL( TUint aChunkHandle ) |
|
127 { |
|
128 const TInt count = iObservers.Count(); |
|
129 for( TInt i=count-1; i>=0; i-- ) |
|
130 { |
|
131 MMemSpyEngineChunkWatcherObserver* obs = iObservers[ i ]; |
|
132 TRAP_IGNORE( obs->HandleChunkAddL( aChunkHandle ) ); |
|
133 } |
|
134 } |
|
135 |
|
136 |
|
137 void CMemSpyEngineChunkWatcher::NotifyChunkDestroyL( TUint aChunkHandle ) |
|
138 { |
|
139 const TInt count = iObservers.Count(); |
|
140 for( TInt i=count-1; i>=0; i-- ) |
|
141 { |
|
142 MMemSpyEngineChunkWatcherObserver* obs = iObservers[ i ]; |
|
143 TRAP_IGNORE( obs->HandleChunkDestroyL( aChunkHandle ) ); |
|
144 } |
|
145 } |
|
146 |