|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * Main functionality of CHeadsetStatusObserver |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifdef __ACCESSORY_FW |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include "CHeadsetStatusObserver.h" |
|
25 #include "HeadsetStatus.h" |
|
26 |
|
27 #include <AccessoryMode.h> |
|
28 |
|
29 // UNNAMED NAMESPACE FOR LOCAL DEFINITIONS |
|
30 namespace |
|
31 { |
|
32 // CONSTANTS |
|
33 #ifdef _DEBUG |
|
34 _LIT( KPanicCat, "HeadsetStatusObserver" ); |
|
35 #endif |
|
36 // DATA TYPES |
|
37 enum TPanicCode |
|
38 { |
|
39 EAlreadyObserving, |
|
40 EInvalidObserver |
|
41 }; |
|
42 } |
|
43 |
|
44 // ========================= MEMBER FUNCTIONS ================================ |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // C++ constructor. |
|
48 // --------------------------------------------------------------------------- |
|
49 CHeadsetStatusObserver::CHeadsetStatusObserver( RAccessoryMode& aAccMode ): |
|
50 CActive( CActive::EPriorityStandard ), |
|
51 iAccMode( aAccMode ) |
|
52 { |
|
53 CActiveScheduler::Add( this ); |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CHeadsetStatusObserver::NewL |
|
58 // |
|
59 // Symbian OS two-phased constructor. |
|
60 // --------------------------------------------------------------------------- |
|
61 CHeadsetStatusObserver* CHeadsetStatusObserver::NewL( RAccessoryMode& aAccMode ) |
|
62 { |
|
63 CHeadsetStatusObserver* self = new ( ELeave ) |
|
64 CHeadsetStatusObserver( aAccMode ); |
|
65 |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop( self ); |
|
69 |
|
70 return self; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CHeadsetStatusObserver::ConstructL |
|
75 // |
|
76 // Symbian OS two-phased constructor. |
|
77 // --------------------------------------------------------------------------- |
|
78 void CHeadsetStatusObserver::ConstructL() |
|
79 { |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // C++ destructor |
|
84 // --------------------------------------------------------------------------- |
|
85 CHeadsetStatusObserver::~CHeadsetStatusObserver() |
|
86 { |
|
87 Cancel(); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CHeadsetStatusObserver::SetObserver |
|
92 // --------------------------------------------------------------------------- |
|
93 void CHeadsetStatusObserver::SetObserver( MHeadsetStatusObserver* aObserver ) |
|
94 { |
|
95 __ASSERT_DEBUG( aObserver, User::Panic( KPanicCat, EInvalidObserver ) ); |
|
96 |
|
97 iObserver = aObserver; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CHeadsetStatusObserver::StartObserving |
|
102 // --------------------------------------------------------------------------- |
|
103 void CHeadsetStatusObserver::StartObserving() |
|
104 { |
|
105 __ASSERT_DEBUG( !IsActive(), User::Panic( KPanicCat, EAlreadyObserving ) ); |
|
106 |
|
107 // Set iStatus to pending and request notifications |
|
108 iAccMode.NotifyAccessoryModeChanged( iStatus, iAccPolMode ); |
|
109 SetActive(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CHeadsetStatusObserver::RunL |
|
114 // --------------------------------------------------------------------------- |
|
115 void CHeadsetStatusObserver::RunL() |
|
116 { |
|
117 TInt err( iStatus.Int() ); |
|
118 if( err == KErrNone ) |
|
119 { |
|
120 // Notify observer |
|
121 NotifyObserverL(); |
|
122 } |
|
123 else |
|
124 { |
|
125 // Notify error |
|
126 NotifyObserverError( err ); |
|
127 } |
|
128 |
|
129 // continue observing |
|
130 StartObserving(); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CHeadsetStatusObserver::DoCancel |
|
135 // --------------------------------------------------------------------------- |
|
136 void CHeadsetStatusObserver::DoCancel() |
|
137 { |
|
138 // cancel acc mode changed notifications |
|
139 iAccMode.CancelNotifyAccessoryModeChanged(); |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CHeadsetStatusObserver::RunError |
|
144 // --------------------------------------------------------------------------- |
|
145 TInt CHeadsetStatusObserver::RunError( TInt aError ) |
|
146 { |
|
147 // error notified to observer |
|
148 NotifyObserverError( aError ); |
|
149 |
|
150 // continue observing |
|
151 StartObserving(); |
|
152 |
|
153 return KErrNone; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // CHeadsetStatusObserver::NotifyObserverL |
|
158 // --------------------------------------------------------------------------- |
|
159 void CHeadsetStatusObserver::NotifyObserverL() |
|
160 { |
|
161 __ASSERT_DEBUG( iObserver, User::Panic( KPanicCat, EInvalidObserver ) ); |
|
162 |
|
163 TBool connected( EFalse ); |
|
164 |
|
165 switch( iAccPolMode.iAccessoryMode ) |
|
166 { |
|
167 // Headset connected |
|
168 case EAccModeWiredHeadset: |
|
169 case EAccModeWirelessHeadset: |
|
170 case EAccModeLoopset: |
|
171 case EAccModeHeadphones: |
|
172 { |
|
173 connected = ETrue; |
|
174 break; |
|
175 } |
|
176 // Headset disconnected |
|
177 case EAccModeHandPortable: |
|
178 case EAccModeWiredCarKit: |
|
179 case EAccModeWirelessCarKit: |
|
180 case EAccModeTextDevice: |
|
181 case EAccModeMusicStand: |
|
182 default: |
|
183 { |
|
184 // nothing to do |
|
185 break; |
|
186 } |
|
187 } |
|
188 |
|
189 // notify observer |
|
190 iObserver->HeadsetStatusChangedL( connected ); |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CHeadsetStatusObserver::NotifyObserverError |
|
195 // --------------------------------------------------------------------------- |
|
196 void CHeadsetStatusObserver::NotifyObserverError( TInt aError ) |
|
197 { |
|
198 __ASSERT_DEBUG( iObserver, User::Panic( KPanicCat, EInvalidObserver ) ); |
|
199 |
|
200 iObserver->HeadsetStatusError( aError ); |
|
201 } |
|
202 #endif // __ACCESSORY_FW |
|
203 |
|
204 // End of File |