|
1 /* |
|
2 * Copyright (c) 2002-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: Monitors threads death and notifies an event, when thread dies |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CSatThreadDeathMonitor.h" |
|
22 #include "MThreadDeathObserver.h" |
|
23 #include "SatLog.h" |
|
24 #include "MSatUtils.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CSatThreadDeathMonitor::CSatThreadDeathMonitor |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CSatThreadDeathMonitor::CSatThreadDeathMonitor() : CActive( EPriorityStandard ) |
|
35 { |
|
36 LOG( SIMPLE, |
|
37 "SATENGINE: CSatThreadDeathMonitor::CSatThreadDeathMonitor calling" ) |
|
38 |
|
39 CActiveScheduler::Add( this ); |
|
40 |
|
41 LOG( SIMPLE, |
|
42 "SATENGINE: CSatThreadDeathMonitor::CSatThreadDeathMonitor exiting" ) |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CSatThreadDeathMonitor::NewL |
|
47 // Two-phased constructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CSatThreadDeathMonitor* CSatThreadDeathMonitor::NewL() |
|
51 { |
|
52 LOG( SIMPLE, "SATENGINE: CSatThreadDeathMonitor::NewL calling" ) |
|
53 CSatThreadDeathMonitor* deathMonitor = new( ELeave ) CSatThreadDeathMonitor; |
|
54 LOG( SIMPLE, "SATENGINE: CSatThreadDeathMonitor::NewL exiting" ) |
|
55 return deathMonitor; |
|
56 } |
|
57 |
|
58 |
|
59 // Destructor |
|
60 CSatThreadDeathMonitor::~CSatThreadDeathMonitor() |
|
61 { |
|
62 LOG( SIMPLE, |
|
63 "SATENGINE: CSatThreadDeathMonitor::~CSatThreadDeathMonitor calling" ) |
|
64 Cancel(); |
|
65 iThread.Close(); |
|
66 iObserver = NULL; |
|
67 LOG( SIMPLE, |
|
68 "SATENGINE: CSatThreadDeathMonitor::~CSatThreadDeathMonitor exiting" ) |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CSatThreadDeathMonitor::NotifyThreadDeathL |
|
73 // Prepares to notify observer of threads death |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CSatThreadDeathMonitor::NotifyThreadDeathL( |
|
77 const TThreadId& aThreadId, |
|
78 MThreadDeathObserver& aObserver ) |
|
79 { |
|
80 |
|
81 LOG( SIMPLE, |
|
82 "SATENGINE: CSatThreadDeathMonitor::NotifyThreadDeathL calling" ) |
|
83 Cancel(); |
|
84 |
|
85 iThread.Close(); |
|
86 |
|
87 User::LeaveIfError( iThread.Open( aThreadId ) ); |
|
88 |
|
89 iObserver = &aObserver; |
|
90 StartObservingThreadDeath(); |
|
91 LOG( SIMPLE, |
|
92 "SATENGINE: CSatThreadDeathMonitor::NotifyThreadDeathL exiting" ) |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CSatThreadDeathMonitor::StartObservingThreadDeath |
|
97 // Logons to thread and starts observing it's state |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CSatThreadDeathMonitor::StartObservingThreadDeath() |
|
101 { |
|
102 LOG( SIMPLE, "SATENGINE: CSatThreadDeathMonitor::\ |
|
103 StartObservingThreadDeath calling" ) |
|
104 iThread.Logon( iStatus ); |
|
105 SetActive(); |
|
106 LOG( SIMPLE, "SATENGINE: CSatThreadDeathMonitor::\ |
|
107 StartObservingThreadDeath exiting" ) |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CSatThreadDeathMonitor::DoCancel |
|
112 // (other items were commented in a header). |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CSatThreadDeathMonitor::DoCancel() |
|
116 { |
|
117 LOG( SIMPLE, "SATENGINE: CSatThreadDeathMonitor::DoCancel calling" ) |
|
118 iThread.LogonCancel( iStatus ); |
|
119 LOG( SIMPLE, "SATENGINE: CSatThreadDeathMonitor::DoCancel exiting" ) |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CSatThreadDeathMonitor::RunL |
|
124 // (other items were commented in a header). |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CSatThreadDeathMonitor::RunL() |
|
128 { |
|
129 LOG( SIMPLE, "SATENGINE: CSatThreadDeathMonitor::RunL calling" ) |
|
130 |
|
131 const TExitType exitType( iThread.ExitType() ); |
|
132 |
|
133 if ( EExitPending == exitType ) // If thread is still alive, restart |
|
134 { |
|
135 LOG( SIMPLE, " Thread is still alive" ) |
|
136 StartObservingThreadDeath(); |
|
137 } |
|
138 else if ( EExitPanic == exitType ) |
|
139 { |
|
140 LOG( SIMPLE, " Thread has panicked" ) |
|
141 iThread.Close(); |
|
142 iObserver->ThreadPanicedL(); |
|
143 } |
|
144 else |
|
145 { |
|
146 LOG( SIMPLE, " Thread is dead" ) |
|
147 iThread.Close(); |
|
148 iObserver->ThreadDiedL(); |
|
149 } |
|
150 LOG( SIMPLE, "SATENGINE: CSatThreadDeathMonitor::RunL exiting" ) |
|
151 } |
|
152 |
|
153 // End of File |