|
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: |
|
15 * Implements a utility class which holds information about a USB personality |
|
16 * |
|
17 */ |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalAll |
|
22 */ |
|
23 |
|
24 #include "CPersonality.h" |
|
25 #include <usb/usblogger.h> |
|
26 |
|
27 #ifdef __FLOG_ACTIVE |
|
28 _LIT8(KLogComponent, "USBSVR"); |
|
29 #endif |
|
30 |
|
31 /** |
|
32 * Factory method. Constructs a CPersonality object. |
|
33 * |
|
34 * @return a pointer to CPersonality object. |
|
35 */ |
|
36 CPersonality* CPersonality::NewL() |
|
37 { |
|
38 LOG_STATIC_FUNC_ENTRY |
|
39 |
|
40 CPersonality* self = new(ELeave) CPersonality; |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 /** |
|
48 * Allocates max amount of memory for each of 3 strings |
|
49 */ |
|
50 void CPersonality::ConstructL() |
|
51 { |
|
52 LOG_FUNC |
|
53 |
|
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 } |
|
63 |
|
64 /** |
|
65 * standard constructor |
|
66 */ |
|
67 CPersonality::CPersonality() |
|
68 { |
|
69 } |
|
70 |
|
71 /** |
|
72 * destructor |
|
73 */ |
|
74 CPersonality::~CPersonality() |
|
75 { |
|
76 LOG_FUNC |
|
77 |
|
78 iClassUids.Close(); |
|
79 delete iManufacturer; |
|
80 delete iProduct; |
|
81 delete iDescription; |
|
82 delete iDetailedDescription; |
|
83 } |
|
84 |
|
85 /** |
|
86 * @return the index of the first match or KErrNotFound |
|
87 */ |
|
88 TInt CPersonality::ClassSupported(TUid aClassUid) const |
|
89 { |
|
90 TIdentityRelation<TUid> relation(CPersonality::Compare); |
|
91 return iClassUids.Find(aClassUid, relation); |
|
92 } |
|
93 |
|
94 /** |
|
95 * @return KErrNone or system wide error code |
|
96 */ |
|
97 TInt CPersonality::AddSupportedClasses(TUid aClassUid) |
|
98 { |
|
99 return iClassUids.Append(aClassUid); |
|
100 } |
|
101 |
|
102 /** |
|
103 * Sets personality id |
|
104 */ |
|
105 void CPersonality::SetId(TInt aId) |
|
106 { |
|
107 iId = aId; |
|
108 } |
|
109 |
|
110 /** |
|
111 * Sets manufacturer textual description |
|
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 } |
|
133 |
|
134 /** |
|
135 * Compares if two class uids are equal |
|
136 * |
|
137 * @return 1 if they are equal or 0 otherwise |
|
138 */ |
|
139 TInt CPersonality::Compare(const TUid& aFirst, const TUid& aSecond) |
|
140 { |
|
141 return aFirst == aSecond; |
|
142 }; |
|
143 |
|
144 /** |
|
145 * Sets detailed personality textual description |
|
146 */ |
|
147 void CPersonality::SetDetailedDescription(const TDesC* aDetailedDescription) |
|
148 { |
|
149 iDetailedDescription->Des().Copy((*aDetailedDescription).Left(KUsbStringDescStringMaxSize-1)); |
|
150 } |
|
151 |
|
152 /** |
|
153 * Sets version |
|
154 */ |
|
155 void CPersonality::SetVersion(TInt aVersion) |
|
156 { |
|
157 iVersion = aVersion; |
|
158 } |
|
159 |
|
160 /** |
|
161 * Sets property |
|
162 */ |
|
163 void CPersonality::SetProperty(TUint32 aProperty) |
|
164 { |
|
165 iProperty = aProperty; |
|
166 } |