|
1 /* |
|
2 * Copyright (c) 2002-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: An active object that completes when bluetooth SIM access |
|
15 * profile status changes |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CSimStatusNotification.h" |
|
22 |
|
23 // From Virtual Phonebook |
|
24 #include "MSimStatusObserver.h" |
|
25 #include "VPbkSimStoreImplError.h" |
|
26 #include <CVPbkSimStateInformation.h> |
|
27 #include <VPbkSimStoreTemplateFunctions.h> |
|
28 #include <VPbkSimStateDefinitions.h> |
|
29 |
|
30 // System includes |
|
31 #include <featmgr.h> |
|
32 |
|
33 #include <VPbkDebug.h> |
|
34 |
|
35 namespace VPbkSimStoreImpl { |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSimStatusNotification::CSimStatusNotification |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CSimStatusNotification::CSimStatusNotification() |
|
46 : CActive( EPriorityStandard ), |
|
47 iSimStatus( VPbkSimStoreImpl::SimUninitializedStatus ) |
|
48 { |
|
49 CActiveScheduler::Add( this ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CSimStatusNotification::ConstructL |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CSimStatusNotification::ConstructL() |
|
57 { |
|
58 VPBK_DEBUG_PRINT( |
|
59 VPBK_DEBUG_STRING("VPbkSimStoreImpl::CSimStatusNotification::ConstructL") ); |
|
60 User::LeaveIfError( iSimStatusProperty.Attach( |
|
61 KVPbkSimStatusPSCategory, VPbkSimStoreImpl::SimStatusPSKey ) ); |
|
62 // Init state |
|
63 iSimStatus = ReadState(); |
|
64 DoActivate(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CSimStatusNotification::NewL |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CSimStatusNotification* CSimStatusNotification::NewL() |
|
72 { |
|
73 CSimStatusNotification* self = |
|
74 new( ELeave ) CSimStatusNotification(); |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL(); |
|
77 CleanupStack::Pop( self ); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // Destructor |
|
82 CSimStatusNotification::~CSimStatusNotification() |
|
83 { |
|
84 Cancel(); |
|
85 iObservers.Close(); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CSimStatusNotification::ActivateL |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt CSimStatusNotification::CurrentStatus() const |
|
93 { |
|
94 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
95 "VPbkSimStoreImpl::CSimStatusNotification::CurrentStatus(%d)"), |
|
96 iSimStatus); |
|
97 return iSimStatus; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CSimStatusNotification::AddObserverL |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CSimStatusNotification::AddObserverL( MSimStatusObserver& aObserver ) |
|
105 { |
|
106 if ( iObservers.Find( &aObserver ) == KErrNotFound ) |
|
107 { |
|
108 iObservers.AppendL( &aObserver ); |
|
109 } |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CSimStatusNotification::RemoveObserver |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CSimStatusNotification::RemoveObserver( MSimStatusObserver& aObserver ) |
|
117 { |
|
118 TInt pos = iObservers.Find( &aObserver ); |
|
119 if (pos != KErrNotFound ) |
|
120 { |
|
121 iObservers.Remove( pos ); |
|
122 } |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CSimStatusNotification::RunL |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CSimStatusNotification::RunL() |
|
130 { |
|
131 TInt result = iStatus.Int(); |
|
132 |
|
133 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
134 "VPbkSimStoreImpl: CSimStatusNotification::RunL result %d"), result ); |
|
135 |
|
136 // KErrNone means that there was a change in SIM status state. |
|
137 // KErrNotFound means that the PS key was removed. |
|
138 // From VPbkSimServer point of view KErrNotFound means that |
|
139 // we check the state normally and act accoring to that. |
|
140 if ( result == KErrNone || result == KErrNotFound ) |
|
141 { |
|
142 TInt status = ReadState(); |
|
143 if ( status != iSimStatus ) |
|
144 { |
|
145 iSimStatus = status; |
|
146 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
147 "VPbkSimStoreImpl: CSimStatusNotification::RunL activated %d" ), |
|
148 iSimStatus); |
|
149 |
|
150 if ( iSimStatus == VPbkSimStoreImpl::SimOkStatus ) |
|
151 { |
|
152 SendObserverMessage( |
|
153 iObservers, &MSimStatusObserver::SimStatusOk ); |
|
154 } |
|
155 else if ( iSimStatus == VPbkSimStoreImpl::SimUninitializedStatus ) |
|
156 { |
|
157 SendObserverMessage( |
|
158 iObservers, &MSimStatusObserver::SimStatusUninitialized ); |
|
159 } |
|
160 else |
|
161 { |
|
162 SendObserverMessage( |
|
163 iObservers, &MSimStatusObserver::SimStatusNotOk ); |
|
164 } |
|
165 } |
|
166 } |
|
167 else |
|
168 { |
|
169 SendObserverMessageR( iObservers, |
|
170 &MSimStatusObserver::SimStatusNotificationError, result ); |
|
171 } |
|
172 |
|
173 // Activate the notification again |
|
174 DoActivate(); |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CSimStatusNotification::DoCancel |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CSimStatusNotification::DoCancel() |
|
182 { |
|
183 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
184 "VPbkSimStoreImpl: CSimStatusNotification::DoCancel")); |
|
185 iSimStatusProperty.Cancel(); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CSimStatusNotification::RunError |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 TInt CSimStatusNotification::RunError( TInt aError ) |
|
193 { |
|
194 SendObserverMessageR( iObservers, |
|
195 &MSimStatusObserver::SimStatusNotificationError, aError ); |
|
196 return KErrNone; |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CSimStatusNotification::DoActivate |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CSimStatusNotification::DoActivate() |
|
204 { |
|
205 iSimStatusProperty.Subscribe( iStatus ); |
|
206 SetActive(); |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CSimStatusNotification::ReadState |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 TInt CSimStatusNotification::ReadState() |
|
214 { |
|
215 TInt status = KErrNotFound; |
|
216 iSimStatusProperty.Get( |
|
217 KVPbkSimStatusPSCategory, |
|
218 VPbkSimStoreImpl::SimStatusPSKey, |
|
219 status ); |
|
220 |
|
221 return status; |
|
222 } |
|
223 } // namespace VPbkSimStoreImpl |
|
224 // End of File |