|
1 /* |
|
2 * Copyright (c) 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: Observes the state of Bluetooth Sap. When the state is |
|
15 * changed into connected, connection to smart card is closed and |
|
16 * when the state is changed into not connected, initialize |
|
17 * connection to smart card back. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include "WimBTSapObserver.h" |
|
25 #include "WimServer.h" |
|
26 #include "WimSession.h" |
|
27 #include "WimTrace.h" |
|
28 |
|
29 #if defined BT_SAP_TEST_BY_CHARGER |
|
30 #include <PSVariables.h> |
|
31 #else |
|
32 //#include <BTSapInternalPSKeys.h> // Property values |
|
33 #include <BTSapDomainPSKeys.h> |
|
34 #endif // BT_SAP_TEST_BY_CHARGER |
|
35 |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CWimBTSapObserver::CWimBTSapObserver |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CWimBTSapObserver::CWimBTSapObserver() |
|
46 : CActive( EPriorityNormal ) |
|
47 { |
|
48 _WIMTRACE(_L("WIM|CWimBTSapObserver::CWimBTSapObserver|Begin")); |
|
49 CActiveScheduler::Add( this ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CWimBTSapObserver::ConstructL |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CWimBTSapObserver::ConstructL() |
|
58 { |
|
59 _WIMTRACE(_L("WIM|CWimBTSapObserver::ConstructL|Begin")); |
|
60 iWimSvr = CWimServer::Server(); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CWimBTSapObserver::NewL |
|
65 // Two-phased constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CWimBTSapObserver* CWimBTSapObserver::NewL() |
|
69 { |
|
70 _WIMTRACE(_L("WIM|CWimBTSapObserver::NewL|Begin")); |
|
71 CWimBTSapObserver* self = new( ELeave ) CWimBTSapObserver (); |
|
72 |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop( self ); |
|
76 |
|
77 return self; |
|
78 } |
|
79 |
|
80 |
|
81 // Destructor |
|
82 CWimBTSapObserver::~CWimBTSapObserver() |
|
83 { |
|
84 _WIMTRACE(_L("WIM|CWimBTSapObserver::~CWimBTSapObserver|Begin")); |
|
85 Cancel(); |
|
86 iProperty.Close(); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CWimBTSapObserver::Start |
|
91 // Start listening publish and subscribe events |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CWimBTSapObserver::Start() |
|
95 { |
|
96 _WIMTRACE(_L("WIM|CWimBTSapObserver::Start|Begin")); |
|
97 if ( !IsActive() ) // If already active, don't activate |
|
98 { |
|
99 StartListening(); //Start listening |
|
100 } |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CWimBTSapObserver::StartListening |
|
105 // Start listening card status from publish and subscribe |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CWimBTSapObserver::StartListening() |
|
109 { |
|
110 _WIMTRACE(_L("WIM|CWimBTSapObserver::StartListening|Begin")); |
|
111 iStatus = KRequestPending; |
|
112 #if defined BT_SAP_TEST_BY_CHARGER |
|
113 TInt err = iProperty.Attach( KUidSystemCategory, |
|
114 KPSUidChargerStatusValue ); |
|
115 |
|
116 #else |
|
117 TInt err = iProperty.Attach( KPSUidBluetoothSapConnectionState, |
|
118 KBTSapConnectionState ); |
|
119 #endif // BT_SAP_TEST_BY_CHARGER |
|
120 if ( err == KErrNone ) |
|
121 { |
|
122 iProperty.Subscribe( iStatus ); |
|
123 SetActive(); |
|
124 } |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CWimBTSapObserver::RunL |
|
129 // Got event from publish and subscribe |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CWimBTSapObserver::RunL() |
|
133 { |
|
134 _WIMTRACE(_L("WIM|CWimBTSapObserver::RunL|Begin")); |
|
135 //Notify on bluetooth event |
|
136 TInt btState; |
|
137 iProperty.Get( btState ); |
|
138 switch ( btState ) |
|
139 { |
|
140 #if defined BT_SAP_TEST_BY_CHARGER |
|
141 case EPSChargerStatusUninitialized: // Flow through |
|
142 case EPSChargerDisconnected: // Flow through |
|
143 case EPSChargerNotCharging: // Charger not charging, no actions |
|
144 #else |
|
145 case EBTSapNotConnected: // Flow through |
|
146 case EBTSapConnecting: // BT Sap not connected, no actions |
|
147 #endif // BT_SAP_TEST_BY_CHARGER |
|
148 { |
|
149 StartListening(); |
|
150 break; |
|
151 } |
|
152 #if defined BT_SAP_TEST_BY_CHARGER |
|
153 case EPSChargerConnected: |
|
154 #else |
|
155 case EBTSapConnected: |
|
156 #endif // BT_SAP_TEST_BY_CHARGER |
|
157 { |
|
158 if ( CWimServer::iWimInitialized ) |
|
159 { |
|
160 // Wim initialized, can close WIMI immediately. |
|
161 // NOTE: Is it ok to run lengthy operations here? |
|
162 RArray<CWimSession*> sessions; |
|
163 TRAPD( err, iWimSvr->GetSessionsL( sessions ) ); |
|
164 |
|
165 if ( !err ) // Got sessions correctly |
|
166 { |
|
167 // Loop through all sessions and notify all clients that are |
|
168 // requesting the notification |
|
169 for ( TInt i( 0 ); i < sessions.Count(); i++ ) |
|
170 { |
|
171 sessions[i]->NotifyComplete(); |
|
172 } |
|
173 sessions.Reset(); |
|
174 // Close WIMI |
|
175 WIMI_CloseDownReq(); |
|
176 _WIMTRACE(_L("WIM | CWimSatRefreshObserver::Refresh | WIMI closed.")); |
|
177 } |
|
178 } |
|
179 else |
|
180 { |
|
181 _WIMTRACE(_L("WIM | CWimSatRefreshObserver::Refresh | WIMI already closed.")); |
|
182 } |
|
183 } |
|
184 } |
|
185 _WIMTRACE(_L("WIM|CWimBTSapObserver::RunL|End")); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CWimBTSapObserver::DoCancel |
|
190 // Cancel asynchronous request |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CWimBTSapObserver::DoCancel() |
|
194 { |
|
195 _WIMTRACE(_L("WIM|CWimBTSapObserver::DoCancel|Begin")); |
|
196 iProperty.Cancel(); |
|
197 _WIMTRACE(_L("WIM|CWimBTSapObserver::DoCancel|End")); |
|
198 } |
|
199 |
|
200 // End of File |