43 // Symbian 2nd-phase constructor |
43 // Symbian 2nd-phase constructor |
44 // --------------------------------------------------------------------------- |
44 // --------------------------------------------------------------------------- |
45 // |
45 // |
46 void CBTNotifDeviceSelector::ConstructL() |
46 void CBTNotifDeviceSelector::ConstructL() |
47 { |
47 { |
|
48 iServer.DevRepository().AddObserverL(this); |
48 iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); |
49 iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); |
49 } |
50 } |
50 |
51 |
51 // --------------------------------------------------------------------------- |
52 // --------------------------------------------------------------------------- |
52 // NewL. |
53 // NewL. |
65 // Destructor |
66 // Destructor |
66 // --------------------------------------------------------------------------- |
67 // --------------------------------------------------------------------------- |
67 // |
68 // |
68 CBTNotifDeviceSelector::~CBTNotifDeviceSelector() |
69 CBTNotifDeviceSelector::~CBTNotifDeviceSelector() |
69 { |
70 { |
|
71 iServer.DevRepository().RemoveObserver(this); |
70 if( iNotification ) |
72 if( iNotification ) |
71 { |
73 { |
72 // Clear the notification callback, we cannot receive them anymore. |
74 // Clear the notification callback, we cannot receive them anymore. |
73 iNotification->RemoveObserver(); |
75 iNotification->RemoveObserver(); |
74 iNotification->Close(); // Also dequeues the notification from the queue. |
76 iNotification->Close(); // Also dequeues the notification from the queue. |
75 iNotification = NULL; |
77 iNotification = NULL; |
76 } |
78 } |
77 iDevices.ResetAndDestroy(); |
79 iDevices.ResetAndDestroy(); |
78 iDevices.Close(); |
80 iDevices.Close(); |
79 delete iDiscoverer; |
81 delete iDiscoverer; |
|
82 |
80 } |
83 } |
81 |
84 |
82 // --------------------------------------------------------------------------- |
85 // --------------------------------------------------------------------------- |
83 // Process a client message related to notifiers. |
86 // Process a client message related to notifiers. |
84 // --------------------------------------------------------------------------- |
87 // --------------------------------------------------------------------------- |
120 if ( !iMessage.IsNull() ) |
123 if ( !iMessage.IsNull() ) |
121 { |
124 { |
122 aMessage.Complete( KErrServerBusy ); |
125 aMessage.Complete( KErrServerBusy ); |
123 return; |
126 return; |
124 } |
127 } |
125 PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource); |
128 |
126 iDevices.ResetAndDestroy(); |
129 iLoadDevices = EFalse; |
127 iDiscoverer->DiscoverDeviceL(); |
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 } |
128 iMessage = aMessage; |
146 iMessage = aMessage; |
129 break; |
147 break; |
130 } |
148 } |
131 default: |
149 default: |
132 { |
150 { |
152 // --------------------------------------------------------------------------- |
170 // --------------------------------------------------------------------------- |
153 // |
171 // |
154 void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData ) |
172 void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData ) |
155 { |
173 { |
156 TInt err = KErrCancel; |
174 TInt err = KErrCancel; |
157 // const CHbSymbianVariant* value = aData.Get(_L("selectedindex")); |
|
158 if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone) |
175 if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone) |
159 { |
176 { |
160 TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data())); |
177 TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data())); |
161 BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val ); |
178 BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val ); |
162 |
179 |
165 // TInt sel = val;// - TBluetoothDialogParams::EDialogExt; |
182 // TInt sel = val;// - TBluetoothDialogParams::EDialogExt; |
166 TBTDeviceResponseParamsPckg devParams; |
183 TBTDeviceResponseParamsPckg devParams; |
167 if ( val > -1 && val < iDevices.Count() ) |
184 if ( val > -1 && val < iDevices.Count() ) |
168 { |
185 { |
169 devParams().SetDeviceAddress( iDevices[val]->Addr() ); |
186 devParams().SetDeviceAddress( iDevices[val]->Addr() ); |
|
187 devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass()); |
|
188 devParams().SetDeviceName(iDevices[val]->Alias()); |
170 err = iMessage.Write( EBTNotifSrvReplySlot, devParams ); |
189 err = iMessage.Write( EBTNotifSrvReplySlot, devParams ); |
|
190 iNotification->Close(); // Also dequeues the notification from the queue. |
|
191 iNotification->RemoveObserver(); |
|
192 iNotification = NULL; |
171 } |
193 } |
172 iMessage.Complete( err ); |
194 iMessage.Complete( err ); |
173 } |
195 } |
174 |
|
175 iDiscoverer->CancelDiscovery(); |
196 iDiscoverer->CancelDiscovery(); |
176 } |
197 } |
177 else if(aData.Keys().MdcaPoint(0).Compare(_L("Stop"))==KErrNone) |
198 else if(aData.Keys().MdcaPoint(0).Compare(_L("Stop"))==KErrNone) |
178 { |
199 { |
179 iDiscoverer->CancelDiscovery(); |
200 iDiscoverer->CancelDiscovery(); |
180 } |
201 } |
181 else if(aData.Keys().MdcaPoint(0).Compare(_L("Retry"))==KErrNone) |
202 else if(aData.Keys().MdcaPoint(0).Compare(_L("Retry"))==KErrNone) |
182 { |
203 { |
183 iDiscoverer->CancelDiscovery(); |
204 iDiscoverer->CancelDiscovery(); |
184 iDevices.ResetAndDestroy(); |
205 iDevices.ResetAndDestroy(); |
185 delete iDiscoverer; |
206 TRAP_IGNORE( iDiscoverer->DiscoverDeviceL() ); |
186 iDiscoverer = NULL; |
207 |
187 iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); |
208 } |
188 iDiscoverer->DiscoverDeviceL(); |
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(); } ); |
189 } |
218 } |
190 } |
219 } |
191 |
220 |
192 |
221 |
193 // --------------------------------------------------------------------------- |
222 // --------------------------------------------------------------------------- |
230 // --------------------------------------------------------------------------- |
259 // --------------------------------------------------------------------------- |
231 // |
260 // |
232 void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr ) |
261 void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr ) |
233 { |
262 { |
234 (void) aErr; |
263 (void) aErr; |
235 // todo: update dialog |
264 CHbSymbianVariantMap* map = iNotification->Data(); |
236 } |
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 } |
|
282 } |
|
283 |
|
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 |
237 |
338 |
238 // --------------------------------------------------------------------------- |
339 // --------------------------------------------------------------------------- |
239 // Get and configure a notification. |
340 // Get and configure a notification. |
240 // --------------------------------------------------------------------------- |
341 // --------------------------------------------------------------------------- |
241 // |
342 // |
247 iNotification = iServer.NotificationManager()->GetNotification(); |
348 iNotification = iServer.NotificationManager()->GetNotification(); |
248 User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory |
349 User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory |
249 iNotification->SetObserver( this ); |
350 iNotification->SetObserver( this ); |
250 iNotification->SetNotificationType( aType, aResourceId ); |
351 iNotification->SetNotificationType( aType, aResourceId ); |
251 |
352 |
252 /* |
353 iServer.NotificationManager()->QueueNotificationL( iNotification,CBTNotificationManager::EPriorityHigh ); |
253 _LIT(KTitleValue, "BT Search"); |
|
254 TPtrC ptr; |
|
255 ptr.Set( KTitleValue ); |
|
256 iNotification->SetData( TBluetoothDialogParams::EDialogTitle, ptr ); |
|
257 */ |
|
258 |
|
259 /*err = */ iServer.NotificationManager()->QueueNotification( iNotification ); |
|
260 //NOTIF_NOTHANDLED( !err ) |
|
261 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
354 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
262 } |
355 } |
|
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 } |