|
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: Server class for handling commands from clients, and the |
|
15 * central class in btnotif thread. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <hb/hbcore/hbdevicedialogsymbian.h> |
|
21 #include <btnotif.h> |
|
22 #include "btnotifpowernotifier.h" |
|
23 |
|
24 #include "btnotifserver.h" |
|
25 #include "btnotifclientserver.h" |
|
26 #include "bluetoothnotification.h" |
|
27 #include "btnotificationmanager.h" |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // C++ default constructor |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CBTNotifPowerNotifier::CBTNotifPowerNotifier( CBTNotifServer* aServer ) |
|
36 : iServer( aServer ), iTurnBTOn(ETrue) |
|
37 { |
|
38 } |
|
39 |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Symbian 2nd-phase constructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void CBTNotifPowerNotifier::ConstructL() |
|
46 { |
|
47 iBTEngSettings = CBTEngSettings::NewL(this); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // NewL. |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CBTNotifPowerNotifier* CBTNotifPowerNotifier::NewL( CBTNotifServer* aServer ) |
|
55 { |
|
56 CBTNotifPowerNotifier* self = new( ELeave ) CBTNotifPowerNotifier( aServer ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop( self ); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // Destructor |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CBTNotifPowerNotifier::~CBTNotifPowerNotifier() |
|
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 delete iBTEngSettings; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // Process a client message related to notifiers. |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CBTNotifPowerNotifier::HandleNotifierRequestL( const RMessage2& aMessage ) |
|
84 { |
|
85 BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() ); |
|
86 TInt opcode = aMessage.Function(); |
|
87 TInt uid = aMessage.Int0(); |
|
88 TInt err = KErrNone; |
|
89 switch ( opcode ) |
|
90 { |
|
91 case EBTNotifCancelNotifier: |
|
92 { |
|
93 aMessage.Complete( err ); |
|
94 break; |
|
95 } |
|
96 case EBTNotifUpdateNotifier: |
|
97 { |
|
98 aMessage.Complete( err ); |
|
99 break; |
|
100 } |
|
101 case EBTNotifStartSyncNotifier: |
|
102 { |
|
103 TRAP(err,ShowNotificationL(aMessage)); |
|
104 if(err) |
|
105 { |
|
106 aMessage.Complete(err); |
|
107 } |
|
108 break; |
|
109 } |
|
110 case EBTNotifStartAsyncNotifier: |
|
111 { |
|
112 TRAP(err,ShowNotificationL(aMessage)); |
|
113 if(err) |
|
114 { |
|
115 aMessage.Complete(err); |
|
116 } |
|
117 break; |
|
118 } |
|
119 default: |
|
120 { |
|
121 aMessage.Complete( KErrNotSupported ); |
|
122 } |
|
123 } |
|
124 BOstraceFunctionExit1( DUMMY_DEVLIST, this ); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // From class MBTNotificationResult. |
|
129 // Handle a result from a user query. |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 void CBTNotifPowerNotifier::MBRDataReceived( CHbSymbianVariantMap& aData ) |
|
133 { |
|
134 if(aData.Keys().MdcaPoint(0).Compare(_L("actionResult")) == 0) |
|
135 { |
|
136 iTurnBTOn = *(static_cast<TInt*>(aData.Get(_L("actionResult"))->Data())); |
|
137 } |
|
138 } |
|
139 |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // From class MBTNotificationResult. |
|
143 // The notification is finished. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CBTNotifPowerNotifier::MBRNotificationClosed( TInt aError, const TDesC8& aData ) |
|
147 { |
|
148 (void) aError; |
|
149 (void) aData; |
|
150 |
|
151 if(iTurnBTOn) |
|
152 { |
|
153 //Turn BT on. |
|
154 iBTEngSettings->SetPowerState(EBTPowerOn); |
|
155 } |
|
156 |
|
157 else if ( !iNotifierMessage.IsNull() ) |
|
158 { |
|
159 //User choose No. So, complete the request with out turning BT on. |
|
160 iClientResponse() = EFalse; |
|
161 iNotifierMessage.Write(EBTNotifSrvReplySlot, iClientResponse); |
|
162 iNotifierMessage.Complete(KErrNone); |
|
163 } |
|
164 iNotification->RemoveObserver(); |
|
165 iNotification = NULL; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // Get and configure a notification. |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CBTNotifPowerNotifier::ShowNotificationL(const RMessage2& aMessage ) |
|
173 { |
|
174 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
175 |
|
176 iNotifierMessage = aMessage; |
|
177 |
|
178 if(iNotification) |
|
179 { |
|
180 iNotification->RemoveObserver(); |
|
181 iNotification = NULL; |
|
182 } |
|
183 iNotification = iServer->NotificationManager()->GetNotification(); |
|
184 User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory |
|
185 iNotification->SetObserver( this ); |
|
186 //iNotification->SetNotificationType( TBluetoothDialogParams::ENote, EGenericInfo ); |
|
187 |
|
188 // read the message parameters |
|
189 RBuf8 params; |
|
190 params.CreateL( aMessage.GetDesLengthL( EBTNotifSrvParamSlot ) ); |
|
191 aMessage.ReadL( EBTNotifSrvParamSlot, params ); |
|
192 TBTGenericInfoNotifierParams notifparams; |
|
193 TPckgC<TBTGenericInfoNotifierParams> paramsPckg( notifparams ); |
|
194 paramsPckg.Set( params ); |
|
195 TInt notifType = paramsPckg().iMessageType; |
|
196 |
|
197 TCoreAppUIsNetworkConnectionAllowed offLineMode; |
|
198 TBTEnabledInOfflineMode btEnabled; |
|
199 iBTEngSettings->GetOfflineModeSettings(offLineMode, btEnabled); |
|
200 |
|
201 // Choose user interaction |
|
202 // |
|
203 if ( (btEnabled == EBTEnabledInOfflineMode) && |
|
204 (offLineMode == ECoreAppUIsNetworkConnectionNotAllowed) ) |
|
205 { |
|
206 // Allowed to enable BT in offline mode and device is currently in offline mode. |
|
207 // Launch the offline query notification dialog. |
|
208 iNotification->SetNotificationType( TBluetoothDialogParams::EInformationDialog, EIssueOfflineQuery ); |
|
209 iServer->NotificationManager()->QueueNotificationL( iNotification, CBTNotificationManager::EPriorityHigh ); |
|
210 } |
|
211 else if(offLineMode == ECoreAppUIsNetworkConnectionAllowed) |
|
212 { |
|
213 //Device not in offline mode, simply turn BT on. |
|
214 iBTEngSettings->SetPowerState(EBTPowerOn); |
|
215 } |
|
216 else |
|
217 { |
|
218 //Return EFalse, indication that BT should not be switched on. |
|
219 if(!iNotifierMessage.IsNull()) |
|
220 { |
|
221 iClientResponse() = EFalse; |
|
222 iNotifierMessage.Write(EBTNotifSrvReplySlot, iClientResponse); |
|
223 iNotifierMessage.Complete(KErrNone); |
|
224 } |
|
225 } |
|
226 |
|
227 params.Close(); |
|
228 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
229 } |
|
230 |
|
231 void CBTNotifPowerNotifier::PowerStateChanged( TBTPowerStateValue aState ) |
|
232 { |
|
233 if(!iNotifierMessage.IsNull()) |
|
234 { |
|
235 if(aState == EBTPowerOn) |
|
236 { |
|
237 //Request to turn BT on was successful. |
|
238 iClientResponse() = ETrue; |
|
239 iNotifierMessage.Write(EBTNotifSrvReplySlot, iClientResponse); |
|
240 iNotifierMessage.Complete(KErrNone); |
|
241 } |
|
242 else |
|
243 { |
|
244 //Request to turn BT on was not successful. |
|
245 iClientResponse() = EFalse; |
|
246 iNotifierMessage.Write(EBTNotifSrvReplySlot, iClientResponse); |
|
247 iNotifierMessage.Complete(KErrNone); |
|
248 } |
|
249 } |
|
250 } |
|
251 |
|
252 void CBTNotifPowerNotifier::VisibilityModeChanged( TBTVisibilityMode aState ) |
|
253 { |
|
254 (void) aState; |
|
255 } |
|
256 |
|
257 |