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 // ------------------------------------------------------------------------------ |
|
19 // |
|
20 // class CProfilerEngineStatusChecker |
|
21 // |
|
22 // ------------------------------------------------------------------------------ |
|
23 // |
|
24 inline CProfilerEngineStatusChecker* CProfilerEngineStatusChecker::NewL() |
|
25 { |
|
26 CProfilerEngineStatusChecker* self = new(ELeave) CProfilerEngineStatusChecker(); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 CleanupStack::Pop(); |
|
30 return self; |
|
31 } |
|
32 |
|
33 // -------------------------------------------------------------------------------------------- |
|
34 inline CProfilerEngineStatusChecker::CProfilerEngineStatusChecker() : |
|
35 CActive(EPriorityStandard) |
|
36 { |
|
37 } |
|
38 |
|
39 inline CProfilerEngineStatusChecker::~CProfilerEngineStatusChecker() |
|
40 { |
|
41 Cancel(); |
|
42 iEngineStatus.Close(); |
|
43 } |
|
44 |
|
45 // -------------------------------------------------------------------------------------------- |
|
46 inline void CProfilerEngineStatusChecker::ConstructL() |
|
47 { |
|
48 User::LeaveIfError(iEngineStatus.Attach(KEngineStatusPropertyCat, EProfilerEngineStatus)); |
|
49 CActiveScheduler::Add(this); |
|
50 |
|
51 // check engine status, if not available set to idle |
|
52 if(iEngineStatus.Get(iPrevStat) != KErrNone) |
|
53 { |
|
54 iPrevStat = MProfilerStatusObserver::EIdle; |
|
55 } |
|
56 |
|
57 // subscribe to P&S status property |
|
58 iEngineStatus.Subscribe(iStatus); |
|
59 SetActive(); |
|
60 } |
|
61 |
|
62 inline TInt CProfilerEngineStatusChecker::GetInitialState() |
|
63 { |
|
64 // check engine status, if not available set to idle |
|
65 TInt err(iEngineStatus.Get(KEngineStatusPropertyCat, EProfilerEngineStatus, iPrevStat)); |
|
66 if(err != KErrNone) |
|
67 { |
|
68 iPrevStat = MProfilerStatusObserver::EIdle; |
|
69 } |
|
70 return iPrevStat; |
|
71 } |
|
72 |
|
73 // -------------------------------------------------------------------------------------------- |
|
74 inline void CProfilerEngineStatusChecker::RunL() |
|
75 { |
|
76 // resubscribe before processing new value to prevent missing updates |
|
77 iEngineStatus.Subscribe(iStatus); |
|
78 SetActive(); |
|
79 |
|
80 TInt stat(0); |
|
81 if(iEngineStatus.Get(KEngineStatusPropertyCat, EProfilerEngineStatus, stat) == KErrNone) |
|
82 { |
|
83 // check if status one of error codes (< 0) |
|
84 if(stat < KErrNone) |
|
85 { |
|
86 // some error occurred on engine side => set UI idle and show an error note |
|
87 iObserver->HandleProfilerErrorL(stat); |
|
88 } |
|
89 else |
|
90 { |
|
91 if(iPrevStat != stat) |
|
92 { |
|
93 switch(stat) |
|
94 { |
|
95 case 0: |
|
96 iObserver->HandleProfilerStatusChange(MProfilerStatusObserver::EIdle); |
|
97 break; |
|
98 case 1: |
|
99 iObserver->HandleProfilerStatusChange(MProfilerStatusObserver::EInitializing); |
|
100 break; |
|
101 case 2: |
|
102 iObserver->HandleProfilerStatusChange(MProfilerStatusObserver::ERunning); |
|
103 break; |
|
104 case 3: |
|
105 iObserver->HandleProfilerStatusChange(MProfilerStatusObserver::EStopping); |
|
106 break; |
|
107 default: |
|
108 iObserver->HandleProfilerErrorL(stat); |
|
109 break; |
|
110 } |
|
111 iPrevStat = stat; |
|
112 } |
|
113 } |
|
114 } |
|
115 } |
|
116 |
|
117 // -------------------------------------------------------------------------------------------- |
|
118 |
|
119 inline void CProfilerEngineStatusChecker::DoCancel() |
|
120 { |
|
121 iEngineStatus.Cancel(); |
|
122 } |
|
123 |
|
124 // -------------------------------------------------------------------------------------------- |
|
125 inline void CProfilerEngineStatusChecker::SetObserver(MProfilerStatusObserver* aObserver) |
|
126 { |
|
127 iObserver = aObserver; |
|
128 } |
|