|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: UPnPAttribute implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "upnpattribute.h" |
|
21 #include "upnpelement.h" |
|
22 |
|
23 |
|
24 |
|
25 // ============================ MEMBER FUNCTIONS =============================== |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CUpnpAttribute::ConstructL |
|
28 // Symbian 2nd phase constructor can leave. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 void CUpnpAttribute::ConstructL(const TDesC8& aName) |
|
32 { |
|
33 iName = aName.AllocL(); |
|
34 iValue = KNullDesC8().AllocL(); |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CUpnpAttribute::NewLC |
|
39 // Two-phased constructor. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 EXPORT_C CUpnpAttribute* CUpnpAttribute::NewLC(const TDesC8& aName) |
|
43 { |
|
44 CUpnpAttribute* self = new( ELeave ) CUpnpAttribute; |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(aName); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CUpnpAttribute::NewLC |
|
52 // Two-phased constructor. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C CUpnpAttribute* CUpnpAttribute::NewL(const TDesC8& aName) |
|
56 { |
|
57 CUpnpAttribute* self = NewLC(aName); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CUpnpAttribute::CUpnpAttribute |
|
64 // C++ default constructor can NOT contain any code, that |
|
65 // might leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C CUpnpAttribute::CUpnpAttribute() |
|
69 { |
|
70 } |
|
71 |
|
72 // Destructor |
|
73 CUpnpAttribute::~CUpnpAttribute() |
|
74 { |
|
75 delete iName; |
|
76 delete iValue; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CUpnpAttribute::SetNameL |
|
81 // Sets name for the attribute. |
|
82 // (other items were commented in a header). |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 EXPORT_C void CUpnpAttribute::SetNameL( const TDesC8& aName ) |
|
86 { |
|
87 HBufC8* tmp = aName.AllocL(); |
|
88 delete iName; |
|
89 iName = tmp; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CUpnpAttribute::Name |
|
94 // Returns name of the attribute. If null, returns KNullDesC |
|
95 // (other items were commented in a header). |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C const TDesC8& CUpnpAttribute::Name() const |
|
99 { |
|
100 return *iName; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CUpnpAttribute::SetValueL |
|
105 // Sets scope for the attribute. |
|
106 // (other items were commented in a header). |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C void CUpnpAttribute::SetValueL( const TDesC8& aValue ) |
|
110 { |
|
111 HBufC8* tmp = aValue.AllocL(); |
|
112 delete iValue; |
|
113 iValue = tmp; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CUpnpAttribute::Value |
|
118 // Returns scope of the attribute. If null, returns KNullDesC |
|
119 // (other items were commented in a header). |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C const TDesC8& CUpnpAttribute::Value() const |
|
123 { |
|
124 return *iValue; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CUpnpAttribute::ExternalizeL |
|
129 // C++ default constructor can NOT contain any code, that |
|
130 // might leave. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CUpnpAttribute::ExternalizeL( RWriteStream& aStream ) const |
|
134 { |
|
135 TInt ExternalizationLength = MapItemNameToProperLength(*iName); |
|
136 |
|
137 SafeExternalizeL(aStream, *iName, KMaxUpnpObjStringLen); |
|
138 SafeExternalizeL(aStream, *iValue, ExternalizationLength); |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CUpnpAttribute::InternalizeL |
|
143 // C++ default constructor can NOT contain any code, that |
|
144 // might leave. |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CUpnpAttribute::InternalizeL( RReadStream& aStream ) |
|
148 { |
|
149 delete iName; |
|
150 iName = NULL; |
|
151 iName = HBufC8::NewL( aStream, KMaxUpnpObjStringLen ); |
|
152 |
|
153 TInt InternalizationLength = MapItemNameToProperLength(*iName); |
|
154 |
|
155 |
|
156 delete iValue; |
|
157 iValue = NULL; |
|
158 iValue = HBufC8::NewL( aStream, InternalizationLength ); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CUpnpAttribute::SafeExternalizeL |
|
163 // Writes safely aNumber of characters from the content to the stream. |
|
164 // (other items were commented in a header). |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CUpnpAttribute::SafeExternalizeL(RWriteStream& aStream, const TDesC8& aDesc, const TInt aNumber) const |
|
168 { |
|
169 if( aDesc.Length() > aNumber ) |
|
170 aStream << aDesc.Mid(0, aNumber); |
|
171 else |
|
172 aStream << aDesc; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CUpnpAttribute::MapItemNameToProperLength |
|
177 // Counts how many bytes will be used for internalization |
|
178 // (other items were commented in a header). |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 TInt CUpnpAttribute::MapItemNameToProperLength(TDesC8& aItemName) const |
|
182 { |
|
183 // Requirement [7.3.17.4]: The following metadata properties must not exceed 256 bytes each in the XML-escaped form encoded in UTF-8: |
|
184 // - All length-unlimited DIDL-Lite schema defined attributes for <res>, except res@importUri. |
|
185 if( aItemName == _L8("importUri") ) |
|
186 { |
|
187 return KMaxUpnpObjLongStringLen; //1024 |
|
188 } |
|
189 else if( aItemName == _L8("duration") || |
|
190 aItemName == _L8("size") || |
|
191 aItemName == _L8("resolution") || |
|
192 aItemName == _L8("childCount") |
|
193 ) |
|
194 { |
|
195 return KMaxUpnpObjStringLen; // 256 |
|
196 } |
|
197 else |
|
198 { |
|
199 return KMaxUpnpObjStringLen; // 256 |
|
200 } |
|
201 } |
|
202 // End of File |