|
1 /* |
|
2 * Copyright (c) 2005 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: Container of one reactive authorization item |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngAuthorizationItem.h" |
|
20 #include "PEngListLibraryPanics.h" |
|
21 #include <e32std.h> |
|
22 #include <s32strm.h> |
|
23 |
|
24 |
|
25 // ============================ LOCAL FUNCTIONS =============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // Compares two TUint32 numbers. |
|
29 // Follows standard comparison rules. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 TInt CompareTUint32( const TUint32& aA, const TUint32& aB ) |
|
33 { |
|
34 return aA - aB; |
|
35 } |
|
36 |
|
37 |
|
38 #define ARRAY_ORDER TLinearOrder<TUint32> ( CompareTUint32 ) |
|
39 |
|
40 // CONST |
|
41 // Space required in stream to store one TInt32 - 4 bytes |
|
42 const TInt KTIntStoreSize = 4; |
|
43 |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CPEngAuthorizationItem::CPEngAuthorizationItem |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CPEngAuthorizationItem::CPEngAuthorizationItem( TInt& aSize ) |
|
51 : iSize( aSize ) |
|
52 { |
|
53 // length of the User Id => 4 bytes |
|
54 iSize += KTIntStoreSize; |
|
55 } |
|
56 |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CPEngAuthorizationItem::ConstructL() |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CPEngAuthorizationItem::ConstructL( const TDesC& aUserId ) |
|
63 { |
|
64 iUserId = aUserId.AllocL(); |
|
65 iSize += ( aUserId.Length() ); |
|
66 } |
|
67 |
|
68 |
|
69 // Destructor |
|
70 CPEngAuthorizationItem::~CPEngAuthorizationItem() |
|
71 { |
|
72 if ( iUserId ) |
|
73 { |
|
74 iSize -= ( KTIntStoreSize + iUserId->Length() ); |
|
75 } |
|
76 else |
|
77 { |
|
78 iSize -= KTIntStoreSize; |
|
79 } |
|
80 delete iUserId; |
|
81 } |
|
82 |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CPEngAuthorizationItem::UserId() |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 const TDesC& CPEngAuthorizationItem::Id() const |
|
89 { |
|
90 return *iUserId; |
|
91 } |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CPEngAuthorizationItem::LocalFlags() |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 TInt CPEngAuthorizationItem::LocalFlags() const |
|
99 { |
|
100 return iLocalFlags; |
|
101 } |
|
102 |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CPEngAuthorizationItem::SetLocalFlags() |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CPEngAuthorizationItem::SetLocalFlags( TInt aLocalFlag ) |
|
109 { |
|
110 iLocalFlags = aLocalFlag; |
|
111 } |
|
112 |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CPEngAuthorizationItem::ExternalizeL() |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CPEngAuthorizationItem::ExternalizeL( RWriteStream& aStream ) const |
|
119 { |
|
120 aStream.WriteInt32L( iUserId->Length() ); |
|
121 aStream << *iUserId; |
|
122 } |
|
123 |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CPEngAuthorizationItem::InternalizeL() |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CPEngAuthorizationItem::InternalizeL( RReadStream& aStream ) |
|
130 { |
|
131 __ASSERT_DEBUG( !iUserId, Panic( EReactiveAuthInternalizeMisused ) ); |
|
132 |
|
133 // user Id |
|
134 TInt length( aStream.ReadInt32L() ); |
|
135 iUserId = HBufC::NewL( aStream, length ); |
|
136 iSize += length; |
|
137 } |
|
138 |
|
139 |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CPEngAuthorizationItem::ExternalizeArrayL() |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void CPEngAuthorizationItem::ExternalizeArrayL( RWriteStream& aStream, |
|
146 const RArray<TUint32>& aArray ) |
|
147 { |
|
148 TInt count( aArray.Count() ); |
|
149 aStream.WriteInt32L( count ); |
|
150 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
151 { |
|
152 aStream.WriteInt32L( aArray[ x ] ); |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CPEngAuthorizationItem::InternalizeArrayL() |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CPEngAuthorizationItem::InternalizeArrayL( RReadStream& aStream, |
|
162 RArray<TUint32>& aArray, |
|
163 TInt& aSize ) |
|
164 { |
|
165 // 4 bytes per each number |
|
166 aSize -= ( KTIntStoreSize * aArray.Count() ); |
|
167 TInt count( aStream.ReadInt32L() ); |
|
168 aArray.Reset(); |
|
169 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
170 { |
|
171 aArray.AppendL( aStream.ReadInt32L() ); |
|
172 // 4 bytes per each attribute |
|
173 aSize += KTIntStoreSize; |
|
174 } |
|
175 } |
|
176 |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CPEngAuthorizationItem::SizeOfArray() |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 TInt CPEngAuthorizationItem::SizeOfArray( const RArray<TUint32>& aArray ) |
|
183 { |
|
184 // 4 bytes per each element of array + count of the array |
|
185 return KTIntStoreSize * ( aArray.Count() + 1 ); |
|
186 } |
|
187 |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CPEngAuthorizationItem::AddAttributeToArrayL() |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 TInt CPEngAuthorizationItem::AddAttributeToArrayL( RArray<TUint32>& aArray, |
|
194 TUint32 aAttribute ) |
|
195 { |
|
196 TInt err( aArray.InsertInOrder( aAttribute, ARRAY_ORDER ) ); |
|
197 if ( err == KErrAlreadyExists ) |
|
198 { |
|
199 return 0; //nothing was added => size change 0 |
|
200 } |
|
201 |
|
202 User::LeaveIfError( err ); |
|
203 return KTIntStoreSize; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CPEngAuthorizationItem::CopyArrayContentL() |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 TInt CPEngAuthorizationItem::CopyArrayContentL( RArray<TUint32>& aTarget, |
|
211 const TArray<TUint32>& aSource ) |
|
212 { |
|
213 TInt sizeDelta( 0 ); |
|
214 TInt count( aSource.Count() ); |
|
215 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
216 { |
|
217 sizeDelta += AddAttributeToArrayL( aTarget, aSource[ x ] ); |
|
218 } |
|
219 |
|
220 return sizeDelta; |
|
221 } |
|
222 |
|
223 |
|
224 // End of File |