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". |
19 /** |
19 /** |
20 @file |
20 @file |
21 @internalAll |
21 @internalAll |
22 */ |
22 */ |
23 |
23 |
|
24 #include <usb/usblogger.h> |
24 #include "CPersonality.h" |
25 #include "CPersonality.h" |
25 #include <usb/usblogger.h> |
|
26 |
26 |
27 #ifdef __FLOG_ACTIVE |
27 #ifdef __FLOG_ACTIVE |
28 _LIT8(KLogComponent, "USBSVR"); |
28 _LIT8(KLogComponent, "USBSVR"); |
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. |
43 CleanupStack::Pop(self); |
56 CleanupStack::Pop(self); |
44 return self; |
57 return self; |
45 } |
58 } |
46 |
59 |
47 /** |
60 /** |
48 * Allocates max amount of memory for each of 3 strings |
61 * Allocates max amount of memory for description string |
49 */ |
62 */ |
50 void CPersonality::ConstructL() |
63 void CPersonality::ConstructL() |
51 { |
64 { |
52 LOG_FUNC |
65 LOG_FUNC |
53 |
66 iDescription = HBufC::NewL(KUsbStringDescStringMaxSize); |
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(); |
|
62 } |
67 } |
63 |
68 |
64 /** |
69 /** |
65 * standard constructor |
70 * standard constructor |
66 */ |
71 */ |
72 * destructor |
77 * destructor |
73 */ |
78 */ |
74 CPersonality::~CPersonality() |
79 CPersonality::~CPersonality() |
75 { |
80 { |
76 LOG_FUNC |
81 LOG_FUNC |
77 |
82 iPersonalityConfigs.ResetAndDestroy(); |
78 iClassUids.Close(); |
|
79 delete iManufacturer; |
|
80 delete iProduct; |
|
81 delete iDescription; |
83 delete iDescription; |
82 delete iDetailedDescription; |
84 } |
83 } |
85 |
84 |
86 /** |
85 /** |
87 * @return supported class uids |
86 * @return the index of the first match or KErrNotFound |
88 */ |
87 */ |
89 const RArray<CPersonalityConfigurations::TUsbClasses>& CPersonality::SupportedClasses() const |
88 TInt CPersonality::ClassSupported(TUid aClassUid) const |
90 { |
89 { |
91 //we only support configuration 0 now |
90 TIdentityRelation<TUid> relation(CPersonality::Compare); |
92 __ASSERT_DEBUG( iPersonalityConfigs.Count() != 0, _USB_PANIC(KUsbPersonalityPanicCategory, EPersonalityConfigsArrayEmpty) ); |
91 return iClassUids.Find(aClassUid, relation); |
93 return iPersonalityConfigs[0]->Classes(); |
92 } |
94 } |
93 |
95 |
94 /** |
96 /** |
95 * @return KErrNone or system wide error code |
97 * @return ETrue if this class is supported |
96 */ |
98 * otherwise return EFalse |
97 TInt CPersonality::AddSupportedClasses(TUid aClassUid) |
99 */ |
98 { |
100 TBool CPersonality::ClassSupported(TUid aClassUid) const |
99 return iClassUids.Append(aClassUid); |
101 { |
100 } |
102 //we only support configuration 0 now |
101 |
103 __ASSERT_DEBUG( iPersonalityConfigs.Count() != 0, _USB_PANIC(KUsbPersonalityPanicCategory, EPersonalityConfigsArrayEmpty) ); |
102 /** |
104 const RArray<CPersonalityConfigurations::TUsbClasses> &classes = iPersonalityConfigs[0]->Classes(); |
103 * Sets personality id |
105 TInt classesCount = classes.Count(); |
104 */ |
106 for(TInt classesIndex = 0; classesIndex < classesCount; ++classesIndex) |
105 void CPersonality::SetId(TInt aId) |
107 { |
106 { |
108 if(aClassUid == classes[classesIndex].iClassUid) |
107 iId = aId; |
109 { |
108 } |
110 return ETrue; |
109 |
111 } |
110 /** |
112 } |
111 * Sets manufacturer textual description |
113 return EFalse; |
112 */ |
|
113 void CPersonality::SetManufacturer(const TDesC* aManufacturer) |
|
114 { |
|
115 iManufacturer->Des().Copy(*aManufacturer); |
|
116 } |
|
117 |
|
118 /** |
|
119 * Sets product textual description |
|
120 */ |
|
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 } |
114 } |
133 |
115 |
134 /** |
116 /** |
135 * Compares if two class uids are equal |
117 * Compares if two class uids are equal |
136 * |
118 * |
162 */ |
136 */ |
163 void CPersonality::SetProperty(TUint32 aProperty) |
137 void CPersonality::SetProperty(TUint32 aProperty) |
164 { |
138 { |
165 iProperty = aProperty; |
139 iProperty = aProperty; |
166 } |
140 } |
|
141 |
|
142 /** |
|
143 * Sets DeviceClass |
|
144 */ |
|
145 void CPersonality::SetDeviceClass(TUint8 aDeviceClass) |
|
146 { |
|
147 iDeviceClass = aDeviceClass; |
|
148 } |
|
149 |
|
150 /** |
|
151 * Sets DeviceSubClass |
|
152 */ |
|
153 void CPersonality::SetDeviceSubClass(TUint8 aDeviceSubClass) |
|
154 { |
|
155 iDeviceSubClass = aDeviceSubClass; |
|
156 } |
|
157 |
|
158 /** |
|
159 * Sets DeviceProtocol |
|
160 */ |
|
161 void CPersonality::SetDeviceProtocol(TUint8 aDeviceProtocol) |
|
162 { |
|
163 iDeviceProtocol = aDeviceProtocol; |
|
164 } |
|
165 |
|
166 /** |
|
167 * Sets NumConfigurations |
|
168 */ |
|
169 void CPersonality::SetNumConfigurations(TUint8 aNumConfigurations) |
|
170 { |
|
171 iNumConfigurations = aNumConfigurations; |
|
172 } |
|
173 |
|
174 /** |
|
175 * Sets ProductId |
|
176 */ |
|
177 void CPersonality::SetProductId(TUint16 aProductId) |
|
178 { |
|
179 iProductId = aProductId; |
|
180 } |
|
181 |
|
182 /** |
|
183 * Sets FeatureId |
|
184 */ |
|
185 void CPersonality::SetFeatureId(TInt aFeatureId) |
|
186 { |
|
187 iFeatureId = aFeatureId; |
|
188 } |
|
189 |
|
190 /** |
|
191 * Sets BcdDevice |
|
192 */ |
|
193 void CPersonality::SetBcdDevice(TUint16 aBcdDevice) |
|
194 { |
|
195 iBcdDevice = aBcdDevice; |
|
196 } |
|
197 |
|
198 /** |
|
199 * Sets personality id |
|
200 */ |
|
201 void CPersonality::SetPersonalityId(TInt aPersonalityId) |
|
202 { |
|
203 iPersonalityId = aPersonalityId; |
|
204 } |
|
205 |
|
206 /** |
|
207 * Sets Description |
|
208 */ |
|
209 void CPersonality::SetDescription(const TDesC* aDescription) |
|
210 { |
|
211 iDescription->Des().Copy((*aDescription).Left(KUsbStringDescStringMaxSize-1)); |
|
212 } |
|
213 |
|
214 /** |
|
215 * Append PersonalityConfig |
|
216 */ |
|
217 void CPersonality::AppendPersonalityConfigsL(const CPersonalityConfigurations *aPersonalityConfig ) |
|
218 { |
|
219 iPersonalityConfigs.AppendL(aPersonalityConfig); |
|
220 } |
|
221 |
|
222 /** |
|
223 * Sets personality id |
|
224 */ |
|
225 void CPersonalityConfigurations::SetPersonalityId(TInt aPersonalityId) |
|
226 { |
|
227 iPersonalityId = aPersonalityId; |
|
228 } |
|
229 |
|
230 /** |
|
231 * Sets Config Id |
|
232 */ |
|
233 void CPersonalityConfigurations::SetConfigId(TInt aConfigId) |
|
234 { |
|
235 iConfigId = aConfigId; |
|
236 } |
|
237 |
|
238 |
|
239 /** |
|
240 * Append PersonalityConfig |
|
241 */ |
|
242 void CPersonalityConfigurations::AppendClassesL(const TUsbClasses &aClasses ) |
|
243 { |
|
244 iClasses.AppendL(aClasses); |
|
245 } |
|
246 |
|
247 /** |
|
248 * De-Constructor |
|
249 */ |
|
250 CPersonalityConfigurations::~CPersonalityConfigurations() |
|
251 { |
|
252 LOG_FUNC |
|
253 iClasses.Close(); |
|
254 } |