|
1 /* |
|
2 * Copyright (c) 2006-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: CCFContextIndicationImpl class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32strm.h> |
|
20 #include <s32mem.h> |
|
21 |
|
22 #include <cfcontextdataobject.h> |
|
23 |
|
24 #include "CFContextIndicationImpl.h" |
|
25 #include "CFContextObjectImpl.h" |
|
26 #include "cftrace.h" |
|
27 |
|
28 EXPORT_C CCFContextIndicationImpl* CCFContextIndicationImpl::NewL( |
|
29 const TUid& aUid ) |
|
30 { |
|
31 FUNC_LOG; |
|
32 |
|
33 CCFContextIndicationImpl* self = |
|
34 CCFContextIndicationImpl::NewLC( aUid ); |
|
35 CleanupStack::Pop( self ); |
|
36 |
|
37 return self; |
|
38 } |
|
39 |
|
40 EXPORT_C CCFContextIndicationImpl* CCFContextIndicationImpl::NewLC( |
|
41 const TUid& aUid ) |
|
42 { |
|
43 FUNC_LOG; |
|
44 |
|
45 CCFContextIndicationImpl* self = |
|
46 new( ELeave ) CCFContextIndicationImpl( aUid ); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 EXPORT_C CCFContextIndicationImpl* CCFContextIndicationImpl::NewL( |
|
54 RReadStream& aStream ) |
|
55 { |
|
56 FUNC_LOG; |
|
57 |
|
58 CCFContextIndicationImpl* self = |
|
59 CCFContextIndicationImpl::NewLC( aStream ); |
|
60 CleanupStack::Pop( self ); |
|
61 |
|
62 return self; |
|
63 } |
|
64 |
|
65 EXPORT_C CCFContextIndicationImpl* CCFContextIndicationImpl::NewLC( |
|
66 RReadStream& aStream) |
|
67 { |
|
68 FUNC_LOG; |
|
69 |
|
70 CCFContextIndicationImpl* self = |
|
71 new( ELeave ) CCFContextIndicationImpl( KNullUid ); |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 self->InternalizeL( aStream ); |
|
75 |
|
76 return self; |
|
77 } |
|
78 |
|
79 CCFContextIndicationImpl::~CCFContextIndicationImpl() |
|
80 { |
|
81 FUNC_LOG; |
|
82 |
|
83 delete iContext; |
|
84 delete iData; |
|
85 } |
|
86 |
|
87 CCFContextIndicationImpl::CCFContextIndicationImpl( const TUid& aUid ): |
|
88 iUid( aUid ) |
|
89 { |
|
90 FUNC_LOG; |
|
91 } |
|
92 |
|
93 void CCFContextIndicationImpl::ConstructL() |
|
94 { |
|
95 FUNC_LOG; |
|
96 |
|
97 iContext = CCFContextObjectImpl::NewL(); |
|
98 } |
|
99 |
|
100 // METHODS |
|
101 |
|
102 //----------------------------------------------------------------------------- |
|
103 // CCFContextIndicationImpl::Context |
|
104 //----------------------------------------------------------------------------- |
|
105 // |
|
106 const CCFContextObject& CCFContextIndicationImpl::Context() const |
|
107 { |
|
108 FUNC_LOG; |
|
109 |
|
110 return *iContext; |
|
111 } |
|
112 |
|
113 //----------------------------------------------------------------------------- |
|
114 // CCFContextIndicationImpl::Uid |
|
115 //----------------------------------------------------------------------------- |
|
116 // |
|
117 const TUid& CCFContextIndicationImpl::Uid() const |
|
118 { |
|
119 FUNC_LOG; |
|
120 |
|
121 return iUid; |
|
122 } |
|
123 |
|
124 //----------------------------------------------------------------------------- |
|
125 // CCFContextIndicationImpl::CreateDataObjectL |
|
126 //----------------------------------------------------------------------------- |
|
127 // |
|
128 void CCFContextIndicationImpl::CreateDataObjectL( |
|
129 CCFContextDataObject& aDataObject ) |
|
130 { |
|
131 FUNC_LOG; |
|
132 |
|
133 if( iUid != KNullUid && iData ) |
|
134 { |
|
135 RDesReadStream readStream( *iData ); |
|
136 readStream.PushL(); |
|
137 aDataObject.InternalizeL( readStream ); |
|
138 |
|
139 // Cleanup |
|
140 CleanupStack::PopAndDestroy( &readStream ); |
|
141 } |
|
142 else |
|
143 { |
|
144 // Leave since client has requested the operation incorrectly. |
|
145 User::Leave( KErrNotFound ); |
|
146 } |
|
147 } |
|
148 |
|
149 //----------------------------------------------------------------------------- |
|
150 // CCFContextIndicationImpl::ExternalizeL |
|
151 //----------------------------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C void CCFContextIndicationImpl::ExternalizeL( RWriteStream& aStream ) |
|
154 { |
|
155 FUNC_LOG; |
|
156 |
|
157 // Write context object |
|
158 iContext->ExternalizeL( aStream ); |
|
159 |
|
160 // Write data object |
|
161 TPtrC8 data; |
|
162 TInt length = 0; |
|
163 if( iData ) |
|
164 { |
|
165 data.Set( *iData ); |
|
166 length = data.Length(); |
|
167 } |
|
168 aStream.WriteInt32L( iUid.iUid ); |
|
169 aStream.WriteInt16L( length ); |
|
170 if( length ) |
|
171 { |
|
172 aStream.WriteL( data, length ); |
|
173 } |
|
174 |
|
175 // Commit data in the stream |
|
176 aStream.CommitL(); |
|
177 } |
|
178 |
|
179 //----------------------------------------------------------------------------- |
|
180 // CCFContextIndicationImpl::InternalizeL |
|
181 //----------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C void CCFContextIndicationImpl::InternalizeL( RReadStream& aStream ) |
|
184 { |
|
185 FUNC_LOG; |
|
186 |
|
187 // Read context object |
|
188 iContext->InternalizeL( aStream ); |
|
189 |
|
190 // Read data object |
|
191 iUid.iUid = aStream.ReadInt32L(); |
|
192 TInt length = aStream.ReadInt16L(); |
|
193 if( length ) |
|
194 { |
|
195 HBufC8* data = HBufC8::NewLC( length ); |
|
196 TPtr8 dataPtr = data->Des(); |
|
197 aStream.ReadL( dataPtr, length ); |
|
198 CleanupStack::Pop( data ); |
|
199 iData = data; |
|
200 } |
|
201 } |
|
202 |
|
203 //----------------------------------------------------------------------------- |
|
204 // CCFContextIndicationImpl::Size |
|
205 //----------------------------------------------------------------------------- |
|
206 // |
|
207 EXPORT_C TInt CCFContextIndicationImpl::Size() const |
|
208 { |
|
209 FUNC_LOG; |
|
210 |
|
211 TInt size = 0; |
|
212 |
|
213 // Context object |
|
214 size += iContext->Size(); |
|
215 |
|
216 // UID size |
|
217 size += sizeof( TInt32 ); |
|
218 |
|
219 // Length of the data |
|
220 size += sizeof( TInt ); |
|
221 if( iData ) |
|
222 { |
|
223 size += iData->Size(); |
|
224 } |
|
225 |
|
226 return size; |
|
227 } |
|
228 |
|
229 //----------------------------------------------------------------------------- |
|
230 // CCFContextIndicationImpl::SetContextL |
|
231 //----------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C void CCFContextIndicationImpl::SetContextL( |
|
234 const CCFContextObject& aContext ) |
|
235 { |
|
236 FUNC_LOG; |
|
237 |
|
238 iContext->CopyL( aContext ); |
|
239 } |
|
240 |
|
241 //----------------------------------------------------------------------------- |
|
242 // CCFContextIndicationImpl::SetDataObjectUid |
|
243 //----------------------------------------------------------------------------- |
|
244 // |
|
245 EXPORT_C void CCFContextIndicationImpl::SetDataObjectUid( const TUid& aUid ) |
|
246 { |
|
247 FUNC_LOG; |
|
248 |
|
249 iUid = aUid; |
|
250 } |
|
251 |
|
252 //----------------------------------------------------------------------------- |
|
253 // CCFContextIndicationImpl::SetDataObject |
|
254 //----------------------------------------------------------------------------- |
|
255 // |
|
256 EXPORT_C void CCFContextIndicationImpl::SetDataObject( HBufC8* aData ) |
|
257 { |
|
258 FUNC_LOG; |
|
259 |
|
260 if( iData ) |
|
261 { |
|
262 delete iData; |
|
263 iData = NULL; |
|
264 } |
|
265 iData = aData; |
|
266 } |