|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 /** |
|
18 @file |
|
19 @internalComponent |
|
20 */ |
|
21 #include <e32base.h> |
|
22 #include <remcon/remconifdetails.h> |
|
23 #include <s32strm.h> |
|
24 |
|
25 |
|
26 EXPORT_C CRemConInterfaceDetailsArray* CRemConInterfaceDetailsArray::NewL() |
|
27 { |
|
28 CRemConInterfaceDetailsArray* self = new(ELeave) CRemConInterfaceDetailsArray(); |
|
29 return self; |
|
30 } |
|
31 |
|
32 CRemConInterfaceDetailsArray::CRemConInterfaceDetailsArray() |
|
33 { |
|
34 } |
|
35 |
|
36 CRemConInterfaceDetailsArray::~CRemConInterfaceDetailsArray() |
|
37 { |
|
38 iArray.ResetAndDestroy(); |
|
39 } |
|
40 |
|
41 EXPORT_C TArray<CRemConInterfaceDetails*> CRemConInterfaceDetailsArray::Array() const |
|
42 { |
|
43 return iArray.Array(); |
|
44 } |
|
45 |
|
46 EXPORT_C CRemConInterfaceDetailsArray* CRemConInterfaceDetailsArray::InternalizeL(RReadStream& aStream) |
|
47 { |
|
48 CRemConInterfaceDetailsArray* self = new(ELeave) CRemConInterfaceDetailsArray(); |
|
49 CleanupStack::PushL(self); |
|
50 TInt count = aStream.ReadInt32L(); |
|
51 for(TInt ix=0; ix<count; ++ix) |
|
52 { |
|
53 CRemConInterfaceDetails* details = CRemConInterfaceDetails::InternalizeL(aStream); |
|
54 CleanupStack::PushL(details); |
|
55 self->iArray.AppendL(details); |
|
56 CleanupStack::Pop(details); |
|
57 } |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 EXPORT_C void CRemConInterfaceDetailsArray::ExternalizeL(RWriteStream& aStream, TRemConClientType aTypeFilter) |
|
63 { |
|
64 TInt arrayCount = iArray.Count(); |
|
65 TInt count = arrayCount; |
|
66 #ifdef _DEBUG |
|
67 TInt checkCount = arrayCount; |
|
68 #endif //_DEBUG |
|
69 |
|
70 if(aTypeFilter != ERemConClientTypeUndefined) |
|
71 { |
|
72 count = 0; |
|
73 for(TInt ix=0; ix<arrayCount; ++ix) |
|
74 { |
|
75 if(iArray[ix]->Type() == aTypeFilter) |
|
76 { |
|
77 ++count; |
|
78 } |
|
79 } |
|
80 #ifdef _DEBUG |
|
81 checkCount = count; |
|
82 #endif // _DEBUG |
|
83 } |
|
84 aStream.WriteInt32L(count); |
|
85 for(TInt ix=0; ix<arrayCount; ++ix) |
|
86 { |
|
87 if(aTypeFilter == ERemConClientTypeUndefined || aTypeFilter == iArray[ix]->Type()) |
|
88 { |
|
89 iArray[ix]->ExternalizeL(aStream); |
|
90 #ifdef _DEBUG |
|
91 --checkCount; |
|
92 #endif // _DEBUG |
|
93 } |
|
94 } |
|
95 ASSERT(checkCount == 0); |
|
96 } |
|
97 |
|
98 EXPORT_C void CRemConInterfaceDetailsArray::AppendL(CRemConInterfaceDetails* aDetails) |
|
99 { |
|
100 iArray.AppendL(aDetails); |
|
101 } |
|
102 |
|
103 |
|
104 |
|
105 EXPORT_C CRemConInterfaceDetails* CRemConInterfaceDetails::NewLC(TUid aUid, TRemConClientType aType, TBool aIsBulk, CRemConInterfaceBase* aInterface, const TDesC8& aFeatures) |
|
106 { |
|
107 CRemConInterfaceDetails* self = new(ELeave) CRemConInterfaceDetails(aUid, aType, aIsBulk, aInterface); |
|
108 CleanupStack::PushL(self); |
|
109 self->ConstructL(aFeatures); |
|
110 return self; |
|
111 } |
|
112 |
|
113 CRemConInterfaceDetails::CRemConInterfaceDetails(TUid aUid, TRemConClientType aType, TBool aIsBulk, CRemConInterfaceBase* aInterface) |
|
114 : iInterface(aInterface) |
|
115 , iUid(aUid) |
|
116 , iType(aType) |
|
117 , iBulk(aIsBulk) |
|
118 { |
|
119 } |
|
120 |
|
121 CRemConInterfaceDetails::~CRemConInterfaceDetails() |
|
122 { |
|
123 ASSERT(!iInterface); |
|
124 iFeatures.Close(); |
|
125 } |
|
126 |
|
127 void CRemConInterfaceDetails::ConstructL(const TDesC8& aFeatures) |
|
128 { |
|
129 if(aFeatures.Length() % sizeof(TUint) != 0) |
|
130 { |
|
131 User::Leave(KErrCorrupt); |
|
132 } |
|
133 iFeatures.Assign(aFeatures.AllocL()); |
|
134 } |
|
135 |
|
136 void CRemConInterfaceDetails::AddFeatures(RBuf8& aFeatures) |
|
137 { |
|
138 iFeatures.Close(); |
|
139 iFeatures.Swap(aFeatures); |
|
140 } |
|
141 |
|
142 EXPORT_C void CRemConInterfaceDetails::DeleteFeatures() |
|
143 { |
|
144 iFeatures.Close(); |
|
145 } |
|
146 |
|
147 EXPORT_C CRemConInterfaceBase*& CRemConInterfaceDetails::Interface() |
|
148 { |
|
149 return iInterface; |
|
150 } |
|
151 |
|
152 EXPORT_C TUid CRemConInterfaceDetails::Uid() const |
|
153 { |
|
154 return iUid; |
|
155 } |
|
156 |
|
157 EXPORT_C TBool CRemConInterfaceDetails::IsBulk() const |
|
158 { |
|
159 return iBulk; |
|
160 } |
|
161 |
|
162 EXPORT_C TRemConClientType CRemConInterfaceDetails::Type() const |
|
163 { |
|
164 return iType; |
|
165 } |
|
166 |
|
167 EXPORT_C void CRemConInterfaceDetails::GetRemConInterfaceFeaturesL(RArray<TUint>& aRemConInterfaceFeatures) const |
|
168 { |
|
169 aRemConInterfaceFeatures.Reset(); |
|
170 CleanupClosePushL(aRemConInterfaceFeatures); |
|
171 |
|
172 TInt numFeatures = iFeatures.Length() / sizeof(TUint); |
|
173 for(TInt i=0; i<numFeatures; ++i) |
|
174 { |
|
175 TPtrC8 ptr = iFeatures.Mid(i*sizeof(TUint), sizeof(TUint)); |
|
176 TPckgC<TUint>& val = *reinterpret_cast<TPckgC<TUint>*>(&ptr); |
|
177 aRemConInterfaceFeatures.AppendL(val()); |
|
178 } |
|
179 |
|
180 CleanupStack::Pop(&aRemConInterfaceFeatures); |
|
181 } |
|
182 |
|
183 |
|
184 CRemConInterfaceDetails* CRemConInterfaceDetails::InternalizeL(RReadStream& aStream) |
|
185 { |
|
186 TUid uid = TUid::Uid(aStream.ReadInt32L()); |
|
187 TRemConClientType type = static_cast<TRemConClientType>(aStream.ReadInt32L()); |
|
188 TBool bulk = aStream.ReadUint8L(); |
|
189 TInt featureSize = aStream.ReadInt32L(); |
|
190 RBuf8 features; |
|
191 features.CreateL(featureSize); |
|
192 features.CleanupClosePushL(); |
|
193 aStream.ReadL(features); |
|
194 CRemConInterfaceDetails* self = new(ELeave) CRemConInterfaceDetails(uid, type, bulk, NULL); |
|
195 self->AddFeatures(features); |
|
196 CleanupStack::PopAndDestroy(&features); |
|
197 return self; |
|
198 } |
|
199 |
|
200 void CRemConInterfaceDetails::ExternalizeL(RWriteStream& aStream) |
|
201 { |
|
202 aStream.WriteInt32L(iUid.iUid); |
|
203 aStream.WriteInt32L(iType); |
|
204 aStream.WriteUint8L(!!iBulk); |
|
205 aStream.WriteInt32L(iFeatures.Size()); |
|
206 aStream.WriteL(iFeatures); |
|
207 } |