1 /* |
1 /* |
2 * ============================================================================ |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * Name : btnotificationmanager.cpp |
3 * All rights reserved. |
4 * Part of : bluetoothengine / btnotif |
4 * This component and the accompanying materials are made available |
5 * Description : Class for managing user notification and query objects, and for serializing access to the notification server. |
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". |
6 * |
8 * |
7 * Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). |
9 * Initial Contributors: |
8 * All rights reserved. |
10 * Nokia Corporation - initial contribution. |
9 * This component and the accompanying materials are made available |
|
10 * under the terms of "Eclipse Public License v1.0" |
|
11 * which accompanies this distribution, and is available |
|
12 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
13 * |
11 * |
14 * Initial Contributors: |
12 * Contributors: |
15 * Nokia Corporation - initial contribution. |
|
16 * |
13 * |
17 * Contributors: |
14 * Description: Class for managing user notification and query objects, |
18 * Nokia Corporation |
15 * and for serializing access to the notification server. |
19 * ============================================================================ |
16 * |
20 * Template version: 4.1 |
|
21 */ |
17 */ |
22 |
18 |
23 #include "btnotificationmanager.h" |
19 #include "btnotificationmanager.h" |
24 #include "btnotifserver.h" |
20 #include "btnotifserver.h" |
25 |
21 |
70 // |
63 // |
71 CBTNotificationManager::~CBTNotificationManager() |
64 CBTNotificationManager::~CBTNotificationManager() |
72 { |
65 { |
73 iNotificationQ.ResetAndDestroy(); |
66 iNotificationQ.ResetAndDestroy(); |
74 iNotificationQ.Close(); |
67 iNotificationQ.Close(); |
75 iUnusedQ.ResetAndDestroy(); |
|
76 iUnusedQ.Close(); |
|
77 delete iAsyncCb; |
|
78 } |
68 } |
79 |
69 |
80 |
70 |
81 // --------------------------------------------------------------------------- |
71 // --------------------------------------------------------------------------- |
82 // Get a new notification |
72 // Get a new notification |
83 // --------------------------------------------------------------------------- |
73 // --------------------------------------------------------------------------- |
84 // |
74 // |
85 CBluetoothNotification* CBTNotificationManager::GetNotification() |
75 CBluetoothNotification* CBTNotificationManager::GetNotification() |
86 { |
76 { |
87 CBluetoothNotification* notification = NULL; |
77 CBluetoothNotification* notification = NULL; |
88 if( iUnusedQ.Count() ) |
78 TRAP_IGNORE( notification = CBluetoothNotification::NewL( this ) ); |
89 { |
|
90 // Re-use the first idle notification. |
|
91 notification = iUnusedQ[0]; |
|
92 iUnusedQ.Remove( 0 ); |
|
93 } |
|
94 else |
|
95 { |
|
96 TRAP_IGNORE( notification = CBluetoothNotification::NewL( this ) ); |
|
97 } |
|
98 if( notification ) |
79 if( notification ) |
99 { |
80 { |
100 if( iNotificationQ.Append( notification ) ) |
81 if( iNotificationQ.Append( notification ) ) |
101 { |
82 { |
102 // In case the appending fails, we just delete the notification. |
83 // In case the appending fails, we just delete the notification. |
116 void CBTNotificationManager::ReleaseNotification( CBluetoothNotification* aNotification ) |
97 void CBTNotificationManager::ReleaseNotification( CBluetoothNotification* aNotification ) |
117 { |
98 { |
118 __ASSERT_ALWAYS( aNotification, PanicServer( EBTNotifPanicBadArgument ) ); |
99 __ASSERT_ALWAYS( aNotification, PanicServer( EBTNotifPanicBadArgument ) ); |
119 TInt pos = iNotificationQ.Find( aNotification ); |
100 TInt pos = iNotificationQ.Find( aNotification ); |
120 __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); |
101 __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); |
121 // ToDo: Cancel outstanding notification! |
|
122 iNotificationQ.Remove( pos ); |
102 iNotificationQ.Remove( pos ); |
123 TInt err = iUnusedQ.Append( aNotification ); |
103 // Just delete the notification. |
124 aNotification->Reset(); // Clean up notification's resources |
104 delete aNotification; |
125 if( err ) |
105 if(!iNotificationQ.Count() ) |
126 { |
106 { |
127 // Just delete the notification. |
107 // the queue is empty, reset it. |
128 delete aNotification; |
108 iNotificationQ.Compress(); |
129 } |
|
130 if( !iAsyncCb->IsActive() ) |
|
131 { |
|
132 if( !iNotificationQ.Count() ) |
|
133 { |
|
134 // Set the priority so that this is the last scheduled active object to execute. |
|
135 iAsyncCb->SetPriority( CActive::EPriorityIdle ); |
|
136 } |
|
137 iAsyncCb->CallBack(); |
|
138 } |
109 } |
139 } |
110 } |
140 |
111 |
141 |
112 |
142 // --------------------------------------------------------------------------- |
113 // --------------------------------------------------------------------------- |
143 // Queue the notification with given priority |
114 // Queue the notification with given priority |
144 // --------------------------------------------------------------------------- |
115 // --------------------------------------------------------------------------- |
145 // |
116 // |
146 TInt CBTNotificationManager::QueueNotification( CBluetoothNotification* aNotification, |
117 void CBTNotificationManager::QueueNotificationL( |
147 TNotificationPriority aPriority ) |
118 CBluetoothNotification* aNotification, |
|
119 TNotificationPriority aPriority ) |
148 { |
120 { |
|
121 (void) aPriority; |
149 TInt pos = iNotificationQ.Find( aNotification ); |
122 TInt pos = iNotificationQ.Find( aNotification ); |
150 __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); |
123 __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); |
151 if( aPriority == EPriorityHigh && pos != 0 ) |
124 if( /*aPriority == EPriorityHigh &&*/ pos != 0 ) |
152 { |
125 { |
153 // ToDo: Move the note to the front of the queue |
126 CBluetoothNotification* notification = NULL; |
|
127 notification = iNotificationQ[pos]; |
|
128 iNotificationQ.Remove( pos ); |
|
129 iNotificationQ.InsertL(notification,0); |
154 } |
130 } |
155 if( !iAsyncCb->IsActive() ) |
131 ProcessNotificationQueueL(); |
156 { |
|
157 if( iAsyncCb->Priority() != iServer->Priority() ) |
|
158 { |
|
159 // Reset priority back to original value |
|
160 // We first check the current priority, otherwise CActive will do an |
|
161 // unnecessary removal and adding of the callback from the active scheduler. |
|
162 iAsyncCb->SetPriority( iServer->Priority() ); |
|
163 } |
|
164 iAsyncCb->CallBack(); |
|
165 } |
|
166 return KErrNone; |
|
167 } |
132 } |
168 |
|
169 |
133 |
170 // --------------------------------------------------------------------------- |
134 // --------------------------------------------------------------------------- |
171 // Process the notification queue and launch the next notification. |
135 // Process the notification queue and launch the next notification. |
172 // --------------------------------------------------------------------------- |
136 // --------------------------------------------------------------------------- |
173 // |
137 // |
174 void CBTNotificationManager::ProcessNotificationQueueL() |
138 void CBTNotificationManager::ProcessNotificationQueueL() |
175 { |
139 { |
176 if( iNotificationQ.Count() ) |
140 if( iNotificationQ.Count() ) |
177 { |
141 { |
178 TInt err = iNotificationQ[0]->Show(); |
142 iNotificationQ[0]->ShowL(); |
179 // If the note is already showing, it will return KErrAlreadyExists |
|
180 (void) err; // ToDo: add error handling!! |
|
181 NOTIF_NOTHANDLED( !err || err == KErrAlreadyExists || err == KErrNotFound ) |
|
182 } |
143 } |
183 else |
144 else |
184 { |
145 { |
185 // No outstanding notifications, and unused notifications. |
146 // No outstanding notifications |
186 // Clean up the unused notifications. |
147 iNotificationQ.Compress(); // the queue is empty, reset it. |
187 iUnusedQ.ResetAndDestroy(); |
|
188 iNotificationQ.Reset(); // the queue is empty, reset it. |
|
189 // Also clean up any resources. |
|
190 } |
148 } |
191 } |
149 } |
192 |
150 |
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // Callback for asynchronous processing of queued notification requests. |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 TInt CBTNotificationManager::AsyncCallback( TAny* aPtr ) |
|
199 { |
|
200 TRAPD( err, ( (CBTNotificationManager*) aPtr )->ProcessNotificationQueueL() ); |
|
201 return err; |
|
202 } |
|