|
1 /* |
|
2 * Copyright (c) 2007 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 // INCLUDE FILES |
|
20 #include "siprfsmonitorao.h" |
|
21 #include <sipsystemstatemonitorpskeys.h> |
|
22 #include <sipsystemstateobserver.h> |
|
23 |
|
24 _LIT_SECURITY_POLICY_PASS( KSIPRfsAlwaysPass ); |
|
25 |
|
26 static const TInt KMicroSecondsInSecond = 1000000; |
|
27 static const TInt KGuardTimerSeconds = 20; |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CSipRfsMonitorAo::NewL |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CSipRfsMonitorAo* CSipRfsMonitorAo::NewL() |
|
34 { |
|
35 CSipRfsMonitorAo* self = new( ELeave )CSipRfsMonitorAo(); |
|
36 CleanupStack::PushL ( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CSipRfsMonitorAo::ConstructL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void CSipRfsMonitorAo::ConstructL () |
|
47 { |
|
48 iGuardTimer = CPeriodic::NewL( EPriorityNormal ); |
|
49 TInt err = iProperty.Define( KPSSipRfsUid, KSipRfsState, RProperty::EInt, |
|
50 KSIPRfsAlwaysPass, KSIPRfsAlwaysPass); |
|
51 if ( KErrNone != err && KErrAlreadyExists != err && |
|
52 KErrPermissionDenied != err ) |
|
53 { |
|
54 User::Leave( err ); |
|
55 } |
|
56 User::LeaveIfError( iProperty.Attach(KPSSipRfsUid, KSipRfsState)); |
|
57 iProperty.Subscribe( iStatus ); |
|
58 SetActive(); |
|
59 |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CSipRfsMonitorAo::CSipRfsMonitorAo |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CSipRfsMonitorAo::CSipRfsMonitorAo(): |
|
67 CActive(EPriorityStandard) |
|
68 { |
|
69 CActiveScheduler::Add( this ); |
|
70 iCount = 0; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CSipRfsMonitorAo::~CSipRfsMonitorAo |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CSipRfsMonitorAo::~CSipRfsMonitorAo() |
|
78 { |
|
79 if(iGuardTimer) |
|
80 { |
|
81 iGuardTimer->Cancel(); |
|
82 delete iGuardTimer; |
|
83 iGuardTimer = NULL; |
|
84 } |
|
85 CActive::Cancel(); |
|
86 iProperty.Close(); |
|
87 iProperty.Delete(KPSSipRfsUid,KSipRfsState); |
|
88 iObservers.Close(); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CSipRfsMonitorAo::AddObserverL |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CSipRfsMonitorAo::AddObserverL( |
|
96 MSipSystemStateObserver& aObserver ) |
|
97 { |
|
98 iObservers.InsertInAddressOrderL( &aObserver ); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CSipRfsMonitorAo::RemoveObserver |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CSipRfsMonitorAo::RemoveObserver( |
|
106 MSipSystemStateObserver& aObserver ) |
|
107 { |
|
108 TInt index = iObservers.Find( &aObserver ); |
|
109 if ( index >= 0 ) |
|
110 { |
|
111 iObservers.Remove( index ); |
|
112 } |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CSipRfsMonitorAo::NotifyObservers |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void CSipRfsMonitorAo::NotifyObservers() |
|
120 { |
|
121 for ( TInt i = iObservers.Count()-1; i >= 0; i-- ) |
|
122 { |
|
123 iObservers[i]->SystemVariableUpdated( |
|
124 CSipSystemStateMonitor::ERfsState, |
|
125 0, |
|
126 iState); |
|
127 } |
|
128 if(iObservers.Count() && iState == CSipSystemStateMonitor::ERfsStarted) |
|
129 { |
|
130 iGuardTimer->Cancel(); |
|
131 iGuardTimer->Start( |
|
132 TTimeIntervalMicroSeconds32( KGuardTimerSeconds * KMicroSecondsInSecond ), |
|
133 TTimeIntervalMicroSeconds32( KGuardTimerSeconds * KMicroSecondsInSecond ), |
|
134 TCallBack( TimerExpired, this ) ); |
|
135 } |
|
136 |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CSipRfsMonitorAo::State |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 CSipSystemStateMonitor::TRfsState CSipRfsMonitorAo::State() const |
|
144 { |
|
145 return iState; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CSipRfsMonitorAo::EventProcessingCompleted |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CSipRfsMonitorAo::EventProcessingCompleted( |
|
153 MSipSystemStateObserver& /*aObserver*/ ) |
|
154 { |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CSipRfsMonitorAo::EventProcessingCompleted |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CSipRfsMonitorAo::EventProcessingCompleted() |
|
162 { |
|
163 iGuardTimer->Cancel(); |
|
164 iProperty.Set(KPSSipRfsUid, KSipRfsState, ESipRfsEventProcessingCompleted ); |
|
165 iCount = 0; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CSipRfsMonitorAo::TimerExpired |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CSipRfsMonitorAo::TimerExpired(TAny* aSelf) |
|
173 { |
|
174 CSipRfsMonitorAo* self = reinterpret_cast<CSipRfsMonitorAo*>(aSelf); |
|
175 self->EventProcessingCompleted(); |
|
176 return ETrue; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CSipRfsMonitorAo::RunL |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CSipRfsMonitorAo::RunL() |
|
184 { |
|
185 TInt state ( 0 ); |
|
186 if ( KErrNone == iProperty.Get( state ) ) |
|
187 { |
|
188 if (MappedState(state)) |
|
189 NotifyObservers(); |
|
190 } |
|
191 iProperty.Subscribe( iStatus ); |
|
192 SetActive(); |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CSipRfsMonitorAo::RunError |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 TInt CSipRfsMonitorAo::RunError( TInt /*aError*/ ) |
|
200 { |
|
201 return KErrNone; // RunL cannot leave at the moment |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CSipRfsMonitorAo::DoCancel |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void CSipRfsMonitorAo::DoCancel() |
|
209 { |
|
210 iProperty.Cancel(); |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CSipRfsMonitorAo::MappedState |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 TBool CSipRfsMonitorAo::MappedState(TInt aState) |
|
218 { |
|
219 TBool ret = ETrue; |
|
220 switch(aState) |
|
221 { |
|
222 case CSipSystemStateMonitor::ERfsStarted: |
|
223 iState = CSipSystemStateMonitor::ERfsStarted; |
|
224 break; |
|
225 case CSipSystemStateMonitor::ERfsFailed: |
|
226 iState = CSipSystemStateMonitor::ERfsFailed; |
|
227 break; |
|
228 case CSipSystemStateMonitor::ERfsCompleted: |
|
229 iState = CSipSystemStateMonitor::ERfsCompleted; |
|
230 break; |
|
231 default: |
|
232 ret = EFalse; |
|
233 } |
|
234 return ret; |
|
235 } |