|
1 /* |
|
2 * Copyright (c) 2003-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: The CNssTagSelectNotification class allows the client to |
|
15 * register and deregister for a voice tag select event. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 #include "nssvasctagselectnotification.h" |
|
23 #include "nssvasmtagselecthandler.h" |
|
24 #include "nssvasctagselectdata.h" |
|
25 #include "rubydebug.h" |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CNssTagSelectNotification::NewL |
|
32 // Two-phased constructor. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CNssTagSelectNotification* CNssTagSelectNotification::NewL() |
|
36 { |
|
37 // version of NewLC which leaves nothing on the cleanup stack |
|
38 CNssTagSelectNotification* self=NewLC(); |
|
39 CleanupStack::Pop(self); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CNssTagSelectNotification::NewLC |
|
45 // Two-phased constructor. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CNssTagSelectNotification* CNssTagSelectNotification::NewLC() |
|
49 { |
|
50 // NewLC with two stage construct |
|
51 CNssTagSelectNotification* self=new (ELeave) CNssTagSelectNotification(); |
|
52 // get new, leave if can't |
|
53 CleanupStack::PushL(self); |
|
54 // push onto cleanup stack |
|
55 // (in case self->ConstructL leaves) |
|
56 self->ConstructL(); // use two-stage construct |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CNssTagSelectNotification::~CNssTagSelectNotification |
|
62 // Destructor |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CNssTagSelectNotification::~CNssTagSelectNotification() |
|
66 { |
|
67 RUBY_DEBUG0( "CNssTagSelectNotification::~CNssTagSelectNotification" ); |
|
68 |
|
69 if ( iDBTagSelectNotifier ) |
|
70 { |
|
71 iDBTagSelectNotifier->Deregister( this ); |
|
72 } |
|
73 |
|
74 if ( iTagSelectDataList ) |
|
75 { |
|
76 iTagSelectDataList->ResetAndDestroy(); |
|
77 delete iTagSelectDataList; |
|
78 } |
|
79 CNssVASDBBuilder::RemoveInstance(); // remove iVasDBBuilder instance |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CNssTagSelectNotification::RegisterL |
|
84 // Method to register for voice tag select notification. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 MNssTagSelectNotification::TNssSelectResult CNssTagSelectNotification::RegisterL( |
|
88 MNssContext* aContext, |
|
89 MNssTagSelectHandler* aTagSelectHandler ) |
|
90 { |
|
91 RUBY_DEBUG_BLOCK( "CNssTagSelectNotification::RegisterL" ); |
|
92 |
|
93 if ( iTagSelectDataList->Count() == 0 ) |
|
94 { |
|
95 // register ourself |
|
96 TInt dbErrorCode; |
|
97 dbErrorCode = iDBTagSelectNotifier->RegisterForNotification( this ); |
|
98 if ( dbErrorCode != KErrNone ) |
|
99 { |
|
100 return EVasSelectFailed; |
|
101 } |
|
102 } |
|
103 CNssTagSelectData* tagSelectData = CNssTagSelectData::NewL( (CNssContext *) aContext, |
|
104 aTagSelectHandler ); |
|
105 |
|
106 CleanupStack::PushL(tagSelectData); |
|
107 iTagSelectDataList->AppendL( tagSelectData ); |
|
108 CleanupStack::Pop(tagSelectData); // do not destroy tagSelectData; it is appended |
|
109 return EVasErrorNone; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CNssTagSelectNotification::Deregister |
|
114 // Method to deregister from voice tag select notification |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 MNssTagSelectNotification::TNssSelectResult CNssTagSelectNotification::Deregister( |
|
118 MNssContext* aContext, |
|
119 MNssTagSelectHandler* aTagSelectHandler ) |
|
120 { |
|
121 RUBY_DEBUG0( "CNssTagSelectNotification::Deregister" ); |
|
122 |
|
123 // if there is no registration, fail the deregister |
|
124 if ( iTagSelectDataList->Count() == 0 ) |
|
125 { |
|
126 return EVasSelectFailed; |
|
127 } |
|
128 |
|
129 // loop through the TagSelectDataList entries |
|
130 // for each context match, check if the event handler also matches |
|
131 // if yes, delete the entry |
|
132 for ( TInt index=0; index < iTagSelectDataList->Count(); index++ ) |
|
133 { |
|
134 |
|
135 TBool match = CompareContexts( (CNssContext *) aContext, index ); |
|
136 |
|
137 MNssTagSelectHandler* tagSelectHandler; |
|
138 tagSelectHandler = iTagSelectDataList->At( index )->TagSelectHandler(); |
|
139 |
|
140 if ( ( match == (TInt)ETrue ) && |
|
141 (aTagSelectHandler == tagSelectHandler)) |
|
142 { |
|
143 CNssTagSelectData* tagSelectData = iTagSelectDataList->At( index ); |
|
144 iTagSelectDataList->Delete( index ); |
|
145 delete tagSelectData; |
|
146 break; // exit the for loop |
|
147 } |
|
148 } |
|
149 if ( iTagSelectDataList->Count() == 0 ) |
|
150 { |
|
151 // deregister ourself |
|
152 TInt dbErrorCode; |
|
153 dbErrorCode = iDBTagSelectNotifier->Deregister( this ); |
|
154 if ( dbErrorCode != KErrNone ) |
|
155 { |
|
156 RUBY_DEBUG0( "CNssTagSelectNotification, DBTagSelectNotifier->Deregister failed" ); |
|
157 } |
|
158 } |
|
159 return EVasErrorNone; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CNssTagSelectNotification::HandleSelection |
|
164 // Method called into the client by CNssDBTagSelectNotifier |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CNssTagSelectNotification::HandleSelection(CNssTag* aTag) |
|
168 { |
|
169 RUBY_DEBUG0( "CNssTagSelectNotification::HandleSelection" ); |
|
170 |
|
171 // loop through the TagSelectDataList entries |
|
172 // for each context match, issue a HandleTagSelect response event |
|
173 for ( TInt index=0; index < iTagSelectDataList->Count(); index++ ) |
|
174 { |
|
175 TBool result = CompareContexts((CNssContext *)(aTag->Context()), index); |
|
176 if ( result == (TInt)ETrue ) |
|
177 { |
|
178 // make a copy of the tag for each client which registered for |
|
179 // the context of aTag |
|
180 // the client is responsible for deleting clientTag |
|
181 CNssTag* clientTag=NULL; |
|
182 TRAPD( err, ( clientTag = aTag->CopyL() ) ); |
|
183 if ( err != KErrNone ) |
|
184 { |
|
185 RUBY_DEBUG0( "CNssTagSelectNotification: TRAPD CNssTag CopyL failed" ); |
|
186 return; |
|
187 } |
|
188 |
|
189 iTagSelectDataList->At( index )->TagSelectHandler()-> |
|
190 HandleTagSelect( (MNssTag*)clientTag ); |
|
191 } |
|
192 } |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CNssTagSelectNotification::CNssTagSelectNotification |
|
197 // C++ default constructor can NOT contain any code, that |
|
198 // might leave. |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 CNssTagSelectNotification::CNssTagSelectNotification() |
|
202 { |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CNssTagSelectNotification::ConstructL |
|
207 // Symbian 2nd phase constructor can leave. |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CNssTagSelectNotification::ConstructL() |
|
211 { |
|
212 iTagSelectDataList = new (ELeave) CArrayPtrFlat<CNssTagSelectData>(1); |
|
213 |
|
214 iVasDBBuilder = CNssVASDBBuilder::InstanceL(); |
|
215 |
|
216 iDBTagSelectNotifier = iVasDBBuilder->GetTagSelectNotifier(); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CNssTagSelectNotification::CompareContexts |
|
221 // Method to compare a context with a TagSelectDataList entry context. |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 TBool CNssTagSelectNotification::CompareContexts( CNssContext* aContext, TInt aIndex ) |
|
225 { |
|
226 CNssContext* context; |
|
227 context = iTagSelectDataList->At( aIndex )->Context(); |
|
228 |
|
229 if ( context->ContextName().Compare( aContext->ContextName() )==0 ) |
|
230 { |
|
231 return ETrue; |
|
232 } |
|
233 else |
|
234 { |
|
235 return EFalse; |
|
236 } |
|
237 } |
|
238 |
|
239 // End of file |