|
1 /* |
|
2 * Copyright (c) 2010 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 * Listens for changes in dial-up PDP context override P&S-key. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32property.h> |
|
21 |
|
22 #include "connmondialupoverridenotifier.h" |
|
23 #include "connectionmonitorpskeys.h" |
|
24 #include "ConnMonServ.h" |
|
25 #include "ConnMonIAP.h" |
|
26 #include "log.h" |
|
27 |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // Two phased construction. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CConnMonDialUpOverrideNotifier* CConnMonDialUpOverrideNotifier::NewL( |
|
34 CConnMonServer* aServer ) |
|
35 { |
|
36 CConnMonDialUpOverrideNotifier* self = |
|
37 CConnMonDialUpOverrideNotifier::NewLC( aServer ); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // Two phased construction. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CConnMonDialUpOverrideNotifier* CConnMonDialUpOverrideNotifier::NewLC( |
|
47 CConnMonServer* aServer ) |
|
48 { |
|
49 CConnMonDialUpOverrideNotifier* self = |
|
50 new( ELeave ) CConnMonDialUpOverrideNotifier( aServer ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // Destructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CConnMonDialUpOverrideNotifier::~CConnMonDialUpOverrideNotifier() |
|
61 { |
|
62 // Cancel outstanding request, if exists. |
|
63 Cancel(); |
|
64 iDialUpProperty.Delete( KConnectionMonitorPS, KDialUpConnection ); |
|
65 iDialUpProperty.Close(); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CConnMonDialUpOverrideNotifier::ResetStatus |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 TInt CConnMonDialUpOverrideNotifier::ResetStatus() |
|
73 { |
|
74 // Set property value to EConnMonReady. |
|
75 TInt err = iDialUpProperty.Set( EConnMonReady ); |
|
76 LOGIT1("ResetStatus: Dial-up property value set to EConnMonReady <%d>", err) |
|
77 return err; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // Constructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CConnMonDialUpOverrideNotifier::CConnMonDialUpOverrideNotifier( |
|
85 CConnMonServer* aServer ) |
|
86 : |
|
87 CActive( EConnMonPriorityMedium ), |
|
88 iServer( aServer), |
|
89 iErrorCounter( 0 ) |
|
90 { |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // Two phased construction. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CConnMonDialUpOverrideNotifier::ConstructL() |
|
98 { |
|
99 LOGENTRFN("CConnMonDialUpOverrideNotifier::ConstructL()") |
|
100 |
|
101 // Define Dial-up property. |
|
102 TInt err = iDialUpProperty.Define( |
|
103 KConnectionMonitorPS, |
|
104 KDialUpConnection, |
|
105 RProperty::EInt, |
|
106 KDialUpOverrideReadC0, // Read: Always pass |
|
107 KDialUpOverrideWriteC2, // Write: NetworkControl, NetworkServices |
|
108 0 ); |
|
109 LOGIT1("Dial-up property defined <%d>", err) |
|
110 User::LeaveIfError( err ); |
|
111 |
|
112 // Attach to property. |
|
113 err = iDialUpProperty.Attach( |
|
114 KConnectionMonitorPS, |
|
115 KDialUpConnection ); |
|
116 LOGIT1("Dial-up property attach <%d>", err) |
|
117 User::LeaveIfError( err ); |
|
118 |
|
119 // Set property value to EConnMonReady. |
|
120 ResetStatus(); |
|
121 |
|
122 CActiveScheduler::Add( this ); |
|
123 RequestNotifications(); |
|
124 |
|
125 LOGEXITFN("CConnMonDialUpOverrideNotifier::ConstructL()") |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CConnMonDialUpOverrideNotifier::RequestNotifications |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CConnMonDialUpOverrideNotifier::RequestNotifications() |
|
133 { |
|
134 LOGENTRFN("CConnMonDialUpOverrideNotifier::RequestNotifications()") |
|
135 |
|
136 if ( !IsActive() ) |
|
137 { |
|
138 iDialUpProperty.Subscribe( iStatus ); |
|
139 LOGIT("KDialUpConnection-key, Subscribe()") |
|
140 SetActive(); |
|
141 } |
|
142 |
|
143 LOGEXITFN("CConnMonDialUpOverrideNotifier::RequestNotifications()") |
|
144 return; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CConnMonDialUpOverrideNotifier::DoCancel |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CConnMonDialUpOverrideNotifier::DoCancel() |
|
152 { |
|
153 LOGIT("Canceling dialup property subscription.") |
|
154 iDialUpProperty.Cancel(); |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CConnMonDialUpOverrideNotifier::RunL |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CConnMonDialUpOverrideNotifier::RunL() |
|
162 { |
|
163 LOGIT(".") |
|
164 LOGIT1("RunL: CConnMonDialUpOverrideNotifier <%d>", iStatus.Int()) |
|
165 |
|
166 if ( iStatus.Int() == KErrNone ) |
|
167 { |
|
168 iErrorCounter = 0; |
|
169 TInt value = -1; |
|
170 TInt err = iDialUpProperty.Get( value ); |
|
171 LOGIT2("Dial-up override value is %d <%d>", value, err) |
|
172 |
|
173 switch ( value ) |
|
174 { |
|
175 case EConnMonDialUpClosed: |
|
176 { |
|
177 // Deactivate the dial-up override (if active). This will return |
|
178 // cellular data connectivity back to normal. |
|
179 iServer->SetDialUpOverrideStatus( EConnMonDialUpOverrideInactive ); |
|
180 ResetStatus(); |
|
181 } |
|
182 break; |
|
183 case EConnMonDialUpInit: |
|
184 { |
|
185 // Set the dial-up override status to active. This will block |
|
186 // other cellular data connectivity and start the timeout timer. |
|
187 iServer->SetDialUpOverrideStatus( EConnMonDialUpOverrideActive ); |
|
188 |
|
189 // If there are no active packetdata connections, signal EConnMonReady |
|
190 // immediately. If there are active connections, EConnMonReady is |
|
191 // signaled when those connections have gone down. |
|
192 if ( !iServer->Iap()->ActivePacketdataConnectionsFound() ) |
|
193 { |
|
194 ResetStatus(); |
|
195 } |
|
196 } |
|
197 break; |
|
198 case EConnMonReady: |
|
199 default: |
|
200 break; |
|
201 } |
|
202 } |
|
203 else |
|
204 { |
|
205 LOGIT1("Dial-up override notification error <%d>", iStatus.Int()) |
|
206 iErrorCounter++; |
|
207 if ( iErrorCounter > KConnMonPsEventErrorThreshold ) |
|
208 { |
|
209 LOGIT1("Over %d consecutive errors, stopping", KConnMonPsEventErrorThreshold) |
|
210 return; |
|
211 } |
|
212 } |
|
213 RequestNotifications(); |
|
214 } |
|
215 |
|
216 // End of file |