|
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: SVP telephony volume observer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 #include <TelephonyAudioRouting.h> |
|
21 #include <telephonydomaincrkeys.h> |
|
22 |
|
23 #include "svpvolumeobserver.h" |
|
24 #include "svplogger.h" |
|
25 #include "svpvolumeupdateobserver.h" |
|
26 |
|
27 // Default volume for initialization |
|
28 const TInt KDefaultVolume = 4; |
|
29 |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CSVPVolumeObserver::CSVPVolumeObserver |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CSVPVolumeObserver::CSVPVolumeObserver( MSVPVolumeUpdateObserver& aObserver ) |
|
36 : iCurrentIhfVolume( KDefaultVolume ), iCurrentEarVolume( KDefaultVolume ), |
|
37 iMode( CTelephonyAudioRouting::EHandset ), iRepository( NULL ), |
|
38 iVolumeUpdate( aObserver ) |
|
39 { |
|
40 SVPDEBUG1("CSVPVolumeObserver::CSVPVolumeObserver()"); |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CSVPVolumeObserver::ConstructL |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 void CSVPVolumeObserver::ConstructL() |
|
48 { |
|
49 iRepository = CRepository::NewL( KCRUidInCallVolume ); |
|
50 iNotifier = CCenRepNotifyHandler::NewL( *this, *iRepository ); |
|
51 |
|
52 // Get the current EAR volume from repository |
|
53 User::LeaveIfError( |
|
54 iRepository->Get( KTelIncallEarVolume, iCurrentEarVolume ) ); |
|
55 |
|
56 // Get the current IHF volume from repository |
|
57 User::LeaveIfError( iRepository->Get( KTelIncallLoudspeakerVolume, |
|
58 iCurrentIhfVolume ) ); |
|
59 |
|
60 // create instance of telephony audio routing for tracking mode changes |
|
61 iTelephonyAudioRouting = CTelephonyAudioRouting::NewL( *this ); |
|
62 |
|
63 SVPDEBUG2("CSVPVolumeObserver::ConstructL iCurrentIhfVolume: %d", |
|
64 iCurrentIhfVolume ); |
|
65 SVPDEBUG2("CSVPVolumeObserver::ConstructL iCurrentEarVolume: %d", |
|
66 iCurrentEarVolume ); |
|
67 |
|
68 iNotifier->StartListeningL(); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CSVPVolumeObserver::NewL |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CSVPVolumeObserver* CSVPVolumeObserver::NewL( |
|
76 MSVPVolumeUpdateObserver& aObserver ) |
|
77 { |
|
78 CSVPVolumeObserver* self = new( ELeave ) CSVPVolumeObserver( aObserver ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop( self ); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CSVPVolumeObserver::~CSVPVolumeObserver |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CSVPVolumeObserver::~CSVPVolumeObserver() |
|
90 { |
|
91 if ( iNotifier ) |
|
92 { |
|
93 iNotifier->StopListening(); |
|
94 } |
|
95 |
|
96 delete iNotifier; |
|
97 delete iRepository; |
|
98 delete iTelephonyAudioRouting; |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CSVPVolumeObserver::HandleNotifyGeneric |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CSVPVolumeObserver::HandleNotifyGeneric( TUint32 aId ) |
|
106 { |
|
107 SVPDEBUG1("CSVPVolumeObserver::HandleNotifyGeneric() In"); |
|
108 TInt error = KErrArgument; |
|
109 |
|
110 if ( KTelIncallEarVolume == aId ) |
|
111 { |
|
112 error = iRepository->Get( KTelIncallEarVolume, iCurrentEarVolume ); |
|
113 |
|
114 SVPDEBUG2("CSVPVolumeObserver::HandleNotifyGeneric EAR VOL: %d", |
|
115 iCurrentEarVolume ); |
|
116 } |
|
117 else if ( KTelIncallLoudspeakerVolume == aId ) |
|
118 { |
|
119 error = iRepository->Get( KTelIncallLoudspeakerVolume, |
|
120 iCurrentIhfVolume ); |
|
121 |
|
122 SVPDEBUG2("CSVPVolumeObserver::HandleNotifyGeneric IHF VOL: %d", |
|
123 iCurrentIhfVolume ); |
|
124 } |
|
125 // else we are not interested in this notification. Note that we set error |
|
126 // to be KErrArgument and thus we do not set volume if aId is not what |
|
127 // we accept it to be. |
|
128 |
|
129 if( KErrNone == error ) |
|
130 { |
|
131 // Handle volume so that everything else is like earpiece but |
|
132 // loudspeaker. |
|
133 TInt volume = KDefaultVolume; |
|
134 if ( CTelephonyAudioRouting::ELoudspeaker == iMode ) |
|
135 { |
|
136 volume = iCurrentIhfVolume; |
|
137 } |
|
138 else |
|
139 { |
|
140 volume = iCurrentEarVolume; |
|
141 } |
|
142 |
|
143 // volume update |
|
144 iVolumeUpdate.VolumeChanged( volume ); |
|
145 } |
|
146 |
|
147 SVPDEBUG2("CSVPVolumeObserver::HandleNotifyGeneric ERROR: %d", error ); |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CSVPVolumeObserver::OutputChanged |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CSVPVolumeObserver::OutputChanged( |
|
155 CTelephonyAudioRouting& aTelephonyAudioRouting ) |
|
156 { |
|
157 SVPDEBUG1("CSVPVolumeObserver::OutputChanged In"); |
|
158 |
|
159 // Only unique audio route is the loudspeaker. |
|
160 if ( CTelephonyAudioRouting::ELoudspeaker == |
|
161 aTelephonyAudioRouting.Output() ) |
|
162 { |
|
163 SVPDEBUG1("CSVPVolumeObserver::OutputChanged to LOUDSPEAKER"); |
|
164 iMode = CTelephonyAudioRouting::ELoudspeaker; |
|
165 iVolumeUpdate.VolumeChanged( iCurrentIhfVolume ); |
|
166 } |
|
167 else |
|
168 { |
|
169 // in other cases apply earpiece volume level. |
|
170 SVPDEBUG2("CSVPVolumeObserver::OutputChanged to %d", |
|
171 aTelephonyAudioRouting.Output() ); |
|
172 |
|
173 iMode = CTelephonyAudioRouting::EHandset; |
|
174 iVolumeUpdate.VolumeChanged( iCurrentEarVolume ); |
|
175 } |
|
176 |
|
177 SVPDEBUG1("CSVPVolumeObserver::OutputChanged Out"); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CSVPVolumeObserver::SetOutputComplete |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 void CSVPVolumeObserver::SetOutputComplete( |
|
185 CTelephonyAudioRouting& /*aTelephonyAudioRouting*/, TInt /*aError*/ ) |
|
186 { |
|
187 // no operations |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CSVPVolumeObserver::AvailableOutputsChanged |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void CSVPVolumeObserver::AvailableOutputsChanged( |
|
195 CTelephonyAudioRouting& /*aTelephonyAudioRouting*/ ) |
|
196 { |
|
197 // no operations |
|
198 } |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |