|
1 /* |
|
2 * Copyright (c) 2004 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: Implementation of the active event observer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #ifdef _DEBUG |
|
23 #include <e32svr.h> |
|
24 #endif |
|
25 |
|
26 #include "LoudnessEventObserver.h" |
|
27 |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CLoudnessEventObserver::CLoudnessEventObserver |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CLoudnessEventObserver::CLoudnessEventObserver() |
|
38 : CActive(CActive::EPriorityStandard), |
|
39 iStopped(EFalse) |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CLoudnessEventObserver::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CLoudnessEventObserver::ConstructL( |
|
49 TMMFMessageDestinationPckg aMessageHandler, |
|
50 MCustomCommand& aCustomCommand, |
|
51 MLoudnessCallback& aCallback ) |
|
52 { |
|
53 CActiveScheduler::Add(this); |
|
54 iMessageHandler = aMessageHandler; |
|
55 iCustomCommand = &aCustomCommand; |
|
56 iCallback = &aCallback; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CLoudnessEventObserver::NewL |
|
61 // Two-phased constructor. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CLoudnessEventObserver* CLoudnessEventObserver::NewL( |
|
65 TMMFMessageDestinationPckg aMessageHandler, |
|
66 MCustomCommand& aCustomCommand, |
|
67 MLoudnessCallback& aCallback ) |
|
68 { |
|
69 CLoudnessEventObserver* self = new(ELeave) CLoudnessEventObserver(); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(aMessageHandler, aCustomCommand, aCallback); |
|
72 CleanupStack::Pop(self); |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CLoudnessEventObserver::~CLoudnessEventObserver |
|
79 // Destructor |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CLoudnessEventObserver::~CLoudnessEventObserver() |
|
83 { |
|
84 // We should not have to cancel the outstanding request because the message |
|
85 // handler will complete our request with KErrCancel in its destructor. |
|
86 Cancel(); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CLoudnessEventObserver::Start |
|
91 // Kickoff the event observer by issuing the first observation message. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CLoudnessEventObserver::Start() |
|
95 { |
|
96 if( !iStopped && !IsActive() ) |
|
97 { |
|
98 iCustomCommand->CustomCommandAsync(iMessageHandler, (TInt)ELefObserve, KNullDesC8, KNullDesC8, iDataPckgFrom, iStatus); |
|
99 iStopped = EFalse; |
|
100 SetActive(); |
|
101 } |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CLoudnessEventObserver::Stop |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CLoudnessEventObserver::Stop() |
|
109 { |
|
110 iStopped = ETrue; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CLoudnessEventObserver::RunL |
|
115 // Invoke by the active scheduler when a request completes, In this case, our |
|
116 // observation message has completed. |
|
117 // The proxy is notified. Afterwards, reissue the request to continue observation. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CLoudnessEventObserver::RunL() |
|
121 { |
|
122 #ifdef _DEBUG |
|
123 RDebug::Print(_L("CLoudnessEventObserver::RunL()\n")); |
|
124 #endif |
|
125 |
|
126 if( iStatus == KErrNone ) |
|
127 { |
|
128 iCallback->LoudnessEvent(iDataPckgFrom); |
|
129 Start(); |
|
130 } |
|
131 else |
|
132 { |
|
133 iStopped = ETrue; |
|
134 } |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CLoudnessEventObserver::DoCancel |
|
139 // Cancels the current and any on going requests/tasks. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CLoudnessEventObserver::DoCancel() |
|
143 { |
|
144 #ifdef _DEBUG |
|
145 RDebug::Print(_L("CLoudnessEventObserver::DoCancel()\n")); |
|
146 #endif |
|
147 iStopped = ETrue; |
|
148 } |
|
149 |
|
150 // End of file |
|
151 |