|
1 /* |
|
2 * Copyright (c) 2004-2005 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: SIM Status Monitor. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "CSosEnPolicySimStatusMonitor.h" |
|
22 #include <startupdomainpskeys.h> // Property values |
|
23 #include <PSVariables.h> |
|
24 |
|
25 |
|
26 |
|
27 // CONSTANTS |
|
28 const TUint KENPolicySAConnectionRetryTime = 2000000; // 2s |
|
29 const TInt KENPolicySAConnectionRetries = 3; |
|
30 |
|
31 _LIT( KENPolicyPanicCategory, "ENPolicyFault" ); |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CSosEnPolicySimStatusMonitor::CSosEnPolicySimStatusMonitor |
|
37 // C++ constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CSosEnPolicySimStatusMonitor::CSosEnPolicySimStatusMonitor( |
|
42 CSosEmergencyNumberPolicyHandler& aObserver ) : |
|
43 CActive( EPriorityStandard ), |
|
44 iObserver( aObserver ) |
|
45 { |
|
46 CActiveScheduler::Add( this ); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CSosEnPolicySimStatusMonitor::NewL |
|
51 // Two-phased constructor. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CSosEnPolicySimStatusMonitor* CSosEnPolicySimStatusMonitor::NewL( |
|
55 CSosEmergencyNumberPolicyHandler& aObserver ) |
|
56 { |
|
57 CSosEnPolicySimStatusMonitor* self = new ( ELeave ) |
|
58 CSosEnPolicySimStatusMonitor( aObserver ); |
|
59 |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CSosEnPolicySimStatusMonitor::~CSosEnPolicySimStatusMonitor |
|
68 // Destructor. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CSosEnPolicySimStatusMonitor::~CSosEnPolicySimStatusMonitor() |
|
72 { |
|
73 Cancel(); |
|
74 |
|
75 iProperty.Close(); |
|
76 |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CSosEnPolicySimStatusMonitor::ConstructL |
|
81 // |
|
82 // Construction. Creates also connection to system agent. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CSosEnPolicySimStatusMonitor::ConstructL() |
|
86 { |
|
87 TInt err = KErrNotSupported; |
|
88 for( TInt i = 0; i < KENPolicySAConnectionRetries; i++ ) |
|
89 { |
|
90 err = iProperty.Attach( KPSUidStartup, KPSSimStatus ); |
|
91 if( err == KErrNone ) |
|
92 { |
|
93 i = KENPolicySAConnectionRetries; |
|
94 } |
|
95 else |
|
96 { |
|
97 // _DPRINT( 4, "ENPolicy.SimStatus.Attach.RETRY" ); |
|
98 User::After( KENPolicySAConnectionRetryTime ); |
|
99 } |
|
100 } |
|
101 //if connection not established. |
|
102 __ASSERT_ALWAYS( err == KErrNone, User::Panic( |
|
103 KENPolicyPanicCategory, EEnPolicyPanicCentralRepositoryConnectionFailure ) ); |
|
104 IssueRequest(); |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CSosEnPolicySimStatusMonitor::DoCancel |
|
109 // |
|
110 // Cancellation of notify. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CSosEnPolicySimStatusMonitor::DoCancel() |
|
114 { |
|
115 iProperty.Cancel(); |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CSosEnPolicySimStatusMonitor::RunL |
|
120 // |
|
121 // SIM event occurred. |
|
122 // Basically events make three kinds of responses. |
|
123 // If there is an error in notify, nothing is made. Othervice, event |
|
124 // may indicate that SIM is accessible or not. Depending on that, action is |
|
125 // send for observer. |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CSosEnPolicySimStatusMonitor::RunL() |
|
129 { |
|
130 TInt state = KErrGeneral; |
|
131 |
|
132 iProperty.Get( state ); |
|
133 |
|
134 // _DDPRINT( 4, "ENPolicy.SimStatus.status.e.", iStatus.Int() ); |
|
135 // _DDPRINT( 4, "ENPolicy.SimStatus.status.", state ); |
|
136 CSosEmergencyNumberPolicyHandler::TSosEnPolicySimEmergencyNumberAction |
|
137 action = CSosEmergencyNumberPolicyHandler:: |
|
138 ESosEnPolicySimEmergencyNumberClear; |
|
139 switch ( iStatus.Int() ) |
|
140 { |
|
141 case KErrNotSupported: |
|
142 case KErrCancel: |
|
143 return; |
|
144 case KErrNone: |
|
145 { |
|
146 if ( TranslateState( state ) ) |
|
147 { |
|
148 action = |
|
149 CSosEmergencyNumberPolicyHandler:: |
|
150 ESosEnPolicySimEmergencyNumberRead; |
|
151 } |
|
152 iObserver.CpsssmHandleSimStatusEvent( action ); |
|
153 } |
|
154 default: |
|
155 break; |
|
156 } |
|
157 IssueRequest(); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CSosEnPolicySimStatusMonitor::IsReadingAllowed |
|
162 // |
|
163 // Checks sim state from system agent |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 TBool CSosEnPolicySimStatusMonitor::IsReadingAllowed() |
|
167 { |
|
168 TInt state = KErrGeneral; |
|
169 |
|
170 iProperty.Get( state ); |
|
171 return TranslateState( state ); |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CSosEnPolicySimStatusMonitor::IssueRequest |
|
176 // |
|
177 // Issue notify request to System agent. |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CSosEnPolicySimStatusMonitor::IssueRequest() |
|
181 { |
|
182 iProperty.Subscribe( iStatus ); |
|
183 |
|
184 SetActive(); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CSosEnPolicySimStatusMonitor::TranslateState |
|
189 // |
|
190 // Translate the state information. |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 TBool CSosEnPolicySimStatusMonitor::TranslateState( TInt aState ) |
|
194 { |
|
195 switch ( aState ) |
|
196 { |
|
197 case ESimUsable: |
|
198 case ESimReadable: |
|
199 return ETrue; |
|
200 case ESimStatusUninitialized: |
|
201 case ESimNotReady: |
|
202 case ESimNotSupported: |
|
203 case ESimNotPresent: |
|
204 return EFalse; |
|
205 default: |
|
206 return EFalse; |
|
207 } |
|
208 } |
|
209 |
|
210 |
|
211 // End of File |