|
1 /* |
|
2 * Copyright (c) 2007 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: Generates DTMF events in Inband DTMF |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "svpdtmfeventgenerator.h" |
|
20 #include "svplogger.h" |
|
21 #include "svpdtmfeventobserver.h" |
|
22 |
|
23 const TInt KSvpNormalEventInterval = 300000; |
|
24 // Pause character ('p') interval is 2500 ms |
|
25 const TInt KSvpPauseEventInterval = 2500000; |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CSVPDTMFEventGenerator::CSVPDTMFEventGenerator |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CSVPDTMFEventGenerator::CSVPDTMFEventGenerator( |
|
32 MSVPDTMFEventObserver& aObserver ): |
|
33 |
|
34 CActive( EPriorityStandard ), |
|
35 iObserver( aObserver ) |
|
36 { |
|
37 // add object to active scheduler |
|
38 CActiveScheduler::Add( this ); |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CSVPDTMFEventGenerator::CSVPDTMFEventGenerator |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void CSVPDTMFEventGenerator::ConstructL() |
|
46 { |
|
47 // create timer |
|
48 User::LeaveIfError( iTimer.CreateLocal() ); |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CSVPDTMFEventGenerator::CSVPDTMFEventGenerator |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CSVPDTMFEventGenerator* CSVPDTMFEventGenerator::NewL( |
|
56 MSVPDTMFEventObserver& aObserver ) |
|
57 { |
|
58 CSVPDTMFEventGenerator* self = |
|
59 new ( ELeave ) CSVPDTMFEventGenerator( aObserver ); |
|
60 |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop( self ); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CSVPDTMFEventGenerator::~CSVPDTMFEventGenerator |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CSVPDTMFEventGenerator::~CSVPDTMFEventGenerator() |
|
73 { |
|
74 // cancel outgoing requests and close timer |
|
75 Cancel(); |
|
76 iTimer.Close(); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CSVPDTMFEventGenerator::RunL |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CSVPDTMFEventGenerator::RunL() |
|
84 { |
|
85 SVPDEBUG2( "CSVPDTMFEventGenerator::RunL tick: %u", User::TickCount() ) |
|
86 SVPDEBUG2( "CSVPDTMFEventGenerator::RunL iStatus: %d", iStatus.Int() ) |
|
87 SVPDEBUG2( "CSVPDTMFEventGenerator::RunL iStringLength: %d", iStringLength ) |
|
88 |
|
89 if ( KErrNone == iStatus.Int() ) |
|
90 { |
|
91 if ( !iStartSent && iStringLength ) |
|
92 { |
|
93 iObserver.InbandDtmfEventOccurred( ESvpDtmfSendStarted ); |
|
94 iStartSent = ETrue; |
|
95 iStringLength--; |
|
96 TTimeIntervalMicroSeconds32 delay; |
|
97 if ( iPause ) |
|
98 { |
|
99 delay = KSvpPauseEventInterval; |
|
100 iPause = EFalse; |
|
101 } |
|
102 else |
|
103 { |
|
104 delay = KSvpNormalEventInterval; |
|
105 } |
|
106 if ( !IsActive() ) |
|
107 { |
|
108 iTimer.After ( iStatus, delay ); |
|
109 SetActive(); |
|
110 } |
|
111 } |
|
112 else |
|
113 { |
|
114 iObserver.InbandDtmfEventOccurred( ESvpDtmfSendStopped ); |
|
115 iStartSent = EFalse; |
|
116 |
|
117 if ( iStringLength ) |
|
118 { |
|
119 TTimeIntervalMicroSeconds32 delay = KSvpNormalEventInterval; |
|
120 if ( !IsActive() ) |
|
121 { |
|
122 iTimer.After ( iStatus, delay ); |
|
123 SetActive(); |
|
124 } |
|
125 } |
|
126 else |
|
127 { |
|
128 iObserver.InbandDtmfEventOccurred( ESvpDtmfSendCompleted ); |
|
129 } |
|
130 } |
|
131 } |
|
132 else |
|
133 { |
|
134 User::Leave( iStatus.Int() ); |
|
135 } |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CSVPDTMFEventGenerator::StartDtmfEvents |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CSVPDTMFEventGenerator::StartDtmfEvents( TInt aStringLength, TBool aPause ) |
|
143 { |
|
144 SVPDEBUG1("CSVPDTMFEventGenerator::StartDtmfEvents In"); |
|
145 Cancel(); |
|
146 // Give the time to CTimer as microseconds |
|
147 // event interval is default => 300ms |
|
148 if ( aStringLength ) |
|
149 { |
|
150 // save string length |
|
151 iStringLength = aStringLength; |
|
152 iPause = aPause; |
|
153 iTimer.After( iStatus, KSvpNormalEventInterval ); |
|
154 SetActive(); |
|
155 } |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CSVPDTMFEventGenerator::DoCancel |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CSVPDTMFEventGenerator::DoCancel() |
|
163 { |
|
164 SVPDEBUG1( "CSVPDTMFEventGenerator::DoCancel" ) |
|
165 iStringLength = 0; |
|
166 iStartSent = EFalse; |
|
167 iPause = EFalse; |
|
168 iTimer.Cancel(); |
|
169 } |
|
170 |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CSVPDTMFEventGenerator::StopEvents |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CSVPDTMFEventGenerator::StopEvents() |
|
177 { |
|
178 SVPDEBUG1("CSVPDTMFEventGenerator::StopEvents In"); |
|
179 // Always call through Cancel() as it will |
|
180 // cancel the request in the scheduler and then it will call DoCancel() |
|
181 Cancel(); |
|
182 } |
|
183 |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // CSVPDTMFEventGenerator::RunError |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 TInt CSVPDTMFEventGenerator::RunError( TInt aError ) |
|
190 { |
|
191 SVPDEBUG2( "CSVPDTMFEventGenerator::RunError aError: %d", aError ) |
|
192 |
|
193 return aError; |
|
194 } |
|
195 |
|
196 // End of File |