32
|
1 |
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include "btmpagescanparametersmanager.h"
|
|
17 |
#include <ctsydomainpskeys.h>
|
|
18 |
#include <bt_subscribe.h>
|
|
19 |
#include <bt_subscribe_partner.h>
|
|
20 |
#include <bttypespartner.h>
|
|
21 |
#include "debug.h"
|
|
22 |
|
|
23 |
// in the current configuration an incoming call ringing limit is 30 seconds
|
|
24 |
// if for some reason we don't receive the call state change
|
|
25 |
// we disable fast connection page scan settings in 35 seconds
|
|
26 |
const TInt KFastConnectionTime = 35000000;
|
|
27 |
// a timeout for resetting page scan settings
|
|
28 |
// if we don't receive a confirmation we try to reset again
|
|
29 |
const TInt KRestoreStandardParametersTime = 1000000;
|
|
30 |
|
|
31 |
const TInt KCallStateListenerService = 8;
|
|
32 |
const TInt KPageScanParametersListenerService = 9;
|
|
33 |
const TInt KFastConnectionService = 10;
|
|
34 |
const TInt KRestoreStandardParametersService = 11;
|
|
35 |
|
|
36 |
CBtmPageScanParametersManager::CBtmPageScanParametersManager()
|
|
37 |
: iIsBeingDeactivated(EFalse)
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
CBtmPageScanParametersManager::~CBtmPageScanParametersManager()
|
|
42 |
{
|
|
43 |
TRACE_FUNC_ENTRY
|
|
44 |
delete iTimerActive;
|
|
45 |
iTimer.Close();
|
|
46 |
if (iCallStateKey.Handle())
|
|
47 |
{
|
|
48 |
iCallStateKey.Cancel();
|
|
49 |
}
|
|
50 |
delete iPageScanParametersListener;
|
|
51 |
iCallStateKey.Close();
|
|
52 |
if (iPageScanParametersKey.Handle())
|
|
53 |
{
|
|
54 |
iPageScanParametersKey.Cancel();
|
|
55 |
}
|
|
56 |
delete iCallStateListener;
|
|
57 |
iPageScanParametersKey.Close();
|
|
58 |
TRACE_FUNC_EXIT
|
|
59 |
}
|
|
60 |
|
|
61 |
void CBtmPageScanParametersManager::ConstructL()
|
|
62 |
{
|
|
63 |
TRACE_FUNC_ENTRY
|
|
64 |
LEAVE_IF_ERROR(iCallStateKey.Attach(KPSUidCtsyCallInformation, KCTsyCallState));
|
|
65 |
iCallStateListener = CBtmActive::NewL(*this, CActive::EPriorityStandard,
|
|
66 |
KCallStateListenerService);
|
|
67 |
|
|
68 |
LEAVE_IF_ERROR(iPageScanParametersKey.Attach(KPropertyUidBluetoothCategory,
|
|
69 |
KPropertyKeyBluetoothGetPageScanParameters));
|
|
70 |
iPageScanParametersListener = CBtmActive::NewL(*this, CActive::EPriorityStandard,
|
|
71 |
KPageScanParametersListenerService);
|
|
72 |
|
|
73 |
iTimerActive = CBtmActive::NewL(*this, CActive::EPriorityStandard, KFastConnectionService);
|
|
74 |
TRACE_FUNC_EXIT
|
|
75 |
}
|
|
76 |
|
|
77 |
CBtmPageScanParametersManager* CBtmPageScanParametersManager::NewL()
|
|
78 |
{
|
|
79 |
TRACE_STATIC_FUNC_ENTRY
|
|
80 |
CBtmPageScanParametersManager* self = new( ELeave ) CBtmPageScanParametersManager();
|
|
81 |
CleanupStack::PushL(self);
|
|
82 |
self->ConstructL();
|
|
83 |
CleanupStack::Pop(self);
|
|
84 |
return self;
|
|
85 |
}
|
|
86 |
|
|
87 |
void CBtmPageScanParametersManager::StartTimer(TInt aService, TInt aTimeout)
|
|
88 |
{
|
|
89 |
if (!iTimerActive->IsActive())
|
|
90 |
{
|
|
91 |
TRACE_FUNC_ENTRY
|
|
92 |
iTimer.CreateLocal();
|
|
93 |
iTimer.After(iTimerActive->iStatus, aTimeout);
|
|
94 |
iTimerActive->SetRequestId(aService);
|
|
95 |
iTimerActive->GoActive();
|
|
96 |
TRACE_FUNC_EXIT
|
|
97 |
}
|
|
98 |
else
|
|
99 |
{
|
|
100 |
TRACE_WARNING(_L("WARNING, page scan manager timer is already active"))
|
|
101 |
}
|
|
102 |
}
|
|
103 |
|
|
104 |
void CBtmPageScanParametersManager::StopTimer()
|
|
105 |
{
|
|
106 |
if (iTimerActive->IsActive())
|
|
107 |
{
|
|
108 |
TRACE_FUNC_ENTRY
|
|
109 |
iTimerActive->Cancel();
|
|
110 |
iTimer.Close();
|
|
111 |
TRACE_FUNC_EXIT
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
void CBtmPageScanParametersManager::RequestCompletedL(CBtmActive& aActive)
|
|
116 |
{
|
|
117 |
TRACE_FUNC_ENTRY
|
|
118 |
TRACE_INFO((_L("request id %d status %d"), aActive.RequestId(), aActive.iStatus.Int()))
|
|
119 |
if (aActive.iStatus.Int() == KErrNone)
|
|
120 |
{
|
|
121 |
switch (aActive.RequestId())
|
|
122 |
{
|
|
123 |
case KCallStateListenerService:
|
|
124 |
{
|
|
125 |
iCallStateKey.Subscribe(aActive.iStatus);
|
|
126 |
aActive.GoActive();
|
|
127 |
|
|
128 |
TInt callState;
|
|
129 |
TInt ret = iCallStateKey.Get(callState);
|
|
130 |
if (ret == KErrNone)
|
|
131 |
{
|
|
132 |
TRACE_INFO((_L("call state received %d"), callState))
|
|
133 |
if (callState == EPSCTsyCallStateRinging)
|
|
134 |
{
|
|
135 |
// an incoming call ringing => switch to fast page scanning
|
|
136 |
TRACE_INFO((_L("switching to fast page scanning")))
|
|
137 |
(void) RProperty::Set(KPropertyUidBluetoothCategory,
|
|
138 |
KPropertyKeyBluetoothSetPageScanParameters,
|
|
139 |
EFastConnectionPageScanParameters);
|
|
140 |
|
|
141 |
// we will disable fast page scanning when the timer gets expired
|
|
142 |
StartTimer(KFastConnectionService, KFastConnectionTime);
|
|
143 |
}
|
|
144 |
else if (iTimerActive->IsActive() && iTimerActive->RequestId() == KFastConnectionService)
|
|
145 |
{
|
|
146 |
// the incoming call is not ringing anymore => switch to standard page scanning
|
|
147 |
TRACE_INFO((_L("switching to standard page scanning")))
|
|
148 |
DisableFastConnection();
|
|
149 |
}
|
|
150 |
}
|
|
151 |
break;
|
|
152 |
}
|
|
153 |
|
|
154 |
case KPageScanParametersListenerService:
|
|
155 |
{
|
|
156 |
iPageScanParametersKey.Subscribe(aActive.iStatus);
|
|
157 |
aActive.GoActive();
|
|
158 |
|
|
159 |
TInt pageScanParameters;
|
|
160 |
TInt ret = iPageScanParametersKey.Get(pageScanParameters);
|
|
161 |
if (ret == KErrNone)
|
|
162 |
{
|
|
163 |
TRACE_INFO((_L("page scan parameters received %d"), pageScanParameters))
|
|
164 |
if (iTimerActive->IsActive() && iTimerActive->RequestId() == KRestoreStandardParametersService
|
|
165 |
&& pageScanParameters == EStandardPageScanParameters)
|
|
166 |
{
|
|
167 |
TRACE_INFO((_L("standard page scan parameters enabled")))
|
|
168 |
StopTimer();
|
|
169 |
if (iIsBeingDeactivated)
|
|
170 |
{
|
|
171 |
TRACE_INFO((_L("page scan parameters service is stopped")))
|
|
172 |
iPageScanParametersKey.Cancel();
|
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|
|
176 |
break;
|
|
177 |
}
|
|
178 |
|
|
179 |
case KFastConnectionService:
|
|
180 |
case KRestoreStandardParametersService:
|
|
181 |
{
|
|
182 |
// try to reset the page scan setting because it hasn't been confirmed yet
|
|
183 |
TRACE_INFO((_L("timer expired, switching to standard page scanning")))
|
|
184 |
DisableFastConnection();
|
|
185 |
break;
|
|
186 |
}
|
|
187 |
|
|
188 |
default:
|
|
189 |
{
|
|
190 |
TRACE_WARNING(_L("WARNING, unknown service"))
|
|
191 |
break;
|
|
192 |
}
|
|
193 |
}
|
|
194 |
}
|
|
195 |
TRACE_FUNC_EXIT
|
|
196 |
}
|
|
197 |
|
|
198 |
void CBtmPageScanParametersManager::CancelRequest(CBtmActive& aActive)
|
|
199 |
{
|
|
200 |
TRACE_FUNC_ENTRY
|
|
201 |
switch (aActive.RequestId())
|
|
202 |
{
|
|
203 |
case KFastConnectionService:
|
|
204 |
case KRestoreStandardParametersService:
|
|
205 |
{
|
|
206 |
iTimer.Cancel();
|
|
207 |
break;
|
|
208 |
}
|
|
209 |
default:
|
|
210 |
break;
|
|
211 |
}
|
|
212 |
TRACE_FUNC_EXIT
|
|
213 |
}
|
|
214 |
|
|
215 |
void CBtmPageScanParametersManager::DisableFastConnection()
|
|
216 |
{
|
|
217 |
TRACE_FUNC_ENTRY
|
|
218 |
StopTimer();
|
|
219 |
|
|
220 |
// switch to standard page scanning
|
|
221 |
(void) RProperty::Set(KPropertyUidBluetoothCategory,
|
|
222 |
KPropertyKeyBluetoothSetPageScanParameters,
|
|
223 |
EStandardPageScanParameters);
|
|
224 |
|
|
225 |
// we will disable fast page scanning when the timer gets expired
|
|
226 |
StartTimer(KRestoreStandardParametersService, KRestoreStandardParametersTime);
|
|
227 |
TRACE_FUNC_EXIT
|
|
228 |
}
|
|
229 |
|
|
230 |
void CBtmPageScanParametersManager::Activate()
|
|
231 |
{
|
|
232 |
TRACE_FUNC_ENTRY
|
|
233 |
iIsBeingDeactivated = EFalse;
|
|
234 |
|
|
235 |
if (!iCallStateListener->IsActive())
|
|
236 |
{
|
|
237 |
iCallStateKey.Subscribe(iCallStateListener->iStatus);
|
|
238 |
iCallStateListener->GoActive();
|
|
239 |
}
|
|
240 |
else
|
|
241 |
{
|
|
242 |
TRACE_WARNING(_L("WARNING, call state is already being listened"))
|
|
243 |
}
|
|
244 |
|
|
245 |
if (!iPageScanParametersListener->IsActive())
|
|
246 |
{
|
|
247 |
iPageScanParametersKey.Subscribe(iPageScanParametersListener->iStatus);
|
|
248 |
iPageScanParametersListener->GoActive();
|
|
249 |
}
|
|
250 |
else
|
|
251 |
{
|
|
252 |
TRACE_WARNING(_L("WARNING, call state is already being listened"))
|
|
253 |
}
|
|
254 |
|
|
255 |
TInt callState;
|
|
256 |
TInt err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callState);
|
|
257 |
if(err == KErrNone && callState == EPSCTsyCallStateRinging)
|
|
258 |
{
|
|
259 |
// an incoming call already ringing => switch to fast page scanning
|
|
260 |
TRACE_INFO((_L("call is already ringing, switching to fast page scanning")))
|
|
261 |
(void) RProperty::Set(KPropertyUidBluetoothCategory,
|
|
262 |
KPropertyKeyBluetoothSetPageScanParameters,
|
|
263 |
EFastConnectionPageScanParameters);
|
|
264 |
|
|
265 |
// we will disable fast page scanning when the timer gets expired
|
|
266 |
StartTimer(KFastConnectionService, KFastConnectionTime);
|
|
267 |
}
|
|
268 |
TRACE_FUNC_EXIT
|
|
269 |
}
|
|
270 |
|
|
271 |
void CBtmPageScanParametersManager::Deactivate()
|
|
272 |
{
|
|
273 |
TRACE_FUNC_ENTRY
|
|
274 |
iIsBeingDeactivated = ETrue;
|
|
275 |
|
|
276 |
// stop call state listening
|
|
277 |
iCallStateKey.Cancel();
|
|
278 |
|
|
279 |
if (iTimerActive->IsActive())
|
|
280 |
{
|
|
281 |
// if fast page scanning is active, disable it
|
|
282 |
// if we're already switching to standard page scanning, do nothing
|
|
283 |
if (iTimerActive->RequestId() == KFastConnectionService)
|
|
284 |
{
|
|
285 |
TRACE_INFO((_L("deactivation started, switching to standard page scanning")))
|
|
286 |
DisableFastConnection();
|
|
287 |
}
|
|
288 |
}
|
|
289 |
else
|
|
290 |
{
|
|
291 |
// if no timer is active we just stop page scan parameters listening
|
|
292 |
iPageScanParametersKey.Cancel();
|
|
293 |
}
|
|
294 |
TRACE_FUNC_EXIT
|
|
295 |
}
|