46
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: Observer of accessory connection.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "fmradiovariant.hrh" // include first for variation
|
|
18 |
#include <AccessoryServer.h>
|
|
19 |
#include <AccessoryConnection.h>
|
|
20 |
#include <AccPolGenericID.h>
|
|
21 |
#include <AccPolGenericIDArray.h>
|
|
22 |
#include <AccPolGenericIdDefinitions.h>
|
|
23 |
|
|
24 |
#include "fmradioaccessoryconnection.h"
|
|
25 |
#include "fmradioheadseteventobserver.h"
|
|
26 |
#include "debug.h"
|
|
27 |
|
|
28 |
#ifdef __FMRADIO_ADVANCED_AUTO_RESUME // same flag can be used to determine correct mask
|
|
29 |
#include <internal/accpolpropgenericid.h>
|
|
30 |
const TUint KPhysicalConnectionBitmask = KPCNokiaAV | KPCWired;
|
|
31 |
#else
|
|
32 |
const TUint KPhysicalConnectionBitmask = KPCWired;
|
|
33 |
#endif // __FMRADIO_ADVANCED_AUTO_RESUME
|
|
34 |
|
|
35 |
// ---------------------------------------------------------------------------
|
|
36 |
// CFMRadioAccessoryConnection::CFMRadioAccessoryConnection
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
CFMRadioAccessoryConnection::CFMRadioAccessoryConnection() :
|
|
40 |
CActive(EPriorityStandard), iObserver ( NULL ),
|
|
41 |
iWiredHeadsetConnected ( EFalse ), iAccessoryCount( 0 )
|
|
42 |
{
|
|
43 |
}
|
|
44 |
|
|
45 |
// ---------------------------------------------------------------------------
|
|
46 |
// CFMRadioAccessoryConnection::NewL
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
//
|
|
49 |
CFMRadioAccessoryConnection* CFMRadioAccessoryConnection::NewL()
|
|
50 |
{
|
|
51 |
CFMRadioAccessoryConnection* self = new (ELeave) CFMRadioAccessoryConnection();
|
|
52 |
CleanupStack::PushL(self);
|
|
53 |
self->ConstructL();
|
|
54 |
CleanupStack::Pop(); // self;
|
|
55 |
return self;
|
|
56 |
}
|
|
57 |
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
// CFMRadioAccessoryConnection::ConstructL
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
void CFMRadioAccessoryConnection::ConstructL()
|
|
63 |
{
|
|
64 |
FTRACE( FPrint(_L("CFMRadioAccessoryConnection::ConstructL() -- ENTER") ) )
|
|
65 |
|
|
66 |
// Creates a new session and sub-session.
|
|
67 |
User::LeaveIfError( iAccessoryServer.Connect() );
|
|
68 |
User::LeaveIfError( iAccessoryConnection.CreateSubSession( iAccessoryServer ) );
|
|
69 |
User::LeaveIfError( iAccessoryConnection.GetAccessoryConnectionStatus( iAccessoryArray ) );
|
|
70 |
|
|
71 |
iWiredHeadsetConnected = WiredHeadsetInArrayL();
|
|
72 |
iAccessoryCount = iAccessoryArray.Count();
|
|
73 |
CActiveScheduler::Add(this); // Add to scheduler
|
|
74 |
|
|
75 |
iAccessoryConnection.NotifyAccessoryConnectionStatusChanged( iStatus, iAccessoryArray );
|
|
76 |
SetActive(); // Tell scheduler a request is active
|
|
77 |
}
|
|
78 |
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
// CFMRadioAccessoryConnection::~CFMRadioAccessoryConnection
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
CFMRadioAccessoryConnection::~CFMRadioAccessoryConnection()
|
|
84 |
{
|
|
85 |
Cancel(); // Cancel any request, if outstanding
|
|
86 |
iAccessoryConnection.CloseSubSession();
|
|
87 |
iAccessoryServer.Close();
|
|
88 |
}
|
|
89 |
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
// CFMRadioAccessoryConnection::DoCancel
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
void CFMRadioAccessoryConnection::DoCancel()
|
|
95 |
{
|
|
96 |
iAccessoryConnection.CancelNotifyAccessoryConnectionStatusChanged();
|
|
97 |
}
|
|
98 |
|
|
99 |
// ---------------------------------------------------------------------------
|
|
100 |
// CFMRadioAccessoryConnection::WiredHeadsetInArrayL
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
TBool CFMRadioAccessoryConnection::WiredHeadsetInArrayL()
|
|
104 |
{
|
|
105 |
FTRACE(FPrint(_L("CFMRadioAccessoryConnection::WiredHeadsetInArray()-- ENTER")));
|
|
106 |
TAccPolGenericID genId;
|
|
107 |
TUint32 devCaps;
|
|
108 |
TUint32 phyCaps;
|
|
109 |
|
|
110 |
for ( TInt i = 0; i < iAccessoryArray.Count(); i++ )
|
|
111 |
{
|
|
112 |
genId = iAccessoryArray.GetGenericIDL( i );
|
|
113 |
devCaps = genId.DeviceTypeCaps();
|
|
114 |
phyCaps = genId.PhysicalConnectionCaps();
|
|
115 |
FTRACE(FPrint(_L("CFMRadioAccessoryConnection::devCaps-- %u"), devCaps ));
|
|
116 |
FTRACE(FPrint(_L("CFMRadioAccessoryConnection::phyCaps()-- %u"), phyCaps ));
|
|
117 |
|
|
118 |
//we're explicitly interested about wired headset type, without extra caps masked in
|
|
119 |
if ( devCaps == KDTHeadset && phyCaps == KPhysicalConnectionBitmask )
|
|
120 |
{
|
|
121 |
return ETrue;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
return EFalse;
|
|
125 |
}
|
|
126 |
|
|
127 |
// ---------------------------------------------------------------------------
|
|
128 |
// CFMRadioAccessoryConnection::WiredHeadsetConnected
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
TBool CFMRadioAccessoryConnection::WiredHeadsetConnected()
|
|
132 |
{
|
|
133 |
#ifdef __WINS__
|
|
134 |
return ETrue;
|
|
135 |
#else
|
|
136 |
return iWiredHeadsetConnected;
|
|
137 |
#endif
|
|
138 |
}
|
|
139 |
|
|
140 |
// ---------------------------------------------------------------------------
|
|
141 |
// CFMRadioAccessoryConnection::WiredHeadsetFirstInArray
|
|
142 |
// ---------------------------------------------------------------------------
|
|
143 |
//
|
|
144 |
TBool CFMRadioAccessoryConnection::WiredHeadsetFirstInArrayL()
|
|
145 |
{
|
|
146 |
FTRACE(FPrint(_L("CFMRadioAccessoryConnection::WiredHeadsetFirstInArrayL()-- ENTER")));
|
|
147 |
if ( iAccessoryArray.Count() > 0 )
|
|
148 |
{
|
|
149 |
TAccPolGenericID genId = iAccessoryArray.GetGenericIDL( 0 );
|
|
150 |
|
|
151 |
TUint32 devCaps = genId.DeviceTypeCaps();
|
|
152 |
TUint32 phyCaps = genId.PhysicalConnectionCaps();
|
|
153 |
|
|
154 |
FTRACE(FPrint(_L("CFMRadioAccessoryConnection::devCaps-- %u"), devCaps ));
|
|
155 |
FTRACE(FPrint(_L("CFMRadioAccessoryConnection::phyCaps-- %u"), phyCaps ));
|
|
156 |
|
|
157 |
//we're explicitly interested about wired headset type, without extra caps masked in
|
|
158 |
if ( devCaps == KDTHeadset && phyCaps == KPhysicalConnectionBitmask )
|
|
159 |
{
|
|
160 |
return ETrue;
|
|
161 |
}
|
|
162 |
}
|
|
163 |
return EFalse;
|
|
164 |
}
|
|
165 |
|
|
166 |
// ---------------------------------------------------------------------------
|
|
167 |
// CFMRadioAccessoryConnection::RunL
|
|
168 |
// ---------------------------------------------------------------------------
|
|
169 |
//
|
|
170 |
void CFMRadioAccessoryConnection::RunL()
|
|
171 |
{
|
|
172 |
FTRACE(FPrint(_L("CFMRadioAccessoryConnection::RunL()-- ENTER")));
|
|
173 |
if ( iStatus == KErrNone )
|
|
174 |
{
|
|
175 |
if ( iAccessoryCount < iAccessoryArray.Count() )
|
|
176 |
{ //accessory has been added
|
|
177 |
if ( WiredHeadsetFirstInArrayL() ) //and it is a wired headset
|
|
178 |
{
|
|
179 |
iWiredHeadsetConnected = ETrue;
|
|
180 |
if ( iObserver )
|
|
181 |
{
|
|
182 |
iObserver->HeadsetAccessoryConnectedCallbackL();
|
|
183 |
}
|
|
184 |
}
|
|
185 |
}
|
|
186 |
else
|
|
187 |
{ //accessory has been removed
|
|
188 |
if ( !WiredHeadsetInArrayL() ) // and it is a wired headset
|
|
189 |
{
|
|
190 |
iWiredHeadsetConnected = EFalse;
|
|
191 |
if ( iObserver )
|
|
192 |
{
|
|
193 |
iObserver->HeadsetAccessoryDisconnectedCallbackL();
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|
|
197 |
iAccessoryCount = iAccessoryArray.Count();
|
|
198 |
}
|
|
199 |
//reassign the notification request
|
|
200 |
iAccessoryConnection.NotifyAccessoryConnectionStatusChanged( iStatus, iAccessoryArray );
|
|
201 |
SetActive(); // Tell scheduler a request is active
|
|
202 |
FTRACE(FPrint(_L("CFMRadioAccessoryConnection::RunL()-- EXIT")));
|
|
203 |
}
|
|
204 |
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
// CFMRadioAccessoryConnection::SetObserver
|
|
207 |
// ---------------------------------------------------------------------------
|
|
208 |
//
|
|
209 |
void CFMRadioAccessoryConnection::SetObserver( MFMRadioHeadsetEventObserver* aObserver )
|
|
210 |
{
|
|
211 |
iObserver = aObserver;
|
|
212 |
}
|
|
213 |
|
|
214 |
//end of file
|