0
|
1 |
/*------------------------------------------------------------------
|
|
2 |
-
|
|
3 |
* Software Name : UserEmulator
|
|
4 |
* Version : v4.2.1309
|
|
5 |
*
|
|
6 |
* Copyright (c) 2009 France Telecom. All rights reserved.
|
|
7 |
* This software is distributed under the License
|
|
8 |
* "Eclipse Public License - v 1.0" the text of which is available
|
|
9 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
10 |
*
|
|
11 |
* Initial Contributors:
|
|
12 |
* France Telecom
|
|
13 |
*
|
|
14 |
* Contributors:
|
|
15 |
*------------------------------------------------------------------
|
|
16 |
-
|
|
17 |
* File Name: ThreadNotifier.cpp
|
|
18 |
*
|
|
19 |
* Created: 13/08/2009
|
|
20 |
* Author(s): Marcell Kiss, Reshma Sandeep Das
|
|
21 |
*
|
|
22 |
* Description:
|
|
23 |
* Active object implementation for capturing panics
|
|
24 |
*------------------------------------------------------------------
|
|
25 |
-
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
|
|
29 |
//System Includes
|
|
30 |
#include <icl\ImageData.h>
|
|
31 |
#include <icl\ImageCodecData.h>
|
|
32 |
#include <coemain.h>
|
|
33 |
#include <PathInfo.h>
|
|
34 |
#include <bautils.h>
|
|
35 |
#include <apgwgnam.h>
|
|
36 |
|
|
37 |
// User Includes
|
|
38 |
#include "ThreadNotifier.h"
|
|
39 |
|
|
40 |
//Constants
|
|
41 |
_LIT(KTHREADPANICMSG, "THREAD-NOTIFIER");
|
|
42 |
_LIT(KKill,"Kill");
|
|
43 |
_LIT(KTerminate,"Terminate");
|
|
44 |
_LIT(KPanic,"Panic");
|
|
45 |
_LIT(KPending,"Pending");
|
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
// CThreadNotifier::NewL
|
|
49 |
// Creates the instance of class and returns it.
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CThreadNotifier* CThreadNotifier::NewL(MPanicObserver& aObserver, CLogger& aLogger,
|
|
53 |
CSettings& aSettings, CEikonEnv* aEikonEnv)
|
|
54 |
{
|
|
55 |
CThreadNotifier* self=CThreadNotifier::NewLC(aObserver,aLogger,aSettings,aEikonEnv);
|
|
56 |
CleanupStack::Pop(); // self;
|
|
57 |
return self;
|
|
58 |
}
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
// CThreadNotifier::NewLC
|
|
61 |
// Creates the instance of class and pushes it to the CleanupStack and return
|
|
62 |
// it.
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
CThreadNotifier* CThreadNotifier::NewLC(MPanicObserver& aObserver, CLogger& aLogger,
|
|
66 |
CSettings& aSettings, CEikonEnv* aEikonEnv)
|
|
67 |
{
|
|
68 |
CThreadNotifier* self = new (ELeave)CThreadNotifier(aObserver,aLogger,aSettings,aEikonEnv);
|
|
69 |
CleanupStack::PushL(self);
|
|
70 |
self->ConstructL();
|
|
71 |
return self;
|
|
72 |
}
|
|
73 |
|
|
74 |
|
|
75 |
// -----------------------------------------------------------------------------
|
|
76 |
// CThreadNotifier::CThreadNotifier
|
|
77 |
// Calls base classes constructor with priority value. Add class to the
|
|
78 |
// active sheduler.
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
CThreadNotifier::CThreadNotifier(MPanicObserver& aObserver, CLogger& aLogger, CSettings& aSettings,
|
|
82 |
CEikonEnv* aEikonEnv)
|
|
83 |
: CActive(CActive::EPriorityStandard), iThreadHandle(0),
|
|
84 |
iObserver(aObserver), iLogger(aLogger), iSettings(aSettings), iEEnv(aEikonEnv)
|
|
85 |
{
|
|
86 |
CActiveScheduler::Add(this);
|
|
87 |
}
|
|
88 |
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
// CThreadNotifier::ConstructL
|
|
91 |
// Construction of parser and buffer allocations
|
|
92 |
// -----------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
void CThreadNotifier::ConstructL()
|
|
95 |
{
|
|
96 |
User::LeaveIfError(iUndertaker.Create());
|
|
97 |
}
|
|
98 |
|
|
99 |
// -----------------------------------------------------------------------------
|
|
100 |
// CThreadNotifier::~CThreadNotifier
|
|
101 |
// Cancels any outstanding requests and deletes members.
|
|
102 |
// -----------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
CThreadNotifier::~CThreadNotifier()
|
|
105 |
{
|
|
106 |
Cancel();
|
|
107 |
}
|
|
108 |
// -----------------------------------------------------------------------------
|
|
109 |
// CThreadNotifier::IssueRequest
|
|
110 |
// Function to issues a request for notification of the death of a thread.
|
|
111 |
// -----------------------------------------------------------------------------
|
|
112 |
//
|
|
113 |
void CThreadNotifier::IssueRequest()
|
|
114 |
{
|
|
115 |
__ASSERT_ALWAYS(!IsActive(), User::Panic(KTHREADPANICMSG, 0));
|
|
116 |
|
|
117 |
iUndertaker.Logon(iStatus, iThreadHandle);
|
|
118 |
SetActive();
|
|
119 |
}
|
|
120 |
|
|
121 |
// -----------------------------------------------------------------------------
|
|
122 |
// CThreadNotifier::RunL
|
|
123 |
// From CActive. Handles the state changes and notifing the observer.
|
|
124 |
// -----------------------------------------------------------------------------
|
|
125 |
//
|
|
126 |
|
|
127 |
void CThreadNotifier::RunL()
|
|
128 |
{
|
|
129 |
if (iStatus == KErrDied)
|
|
130 |
{
|
|
131 |
RThread thread;
|
|
132 |
thread.SetHandle(iThreadHandle);
|
|
133 |
CleanupClosePushL(thread);
|
|
134 |
TExitCategoryName categ = thread.ExitCategory();
|
|
135 |
TBuf<KBuffer1024> buf;
|
|
136 |
_LIT(KPanicFormat, "*PANIC* Thread %S (%d) died (ExitType:%S, Reason:%S-%d)\n");
|
|
137 |
ExitType(thread.ExitType());
|
|
138 |
if(thread.ExitType() != 0)
|
|
139 |
{
|
|
140 |
iObserver.PanicOccured();
|
|
141 |
|
|
142 |
buf.Format(KPanicFormat, &thread.Name(), (int)thread.Id(), &iExitType,&categ,thread.ExitReason());
|
|
143 |
iLogger.WriteLogL(buf,EFalse);
|
|
144 |
|
|
145 |
//Capture a screenshot
|
|
146 |
CApaWindowGroupName* gn = CApaWindowGroupName::NewLC(iEEnv->WsSession(), iEEnv->WsSession().GetFocusWindowGroup());
|
|
147 |
TUid id = gn->AppUid().Null();
|
|
148 |
CleanupStack::PopAndDestroy(gn);
|
|
149 |
|
|
150 |
CImageCapture* imageCapture = CImageCapture::NewL(iSettings,*this,iEEnv);
|
|
151 |
imageCapture->CaptureL(thread.Name(),KN,id);
|
|
152 |
}
|
|
153 |
thread.Close();
|
|
154 |
CleanupStack::PopAndDestroy();//thread
|
|
155 |
IssueRequest();
|
|
156 |
}
|
|
157 |
}
|
|
158 |
// -----------------------------------------------------------------------------
|
|
159 |
// CThreadNotifier::PerformNextAction
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
void CThreadNotifier::PerformNextAction(TInt aInterval)
|
|
163 |
{
|
|
164 |
iObserver.RestartRandomTests();
|
|
165 |
}
|
|
166 |
// -----------------------------------------------------------------------------
|
|
167 |
// CThreadNotifier::ExitType
|
|
168 |
// Function that indicates the exit type of the thread
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
void CThreadNotifier::ExitType(TInt aExitType)
|
|
172 |
{
|
|
173 |
switch(aExitType)
|
|
174 |
{
|
|
175 |
case EExitKill:
|
|
176 |
iExitType.Copy(KKill);
|
|
177 |
break;
|
|
178 |
case EExitTerminate:
|
|
179 |
iExitType.Copy(KTerminate);
|
|
180 |
break;
|
|
181 |
case EExitPanic:
|
|
182 |
iExitType.Copy(KPanic);
|
|
183 |
break;
|
|
184 |
case EExitPending:
|
|
185 |
iExitType.Copy(KPending);
|
|
186 |
break;
|
|
187 |
}
|
|
188 |
}
|
|
189 |
// -----------------------------------------------------------------------------
|
|
190 |
// CThreadNotifier::DoCancel
|
|
191 |
// From CActive. Cancels any outstanding request according the engine state.
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
//
|
|
194 |
void CThreadNotifier::DoCancel()
|
|
195 |
{
|
|
196 |
TInt res = iUndertaker.LogonCancel();
|
|
197 |
if(res!=-2)
|
|
198 |
iUndertaker.Close();
|
|
199 |
}
|