29
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <btextnotifiers.h>
|
|
20 |
#include <btservices/advancedevdiscoverer.h>
|
|
21 |
#include <btservices/btdevextension.h>
|
|
22 |
#include <hb/hbcore/hbdevicedialogsymbian.h>
|
|
23 |
#include <hb/hbcore/hbsymbianvariant.h>
|
|
24 |
#include "btnotifdeviceselector.h"
|
|
25 |
|
|
26 |
#include "btnotifserver.h"
|
|
27 |
#include "btnotificationmanager.h"
|
|
28 |
#include "btnotifclientserver.h"
|
|
29 |
|
|
30 |
// ======== MEMBER FUNCTIONS ========
|
|
31 |
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
// C++ default constructor
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
CBTNotifDeviceSelector::CBTNotifDeviceSelector( CBTNotifServer& aServer )
|
|
37 |
: iServer( aServer )
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
// Symbian 2nd-phase constructor
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
void CBTNotifDeviceSelector::ConstructL()
|
|
47 |
{
|
31
|
48 |
iServer.DevRepository().AddObserverL(this);
|
29
|
49 |
iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this );
|
|
50 |
}
|
|
51 |
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
// NewL.
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
CBTNotifDeviceSelector* CBTNotifDeviceSelector::NewL( CBTNotifServer& aServer )
|
|
57 |
{
|
|
58 |
CBTNotifDeviceSelector* self = new( ELeave ) CBTNotifDeviceSelector( aServer );
|
|
59 |
CleanupStack::PushL( self );
|
|
60 |
self->ConstructL();
|
|
61 |
CleanupStack::Pop( self );
|
|
62 |
return self;
|
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
// Destructor
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
CBTNotifDeviceSelector::~CBTNotifDeviceSelector()
|
|
70 |
{
|
31
|
71 |
iServer.DevRepository().RemoveObserver(this);
|
29
|
72 |
if( iNotification )
|
|
73 |
{
|
|
74 |
// Clear the notification callback, we cannot receive them anymore.
|
|
75 |
iNotification->RemoveObserver();
|
|
76 |
iNotification->Close(); // Also dequeues the notification from the queue.
|
|
77 |
iNotification = NULL;
|
|
78 |
}
|
|
79 |
iDevices.ResetAndDestroy();
|
|
80 |
iDevices.Close();
|
|
81 |
delete iDiscoverer;
|
31
|
82 |
|
29
|
83 |
}
|
|
84 |
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
// Process a client message related to notifiers.
|
|
87 |
// ---------------------------------------------------------------------------
|
|
88 |
//
|
|
89 |
void CBTNotifDeviceSelector::DispatchNotifierMessageL( const RMessage2& aMessage )
|
|
90 |
{
|
|
91 |
BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() );
|
|
92 |
TInt opcode = aMessage.Function();
|
|
93 |
TInt uid = aMessage.Int0();
|
|
94 |
switch ( opcode )
|
|
95 |
{
|
|
96 |
case EBTNotifCancelNotifier:
|
|
97 |
{
|
|
98 |
// We only accept a cancel message from the same session as the original
|
|
99 |
// request (this is enforced by the RNotifier backend).
|
|
100 |
TInt err( KErrNotFound );
|
|
101 |
if ( !iMessage.IsNull() && opcode == iMessage.Function() &&
|
|
102 |
aMessage.Session() == iMessage.Session() )
|
|
103 |
{
|
|
104 |
iMessage.Complete( KErrCancel );
|
|
105 |
err = KErrNone;
|
|
106 |
}
|
|
107 |
aMessage.Complete( err );
|
|
108 |
break;
|
|
109 |
}
|
|
110 |
case EBTNotifUpdateNotifier:
|
|
111 |
{
|
|
112 |
// not handling so far
|
|
113 |
break;
|
|
114 |
}
|
|
115 |
case EBTNotifStartSyncNotifier:
|
|
116 |
{
|
|
117 |
// synch version of device searching is not supported:
|
|
118 |
aMessage.Complete( KErrNotSupported );
|
|
119 |
break;
|
|
120 |
}
|
|
121 |
case EBTNotifStartAsyncNotifier:
|
|
122 |
{
|
|
123 |
if ( !iMessage.IsNull() )
|
|
124 |
{
|
|
125 |
aMessage.Complete( KErrServerBusy );
|
|
126 |
return;
|
|
127 |
}
|
31
|
128 |
|
|
129 |
iLoadDevices = EFalse;
|
|
130 |
if(iServer.DevRepository().IsInitialized())
|
|
131 |
{
|
|
132 |
iLoadDevices = ETrue;
|
|
133 |
if(iServer.DevRepository().AllDevices().Count()==0)
|
|
134 |
{
|
|
135 |
PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource);
|
|
136 |
iDevices.ResetAndDestroy();
|
|
137 |
iDiscoverer->DiscoverDeviceL();
|
|
138 |
}
|
|
139 |
else
|
|
140 |
{
|
|
141 |
iDevices.ResetAndDestroy();
|
|
142 |
PrepareNotificationL(TBluetoothDialogParams::EMoreDevice, ENoResource);
|
|
143 |
LoadUsedDevicesL();
|
|
144 |
}
|
|
145 |
}
|
29
|
146 |
iMessage = aMessage;
|
|
147 |
break;
|
|
148 |
}
|
|
149 |
default:
|
|
150 |
{
|
|
151 |
aMessage.Complete( KErrNotSupported );
|
|
152 |
}
|
|
153 |
}
|
|
154 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
155 |
}
|
|
156 |
|
|
157 |
|
|
158 |
// ---------------------------------------------------------------------------
|
|
159 |
// Cancels an outstanding client message related to notifiers.
|
|
160 |
// ---------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
void CBTNotifDeviceSelector::CancelNotifierMessageL( const RMessage2& aMessage )
|
|
163 |
{
|
|
164 |
(void) aMessage;
|
|
165 |
}
|
|
166 |
|
|
167 |
// ---------------------------------------------------------------------------
|
|
168 |
// From class MBTNotificationResult.
|
|
169 |
// Handle a result from a user query.
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
//
|
|
172 |
void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData )
|
|
173 |
{
|
|
174 |
TInt err = KErrCancel;
|
|
175 |
if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone)
|
|
176 |
{
|
|
177 |
TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data()));
|
|
178 |
BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val );
|
|
179 |
|
|
180 |
if ( !iMessage.IsNull() )
|
|
181 |
{
|
|
182 |
// TInt sel = val;// - TBluetoothDialogParams::EDialogExt;
|
|
183 |
TBTDeviceResponseParamsPckg devParams;
|
|
184 |
if ( val > -1 && val < iDevices.Count() )
|
|
185 |
{
|
|
186 |
devParams().SetDeviceAddress( iDevices[val]->Addr() );
|
31
|
187 |
devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass());
|
|
188 |
devParams().SetDeviceName(iDevices[val]->Alias());
|
29
|
189 |
err = iMessage.Write( EBTNotifSrvReplySlot, devParams );
|
31
|
190 |
iNotification->Close(); // Also dequeues the notification from the queue.
|
|
191 |
iNotification->RemoveObserver();
|
|
192 |
iNotification = NULL;
|
29
|
193 |
}
|
|
194 |
iMessage.Complete( err );
|
|
195 |
}
|
|
196 |
iDiscoverer->CancelDiscovery();
|
|
197 |
}
|
|
198 |
else if(aData.Keys().MdcaPoint(0).Compare(_L("Stop"))==KErrNone)
|
|
199 |
{
|
|
200 |
iDiscoverer->CancelDiscovery();
|
|
201 |
}
|
|
202 |
else if(aData.Keys().MdcaPoint(0).Compare(_L("Retry"))==KErrNone)
|
|
203 |
{
|
|
204 |
iDiscoverer->CancelDiscovery();
|
|
205 |
iDevices.ResetAndDestroy();
|
31
|
206 |
TRAP_IGNORE( iDiscoverer->DiscoverDeviceL() );
|
|
207 |
|
|
208 |
}
|
|
209 |
else if(aData.Keys().MdcaPoint(0).Compare(_L("MoreDevices"))==KErrNone)
|
|
210 |
{
|
|
211 |
iNotification->Close(); // Also dequeues the notification from the queue.
|
|
212 |
iNotification->RemoveObserver();
|
|
213 |
iNotification = NULL;
|
|
214 |
iDevices.ResetAndDestroy();
|
|
215 |
TRAP_IGNORE( {
|
|
216 |
PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource);
|
|
217 |
iDiscoverer->DiscoverDeviceL(); } );
|
29
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
|
|
222 |
// ---------------------------------------------------------------------------
|
|
223 |
// From class MBTNotificationResult.
|
|
224 |
// The notification is finished.
|
|
225 |
// ---------------------------------------------------------------------------
|
|
226 |
//
|
|
227 |
void CBTNotifDeviceSelector::MBRNotificationClosed( TInt aError, const TDesC8& aData )
|
|
228 |
{
|
|
229 |
(void) aError;
|
|
230 |
(void) aData;
|
|
231 |
iNotification->RemoveObserver();
|
|
232 |
iNotification = NULL;
|
|
233 |
}
|
|
234 |
|
|
235 |
// ---------------------------------------------------------------------------
|
|
236 |
// HandleNextDiscoveryResultL
|
|
237 |
// ---------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
void CBTNotifDeviceSelector::HandleNextDiscoveryResultL(
|
|
240 |
const TInquirySockAddr& aAddr, const TDesC& aName )
|
|
241 |
{
|
|
242 |
// Todo: look for this device in repository before creating it.
|
|
243 |
CBtDevExtension* devext = CBtDevExtension::NewLC( aAddr, aName );
|
|
244 |
iDevices.AppendL( devext );
|
|
245 |
CleanupStack::Pop( devext );
|
|
246 |
CHbSymbianVariantMap* map = iNotification->Data();
|
|
247 |
TBuf<8> keyStr;
|
|
248 |
CHbSymbianVariant* devEntry;
|
|
249 |
|
|
250 |
keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
|
|
251 |
devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()),
|
|
252 |
CHbSymbianVariant::EDes );
|
|
253 |
map->Add( keyStr, devEntry );
|
|
254 |
iNotification->Update();
|
|
255 |
}
|
|
256 |
|
|
257 |
// ---------------------------------------------------------------------------
|
|
258 |
// HandleDiscoveryCompleted
|
|
259 |
// ---------------------------------------------------------------------------
|
|
260 |
//
|
|
261 |
void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr )
|
|
262 |
{
|
|
263 |
(void) aErr;
|
31
|
264 |
CHbSymbianVariantMap* map = iNotification->Data();
|
|
265 |
TBuf<25> keyStr;
|
|
266 |
|
|
267 |
|
|
268 |
//TODO compile fail here we need to send the discovery completed text to the dialog
|
|
269 |
keyStr.Copy(_L("Search Completed"));
|
|
270 |
CHbSymbianVariant* devEntry( NULL );
|
|
271 |
TRAP_IGNORE( devEntry = CHbSymbianVariant::NewL( (TAny*) &(keyStr),
|
|
272 |
CHbSymbianVariant::EDes ) );
|
|
273 |
if ( devEntry )
|
|
274 |
{
|
|
275 |
map->Add( keyStr, devEntry );
|
|
276 |
iNotification->Update();
|
|
277 |
}
|
|
278 |
else
|
|
279 |
{
|
|
280 |
// todo: Complete client request with error
|
|
281 |
}
|
29
|
282 |
}
|
|
283 |
|
31
|
284 |
// From MBtDeviceRepositoryObserver
|
|
285 |
|
|
286 |
void CBTNotifDeviceSelector::RepositoryInitialized()
|
|
287 |
{
|
|
288 |
iRepositoryInitialized = ETrue;
|
|
289 |
TInt err(KErrNone);
|
|
290 |
if(!iLoadDevices)
|
|
291 |
{
|
|
292 |
iLoadDevices = ETrue;
|
|
293 |
if(iServer.DevRepository().AllDevices().Count()==0)
|
|
294 |
{
|
|
295 |
iDevices.ResetAndDestroy();
|
|
296 |
TRAP(err, {
|
|
297 |
PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource);
|
|
298 |
iDiscoverer->DiscoverDeviceL(); } );
|
|
299 |
}
|
|
300 |
else
|
|
301 |
{
|
|
302 |
iDevices.ResetAndDestroy();
|
|
303 |
TRAP( err,
|
|
304 |
{PrepareNotificationL(
|
|
305 |
TBluetoothDialogParams::EMoreDevice, ENoResource);
|
|
306 |
LoadUsedDevicesL();
|
|
307 |
} );
|
|
308 |
}
|
|
309 |
}
|
|
310 |
if ( err )
|
|
311 |
{
|
|
312 |
// todo: complete client request
|
|
313 |
}
|
|
314 |
}
|
|
315 |
|
|
316 |
void CBTNotifDeviceSelector::DeletedFromRegistry( const TBTDevAddr& aAddr )
|
|
317 |
{
|
|
318 |
(void) aAddr;
|
|
319 |
}
|
|
320 |
|
|
321 |
void CBTNotifDeviceSelector::AddedToRegistry( const CBtDevExtension& aDev )
|
|
322 |
{
|
|
323 |
(void) aDev;
|
|
324 |
}
|
|
325 |
|
|
326 |
void CBTNotifDeviceSelector::ChangedInRegistry( const CBtDevExtension& aDev, TUint aSimilarity )
|
|
327 |
{
|
|
328 |
(void) aDev;
|
|
329 |
(void) aSimilarity;
|
|
330 |
}
|
|
331 |
|
|
332 |
void CBTNotifDeviceSelector::ServiceConnectionChanged(const CBtDevExtension& aDev, TBool aConnected )
|
|
333 |
{
|
|
334 |
(void) aDev;
|
|
335 |
(void) aConnected;
|
|
336 |
}
|
|
337 |
|
|
338 |
|
29
|
339 |
// ---------------------------------------------------------------------------
|
|
340 |
// Get and configure a notification.
|
|
341 |
// ---------------------------------------------------------------------------
|
|
342 |
//
|
|
343 |
void CBTNotifDeviceSelector::PrepareNotificationL(
|
|
344 |
TBluetoothDialogParams::TBTDialogType aType,
|
|
345 |
TBTDialogResourceId aResourceId )
|
|
346 |
{
|
|
347 |
BOstraceFunctionEntry0( DUMMY_DEVLIST );
|
|
348 |
iNotification = iServer.NotificationManager()->GetNotification();
|
|
349 |
User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
|
|
350 |
iNotification->SetObserver( this );
|
|
351 |
iNotification->SetNotificationType( aType, aResourceId );
|
|
352 |
|
31
|
353 |
iServer.NotificationManager()->QueueNotificationL( iNotification,CBTNotificationManager::EPriorityHigh );
|
29
|
354 |
BOstraceFunctionExit0( DUMMY_DEVLIST );
|
|
355 |
}
|
31
|
356 |
|
|
357 |
void CBTNotifDeviceSelector::LoadUsedDevicesL()
|
|
358 |
{
|
|
359 |
const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices();
|
|
360 |
for(TInt i=0; i< devArray.Count(); i++ )
|
|
361 |
{
|
|
362 |
const TTime& usedTime = devArray[i]->Device().Used();
|
|
363 |
TTime monthBack;
|
|
364 |
monthBack.HomeTime();
|
|
365 |
monthBack -= TTimeIntervalDays(30);
|
|
366 |
if(usedTime >= monthBack)
|
|
367 |
{
|
|
368 |
iDevices.AppendL( devArray[i]->CopyL() );
|
|
369 |
CHbSymbianVariantMap* map = iNotification->Data();
|
|
370 |
TBuf<8> keyStr;
|
|
371 |
CHbSymbianVariant* devEntry;
|
|
372 |
|
|
373 |
keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
|
|
374 |
devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()),
|
|
375 |
CHbSymbianVariant::EDes );
|
|
376 |
map->Add( keyStr, devEntry );
|
|
377 |
iNotification->Update();
|
|
378 |
}
|
|
379 |
}
|
|
380 |
}
|