|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Monitors the Tv Out Connection |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 * @internal reviewed 24/08/2007 by D Holland |
|
22 */ |
|
23 |
|
24 // CLASS HEADER |
|
25 #include "glxtvconnectionmonitor.h" |
|
26 |
|
27 // EXTERNAL INCLUDES |
|
28 |
|
29 // INTERNAL INCLUDES |
|
30 |
|
31 #include <glxlog.h> |
|
32 #include <glxpanic.h> |
|
33 #include "glxtv.h" |
|
34 #include <AccPolGenericIdDefinitions.h> |
|
35 #include <AccPolSubblockNameArray.h> |
|
36 //----------------------------------------------------------------------------- |
|
37 // Return new object |
|
38 //----------------------------------------------------------------------------- |
|
39 // |
|
40 CGlxTvConnectionMonitor* CGlxTvConnectionMonitor::NewL( |
|
41 MGlxTvConnectionObserver& aConnectionObserver ) |
|
42 { |
|
43 GLX_LOG_INFO("CGlxTvConnectionMonitor::NewL"); |
|
44 CGlxTvConnectionMonitor* self = new (ELeave) |
|
45 CGlxTvConnectionMonitor( aConnectionObserver ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 |
|
53 //----------------------------------------------------------------------------- |
|
54 // Destructor |
|
55 //----------------------------------------------------------------------------- |
|
56 // |
|
57 CGlxTvConnectionMonitor::~CGlxTvConnectionMonitor() |
|
58 { |
|
59 GLX_LOG_INFO("~CGlxTvConnectionMonitor"); |
|
60 Cancel(); |
|
61 iTvAccCon.CloseSubSession(); |
|
62 iTvAccServer.Disconnect(); |
|
63 } |
|
64 |
|
65 |
|
66 //----------------------------------------------------------------------------- |
|
67 // Default C++ constructor |
|
68 //----------------------------------------------------------------------------- |
|
69 // |
|
70 CGlxTvConnectionMonitor::CGlxTvConnectionMonitor |
|
71 ( MGlxTvConnectionObserver& aConnectionObserver ) |
|
72 :CActive(EPriorityStandard), |
|
73 iConnectionObserver ( aConnectionObserver ) |
|
74 { |
|
75 GLX_LOG_INFO("CGlxTvConnectionMonitor"); |
|
76 CActiveScheduler::Add( this ); |
|
77 } |
|
78 |
|
79 |
|
80 //----------------------------------------------------------------------------- |
|
81 // Symbian second phase constructor |
|
82 //----------------------------------------------------------------------------- |
|
83 // |
|
84 void CGlxTvConnectionMonitor::ConstructL() |
|
85 { |
|
86 GLX_LOG_INFO("CGlxTvConnectionMonitor::ConstructL"); |
|
87 User::LeaveIfError(iTvAccServer.Connect()); |
|
88 User::LeaveIfError(iTvAccCon.CreateSubSession(iTvAccServer)); |
|
89 User::LeaveIfError(iTvAccCon.GetAccessoryConnectionStatus(iCurrentAccArray)); |
|
90 for (int i = 0; i < iCurrentAccArray.Count(); i++) |
|
91 { |
|
92 iTvOutConnectionState |
|
93 = (iCurrentAccArray.GetGenericIDL(i).PhysicalConnectionCaps() |
|
94 == KPCWired); |
|
95 iHDMIConnectionState |
|
96 = (iCurrentAccArray.GetGenericIDL(i).PhysicalConnectionCaps() |
|
97 == KPCHDMI); |
|
98 } |
|
99 IssueRequest(); |
|
100 } |
|
101 |
|
102 //----------------------------------------------------------------------------- |
|
103 // From class CActive. |
|
104 // Receive notification of change in the connection state |
|
105 //----------------------------------------------------------------------------- |
|
106 // |
|
107 void CGlxTvConnectionMonitor::RunL() |
|
108 { |
|
109 GLX_LOG_INFO("CGlxTvConnectionMonitor::RunL"); |
|
110 // Check for errors |
|
111 User::LeaveIfError( iStatus.Int() ); |
|
112 // Notify observers |
|
113 IssueNotificationL(); |
|
114 // Request the next event |
|
115 IssueRequest(); |
|
116 } |
|
117 |
|
118 |
|
119 //----------------------------------------------------------------------------- |
|
120 // From class CActive. |
|
121 // DoCancel |
|
122 //----------------------------------------------------------------------------- |
|
123 // |
|
124 void CGlxTvConnectionMonitor::DoCancel() |
|
125 { |
|
126 GLX_LOG_INFO("CGlxTvConnectionMonitor::DoCancel"); |
|
127 iTvAccCon.CancelGetAccessoryConnectionStatus(); |
|
128 iTvAccCon.CancelNotifyAccessoryConnectionStatusChanged(); |
|
129 } |
|
130 |
|
131 |
|
132 |
|
133 //----------------------------------------------------------------------------- |
|
134 // From class CActive. |
|
135 // RunError |
|
136 //----------------------------------------------------------------------------- |
|
137 // |
|
138 TInt CGlxTvConnectionMonitor::RunError(TInt aError) |
|
139 { |
|
140 GLX_LOG_INFO1("CGlxTvConnectionMonitor::RunError - %d", aError); |
|
141 return KErrNone; |
|
142 } |
|
143 |
|
144 //----------------------------------------------------------------------------- |
|
145 // Is the TV out cable connected |
|
146 // IsConnected |
|
147 //----------------------------------------------------------------------------- |
|
148 // |
|
149 TBool CGlxTvConnectionMonitor::IsConnected() const |
|
150 { |
|
151 GLX_LOG_INFO("CGlxTvConnectionMonitor::IsConnected"); |
|
152 GLX_LOG_INFO1("CGlxTvConnectionMonitor::IsConnected iTvOutConnectionState=%d",iTvOutConnectionState); |
|
153 return iTvOutConnectionState; |
|
154 } |
|
155 |
|
156 //----------------------------------------------------------------------------- |
|
157 // Is the TV out cable connected |
|
158 // IsConnected |
|
159 //----------------------------------------------------------------------------- |
|
160 // |
|
161 TBool CGlxTvConnectionMonitor::IsHDMIConnected() const |
|
162 { |
|
163 GLX_LOG_INFO("CGlxTvConnectionMonitor::IsHDMIConnected"); |
|
164 GLX_LOG_INFO1("CGlxTvConnectionMonitor::IsHDMIConnected iHDMIConnectionState=%d",iHDMIConnectionState); |
|
165 return iHDMIConnectionState; |
|
166 } |
|
167 |
|
168 //----------------------------------------------------------------------------- |
|
169 // Request accessory server events |
|
170 //----------------------------------------------------------------------------- |
|
171 // |
|
172 void CGlxTvConnectionMonitor::IssueRequest() |
|
173 { |
|
174 GLX_LOG_INFO("CGlxTvConnectionMonitor::IssueRequest"); |
|
175 if (!IsActive()) // required for testing |
|
176 { |
|
177 iTvAccCon.NotifyAccessoryConnectionStatusChanged(iStatus,iCurrentAccArray); |
|
178 SetActive(); |
|
179 } |
|
180 } |
|
181 |
|
182 |
|
183 //----------------------------------------------------------------------------- |
|
184 // Sends notification to observers if TV Out is connected |
|
185 //----------------------------------------------------------------------------- |
|
186 // |
|
187 void CGlxTvConnectionMonitor::IssueNotificationL() |
|
188 { |
|
189 GLX_LOG_INFO("CGlxTvConnectionMonitor::IssueNotificationL"); |
|
190 TBool previousTvState = iTvOutConnectionState; |
|
191 TBool previousHDMIState = iHDMIConnectionState; |
|
192 GLX_LOG_INFO2("previousTvState = %d , previousHDMIState = %d", |
|
193 previousTvState,previousHDMIState); |
|
194 |
|
195 //gets the TV status in to the iCurrentAccArray and haves the Latest Accesory in 0-index |
|
196 User::LeaveIfError(iTvAccCon.GetAccessoryConnectionStatus(iCurrentAccArray)); |
|
197 |
|
198 CAccPolSubblockNameArray* nameArray = CAccPolSubblockNameArray::NewL(); |
|
199 CleanupStack::PushL(nameArray); |
|
200 |
|
201 // |
|
202 // Get the number of currently connected accessories |
|
203 // Loop through each connected accessory looking for |
|
204 // the desired capabilities |
|
205 // |
|
206 iTvOutConnectionState = EFalse; |
|
207 iHDMIConnectionState = EFalse; |
|
208 const TInt count = iCurrentAccArray.Count(); |
|
209 for (TInt index = 0; index < count; index++) |
|
210 { |
|
211 TAccPolGenericID genId = iCurrentAccArray.GetGenericIDL(index); |
|
212 // Get all supported capabilities for this connected accessory. |
|
213 iTvAccCon.GetSubblockNameArrayL(genId, *nameArray); |
|
214 // Check if this connected accessory supports TV-Out capabality. |
|
215 if (nameArray->HasName(KAccVideoOut)) |
|
216 { |
|
217 GLX_LOG_INFO("TV-Out Capabilities Exist"); |
|
218 TAccPolNameRecord nameRecord; |
|
219 nameRecord.SetNameL(KAccVideoOut); |
|
220 TAccValueTypeTInt value; |
|
221 iTvAccCon.GetValueL(genId, nameRecord, value); |
|
222 if (value.iValue == EAccVideoOutEHDMI) |
|
223 { |
|
224 GLX_LOG_INFO("HDMI is connected Capabilities Exist"); |
|
225 iHDMIConnectionState = ETrue; |
|
226 break; |
|
227 } |
|
228 else if (value.iValue == EAccVideoOutCVideo) |
|
229 { |
|
230 GLX_LOG_INFO("TV is connected Capabilities Exist"); |
|
231 iTvOutConnectionState = ETrue; |
|
232 break; |
|
233 } |
|
234 } |
|
235 |
|
236 } |
|
237 CleanupStack::PopAndDestroy(nameArray); |
|
238 |
|
239 if (previousTvState != iTvOutConnectionState || previousHDMIState |
|
240 != iHDMIConnectionState) |
|
241 { |
|
242 GLX_LOG_INFO("CGlxTvConnectionMonitor::IssueNotificationL -" |
|
243 " TvConnectionStatusChanged"); |
|
244 GLX_LOG_INFO2("CurrentTvState = %d , CurrentHDMIState = %d", |
|
245 iTvOutConnectionState,iHDMIConnectionState); |
|
246 iConnectionObserver.HandleTvConnectionStatusChangedL(); |
|
247 } |
|
248 } |
|
249 |
|
250 |
|
251 |
|
252 |