1 /* |
1 /* |
2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2004-2009 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 }; |
|
43 |
30 |
44 /** |
31 /** |
45 * Factory method. Constructs a CPersonality object. |
32 * Factory method. Constructs a CPersonality object. |
46 * |
33 * |
47 * @return a pointer to CPersonality object. |
34 * @return a pointer to CPersonality object. |
48 */ |
35 */ |
49 CPersonality* CPersonality::NewL() |
36 CPersonality* CPersonality::NewL() |
50 { |
37 { |
51 OstTraceFunctionEntry0( CPERSONALITY_NEWL_ENTRY ); |
38 LOG_STATIC_FUNC_ENTRY |
52 |
39 |
53 CPersonality* self = new(ELeave) CPersonality; |
40 CPersonality* self = new(ELeave) CPersonality; |
54 CleanupStack::PushL(self); |
41 CleanupStack::PushL(self); |
55 self->ConstructL(); |
42 self->ConstructL(); |
56 CleanupStack::Pop(self); |
43 CleanupStack::Pop(self); |
57 OstTraceFunctionExit0( CPERSONALITY_NEWL_EXIT ); |
|
58 return self; |
44 return self; |
59 } |
45 } |
60 |
46 |
61 /** |
47 /** |
62 * Allocates max amount of memory for description string |
48 * Allocates max amount of memory for each of 3 strings |
63 */ |
49 */ |
64 void CPersonality::ConstructL() |
50 void CPersonality::ConstructL() |
65 { |
51 { |
66 OstTraceFunctionEntry0( CPERSONALITY_CONSTRUCTL_ENTRY ); |
52 LOG_FUNC |
67 iDescription = HBufC::NewL(KUsbStringDescStringMaxSize); |
53 |
68 OstTraceFunctionExit0( CPERSONALITY_CONSTRUCTL_EXIT ); |
54 iManufacturer = HBufC::NewLC(KUsbStringDescStringMaxSize); |
|
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(); |
69 } |
62 } |
70 |
63 |
71 /** |
64 /** |
72 * standard constructor |
65 * standard constructor |
73 */ |
66 */ |
78 /** |
71 /** |
79 * destructor |
72 * destructor |
80 */ |
73 */ |
81 CPersonality::~CPersonality() |
74 CPersonality::~CPersonality() |
82 { |
75 { |
83 OstTraceFunctionEntry0( CPERSONALITY_CPERSONALITY_DES_ENTRY ); |
76 LOG_FUNC |
84 |
77 |
85 iPersonalityConfigs.ResetAndDestroy(); |
78 iClassUids.Close(); |
|
79 delete iManufacturer; |
|
80 delete iProduct; |
86 delete iDescription; |
81 delete iDescription; |
87 OstTraceFunctionExit0( CPERSONALITY_CPERSONALITY_DES_EXIT ); |
82 delete iDetailedDescription; |
88 } |
83 } |
89 |
84 |
90 /** |
85 /** |
91 * @return supported class uids |
86 * @return the index of the first match or KErrNotFound |
92 */ |
87 */ |
93 const RArray<CPersonalityConfigurations::TUsbClasses>& CPersonality::SupportedClasses() const |
88 TInt CPersonality::ClassSupported(TUid aClassUid) const |
94 { |
89 { |
95 //we only support configuration 0 now |
90 TIdentityRelation<TUid> relation(CPersonality::Compare); |
96 if(iPersonalityConfigs.Count() == 0) |
91 return iClassUids.Find(aClassUid, relation); |
97 { |
92 } |
98 OstTrace1( TRACE_FATAL, CPERSONALITY_SUPPORTEDCLASSES, "CPersonality::SupportedClasses;Panic error=%d", EPersonalityConfigsArrayEmpty ); |
|
99 __ASSERT_DEBUG( EFalse, User::Panic(KUsbPersonalityPanicCategory, EPersonalityConfigsArrayEmpty) ); |
|
100 } |
|
101 return iPersonalityConfigs[0]->Classes(); |
|
102 } |
|
103 |
93 |
104 /** |
94 /** |
105 * @return ETrue if this class is supported |
95 * @return KErrNone or system wide error code |
106 * otherwise return EFalse |
96 */ |
|
97 TInt CPersonality::AddSupportedClasses(TUid aClassUid) |
|
98 { |
|
99 return iClassUids.Append(aClassUid); |
|
100 } |
|
101 |
|
102 /** |
|
103 * Sets personality id |
107 */ |
104 */ |
108 TBool CPersonality::ClassSupported(TUid aClassUid) const |
105 void CPersonality::SetId(TInt aId) |
109 { |
106 { |
110 //we only support configuration 0 now |
107 iId = aId; |
111 if(iPersonalityConfigs.Count() == 0) |
108 } |
112 { |
109 |
113 OstTrace1( TRACE_FATAL, CPERSONALITY_CLASSSUPPORTED, "CPersonality::ClassSupported;Panic error=%d", EPersonalityConfigsArrayEmpty ); |
110 /** |
114 __ASSERT_DEBUG( EFalse, User::Panic(KUsbPersonalityPanicCategory, EPersonalityConfigsArrayEmpty) ); |
111 * Sets manufacturer textual description |
115 } |
112 */ |
116 const RArray<CPersonalityConfigurations::TUsbClasses> &classes = iPersonalityConfigs[0]->Classes(); |
113 void CPersonality::SetManufacturer(const TDesC* aManufacturer) |
117 TInt classesCount = classes.Count(); |
114 { |
118 for(TInt classesIndex = 0; classesIndex < classesCount; ++classesIndex) |
115 iManufacturer->Des().Copy(*aManufacturer); |
119 { |
116 } |
120 if(aClassUid == classes[classesIndex].iClassUid) |
117 |
121 { |
118 /** |
122 return ETrue; |
119 * Sets product textual description |
123 } |
120 */ |
124 } |
121 void CPersonality::SetProduct(const TDesC* aProduct) |
125 return EFalse; |
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)); |
126 } |
132 } |
127 |
133 |
128 /** |
134 /** |
129 * Compares if two class uids are equal |
135 * Compares if two class uids are equal |
130 * |
136 * |
148 */ |
162 */ |
149 void CPersonality::SetProperty(TUint32 aProperty) |
163 void CPersonality::SetProperty(TUint32 aProperty) |
150 { |
164 { |
151 iProperty = aProperty; |
165 iProperty = aProperty; |
152 } |
166 } |
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 } |
|