1 /* |
1 /* |
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
20 @file |
20 @file |
21 @internalAll |
21 @internalAll |
22 */ |
22 */ |
23 |
23 |
24 #include "CPersonality.h" |
24 #include "CPersonality.h" |
25 #include <usb/usblogger.h> |
25 |
26 |
26 #include "OstTraceDefinitions.h" |
27 #ifdef __FLOG_ACTIVE |
27 #ifdef OST_TRACE_COMPILER_IN_USE |
28 _LIT8(KLogComponent, "USBSVR"); |
28 #include "CPersonalityTraces.h" |
29 #endif |
29 #endif |
|
30 |
|
31 // Panic category only used in debug builds |
|
32 #ifdef _DEBUG |
|
33 _LIT(KUsbPersonalityPanicCategory, "CUsbPersonality"); |
|
34 #endif |
|
35 |
|
36 /** |
|
37 * Panic codes for the USB Personality Class |
|
38 */ |
|
39 enum TUsbPersonalityPanic |
|
40 { |
|
41 EPersonalityConfigsArrayEmpty, |
|
42 }; |
30 |
43 |
31 /** |
44 /** |
32 * Factory method. Constructs a CPersonality object. |
45 * Factory method. Constructs a CPersonality object. |
33 * |
46 * |
34 * @return a pointer to CPersonality object. |
47 * @return a pointer to CPersonality object. |
35 */ |
48 */ |
36 CPersonality* CPersonality::NewL() |
49 CPersonality* CPersonality::NewL() |
37 { |
50 { |
38 LOG_STATIC_FUNC_ENTRY |
51 OstTraceFunctionEntry0( CPERSONALITY_NEWL_ENTRY ); |
39 |
52 |
40 CPersonality* self = new(ELeave) CPersonality; |
53 CPersonality* self = new(ELeave) CPersonality; |
41 CleanupStack::PushL(self); |
54 CleanupStack::PushL(self); |
42 self->ConstructL(); |
55 self->ConstructL(); |
43 CleanupStack::Pop(self); |
56 CleanupStack::Pop(self); |
|
57 OstTraceFunctionExit0( CPERSONALITY_NEWL_EXIT ); |
44 return self; |
58 return self; |
45 } |
59 } |
46 |
60 |
47 /** |
61 /** |
48 * Allocates max amount of memory for each of 3 strings |
62 * Allocates max amount of memory for description string |
49 */ |
63 */ |
50 void CPersonality::ConstructL() |
64 void CPersonality::ConstructL() |
51 { |
65 { |
52 LOG_FUNC |
66 OstTraceFunctionEntry0( CPERSONALITY_CONSTRUCTL_ENTRY ); |
53 |
67 iDescription = HBufC::NewL(KUsbStringDescStringMaxSize); |
54 iManufacturer = HBufC::NewLC(KUsbStringDescStringMaxSize); |
68 OstTraceFunctionExit0( CPERSONALITY_CONSTRUCTL_EXIT ); |
55 CleanupStack::Pop(); |
|
56 iProduct = HBufC::NewLC(KUsbStringDescStringMaxSize); |
|
57 CleanupStack::Pop(); |
|
58 iDescription = HBufC::NewLC(KUsbStringDescStringMaxSize); |
|
59 CleanupStack::Pop(); |
|
60 iDetailedDescription = HBufC::NewLC(KUsbStringDescStringMaxSize); |
|
61 CleanupStack::Pop(); |
|
62 } |
69 } |
63 |
70 |
64 /** |
71 /** |
65 * standard constructor |
72 * standard constructor |
66 */ |
73 */ |
71 /** |
78 /** |
72 * destructor |
79 * destructor |
73 */ |
80 */ |
74 CPersonality::~CPersonality() |
81 CPersonality::~CPersonality() |
75 { |
82 { |
76 LOG_FUNC |
83 OstTraceFunctionEntry0( CPERSONALITY_CPERSONALITY_DES_ENTRY ); |
77 |
84 |
78 iClassUids.Close(); |
85 iPersonalityConfigs.ResetAndDestroy(); |
79 delete iManufacturer; |
|
80 delete iProduct; |
|
81 delete iDescription; |
86 delete iDescription; |
82 delete iDetailedDescription; |
87 OstTraceFunctionExit0( CPERSONALITY_CPERSONALITY_DES_EXIT ); |
83 } |
88 } |
84 |
89 |
85 /** |
90 /** |
86 * @return the index of the first match or KErrNotFound |
91 * @return supported class uids |
87 */ |
92 */ |
88 TInt CPersonality::ClassSupported(TUid aClassUid) const |
93 const RArray<CPersonalityConfigurations::TUsbClasses>& CPersonality::SupportedClasses() const |
89 { |
94 { |
90 TIdentityRelation<TUid> relation(CPersonality::Compare); |
95 //we only support configuration 0 now |
91 return iClassUids.Find(aClassUid, relation); |
96 if(iPersonalityConfigs.Count() == 0) |
92 } |
97 { |
93 |
98 OstTrace1( TRACE_FATAL, CPERSONALITY_SUPPORTEDCLASSES, "CPersonality::SupportedClasses;Panic error=%d", EPersonalityConfigsArrayEmpty ); |
94 /** |
99 __ASSERT_DEBUG( EFalse, User::Panic(KUsbPersonalityPanicCategory, EPersonalityConfigsArrayEmpty) ); |
95 * @return KErrNone or system wide error code |
100 } |
96 */ |
101 return iPersonalityConfigs[0]->Classes(); |
97 TInt CPersonality::AddSupportedClasses(TUid aClassUid) |
102 } |
98 { |
103 |
99 return iClassUids.Append(aClassUid); |
104 /** |
100 } |
105 * @return ETrue if this class is supported |
101 |
106 * otherwise return EFalse |
102 /** |
107 */ |
103 * Sets personality id |
108 TBool CPersonality::ClassSupported(TUid aClassUid) const |
104 */ |
109 { |
105 void CPersonality::SetId(TInt aId) |
110 //we only support configuration 0 now |
106 { |
111 if(iPersonalityConfigs.Count() == 0) |
107 iId = aId; |
112 { |
108 } |
113 OstTrace1( TRACE_FATAL, CPERSONALITY_CLASSSUPPORTED, "CPersonality::ClassSupported;Panic error=%d", EPersonalityConfigsArrayEmpty ); |
109 |
114 __ASSERT_DEBUG( EFalse, User::Panic(KUsbPersonalityPanicCategory, EPersonalityConfigsArrayEmpty) ); |
110 /** |
115 } |
111 * Sets manufacturer textual description |
116 const RArray<CPersonalityConfigurations::TUsbClasses> &classes = iPersonalityConfigs[0]->Classes(); |
112 */ |
117 TInt classesCount = classes.Count(); |
113 void CPersonality::SetManufacturer(const TDesC* aManufacturer) |
118 for(TInt classesIndex = 0; classesIndex < classesCount; ++classesIndex) |
114 { |
119 { |
115 iManufacturer->Des().Copy(*aManufacturer); |
120 if(aClassUid == classes[classesIndex].iClassUid) |
116 } |
121 { |
117 |
122 return ETrue; |
118 /** |
123 } |
119 * Sets product textual description |
124 } |
120 */ |
125 return EFalse; |
121 void CPersonality::SetProduct(const TDesC* aProduct) |
|
122 { |
|
123 iProduct->Des().Copy(*aProduct); |
|
124 } |
|
125 |
|
126 /** |
|
127 * Sets personality textual description |
|
128 */ |
|
129 void CPersonality::SetDescription(const TDesC* aDescription) |
|
130 { |
|
131 iDescription->Des().Copy((*aDescription).Left(KUsbStringDescStringMaxSize-1)); |
|
132 } |
126 } |
133 |
127 |
134 /** |
128 /** |
135 * Compares if two class uids are equal |
129 * Compares if two class uids are equal |
136 * |
130 * |
162 */ |
148 */ |
163 void CPersonality::SetProperty(TUint32 aProperty) |
149 void CPersonality::SetProperty(TUint32 aProperty) |
164 { |
150 { |
165 iProperty = aProperty; |
151 iProperty = aProperty; |
166 } |
152 } |
|
153 |
|
154 /** |
|
155 * Sets DeviceClass |
|
156 */ |
|
157 void CPersonality::SetDeviceClass(TUint8 aDeviceClass) |
|
158 { |
|
159 iDeviceClass = aDeviceClass; |
|
160 } |
|
161 |
|
162 /** |
|
163 * Sets DeviceSubClass |
|
164 */ |
|
165 void CPersonality::SetDeviceSubClass(TUint8 aDeviceSubClass) |
|
166 { |
|
167 iDeviceSubClass = aDeviceSubClass; |
|
168 } |
|
169 |
|
170 /** |
|
171 * Sets DeviceProtocol |
|
172 */ |
|
173 void CPersonality::SetDeviceProtocol(TUint8 aDeviceProtocol) |
|
174 { |
|
175 iDeviceProtocol = aDeviceProtocol; |
|
176 } |
|
177 |
|
178 /** |
|
179 * Sets NumConfigurations |
|
180 */ |
|
181 void CPersonality::SetNumConfigurations(TUint8 aNumConfigurations) |
|
182 { |
|
183 iNumConfigurations = aNumConfigurations; |
|
184 } |
|
185 |
|
186 /** |
|
187 * Sets ProductId |
|
188 */ |
|
189 void CPersonality::SetProductId(TUint16 aProductId) |
|
190 { |
|
191 iProductId = aProductId; |
|
192 } |
|
193 |
|
194 /** |
|
195 * Sets FeatureId |
|
196 */ |
|
197 void CPersonality::SetFeatureId(TInt aFeatureId) |
|
198 { |
|
199 iFeatureId = aFeatureId; |
|
200 } |
|
201 |
|
202 /** |
|
203 * Sets BcdDevice |
|
204 */ |
|
205 void CPersonality::SetBcdDevice(TUint16 aBcdDevice) |
|
206 { |
|
207 iBcdDevice = aBcdDevice; |
|
208 } |
|
209 |
|
210 /** |
|
211 * Sets personality id |
|
212 */ |
|
213 void CPersonality::SetPersonalityId(TInt aPersonalityId) |
|
214 { |
|
215 iPersonalityId = aPersonalityId; |
|
216 } |
|
217 |
|
218 /** |
|
219 * Sets Description |
|
220 */ |
|
221 void CPersonality::SetDescription(const TDesC* aDescription) |
|
222 { |
|
223 iDescription->Des().Copy((*aDescription).Left(KUsbStringDescStringMaxSize-1)); |
|
224 } |
|
225 |
|
226 /** |
|
227 * Append PersonalityConfig |
|
228 */ |
|
229 void CPersonality::AppendPersonalityConfigsL(const CPersonalityConfigurations *aPersonalityConfig ) |
|
230 { |
|
231 iPersonalityConfigs.AppendL(aPersonalityConfig); |
|
232 } |
|
233 |
|
234 /** |
|
235 * Sets personality id |
|
236 */ |
|
237 void CPersonalityConfigurations::SetPersonalityId(TInt aPersonalityId) |
|
238 { |
|
239 iPersonalityId = aPersonalityId; |
|
240 } |
|
241 |
|
242 /** |
|
243 * Sets Config Id |
|
244 */ |
|
245 void CPersonalityConfigurations::SetConfigId(TInt aConfigId) |
|
246 { |
|
247 iConfigId = aConfigId; |
|
248 } |
|
249 |
|
250 |
|
251 /** |
|
252 * Append PersonalityConfig |
|
253 */ |
|
254 void CPersonalityConfigurations::AppendClassesL(const TUsbClasses &aClasses ) |
|
255 { |
|
256 iClasses.AppendL(aClasses); |
|
257 } |
|
258 |
|
259 /** |
|
260 * De-Constructor |
|
261 */ |
|
262 CPersonalityConfigurations::~CPersonalityConfigurations() |
|
263 { |
|
264 OstTraceFunctionEntry0( CPERSONALITYCONFIGURATIONS_CPERSONALITYCONFIGURATIONS_DES_ENTRY ); |
|
265 iClasses.Close(); |
|
266 OstTraceFunctionExit0( CPERSONALITYCONFIGURATIONS_CPERSONALITYCONFIGURATIONS_DES_EXIT ); |
|
267 } |