29
|
1 |
/*
|
|
2 |
* Copyright (c) 2004-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: Generic hid finder implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32std.h>
|
|
20 |
#include <e32svr.h>
|
|
21 |
|
|
22 |
#include "finder.h"
|
|
23 |
#include "debug.h"
|
|
24 |
|
|
25 |
// ----------------------------------------------------------------------
|
|
26 |
|
|
27 |
// Define this for additional debug output (this file only):
|
|
28 |
#define EXTRA_DEBUG
|
|
29 |
|
|
30 |
#ifdef EXTRA_DEBUG
|
|
31 |
#define DBG(a) a;
|
|
32 |
#else
|
|
33 |
#define DBG(a)
|
|
34 |
#endif
|
|
35 |
|
|
36 |
// ======== MEMBER FUNCTIONS ========
|
|
37 |
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
// THeadsetFinder()
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
THeadsetFinder::THeadsetFinder() :
|
|
43 |
iAppCollection( 0 ), iFieldList()
|
|
44 |
{
|
|
45 |
// Nothing else to do
|
|
46 |
}
|
|
47 |
|
|
48 |
// --------------------------------------------------------------------------
|
|
49 |
// From class MHidFieldFinder
|
|
50 |
// BeginCollection()
|
|
51 |
// --------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
TBool THeadsetFinder::BeginCollection( const CCollection* aCollection )
|
|
54 |
{
|
|
55 |
TBool examineCollection = ETrue;
|
|
56 |
|
|
57 |
const TInt KConsumerControl = 0x01;
|
|
58 |
|
|
59 |
// Only look at top-level application (consumer devices: consumer
|
|
60 |
// control) collections:
|
|
61 |
//
|
|
62 |
|
|
63 |
if ( ( aCollection->IsApplication() ) && ( iAppCollection == 0 ) )
|
|
64 |
{
|
|
65 |
// Top-level application collection.
|
|
66 |
|
|
67 |
if ( ( aCollection->UsagePage() == EUsagePageConsumer )
|
|
68 |
&& ( aCollection->Usage() == KConsumerControl ) )
|
|
69 |
{
|
|
70 |
TRACE_INFO(_L("[HID]\tTHeadsetFinder::BeginCollection: this is \
|
|
71 |
consumer collection "));
|
|
72 |
// Collection is a consumer device:
|
|
73 |
iAppCollection = aCollection;
|
|
74 |
iFieldList.Reset();
|
|
75 |
}
|
|
76 |
else
|
|
77 |
{
|
|
78 |
TRACE_INFO(_L("[HID]\tTHeadsetFinder::BeginCollection: not \
|
|
79 |
consumer collection"));
|
|
80 |
// Skip other types of top-level application collection:
|
|
81 |
examineCollection = EFalse;
|
|
82 |
}
|
|
83 |
}
|
|
84 |
return examineCollection;
|
|
85 |
|
|
86 |
}
|
|
87 |
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
// From class MHidFieldFinder
|
|
90 |
// EndCollection()
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
//
|
|
93 |
TBool THeadsetFinder::EndCollection( const CCollection* aCollection )
|
|
94 |
{
|
|
95 |
TBool continueSearch = ETrue;
|
|
96 |
|
|
97 |
TRACE_INFO(_L("[HID]\tTHeadsetFinder::EndCollection"));
|
|
98 |
if ( aCollection == iAppCollection )
|
|
99 |
{
|
|
100 |
// Top-level application(Consumer Devices:Consumer Control) finished:
|
|
101 |
//
|
|
102 |
iAppCollection = 0;
|
|
103 |
|
|
104 |
// Stop if we've found a device we can use in this
|
|
105 |
// application collection:
|
|
106 |
//
|
|
107 |
continueSearch = !Found();
|
|
108 |
}
|
|
109 |
|
|
110 |
return continueSearch;
|
|
111 |
}
|
|
112 |
|
|
113 |
// ---------------------------------------------------------------------------
|
|
114 |
// From class MHidFieldFinder
|
|
115 |
// Field()
|
|
116 |
// ---------------------------------------------------------------------------
|
|
117 |
//
|
|
118 |
void THeadsetFinder::Field( const CField* aField )
|
|
119 |
{
|
|
120 |
TRACE_INFO((_L("[HID]\tTHeadsetFinder::Field( 0x%08x)"),aField));
|
|
121 |
TInt error = KErrNone;
|
|
122 |
if ( iAppCollection )
|
|
123 |
{
|
|
124 |
|
|
125 |
if ( IsTelephony( aField ) )
|
|
126 |
{
|
|
127 |
TRACE_INFO((_L("[HID]\tTHeadsetFinder::Field, telephony")));
|
|
128 |
error = iFieldList.Append( aField );
|
|
129 |
if ( error != KErrNone )
|
|
130 |
{
|
|
131 |
TRACE_INFO((_L("[HID]\tTHeadsetFinder::Field, telephony \
|
|
132 |
failed")));
|
|
133 |
}
|
|
134 |
}
|
|
135 |
else if ( IsConsumer( aField ) )
|
|
136 |
{
|
|
137 |
TRACE_INFO(_L("[HID]\tTHeadsetFinder::Field, consumer"));
|
|
138 |
error = iFieldList.Append( aField );
|
|
139 |
if ( error != KErrNone )
|
|
140 |
{
|
|
141 |
TRACE_INFO((_L("[HID]\tTHeadsetFinder::Field, telephony \
|
|
142 |
failed")));
|
|
143 |
}
|
|
144 |
}
|
|
145 |
else
|
|
146 |
{
|
|
147 |
TRACE_INFO(_L("[HID]\tTHeadsetFinder::Field, other, or empty \
|
|
148 |
field"));
|
|
149 |
}
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
// ---------------------------------------------------------------------------
|
|
154 |
// IsConsumer()
|
|
155 |
// ---------------------------------------------------------------------------
|
|
156 |
//
|
|
157 |
TBool THeadsetFinder::IsConsumer( const CField* aField ) const
|
|
158 |
{
|
|
159 |
TBool found = EFalse;
|
|
160 |
|
|
161 |
if ( aField->IsInput() && aField->IsData() && ( aField->UsagePage()
|
|
162 |
== EUsagePageConsumer ) )
|
|
163 |
{
|
|
164 |
#ifdef _DEBUG
|
|
165 |
for ( TInt i = 0; i < aField->UsageCount(); i++ )
|
|
166 |
{
|
|
167 |
TRACE_INFO((_L("[HID]\tTHeadsetFinder::IsConsumer: Usage %d: \
|
|
168 |
%02x"),i,aField->Usage(i)));
|
|
169 |
}
|
|
170 |
#endif
|
|
171 |
// *** Add usage test here ***
|
|
172 |
TRACE_INFO(_L("[HID]\tTHeadsetFinder::IsConsumer: Consumer keys \
|
|
173 |
field found\r\n"));
|
|
174 |
found = ETrue;
|
|
175 |
}
|
|
176 |
return found;
|
|
177 |
}
|
|
178 |
|
|
179 |
// ---------------------------------------------------------------------------
|
|
180 |
// IsTelephony()
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
//
|
|
183 |
TBool THeadsetFinder::IsTelephony( const CField* aField ) const
|
|
184 |
{
|
|
185 |
TBool found = EFalse;
|
|
186 |
|
|
187 |
if ( aField->IsInput() && aField->IsData() && ( aField->UsagePage()
|
|
188 |
== EUsagePageTelephony ) )
|
|
189 |
{
|
|
190 |
const TInt KHookSwitch = 0x20;
|
|
191 |
const TInt KPhoneMute = 0x2F;
|
|
192 |
#ifdef _DEBUG
|
|
193 |
for ( TInt i = 0; i < aField->UsageCount(); i++ )
|
|
194 |
{
|
|
195 |
TRACE_INFO((_L("[HID]\tTHeadsetFinder::IsTelephony: \
|
|
196 |
Usage %d: %02x"),i,aField->Usage(i)));
|
|
197 |
}
|
|
198 |
#endif
|
|
199 |
if ( ( aField->UsageMin() <= KPhoneMute ) && ( aField->UsageMax()
|
|
200 |
>= KHookSwitch ) )
|
|
201 |
{
|
|
202 |
TRACE_INFO(_L("[HID]\tTHeadsetFinder::IsTelephony: Telephony \
|
|
203 |
field found"));
|
|
204 |
found = ETrue;
|
|
205 |
}
|
|
206 |
}
|
|
207 |
return found;
|
|
208 |
}
|
|
209 |
|
|
210 |
// ---------------------------------------------------------------------------
|
|
211 |
// EmptyList()
|
|
212 |
// ---------------------------------------------------------------------------
|
|
213 |
//
|
|
214 |
void THeadsetFinder::EmptyList()
|
|
215 |
{
|
|
216 |
iFieldList.Reset();
|
|
217 |
}
|
|
218 |
|
|
219 |
// ---------------------------------------------------------------------------
|
|
220 |
// FieldCount()
|
|
221 |
// ---------------------------------------------------------------------------
|
|
222 |
//
|
|
223 |
TInt THeadsetFinder::FieldCount()
|
|
224 |
{
|
|
225 |
return iFieldList.Count();
|
|
226 |
}
|
|
227 |
|
|
228 |
// ---------------------------------------------------------------------------
|
|
229 |
// GetFieldAtIndex()
|
|
230 |
// ---------------------------------------------------------------------------
|
|
231 |
//
|
|
232 |
CField* THeadsetFinder::GetFieldAtIndex( TInt aIndex )
|
|
233 |
{
|
|
234 |
return iFieldList[aIndex];
|
|
235 |
}
|
|
236 |
|
|
237 |
// ---------------------------------------------------------------------------
|
|
238 |
// Found()
|
|
239 |
// ---------------------------------------------------------------------------
|
|
240 |
//
|
|
241 |
TBool THeadsetFinder::Found() const
|
|
242 |
{
|
|
243 |
return ( iFieldList.Count() != 0 );
|
|
244 |
}
|