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: Class for managing user notification and query objects, |
|
15 * and for serializing access to the notification server. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "btnotificationmanager.h" |
|
20 #include "btnotifserver.h" |
|
21 |
|
22 #include "bluetoothnotification.h" |
|
23 |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // C++ default constructor |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CBTNotificationManager::CBTNotificationManager( const CBTNotifServer* aServer ) |
|
32 : iServer( aServer ) |
|
33 { |
|
34 } |
|
35 |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Symbian 2nd-phase constructor |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 void CBTNotificationManager::ConstructL() |
|
42 { |
|
43 } |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // NewL. |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CBTNotificationManager* CBTNotificationManager::NewL( const CBTNotifServer* aServer ) |
|
51 { |
|
52 CBTNotificationManager* self = new( ELeave ) CBTNotificationManager( aServer ); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // Destructor |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CBTNotificationManager::~CBTNotificationManager() |
|
65 { |
|
66 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
67 iNotificationQ.ResetAndDestroy(); |
|
68 iNotificationQ.Close(); |
|
69 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
70 } |
|
71 |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Get a new notification |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CBluetoothNotification* CBTNotificationManager::GetNotification() |
|
78 { |
|
79 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
80 CBluetoothNotification* notification = NULL; |
|
81 TRAP_IGNORE( notification = CBluetoothNotification::NewL( this ) ); |
|
82 if( notification ) |
|
83 { |
|
84 if( iNotificationQ.Append( notification ) ) |
|
85 { |
|
86 // In case the appending fails, we just delete the notification. |
|
87 // Otherwise we cannot keep track of it anymore. |
|
88 delete notification; |
|
89 notification = NULL; |
|
90 } |
|
91 } |
|
92 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
93 return notification; |
|
94 } |
|
95 |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Release the notification |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CBTNotificationManager::ReleaseNotification( CBluetoothNotification* aNotification ) |
|
102 { |
|
103 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
104 __ASSERT_ALWAYS( aNotification, PanicServer( EBTNotifPanicBadArgument ) ); |
|
105 TInt pos = iNotificationQ.Find( aNotification ); |
|
106 __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); |
|
107 delete iNotificationQ[pos]; |
|
108 iNotificationQ.Remove( pos ); |
|
109 iNotificationQ.Compress(); |
|
110 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
111 } |
|
112 |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Queue the notification with given priority |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CBTNotificationManager::QueueNotificationL( |
|
119 CBluetoothNotification* aNotification, |
|
120 TNotificationPriority aPriority ) |
|
121 { |
|
122 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
123 (void) aPriority; |
|
124 TInt pos = iNotificationQ.Find( aNotification ); |
|
125 __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); |
|
126 // Always move the newly added notification on top |
|
127 if(pos != 0 ) |
|
128 { |
|
129 CBluetoothNotification* notification = NULL; |
|
130 notification = iNotificationQ[pos]; |
|
131 iNotificationQ.Remove( pos ); |
|
132 iNotificationQ.InsertL(notification,0); |
|
133 } |
|
134 ProcessNotificationQueueL(); |
|
135 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // Process the notification queue and launch the next notification. |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CBTNotificationManager::ProcessNotificationQueueL() |
|
143 { |
|
144 BOstraceFunctionEntry0( DUMMY_DEVLIST ); |
|
145 if( iNotificationQ.Count() ) |
|
146 { |
|
147 iNotificationQ[0]->ShowL(); |
|
148 } |
|
149 else |
|
150 { |
|
151 // No outstanding notifications |
|
152 iNotificationQ.Compress(); // the queue is empty, reset it. |
|
153 } |
|
154 BOstraceFunctionExit0( DUMMY_DEVLIST ); |
|
155 } |
|
156 |
|