|
1 /* |
|
2 * Copyright (c) 2008 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: Checks if wlan scan state changes and informs observer of it |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Include Files |
|
20 #include <commdb.h> |
|
21 #include <d32dbms.h> |
|
22 #include <WlanCdbCols.h> |
|
23 #include <wlanmgmtclient.h> |
|
24 #include "cmcommsdbnotifier.h" |
|
25 #include "cmscheduler.h" |
|
26 #include "msdebug.h" |
|
27 |
|
28 // Two-phased constructor. |
|
29 CCmCommsDbNotifier* CCmCommsDbNotifier::NewL( CCmScheduler& aScheduler ) |
|
30 { |
|
31 CCmCommsDbNotifier* self = new (ELeave) CCmCommsDbNotifier( aScheduler ); |
|
32 |
|
33 CleanupStack::PushL( self ); |
|
34 CActiveScheduler::Add( self ); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 void CCmCommsDbNotifier::ConstructL() |
|
41 { |
|
42 // open comms database |
|
43 iDb = CCommsDatabase::NewL(); |
|
44 // assign notification request |
|
45 RequestNotification(); |
|
46 } |
|
47 |
|
48 // -------------------------------------------------------------------------- |
|
49 // CCmCommsDbNotifier::CCmCommsDbNotifier |
|
50 // C++ default constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // -------------------------------------------------------------------------- |
|
53 // |
|
54 CCmCommsDbNotifier::CCmCommsDbNotifier( CCmScheduler& aScheduler ) : |
|
55 CActive( CActive::EPriorityStandard ) |
|
56 { |
|
57 LOG(_L("[Cm Scheduler]\t CCmCommsDbNotifier::CCmCommsDbNotifier()")); |
|
58 |
|
59 // Scheduler reads scan interval on construction, so we can |
|
60 // assume it's off |
|
61 // now |
|
62 iScanState = 0; |
|
63 iScheduler = &aScheduler; |
|
64 } |
|
65 |
|
66 // Destructor |
|
67 CCmCommsDbNotifier::~CCmCommsDbNotifier() |
|
68 { |
|
69 LOG(_L("[Cm Scheduler]\t CCmCommsDbNotifier::~CCmCommsDbNotifier()")); |
|
70 |
|
71 Cancel(); |
|
72 |
|
73 delete iDb; |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // CCmCommsDbNotifier::RequestNotification |
|
78 // Requests database notification |
|
79 // -------------------------------------------------------------------------- |
|
80 // |
|
81 void CCmCommsDbNotifier::RequestNotification() |
|
82 { |
|
83 LOG(_L("[Cm Scheduler]\t CCmCommsDbNotifier::RequestNotification()")); |
|
84 if ( !IsActive() ) |
|
85 { |
|
86 iDb->RequestNotification( iStatus ); |
|
87 SetActive(); |
|
88 } |
|
89 } |
|
90 |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // CCmCommsDbNotifier::DoCancel |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 void CCmCommsDbNotifier::DoCancel() |
|
97 { |
|
98 // cancel possible requests |
|
99 iDb->CancelRequestNotification(); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CCmCommsDbNotifier::RunL |
|
104 // Called when change in database occurs |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CCmCommsDbNotifier::RunL() |
|
108 { |
|
109 LOG(_L("[Cm Scheduler]\t CCmCommsDbNotifier::RunL()")); |
|
110 |
|
111 if ( iScheduler && |
|
112 iStatus.Int() == RDbNotifier::ECommit && |
|
113 HasScanStateChangedL() ) |
|
114 { |
|
115 iScheduler->WlanScanStateChanged( iScanState ); |
|
116 } |
|
117 |
|
118 // Assign new request |
|
119 RequestNotification(); |
|
120 } |
|
121 |
|
122 // -------------------------------------------------------------------------- |
|
123 // CCmCommsDbNotifier::RunError |
|
124 // Called if RunL leaves |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 #ifdef _DEBUG |
|
128 TInt CCmCommsDbNotifier::RunError( TInt aError ) |
|
129 #else // _DEBUG |
|
130 TInt CCmCommsDbNotifier::RunError( TInt /*aError*/ ) |
|
131 #endif // _DEBUG |
|
132 |
|
133 { |
|
134 TRACE(Print(_L("[Cm Scheduler]\t \ |
|
135 CCmCommsDbNotifier::RunError errorcode = %d"), aError)); |
|
136 |
|
137 return KErrNone; |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // CCmCommsDbNotifier::HasScanStateChangedL |
|
142 // Checks if wlan scanning interval has been changed |
|
143 // -------------------------------------------------------------------------- |
|
144 // |
|
145 TBool CCmCommsDbNotifier::HasScanStateChangedL() |
|
146 { |
|
147 LOG(_L("[Cm Scheduler]\t CCmCommsDbNotifier::HasScanStateChangedL")); |
|
148 |
|
149 TBool status( EFalse ); |
|
150 |
|
151 TUint32 scanState = WlanScanStateL(); |
|
152 |
|
153 if ( iScanState != scanState ) |
|
154 { |
|
155 // value changed |
|
156 iScanState = scanState; |
|
157 status = ETrue; |
|
158 } |
|
159 else |
|
160 { |
|
161 // value not changed |
|
162 status = EFalse; |
|
163 } |
|
164 |
|
165 return status; |
|
166 } |
|
167 |
|
168 // -------------------------------------------------------------------------- |
|
169 // CCmCommsDbNotifier::WlanScanStateL |
|
170 // Returns state of wlan scan interval setting |
|
171 // -------------------------------------------------------------------------- |
|
172 // |
|
173 TUint32 CCmCommsDbNotifier::WlanScanStateL() |
|
174 { |
|
175 TUint32 scanState( 0 ); |
|
176 |
|
177 #ifndef __WINS__ |
|
178 |
|
179 // open wlan table |
|
180 CCommsDbTableView* view = iDb->OpenViewMatchingUintLC |
|
181 ( |
|
182 TPtrC( WLAN_DEVICE_SETTINGS ), |
|
183 TPtrC( WLAN_DEVICE_SETTINGS_TYPE ), KWlanUserSettings |
|
184 ); |
|
185 |
|
186 User::LeaveIfError( view->GotoFirstRecord() ); |
|
187 |
|
188 // read scanning interval |
|
189 view->ReadUintL( TPtrC( WLAN_BG_SCAN_INTERVAL ), |
|
190 scanState ); |
|
191 |
|
192 TRACE(Print(_L("[Cm Scheduler]\t CCmCommsDbNotifier::prev: %d, \ |
|
193 scan :%d"), iScanState, scanState )); |
|
194 |
|
195 |
|
196 CleanupStack::PopAndDestroy( view ); |
|
197 |
|
198 #endif |
|
199 |
|
200 return scanState; |
|
201 } |
|
202 |
|
203 // End of file |