|
1 /* |
|
2 * Copyright (c) 2004 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: Symbian OS Server source. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nsmlagentlog.h" |
|
20 #include "nsmlsosserver.h" |
|
21 #include "nsmldshostclient.h" |
|
22 |
|
23 // -------------------------------------------------------------------------- |
|
24 // CNSmlTask::CNSmlTask( const TInt aProfId, TBool aNewTask ) |
|
25 // -------------------------------------------------------------------------- |
|
26 // |
|
27 CNSmlTask::CNSmlTask( const TInt aProfId, TBool aNewTask, CNSmlSOSSession& aSession) |
|
28 : iProfId(aProfId), iCreatingNew(aNewTask), iSession(aSession), iDataPtr(NULL, 0, 0), iFilterBufPtr(NULL, 0, 0) |
|
29 { |
|
30 } |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // CNSmlTask::~CNSmlTask() |
|
34 // -------------------------------------------------------------------------- |
|
35 // |
|
36 CNSmlTask::~CNSmlTask() |
|
37 { |
|
38 delete iBuffer; |
|
39 delete iFilterBuffer; |
|
40 } |
|
41 |
|
42 // -------------------------------------------------------------------------- |
|
43 // void CNSmlTask::SetDataProviderId( const TInt aTaskUID ) |
|
44 // -------------------------------------------------------------------------- |
|
45 // |
|
46 void CNSmlTask::SetDataProviderId( const TInt aTaskUID ) |
|
47 { |
|
48 iTaskUID = aTaskUID; |
|
49 } |
|
50 |
|
51 |
|
52 // -------------------------------------------------------------------------- |
|
53 // void CNSmlTask::SetCreatorId( const TInt aCreatorId ) |
|
54 // -------------------------------------------------------------------------- |
|
55 // |
|
56 void CNSmlTask::SetCreatorId( const TInt aCreatorId ) |
|
57 { |
|
58 iCreatorId = aCreatorId; |
|
59 } |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // TInt CNSmlTask::FetchDataL( const TInt aTaskId ) |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 TInt CNSmlTask::FetchDataL( const TInt aTaskId ) |
|
66 { |
|
67 TInt ret(KErrNotFound); |
|
68 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
69 if ( prof ) |
|
70 { |
|
71 CleanupStack::PushL(prof); |
|
72 |
|
73 CNSmlDSContentType* ctype = prof->ContentTypeId( aTaskId ); // Table id used when fetching data. |
|
74 // content type is deleted in CNSmlDSProfile destructor. |
|
75 if ( ctype ) |
|
76 { |
|
77 TInt namelen = ctype->StrValue( EDSAdapterDisplayName ).Size(); |
|
78 TInt rdblen = ctype->StrValue( EDSAdapterServerDataSource ).Size(); |
|
79 TInt ldblen = ctype->StrValue( EDSAdapterClientDataSource ).Size(); |
|
80 |
|
81 CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
82 CleanupStack::PushL( buffer ); |
|
83 RBufWriteStream stream( *buffer ); |
|
84 |
|
85 CleanupClosePushL(stream); |
|
86 |
|
87 stream.WriteInt32L( rdblen ); |
|
88 stream << ctype->StrValue( EDSAdapterServerDataSource ); |
|
89 stream.WriteInt32L( ldblen ); |
|
90 stream << ctype->StrValue( EDSAdapterClientDataSource ); |
|
91 |
|
92 iTaskUID = ctype->IntValue( EDSAdapterImplementationId ); |
|
93 stream.WriteInt32L( iTaskUID ); |
|
94 |
|
95 stream.WriteInt8L( ctype->IntValue( EDSAdapterEnabled ) ); |
|
96 stream.WriteInt32L( ctype->IntValue( EDSAdapterCreatorId )); |
|
97 |
|
98 stream.WriteInt32L( namelen ); |
|
99 stream << ctype->StrValue( EDSAdapterDisplayName ); |
|
100 |
|
101 stream.WriteInt8L( ctype->IntValue( EDSAdapterSyncType ) ); |
|
102 |
|
103 CleanupStack::PopAndDestroy(&stream); |
|
104 |
|
105 delete iBuffer; |
|
106 iBuffer = buffer; |
|
107 CleanupStack::Pop( buffer ); |
|
108 |
|
109 ret = KErrNone; |
|
110 } |
|
111 CleanupStack::PopAndDestroy(prof); |
|
112 } |
|
113 return ret; |
|
114 } |
|
115 |
|
116 // -------------------------------------------------------------------------- |
|
117 // TInt CNSmlTask::DataSize() |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CNSmlTask::DataSize() |
|
121 { |
|
122 return iBuffer->Size(); |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // const TPtr8& CNSmlTask::ReadData() |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 const TPtr8& CNSmlTask::ReadData() |
|
130 { |
|
131 if ( iBuffer ) |
|
132 { |
|
133 iDataPtr.Set( iBuffer->Ptr(0) ); |
|
134 } |
|
135 return iDataPtr; |
|
136 } |
|
137 |
|
138 // -------------------------------------------------------------------------- |
|
139 // TInt CNSmlTask::FilterSize() |
|
140 // -------------------------------------------------------------------------- |
|
141 // |
|
142 TInt CNSmlTask::FilterSize() |
|
143 { |
|
144 if ( iFilterBuffer ) |
|
145 { |
|
146 return iFilterBuffer->Size(); |
|
147 } |
|
148 return 0; |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // const TPtr8& CNSmlTask::ReadFilter() |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 const TPtr8& CNSmlTask::ReadFilter() |
|
156 { |
|
157 if ( iFilterBuffer ) |
|
158 { |
|
159 iFilterBufPtr.Set(iFilterBuffer->Ptr(0)); |
|
160 } |
|
161 return iFilterBufPtr; |
|
162 } |
|
163 |
|
164 // -------------------------------------------------------------------------- |
|
165 // TInt CNSmlTask::UpdateDataL( TInt& aId, const TDesC8& aData ) |
|
166 // -------------------------------------------------------------------------- |
|
167 // |
|
168 TInt CNSmlTask::UpdateDataL( TInt& aId, const TDesC8& aData ) |
|
169 { |
|
170 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
171 CleanupStack::PushL(prof); |
|
172 |
|
173 RDesReadStream stream; |
|
174 stream.Open(aData); |
|
175 CleanupClosePushL(stream); |
|
176 |
|
177 TInt maxlen(0); |
|
178 |
|
179 maxlen = stream.ReadInt32L(); |
|
180 HBufC* serverDS = HBufC::NewLC( stream, maxlen ); |
|
181 |
|
182 maxlen = stream.ReadInt32L(); |
|
183 HBufC* clientDS = HBufC::NewLC( stream, maxlen ); |
|
184 |
|
185 CNSmlDSContentType* ctype; |
|
186 |
|
187 if ( iCreatingNew ) |
|
188 { |
|
189 ctype = prof->AddContentTypeL( iTaskUID, *clientDS, *serverDS ); // Implementation UID used when creating/updating task. |
|
190 |
|
191 if ( !ctype ) |
|
192 { |
|
193 User::Leave( KErrAlreadyExists); |
|
194 } |
|
195 } |
|
196 else |
|
197 { |
|
198 ctype = prof->ContentType( iTaskUID ); |
|
199 |
|
200 if ( !ctype ) |
|
201 { |
|
202 User::Leave( KErrNotFound ); |
|
203 } |
|
204 } |
|
205 |
|
206 // Save profile to create id for a new task. |
|
207 TInt ret = prof->SaveL(); |
|
208 |
|
209 CleanupStack::PopAndDestroy(clientDS); |
|
210 CleanupStack::PopAndDestroy(serverDS); |
|
211 |
|
212 User::LeaveIfError( ret ); |
|
213 |
|
214 ctype->SetIntValue( EDSAdapterEnabled, stream.ReadInt8L() ); |
|
215 ctype->SetIntValue( EDSAdapterCreatorId, stream.ReadInt32L() ); |
|
216 |
|
217 maxlen = stream.ReadInt32L(); |
|
218 ctype->SetStrValue( EDSAdapterDisplayName, HBufC::NewLC(stream,maxlen)->Des() ); |
|
219 CleanupStack::PopAndDestroy(); // display name |
|
220 |
|
221 ctype->SetIntValue( EDSAdapterSyncType, stream.ReadInt8L() ); |
|
222 |
|
223 ctype->SetIntValue( EDSAdapterFilterMatchType, stream.ReadInt8L() ); |
|
224 |
|
225 if ( (TSmlProtocolVersion)prof->IntValue( EDSProfileProtocolVersion ) == ESmlVersion1_2 ) |
|
226 { |
|
227 maxlen = stream.ReadInt32L(); |
|
228 RWriteStream filterStream = ctype->FilterWriteStreamL(); |
|
229 CleanupClosePushL(filterStream); |
|
230 |
|
231 filterStream.WriteInt32L(stream.ReadInt32L()); |
|
232 |
|
233 if ( maxlen ) |
|
234 { |
|
235 filterStream.WriteL( stream ); |
|
236 } |
|
237 |
|
238 CleanupStack::PopAndDestroy(&filterStream); |
|
239 ctype->WriteStreamCommitL(); |
|
240 } |
|
241 |
|
242 ret = prof->SaveL(); |
|
243 |
|
244 aId = ctype->IntValue( EDSAdapterTableId ); |
|
245 |
|
246 CleanupStack::PopAndDestroy(&stream); |
|
247 CleanupStack::PopAndDestroy(prof); |
|
248 |
|
249 return ret; |
|
250 } |
|
251 |
|
252 // -------------------------------------------------------------------------- |
|
253 // TInt CNSmlTask::GetSupportedFiltersL() |
|
254 // -------------------------------------------------------------------------- |
|
255 // |
|
256 TInt CNSmlTask::GetSupportedFiltersL() |
|
257 { |
|
258 CNSmlDSHostClient& dsClient = iSession.HostClient(); |
|
259 |
|
260 TInt resultCode(0); |
|
261 TSyncMLFilterMatchType matchType = ESyncMLMatchDisabled; |
|
262 TSyncMLFilterChangeInfo changeInfo = ESyncMLDefault; |
|
263 |
|
264 RPointerArray<CSyncMLFilter>* filterArray; |
|
265 |
|
266 // Initialize data providers. |
|
267 RArray<TInt> idArray; |
|
268 RArray<TInt> resultArray; |
|
269 CleanupClosePushL(resultArray); |
|
270 CleanupClosePushL(idArray); |
|
271 idArray.AppendL(iTaskUID); |
|
272 |
|
273 dsClient.CreateDataProvidersL( idArray, resultArray ); |
|
274 |
|
275 TInt res = resultArray[0]; |
|
276 User::LeaveIfError( res ); |
|
277 |
|
278 CleanupStack::PopAndDestroy(&idArray); |
|
279 CleanupStack::PopAndDestroy(&resultArray); |
|
280 |
|
281 filterArray = dsClient.SupportedServerFiltersL( iTaskUID, matchType, changeInfo, resultCode ); |
|
282 |
|
283 if ( filterArray ) |
|
284 { |
|
285 CleanupStack::PushL(filterArray); |
|
286 PackFilterArrayL( *filterArray, (TInt)matchType, (TInt)changeInfo ); |
|
287 filterArray->ResetAndDestroy(); |
|
288 CleanupStack::PopAndDestroy(filterArray); |
|
289 } |
|
290 else // No filters, write NULL values to the filter buffer. |
|
291 { |
|
292 |
|
293 CBufFlat* filterBuffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
294 CleanupStack::PushL( filterBuffer ); |
|
295 RBufWriteStream stream( *filterBuffer ); |
|
296 |
|
297 CleanupClosePushL(stream); |
|
298 |
|
299 stream.WriteInt8L( changeInfo ); |
|
300 stream.WriteInt8L( matchType ); |
|
301 stream.WriteInt32L( 0 ); // filter count |
|
302 |
|
303 CleanupStack::PopAndDestroy(&stream); |
|
304 |
|
305 delete iFilterBuffer; |
|
306 iFilterBuffer = filterBuffer; |
|
307 CleanupStack::Pop( filterBuffer ); |
|
308 } |
|
309 |
|
310 return resultCode; |
|
311 } |
|
312 |
|
313 // -------------------------------------------------------------------------- |
|
314 // void CNSmlTask::PackFilterArrayL( RPointerArray<CSyncMLFilter>* aFilterArray ) |
|
315 // -------------------------------------------------------------------------- |
|
316 // |
|
317 void CNSmlTask::PackFilterArrayL( RPointerArray<CSyncMLFilter>& aFilterArray, TInt aMatchType, TInt aChangeInfo ) |
|
318 { |
|
319 TInt count = aFilterArray.Count(); |
|
320 |
|
321 CBufFlat* filterBuffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
322 CleanupStack::PushL( filterBuffer ); |
|
323 RBufWriteStream stream( *filterBuffer ); |
|
324 CleanupClosePushL(stream); |
|
325 |
|
326 stream.WriteInt8L( aChangeInfo ); |
|
327 stream.WriteInt8L( aMatchType ); |
|
328 |
|
329 stream.WriteInt32L( count ); |
|
330 |
|
331 for ( TInt i = 0 ; i < count ; i++ ) |
|
332 { |
|
333 aFilterArray[i]->ExternalizeL( stream ); |
|
334 } |
|
335 |
|
336 CleanupStack::PopAndDestroy(&stream); |
|
337 delete iFilterBuffer; |
|
338 iFilterBuffer = filterBuffer; |
|
339 CleanupStack::Pop( filterBuffer ); |
|
340 } |
|
341 |
|
342 // -------------------------------------------------------------------------- |
|
343 // void CNSmlTask::PrepareFilterBufferL() |
|
344 // -------------------------------------------------------------------------- |
|
345 // |
|
346 TInt CNSmlTask::PrepareFilterBufferL( const TInt aTaskId ) |
|
347 { |
|
348 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
349 if ( prof ) |
|
350 { |
|
351 CleanupStack::PushL(prof); |
|
352 |
|
353 CNSmlDSContentType* ctype = prof->ContentTypeId( aTaskId ); // Table id used when fetching data. |
|
354 // content type is deleted in CNSmlDSProfile destructor. |
|
355 if ( ctype ) |
|
356 { |
|
357 TSyncMLFilterMatchType matchType(ESyncMLMatchDisabled); |
|
358 TSyncMLFilterChangeInfo changeInfo(ESyncMLDefault); |
|
359 |
|
360 TInt resultCode(0); |
|
361 |
|
362 // Initialize data providers. |
|
363 RArray<TInt> idArray; |
|
364 RArray<TInt> resultArray; |
|
365 CleanupClosePushL(resultArray); |
|
366 CleanupClosePushL(idArray); |
|
367 idArray.AppendL(iTaskUID); |
|
368 |
|
369 iSession.HostClient().CreateDataProvidersL( idArray, resultArray ); |
|
370 |
|
371 TInt res = resultArray[0]; |
|
372 User::LeaveIfError( res ); |
|
373 |
|
374 CleanupStack::PopAndDestroy(&idArray); |
|
375 CleanupStack::PopAndDestroy(&resultArray); |
|
376 |
|
377 // Filters |
|
378 RReadStream filterStream = ctype->FilterReadStreamL(); |
|
379 CleanupClosePushL( filterStream ); |
|
380 RPointerArray<CSyncMLFilter>* filterArray = new ( ELeave ) RPointerArray<CSyncMLFilter>(); |
|
381 CleanupStack::PushL( filterArray ); |
|
382 TInt count(0); |
|
383 TRAPD(error, count = filterStream.ReadInt32L() ); |
|
384 if ( error == KErrNone ) |
|
385 { |
|
386 for ( TInt i(0) ; i < count ; i++ ) |
|
387 { |
|
388 filterArray->AppendL( CSyncMLFilter::NewLC( filterStream ) ); |
|
389 CleanupStack::Pop(); |
|
390 } |
|
391 } |
|
392 else if ( prof->IntValue( EDSProfileProtocolVersion ) == ESmlVersion1_2 ) |
|
393 { |
|
394 CleanupStack::Pop(); // filterArray; |
|
395 filterArray->ResetAndDestroy(); |
|
396 delete filterArray; |
|
397 filterArray = iSession.HostClient().SupportedServerFiltersL( iTaskUID, matchType, changeInfo, resultCode ); |
|
398 CleanupStack::PushL( filterArray ); |
|
399 } |
|
400 |
|
401 iSession.HostClient().CheckServerFiltersL( iTaskUID, *filterArray, changeInfo, resultCode ); |
|
402 |
|
403 CNSmlDSAgentLog* agentLog = CNSmlDSAgentLog::NewLC(); |
|
404 |
|
405 TRAPD( err, agentLog->SetAgentLogKeyL( iTaskUID, |
|
406 ctype->StrValue( EDSAdapterClientDataSource ), |
|
407 prof->StrValue( EDSProfileServerId ), |
|
408 ctype->StrValue( EDSAdapterServerDataSource ) ) ); |
|
409 |
|
410 if ( err == KErrNone ) |
|
411 { |
|
412 RPointerArray<CNSmlDbCaps> dbCaps; |
|
413 CArrayFix<TNSmlFilterCapData>* filterInfoArr = new (ELeave) CArrayFixFlat<TNSmlFilterCapData> (1); |
|
414 |
|
415 agentLog->GetServerDeviceInfoL( dbCaps ); |
|
416 CleanupClosePushL( dbCaps ); |
|
417 |
|
418 agentLog->GetServerFilterInfoL( filterInfoArr ); |
|
419 CleanupStack::PushL( filterInfoArr ); |
|
420 |
|
421 CNSmlDbCaps* dbCapab = NULL; |
|
422 if ( dbCaps.Count() ) |
|
423 { |
|
424 dbCapab = dbCaps[0]; |
|
425 // Send arrays to the data provider for update. |
|
426 iSession.HostClient().CheckSupportedServerFiltersL( iTaskUID, *dbCapab, *filterInfoArr, *filterArray, changeInfo, resultCode ); |
|
427 } |
|
428 |
|
429 // Read updated array. |
|
430 PackFilterArrayL( *filterArray, ctype->IntValue( EDSAdapterFilterMatchType ), (TInt) changeInfo ); |
|
431 |
|
432 CleanupStack::PopAndDestroy(filterInfoArr); |
|
433 CleanupStack::PopAndDestroy(&dbCaps); |
|
434 } |
|
435 |
|
436 CleanupStack::PopAndDestroy(agentLog); |
|
437 |
|
438 filterArray->ResetAndDestroy(); |
|
439 CleanupStack::PopAndDestroy(filterArray); |
|
440 CleanupStack::PopAndDestroy(&filterStream); |
|
441 } |
|
442 else |
|
443 { |
|
444 GetSupportedFiltersL(); |
|
445 } |
|
446 CleanupStack::PopAndDestroy(prof); |
|
447 } |
|
448 return FilterSize(); |
|
449 } |