57
|
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 |
#include <e32base.h>
|
|
19 |
#include <hb/hbcore/hbdevicedialogsymbian.h>
|
|
20 |
#include <btnotif.h>
|
|
21 |
#include <btservices/btdevextension.h>
|
|
22 |
#include <btservices/btdevrepository.h>
|
|
23 |
#include "btnotifgeninfonotifier.h"
|
|
24 |
|
|
25 |
#include "btnotifserver.h"
|
|
26 |
#include "btnotifclientserver.h"
|
|
27 |
#include "bluetoothnotification.h"
|
|
28 |
#include "btnotificationmanager.h"
|
|
29 |
|
|
30 |
// ======== MEMBER FUNCTIONS ========
|
|
31 |
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
// C++ default constructor
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
CBTNotifGenInfoNotifier::CBTNotifGenInfoNotifier( CBTNotifServer* aServer )
|
70
|
37 |
: iServer( aServer ),iNotification(NULL),iEnterSAPNotification(NULL)
|
57
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
// Symbian 2nd-phase constructor
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
void CBTNotifGenInfoNotifier::ConstructL()
|
|
47 |
{
|
|
48 |
}
|
|
49 |
|
|
50 |
// ---------------------------------------------------------------------------
|
|
51 |
// NewL.
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
CBTNotifGenInfoNotifier* CBTNotifGenInfoNotifier::NewL( CBTNotifServer* aServer )
|
|
55 |
{
|
|
56 |
CBTNotifGenInfoNotifier* self = new( ELeave ) CBTNotifGenInfoNotifier( aServer );
|
|
57 |
CleanupStack::PushL( self );
|
|
58 |
self->ConstructL();
|
|
59 |
CleanupStack::Pop( self );
|
|
60 |
return self;
|
|
61 |
}
|
|
62 |
|
|
63 |
// ---------------------------------------------------------------------------
|
|
64 |
// Destructor
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
CBTNotifGenInfoNotifier::~CBTNotifGenInfoNotifier()
|
|
68 |
{
|
|
69 |
if( iNotification )
|
|
70 |
{
|
|
71 |
// Clear the notification callback, we cannot receive them anymore.
|
|
72 |
iNotification->RemoveObserver();
|
|
73 |
iNotification->Close(); // Also dequeues the notification from the queue.
|
|
74 |
iNotification = NULL;
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
// ---------------------------------------------------------------------------
|
|
79 |
// Process a client message related to notifiers.
|
|
80 |
// ---------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
void CBTNotifGenInfoNotifier::HandleNotifierRequestL( const RMessage2& aMessage )
|
|
83 |
{
|
|
84 |
BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() );
|
|
85 |
TInt opcode = aMessage.Function();
|
|
86 |
TInt uid = aMessage.Int0();
|
|
87 |
TInt err = KErrNone;
|
|
88 |
switch ( opcode )
|
|
89 |
{
|
|
90 |
case EBTNotifCancelNotifier:
|
|
91 |
{
|
|
92 |
aMessage.Complete( err );
|
|
93 |
break;
|
|
94 |
}
|
|
95 |
case EBTNotifUpdateNotifier:
|
|
96 |
{
|
|
97 |
aMessage.Complete( err );
|
|
98 |
break;
|
|
99 |
}
|
|
100 |
case EBTNotifStartSyncNotifier:
|
|
101 |
{
|
|
102 |
TRAP(err,ShowNotificationL(aMessage));
|
|
103 |
aMessage.Complete( err );
|
|
104 |
break;
|
|
105 |
}
|
|
106 |
case EBTNotifStartAsyncNotifier:
|
|
107 |
{
|
|
108 |
TRAP(err,ShowNotificationL(aMessage));
|
|
109 |
aMessage.Complete( err );
|
|
110 |
break;
|
|
111 |
}
|
|
112 |
default:
|
|
113 |
{
|
|
114 |
aMessage.Complete( KErrNotSupported );
|
|
115 |
}
|
|
116 |
}
|
|
117 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
118 |
}
|
|
119 |
|
|
120 |
// ---------------------------------------------------------------------------
|
|
121 |
// From class MBTNotificationResult.
|
|
122 |
// Handle a result from a user query.
|
|
123 |
// ---------------------------------------------------------------------------
|
|
124 |
//
|
|
125 |
void CBTNotifGenInfoNotifier::MBRDataReceived( CHbSymbianVariantMap& aData )
|
|
126 |
{
|
|
127 |
(void) aData;
|
|
128 |
}
|
|
129 |
|
|
130 |
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
// From class MBTNotificationResult.
|
|
133 |
// The notification is finished.
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
void CBTNotifGenInfoNotifier::MBRNotificationClosed( TInt aError, const TDesC8& aData )
|
|
137 |
{
|
|
138 |
(void) aError;
|
|
139 |
(void) aData;
|
|
140 |
iNotification->RemoveObserver();
|
|
141 |
iNotification = NULL;
|
|
142 |
}
|
|
143 |
|
|
144 |
// ---------------------------------------------------------------------------
|
|
145 |
// Get and configure a notification.
|
|
146 |
// ---------------------------------------------------------------------------
|
|
147 |
//
|
|
148 |
void CBTNotifGenInfoNotifier::ShowNotificationL(const RMessage2& aMessage )
|
|
149 |
{
|
|
150 |
BOstraceFunctionEntry0( DUMMY_DEVLIST );
|
70
|
151 |
// read the message parameters
|
|
152 |
RBuf8 params;
|
|
153 |
params.CreateL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) );
|
|
154 |
aMessage.ReadL( EBTNotifSrvParamSlot, params );
|
|
155 |
TBTGenericInfoNotifierParams notifparams;
|
|
156 |
TPckgC<TBTGenericInfoNotifierParams> paramsPckg( notifparams );
|
|
157 |
paramsPckg.Set( params );
|
|
158 |
TInt notifType = paramsPckg().iMessageType;
|
|
159 |
|
|
160 |
TInt err = KErrNone;
|
|
161 |
|
57
|
162 |
if(iNotification)
|
|
163 |
{
|
|
164 |
iNotification->RemoveObserver();
|
|
165 |
iNotification = NULL;
|
|
166 |
}
|
|
167 |
iNotification = iServer->NotificationManager()->GetNotification();
|
|
168 |
User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
|
|
169 |
iNotification->SetObserver( this );
|
|
170 |
|
|
171 |
switch(notifType)
|
|
172 |
{
|
|
173 |
case EBTSwitchedOn:
|
|
174 |
case EBTSwitchedOff:
|
|
175 |
{
|
|
176 |
User::LeaveIfError(iNotification->SetData( TBluetoothDeviceDialog::EAdditionalInt, notifType));
|
70
|
177 |
iNotification->SetNotificationType( TBluetoothDialogParams::ENote, EGenericInfo );
|
57
|
178 |
}break;
|
70
|
179 |
case EBTEnterSap:
|
|
180 |
// save the pointer in order to dismiss the dialog later on
|
|
181 |
iEnterSAPNotification = iNotification;
|
|
182 |
iNotification->SetNotificationType( TBluetoothDialogParams::bt_052_d_entering, EUnusedResource );
|
|
183 |
break;
|
|
184 |
case EBTSapNoSim:
|
|
185 |
iNotification->SetNotificationType( TBluetoothDialogParams::bt_053_d_unable_to_use_no_sim, EUnusedResource );
|
|
186 |
break;
|
|
187 |
case EBTSapFailed:
|
|
188 |
iNotification->SetNotificationType( TBluetoothDialogParams::bt_053_d_unable_to_use, EUnusedResource );
|
|
189 |
break;
|
|
190 |
case EBTSapOk:
|
|
191 |
if(iEnterSAPNotification)
|
|
192 |
iEnterSAPNotification->Close();
|
|
193 |
iNotification->SetNotificationType( TBluetoothDialogParams::bt_054_d_entered_popup, EGenericInfo );
|
|
194 |
// Todo: handler err in a proper way
|
|
195 |
err = iNotification->SetData( TBluetoothDeviceDialog::EAdditionalInt, notifType);
|
|
196 |
break;
|
57
|
197 |
default:
|
|
198 |
{
|
70
|
199 |
iNotification->SetNotificationType( TBluetoothDialogParams::ENote, EGenericInfo );
|
57
|
200 |
TBTDevAddr addr(paramsPckg().iRemoteAddr);
|
|
201 |
|
|
202 |
// Get the device name
|
|
203 |
const CBtDevExtension* dev = iServer->DevRepository().Device(addr);
|
|
204 |
if(dev)
|
|
205 |
{
|
|
206 |
if(0 != dev->Device().FriendlyName().Length()&& dev->Device().IsValidFriendlyName())
|
|
207 |
{
|
|
208 |
// If we have a friendly name use it for the UI
|
|
209 |
err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, dev->Device().FriendlyName() );
|
|
210 |
}
|
|
211 |
else
|
|
212 |
{
|
|
213 |
err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, dev->Alias() );
|
|
214 |
}
|
|
215 |
if(!err)
|
|
216 |
{
|
|
217 |
err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceClass, dev->Device().DeviceClass().DeviceClass());
|
|
218 |
}
|
|
219 |
}
|
|
220 |
else
|
|
221 |
{
|
|
222 |
TBTDeviceName name;
|
|
223 |
addr.GetReadable(name);
|
|
224 |
err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, name);
|
|
225 |
}
|
|
226 |
if(!err)
|
|
227 |
{
|
|
228 |
err = iNotification->SetData( TBluetoothDeviceDialog::EAdditionalInt, notifType);
|
|
229 |
}
|
|
230 |
}break;
|
|
231 |
}
|
|
232 |
|
|
233 |
iServer->NotificationManager()->QueueNotificationL( iNotification,CBTNotificationManager::EPriorityHigh );
|
|
234 |
params.Close();
|
|
235 |
BOstraceFunctionExit0( DUMMY_DEVLIST );
|
|
236 |
}
|
|
237 |
|
|
238 |
|