1 /* |
|
2 * Copyright (c) 2002-2006 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: CNssDBTagSelectNotifier provides tag select notification to |
|
15 * its clients (observers). It itslef receives tag select notification |
|
16 * from Recognition Handler. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // includes |
|
22 #include "nssvascdbtagselectnotifier.h" |
|
23 #include "nssvascoreconstant.h" |
|
24 #include <e32property.h> |
|
25 |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // --------------------------------------------------------- |
|
30 // CNssDBTagSelectNotifier::CNssDBTagSelectNotifier |
|
31 // C++ constructor can NOT contain any code that might leave. |
|
32 // --------------------------------------------------------- |
|
33 // |
|
34 CNssDBTagSelectNotifier::CNssDBTagSelectNotifier(): CActive( EPriorityStandard ) |
|
35 { |
|
36 // Nothing |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------- |
|
40 // CNssDBTagSelectNotifier::CNssDBTagSelectNotifier |
|
41 // overloaded constructor |
|
42 // --------------------------------------------------------- |
|
43 // |
|
44 CNssDBTagSelectNotifier::CNssDBTagSelectNotifier( CNssVASDatabase* aVasDatabase ): |
|
45 CActive( EPriorityStandard ), iVasDatabase( aVasDatabase ) |
|
46 { |
|
47 // Nothing |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------- |
|
51 // CNssDBTagSelectNotifier::ConstructL |
|
52 // symbian constructor |
|
53 // --------------------------------------------------------- |
|
54 // |
|
55 void CNssDBTagSelectNotifier::ConstructL() |
|
56 { |
|
57 iObserverList = new (ELeave) CArrayPtrFlat<MNssDBTagSelectNotifierClient>(1); |
|
58 |
|
59 // Define P&S properties |
|
60 TInt err = RProperty::Define( KSINDUID, EVoiceTagSelectionTagId, RProperty::EInt ); |
|
61 if ( err != KErrAlreadyExists ) |
|
62 { |
|
63 User::LeaveIfError( err ); |
|
64 } |
|
65 err = RProperty::Define( KSINDUID, EVoiceTagSelectionContextId, RProperty::EInt ); |
|
66 if ( err != KErrAlreadyExists ) |
|
67 { |
|
68 User::LeaveIfError( err ); |
|
69 } |
|
70 |
|
71 User::LeaveIfError( iProperty.Attach( KSINDUID, EVoiceTagSelectionTagId ) ); |
|
72 CActiveScheduler::Add( this ); |
|
73 // Subsrcibe for change notifications |
|
74 iProperty.Subscribe( iStatus ); |
|
75 SetActive(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------- |
|
79 // CNssDBTagSelectNotifier::NewL |
|
80 // 2 phase Construction |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 CNssDBTagSelectNotifier* CNssDBTagSelectNotifier::NewL( CNssVASDatabase* aVasDatabase ) |
|
84 { |
|
85 CNssDBTagSelectNotifier* self = NewLC( aVasDatabase ); |
|
86 CleanupStack::Pop( self ); |
|
87 return ( self ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CNssDBTagSelectNotifier::NewLC |
|
92 // 2 phase Construction |
|
93 // --------------------------------------------------------- |
|
94 // |
|
95 CNssDBTagSelectNotifier* CNssDBTagSelectNotifier::NewLC( CNssVASDatabase* aVasDatabase ) |
|
96 { |
|
97 CNssDBTagSelectNotifier* self = new ( ELeave )CNssDBTagSelectNotifier( aVasDatabase ); |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL(); |
|
100 return ( self ); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CNssDBTagSelectNotifier::~CNssDBTagSelectNotifier |
|
105 // destructor |
|
106 // --------------------------------------------------------- |
|
107 // |
|
108 CNssDBTagSelectNotifier::~CNssDBTagSelectNotifier() |
|
109 { |
|
110 if ( iObserverList ) |
|
111 { |
|
112 iObserverList->ResetAndDestroy(); |
|
113 delete iObserverList; |
|
114 iObserverList = NULL; |
|
115 } |
|
116 Cancel(); |
|
117 iProperty.Close(); |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------- |
|
121 // CNssDBTagSelectNotifier::RegisterForNotification |
|
122 // registers a client for notification |
|
123 // --------------------------------------------------------- |
|
124 // |
|
125 TInt CNssDBTagSelectNotifier::RegisterForNotification( MNssDBTagSelectNotifierClient* aObserver ) |
|
126 { |
|
127 TRAPD( err, iObserverList->AppendL( aObserver ) ); |
|
128 return err; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // CNssDBTagSelectNotifier::Deregister |
|
133 // Deregister a client from notification |
|
134 // --------------------------------------------------------- |
|
135 // |
|
136 TInt CNssDBTagSelectNotifier::Deregister( MNssDBTagSelectNotifierClient* aObserver ) |
|
137 { |
|
138 TBool ret = EFalse; |
|
139 if ( iObserverList ) |
|
140 { |
|
141 for ( TInt i = 0;i < iObserverList->Count(); i++ ) |
|
142 if ( (*iObserverList)[i] == aObserver ) |
|
143 { |
|
144 iObserverList->Delete( i ); |
|
145 ret = ETrue; |
|
146 } |
|
147 } |
|
148 if ( ret ) |
|
149 { |
|
150 iObserverList->Compress(); |
|
151 } |
|
152 return (ret ? KErrNone : KErrGeneral); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------- |
|
156 // CNssDBTagSelectNotifier::HandleSelection |
|
157 // calls all its clients, when notified of a tag slection. |
|
158 // --------------------------------------------------------- |
|
159 // |
|
160 void CNssDBTagSelectNotifier::HandleSelection( CNssTag* aTag ) |
|
161 { |
|
162 CNssContext* context = ( CNssContext* ) aTag->Context(); |
|
163 RProperty::Set( KSINDUID, EVoiceTagSelectionContextId, context->ContextId() ); |
|
164 RProperty::Set( KSINDUID, EVoiceTagSelectionTagId, aTag->TagId() ); |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------- |
|
168 // CNssDBTagSelectNotifier::DoHandleSelectionCallback |
|
169 // Forwards the tag selection callback |
|
170 // --------------------------------------------------------- |
|
171 // |
|
172 void CNssDBTagSelectNotifier::DoHandleSelectionCallback( TInt aTagId, TInt aContextId ) |
|
173 { |
|
174 if ( iObserverList->Count() ) |
|
175 { |
|
176 // Go through all observers that have been registered to this instance |
|
177 for ( TInt i = 0; i < iObserverList->Count(); i++ ) |
|
178 { |
|
179 // Find the tags based on ID |
|
180 MNssTagListArray* array = iVasDatabase->GetTag( aTagId ); |
|
181 |
|
182 for ( TInt j = 0; j < array->Count(); j++ ) |
|
183 { |
|
184 CNssTag* tag = ( CNssTag* )array->At( j ); |
|
185 CNssContext* context = ( CNssContext* ) tag->Context(); |
|
186 // Check that context IDs match |
|
187 if ( context->ContextId() == aContextId ) |
|
188 { |
|
189 // Do the callback |
|
190 (*iObserverList)[i]->HandleSelection( tag ); |
|
191 } |
|
192 } |
|
193 |
|
194 array->ResetAndDestroy(); |
|
195 delete array; |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------- |
|
201 // CNssDBTagSelectNotifier::DoCancel |
|
202 // From CActive |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 void CNssDBTagSelectNotifier::DoCancel() |
|
206 { |
|
207 iProperty.Cancel(); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------- |
|
211 // CNssDBTagSelectNotifier::RunL |
|
212 // From CActive |
|
213 // --------------------------------------------------------- |
|
214 // |
|
215 void CNssDBTagSelectNotifier::RunL() |
|
216 { |
|
217 // resubscribe before processing new value to prevent missing updates |
|
218 iProperty.Subscribe( iStatus ); |
|
219 SetActive(); |
|
220 |
|
221 // property updated, get new value |
|
222 iProperty.Get( KSINDUID, EVoiceTagSelectionTagId, iTagId ); |
|
223 iProperty.Get( KSINDUID, EVoiceTagSelectionContextId, iContextId ); |
|
224 DoHandleSelectionCallback( iTagId, iContextId ); |
|
225 } |
|
226 |
|
227 // End of file |
|