|
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 { |
|
48 iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // NewL. |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CBTNotifDeviceSelector* CBTNotifDeviceSelector::NewL( CBTNotifServer& aServer ) |
|
56 { |
|
57 CBTNotifDeviceSelector* self = new( ELeave ) CBTNotifDeviceSelector( aServer ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // Destructor |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CBTNotifDeviceSelector::~CBTNotifDeviceSelector() |
|
69 { |
|
70 if( iNotification ) |
|
71 { |
|
72 // Clear the notification callback, we cannot receive them anymore. |
|
73 iNotification->RemoveObserver(); |
|
74 iNotification->Close(); // Also dequeues the notification from the queue. |
|
75 iNotification = NULL; |
|
76 } |
|
77 iDevices.ResetAndDestroy(); |
|
78 iDevices.Close(); |
|
79 delete iDiscoverer; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // Process a client message related to notifiers. |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CBTNotifDeviceSelector::DispatchNotifierMessageL( const RMessage2& aMessage ) |
|
87 { |
|
88 BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() ); |
|
89 TInt opcode = aMessage.Function(); |
|
90 TInt uid = aMessage.Int0(); |
|
91 switch ( opcode ) |
|
92 { |
|
93 case EBTNotifCancelNotifier: |
|
94 { |
|
95 // We only accept a cancel message from the same session as the original |
|
96 // request (this is enforced by the RNotifier backend). |
|
97 TInt err( KErrNotFound ); |
|
98 if ( !iMessage.IsNull() && opcode == iMessage.Function() && |
|
99 aMessage.Session() == iMessage.Session() ) |
|
100 { |
|
101 iMessage.Complete( KErrCancel ); |
|
102 err = KErrNone; |
|
103 } |
|
104 aMessage.Complete( err ); |
|
105 break; |
|
106 } |
|
107 case EBTNotifUpdateNotifier: |
|
108 { |
|
109 // not handling so far |
|
110 break; |
|
111 } |
|
112 case EBTNotifStartSyncNotifier: |
|
113 { |
|
114 // synch version of device searching is not supported: |
|
115 aMessage.Complete( KErrNotSupported ); |
|
116 break; |
|
117 } |
|
118 case EBTNotifStartAsyncNotifier: |
|
119 { |
|
120 if ( !iMessage.IsNull() ) |
|
121 { |
|
122 aMessage.Complete( KErrServerBusy ); |
|
123 return; |
|
124 } |
|
125 PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource); |
|
126 iDevices.ResetAndDestroy(); |
|
127 iDiscoverer->DiscoverDeviceL(); |
|
128 iMessage = aMessage; |
|
129 break; |
|
130 } |
|
131 default: |
|
132 { |
|
133 aMessage.Complete( KErrNotSupported ); |
|
134 } |
|
135 } |
|
136 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
|
137 } |
|
138 |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // Cancels an outstanding client message related to notifiers. |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CBTNotifDeviceSelector::CancelNotifierMessageL( const RMessage2& aMessage ) |
|
145 { |
|
146 (void) aMessage; |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // From class MBTNotificationResult. |
|
151 // Handle a result from a user query. |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData ) |
|
155 { |
|
156 TInt err = KErrCancel; |
|
157 // const CHbSymbianVariant* value = aData.Get(_L("selectedindex")); |
|
158 if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone) |
|
159 { |
|
160 TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data())); |
|
161 BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val ); |
|
162 |
|
163 if ( !iMessage.IsNull() ) |
|
164 { |
|
165 // TInt sel = val;// - TBluetoothDialogParams::EDialogExt; |
|
166 TBTDeviceResponseParamsPckg devParams; |
|
167 if ( val > -1 && val < iDevices.Count() ) |
|
168 { |
|
169 devParams().SetDeviceAddress( iDevices[val]->Addr() ); |
|
170 err = iMessage.Write( EBTNotifSrvReplySlot, devParams ); |
|
171 } |
|
172 iMessage.Complete( err ); |
|
173 } |
|
174 |
|
175 iDiscoverer->CancelDiscovery(); |
|
176 } |
|
177 else if(aData.Keys().MdcaPoint(0).Compare(_L("Stop"))==KErrNone) |
|
178 { |
|
179 iDiscoverer->CancelDiscovery(); |
|
180 } |
|
181 else if(aData.Keys().MdcaPoint(0).Compare(_L("Retry"))==KErrNone) |
|
182 { |
|
183 iDiscoverer->CancelDiscovery(); |
|
184 iDevices.ResetAndDestroy(); |
|
185 delete iDiscoverer; |
|
186 iDiscoverer = NULL; |
|
187 iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); |
|
188 iDiscoverer->DiscoverDeviceL(); |
|
189 } |
|
190 } |
|
191 |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // From class MBTNotificationResult. |
|
195 // The notification is finished. |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void CBTNotifDeviceSelector::MBRNotificationClosed( TInt aError, const TDesC8& aData ) |
|
199 { |
|
200 (void) aError; |
|
201 (void) aData; |
|
202 iNotification->RemoveObserver(); |
|
203 iNotification = NULL; |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // HandleNextDiscoveryResultL |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void CBTNotifDeviceSelector::HandleNextDiscoveryResultL( |
|
211 const TInquirySockAddr& aAddr, const TDesC& aName ) |
|
212 { |
|
213 // Todo: look for this device in repository before creating it. |
|
214 CBtDevExtension* devext = CBtDevExtension::NewLC( aAddr, aName ); |
|
215 iDevices.AppendL( devext ); |
|
216 CleanupStack::Pop( devext ); |
|
217 CHbSymbianVariantMap* map = iNotification->Data(); |
|
218 TBuf<8> keyStr; |
|
219 CHbSymbianVariant* devEntry; |
|
220 |
|
221 keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); |
|
222 devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), |
|
223 CHbSymbianVariant::EDes ); |
|
224 map->Add( keyStr, devEntry ); |
|
225 iNotification->Update(); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // HandleDiscoveryCompleted |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr ) |
|
233 { |
|
234 (void) aErr; |
|
235 // todo: update dialog |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // Get and configure a notification. |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 void CBTNotifDeviceSelector::PrepareNotificationL( |
|
243 TBluetoothDialogParams::TBTDialogType aType, |
|
244 TBTDialogResourceId aResourceId ) |
|
245 { |
|
246 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
247 iNotification = iServer.NotificationManager()->GetNotification(); |
|
248 User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory |
|
249 iNotification->SetObserver( this ); |
|
250 iNotification->SetNotificationType( aType, aResourceId ); |
|
251 |
|
252 /* |
|
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 ); |
|
262 } |