|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ThreadWatch.h" |
|
17 #include "Starter.h" |
|
18 |
|
19 /** |
|
20 * class CThreadWatcher |
|
21 **/ |
|
22 CThreadWatcher::~CThreadWatcher() |
|
23 { |
|
24 Cancel(); |
|
25 } |
|
26 |
|
27 CThreadWatcher::CThreadWatcher(TInt appType, TFullName aFullName, CStarter* aOwner, TUint32 aAppUid, TBool aViewless) |
|
28 : CActive(EPriorityStandard), iAppType(appType), iFullName(aFullName), iOwner(aOwner), iAppUid(aAppUid), iViewless(aViewless) |
|
29 {} |
|
30 |
|
31 void CThreadWatcher::ConstructL(const TThreadId aThreadId) |
|
32 { |
|
33 iMonitoringThread = ETrue; |
|
34 User::LeaveIfError(iThread.Open(aThreadId)); // Queue logon request |
|
35 iThread.Logon(iStatus); |
|
36 CActiveScheduler::Add(this); |
|
37 SetActive(); // Tell scheduler we're active |
|
38 } |
|
39 |
|
40 CThreadWatcher* CThreadWatcher::NewL(TInt appType, const TThreadId aThreadId, TFullName aFullName, CStarter* aOwner, TUint32 aAppUid, TBool aViewless) |
|
41 { |
|
42 CThreadWatcher* self = new (ELeave) CThreadWatcher(appType, aFullName, aOwner, aAppUid, aViewless); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(aThreadId); |
|
45 CleanupStack::Pop(); // self; |
|
46 return self; |
|
47 } |
|
48 |
|
49 void CThreadWatcher::DoCancel() |
|
50 |
|
51 { |
|
52 iThread.LogonCancel(iStatus); |
|
53 iThread.Close(); |
|
54 } |
|
55 |
|
56 void CThreadWatcher::RunL() |
|
57 { |
|
58 iThread.Close(); |
|
59 if(iMonitoringThread) |
|
60 { |
|
61 TRAPD(err, RestartThreadL()); //ignore error |
|
62 } |
|
63 } |
|
64 |
|
65 void CThreadWatcher::RestartThreadL() |
|
66 { |
|
67 TThreadId threadId; |
|
68 iOwner->RestartMonitoredThreadL(iAppType, threadId, iFullName, iAppUid, iViewless); |
|
69 User::LeaveIfError(iThread.Open(threadId)); // Queue logon request |
|
70 iThread.Logon(iStatus); |
|
71 iStatus = KRequestPending; |
|
72 SetActive(); // Tell scheduler we're active |
|
73 } |
|
74 |