1 /* |
|
2 * Copyright (c) 2004-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: CNssAdaptationItem handles speaker adaptation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "nssvascadaptationitem.h" |
|
21 #include "rubydebug.h" |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CNssAdaptationItem::CNssAdaptationItem |
|
27 // C++ default constructor can NOT contain any code, that |
|
28 // might leave. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CNssAdaptationItem::CNssAdaptationItem( |
|
32 CNssRecognitionHandler* aRecHandlerHost, |
|
33 CSIClientResultSet* aRecResult) |
|
34 |
|
35 : iRecHandler( aRecHandlerHost ), |
|
36 iIsActive ( ETrue ), |
|
37 iAdaptationData( aRecResult ) |
|
38 |
|
39 { |
|
40 // Nothing |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CNssAdaptationItem::NewL |
|
45 // Two-phased constructor. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C CNssAdaptationItem* CNssAdaptationItem::NewL( CNssRecognitionHandler* aHandler, |
|
49 CSIClientResultSet* aResultSet ) |
|
50 { |
|
51 if ( !aHandler || !aResultSet ) |
|
52 { |
|
53 User::Leave( KErrArgument ); |
|
54 } |
|
55 |
|
56 CNssAdaptationItem* self = new( ELeave ) CNssAdaptationItem( aHandler, aResultSet ); |
|
57 |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CNssAdaptationItem::~CNssAdaptationItem |
|
63 // Destructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CNssAdaptationItem::~CNssAdaptationItem() |
|
67 { |
|
68 if ( iAdaptationData ) |
|
69 { |
|
70 delete iAdaptationData; |
|
71 iAdaptationData = 0; |
|
72 } |
|
73 |
|
74 // Announce for the host recognition handler, that we no longer exist. |
|
75 if ( iRecHandler ) |
|
76 { |
|
77 iRecHandler->RemoveAdaptationItem( this ); |
|
78 } |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CNssAdaptationItem::AdaptL |
|
83 // Starts adaptation. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 EXPORT_C void CNssAdaptationItem::AdaptL( MNssAdaptationEventHandler* aHandler, |
|
87 TInt aCorrect ) |
|
88 { |
|
89 // This can happen, if the client has deleted the recognition handler. |
|
90 if ( !iRecHandler ) |
|
91 { |
|
92 User::Leave( KErrNotReady ); |
|
93 } |
|
94 |
|
95 iRecHandler->AdaptL( aHandler, iAdaptationData, aCorrect ); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CNssAdaptationItem::AdaptL |
|
100 // Starts adaptation based on tag |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C void CNssAdaptationItem::AdaptL( MNssAdaptationEventHandler* aHandler, |
|
104 MNssTag& aTag ) |
|
105 { |
|
106 TInt correctIndex( KErrNotFound ); |
|
107 |
|
108 CNssSpeechItem* speechItem = static_cast<CNssSpeechItem*>( aTag.SpeechItem() ); |
|
109 CNssContext* context = static_cast<CNssContext*>( aTag.Context() ); |
|
110 |
|
111 // Find the index for the correct result |
|
112 for ( TInt iCounter = 0; iCounter < iAdaptationData->ResultCount(); iCounter++ ) |
|
113 { |
|
114 const CSIClientResult& result = iAdaptationData->AtL( iCounter ); |
|
115 if ( ( result.GrammarID() == context->GrammarId() ) && ( result.RuleID() == speechItem->RuleID() ) ) |
|
116 { |
|
117 correctIndex = iCounter; |
|
118 } |
|
119 } |
|
120 |
|
121 // Leave with KErrNotFound if no match in grammar id and rule id |
|
122 User::LeaveIfError( correctIndex ); |
|
123 |
|
124 AdaptL( aHandler, correctIndex ); |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CNssAdaptationItem::Disable |
|
129 // Host recognition handler calls this function, when it is destroyed. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 EXPORT_C void CNssAdaptationItem::Disable() |
|
133 { |
|
134 if ( iIsActive ) |
|
135 { |
|
136 RUBY_DEBUG0( "CNssAdaptationItem::Disable() is active" ); |
|
137 |
|
138 delete iAdaptationData; |
|
139 iAdaptationData = 0; |
|
140 |
|
141 iRecHandler = 0; |
|
142 |
|
143 iIsActive = EFalse; |
|
144 } |
|
145 } |
|
146 |
|
147 // End of File |
|