|
1 /* |
|
2 * Copyright (c) 2008 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: Client API for Dynamic Avkon soft notifications. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "AknDynamicSoftNotifier.h" |
|
19 #include "AknDynamicSoftNoteObserver.h" |
|
20 #include "AknDynamicSoftNoteObserver.h" |
|
21 #include "AknDynamicNotifier.h" |
|
22 #include "aknsoftnoteconsts.h" |
|
23 #include <AknDynamicSoftNotificationParams.h> |
|
24 #include <AknNotifySignature.h> |
|
25 #include <aknSDData.h> |
|
26 #include <AknNotifyStd.h> |
|
27 #include <s32mem.h> |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 /// IPC message buffer granularity |
|
32 const TInt KAknBufferGranularity = 1024; |
|
33 /// Observer array granularity |
|
34 const TInt KAknObserverListGranularity = 4; |
|
35 /// Priority of cancel message. Value only needs to be in allowed range. |
|
36 const TInt KAknPriorityOfCancelMessage = 1000; |
|
37 |
|
38 //----------------------------------------------------------------------------- |
|
39 // CAknDynamicSoftNotifier::NewL |
|
40 //----------------------------------------------------------------------------- |
|
41 // |
|
42 EXPORT_C CAknDynamicSoftNotifier* CAknDynamicSoftNotifier::NewL() |
|
43 { |
|
44 CAknDynamicSoftNotifier* self = NewLC(); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 //----------------------------------------------------------------------------- |
|
50 // CAknDynamicSoftNotifier::NewLC |
|
51 //----------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C CAknDynamicSoftNotifier* CAknDynamicSoftNotifier::NewLC() |
|
54 { |
|
55 CAknDynamicSoftNotifier * self = new( ELeave ) CAknDynamicSoftNotifier; |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 //----------------------------------------------------------------------------- |
|
62 // CAknDynamicSoftNotifier::~CAknDynamicSoftNotifier |
|
63 //----------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CAknDynamicSoftNotifier::~CAknDynamicSoftNotifier() |
|
66 { |
|
67 iObservers.ResetAndDestroy(); |
|
68 delete iNotifier; |
|
69 } |
|
70 |
|
71 //----------------------------------------------------------------------------- |
|
72 // CAknDynamicSoftNotifier::ConstructL |
|
73 //----------------------------------------------------------------------------- |
|
74 // |
|
75 void CAknDynamicSoftNotifier::ConstructL() |
|
76 { |
|
77 iNotifier = new(ELeave) CAknDynamicNotifier( KAknSoftNotificationUid ); |
|
78 } |
|
79 |
|
80 //----------------------------------------------------------------------------- |
|
81 // CAknDynamicSoftNotifier::CAknDynamicSoftNotifier |
|
82 //----------------------------------------------------------------------------- |
|
83 // |
|
84 CAknDynamicSoftNotifier::CAknDynamicSoftNotifier() : |
|
85 iObservers( KAknObserverListGranularity ) |
|
86 { |
|
87 } |
|
88 |
|
89 //----------------------------------------------------------------------------- |
|
90 // CAknDynamicSoftNotifier::AddDynamicNotificationL |
|
91 //----------------------------------------------------------------------------- |
|
92 // |
|
93 EXPORT_C TInt CAknDynamicSoftNotifier::AddDynamicNotificationL( |
|
94 TAknDynamicSoftNotificationParams& aParams, |
|
95 TInt aNoteId, // = KErrUnknown |
|
96 TInt aCount ) // = 1 |
|
97 { |
|
98 return SendMessageL( aNoteId, aCount, EFalse, ETrue, aParams ); |
|
99 } |
|
100 |
|
101 //----------------------------------------------------------------------------- |
|
102 // CAknDynamicSoftNotifier::SetDynamicNotificationCountL |
|
103 //----------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C TInt CAknDynamicSoftNotifier::SetDynamicNotificationCountL( |
|
106 TAknDynamicSoftNotificationParams& aParams, |
|
107 TInt aNoteId, |
|
108 TInt aCount ) |
|
109 { |
|
110 return SendMessageL( aNoteId, aCount, EFalse, EFalse, aParams ); |
|
111 } |
|
112 |
|
113 //----------------------------------------------------------------------------- |
|
114 // CAknDynamicSoftNotifier::CancelDynamicSoftNotificationL |
|
115 //----------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C void CAknDynamicSoftNotifier::CancelDynamicNotificationL( |
|
118 TInt aNoteId ) |
|
119 { |
|
120 // parameters are unrelevant |
|
121 TAknDynamicSoftNotificationParams params( KAknPriorityOfCancelMessage ); |
|
122 SendMessageL( aNoteId, 0, ETrue, EFalse, params ); |
|
123 StopObserving( aNoteId ); |
|
124 } |
|
125 |
|
126 //----------------------------------------------------------------------------- |
|
127 // CAknDynamicSoftNotifier::StartObservingL |
|
128 //----------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C void CAknDynamicSoftNotifier::StartObservingL( TInt aNoteId, |
|
131 MAknDynamicSoftNoteObserver* aObserver ) |
|
132 { |
|
133 // Only one observer for a note id allowed. |
|
134 if( FindByNoteId( aNoteId ) != KErrNotFound ) |
|
135 { |
|
136 User::Leave( KErrAlreadyExists ); |
|
137 } |
|
138 |
|
139 CAknDynamicSoftNoteObserver* observer = |
|
140 CAknDynamicSoftNoteObserver::NewLC( *this, aObserver, aNoteId ); |
|
141 |
|
142 iObservers.AppendL( observer ); |
|
143 CleanupStack::Pop( observer ); |
|
144 } |
|
145 |
|
146 //----------------------------------------------------------------------------- |
|
147 // CAknDynamicSoftNotifier::StopObserving |
|
148 //----------------------------------------------------------------------------- |
|
149 // |
|
150 EXPORT_C void CAknDynamicSoftNotifier::StopObserving( TInt aNoteId ) |
|
151 { |
|
152 TInt pos = FindByNoteId( aNoteId ); |
|
153 if( pos != KErrNotFound ) |
|
154 { |
|
155 delete iObservers[pos]; |
|
156 iObservers.Remove(pos); |
|
157 } |
|
158 } |
|
159 |
|
160 //----------------------------------------------------------------------------- |
|
161 // CAknDynamicSoftNotifier::DeleteObserver |
|
162 //----------------------------------------------------------------------------- |
|
163 // |
|
164 void CAknDynamicSoftNotifier::DeleteObserver( |
|
165 CAknDynamicSoftNoteObserver* aObserver ) |
|
166 { |
|
167 TInt pos = iObservers.Find( aObserver ); |
|
168 if( pos != KErrNotFound ) |
|
169 { |
|
170 iObservers.Remove( pos ); |
|
171 } |
|
172 delete aObserver; |
|
173 } |
|
174 |
|
175 //----------------------------------------------------------------------------- |
|
176 // CAknDynamicSoftNotifier::SetSecondaryDisplayData |
|
177 //----------------------------------------------------------------------------- |
|
178 // |
|
179 EXPORT_C void CAknDynamicSoftNotifier::SetSecondaryDisplayData( |
|
180 CAknSDData* aData ) |
|
181 { |
|
182 delete iSecondaryDisplayData; |
|
183 iSecondaryDisplayData = aData; |
|
184 } |
|
185 |
|
186 //----------------------------------------------------------------------------- |
|
187 // CAknDynamicSoftNotifier::SecondaryDisplayData |
|
188 //----------------------------------------------------------------------------- |
|
189 // |
|
190 CAknSDData* CAknDynamicSoftNotifier::SecondaryDisplayData() |
|
191 { |
|
192 return iSecondaryDisplayData; |
|
193 } |
|
194 |
|
195 //----------------------------------------------------------------------------- |
|
196 // CAknDynamicSoftNotifier::SendMessageL |
|
197 //----------------------------------------------------------------------------- |
|
198 // |
|
199 TInt CAknDynamicSoftNotifier::SendMessageL( |
|
200 TInt aNoteId, |
|
201 TInt aCount, |
|
202 TBool aCancel, |
|
203 TBool aAddCount, |
|
204 TAknDynamicSoftNotificationParams& aParams ) |
|
205 { |
|
206 CBufFlat* buf = CBufFlat::NewL( KAknBufferGranularity ); |
|
207 CleanupStack::PushL( buf ); |
|
208 |
|
209 RBufWriteStream bufStream( *buf ); |
|
210 bufStream.PushL(); |
|
211 |
|
212 // Common data for dynamic notification |
|
213 bufStream.WriteInt32L( KAKNNOTIFIERSIGNATURE ); |
|
214 bufStream.WriteUint8L( ECustomSoftNotification ); |
|
215 bufStream.WriteInt16L( aCount ); // count |
|
216 bufStream.WriteUint8L( aCancel ? ETrue : EFalse ); // convert TBool to 0 or 1 |
|
217 bufStream.WriteUint8L( aAddCount ? ETrue : EFalse ); // convert TBool to 0 or 1 |
|
218 // text prompt (not used in this type of notification). |
|
219 // It's put here to simplify changes in server side |
|
220 bufStream << KNullDesC(); |
|
221 bufStream.WriteInt32L( aNoteId ); // notification id |
|
222 |
|
223 // Type Specific data for this dynamic notification |
|
224 // Keep this synchronized with AknDynamicNotificationData |
|
225 // |
|
226 bufStream.WriteInt16L( KAknSoftNotificationDynamic ); // parameter type id |
|
227 bufStream.WriteInt32L( aNoteId ); // notification id |
|
228 bufStream << aParams; |
|
229 |
|
230 // Additional data |
|
231 // |
|
232 // Secondary display data not available |
|
233 bufStream.WriteInt8L( EFalse ); |
|
234 |
|
235 bufStream.CommitL(); |
|
236 CleanupStack::PopAndDestroy(); // bufStream |
|
237 |
|
238 TPckgBuf<TInt> response; |
|
239 User::LeaveIfError( iNotifier->StartOrUpdate( buf->Ptr( 0 ), response ) ); |
|
240 |
|
241 CleanupStack::PopAndDestroy( buf ); |
|
242 return response(); |
|
243 } |
|
244 |
|
245 //----------------------------------------------------------------------------- |
|
246 // CAknDynamicSoftNotifier::FindByNoteId |
|
247 //----------------------------------------------------------------------------- |
|
248 // |
|
249 TInt CAknDynamicSoftNotifier::FindByNoteId( TInt aNoteId ) const |
|
250 { |
|
251 TInt result = KErrNotFound; |
|
252 |
|
253 const TInt count = iObservers.Count(); |
|
254 for( TInt i = 0; i < count; i++ ) |
|
255 { |
|
256 if( aNoteId == iObservers[i]->NoteId() ) |
|
257 { |
|
258 result = i; |
|
259 break; |
|
260 } |
|
261 } |
|
262 |
|
263 return result; |
|
264 } |
|
265 |
|
266 // End of File |