|
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: LUID buffering |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <nsmldebug.h> |
|
21 #include "nsmldsluidbuffer.h" |
|
22 #include "nsmlcliagconstants.h" |
|
23 #include "nsmldshostclient.h" |
|
24 #include "nsmldscontent.h" |
|
25 #include "NsmlDSContentItem.h" |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CNSmlDSLUIDBuffer::CNSmlDSLUIDBuffer |
|
31 // C++ constructor. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CNSmlDSLUIDBuffer::CNSmlDSLUIDBuffer( |
|
35 CNSmlDSHostClient& aHostClient, |
|
36 CNSmlDSContentItem& aContentItem ) : iHostClient( aHostClient ), |
|
37 iContentItem( aContentItem ), |
|
38 iWrittenItems( 0 ) |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CNSmlDSUIDBuffer::~CNSmlDSUIDBuffer |
|
44 // Destructor. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CNSmlDSLUIDBuffer::~CNSmlDSLUIDBuffer() |
|
48 { |
|
49 iModificationSet.Close(); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CNSmlDSLUIDBuffer::NextUIDL |
|
54 // Gets the first UID and its modification type from the buffer. The aCmdName |
|
55 // parameter is determined by the modification type. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 TInt CNSmlDSLUIDBuffer::NextUIDL( TSmlDbItemUid& aLocalUID, TDes8& aCmdName ) |
|
59 { |
|
60 TInt ret( KErrNone ); |
|
61 |
|
62 switch ( iCurrState ) |
|
63 { |
|
64 case EModifications: |
|
65 if ( iModificationSet.ItemCount() > 0 ) |
|
66 { |
|
67 aLocalUID = iModificationSet.ItemAt( 0 ).ItemId(); |
|
68 |
|
69 switch ( iModificationSet.ItemAt( 0 ).ModificationType() ) |
|
70 { |
|
71 case TNSmlDbItemModification::ENSmlDbItemAdd: |
|
72 aCmdName = KNSmlAgentAdd; |
|
73 break; |
|
74 |
|
75 case TNSmlDbItemModification::ENSmlDbItemModify: |
|
76 aCmdName = KNSmlAgentReplace; |
|
77 break; |
|
78 |
|
79 case TNSmlDbItemModification::ENSmlDbItemDelete: |
|
80 aCmdName = KNSmlAgentDelete; |
|
81 break; |
|
82 |
|
83 case TNSmlDbItemModification::ENSmlDbItemMove: |
|
84 aCmdName = KNSmlAgentMove; |
|
85 break; |
|
86 |
|
87 case TNSmlDbItemModification::ENSmlDbItemSoftDelete: |
|
88 aCmdName = KNSmlAgentSoftDelete; |
|
89 break; |
|
90 |
|
91 default: |
|
92 User::Leave( KErrGeneral ); |
|
93 } |
|
94 } |
|
95 else |
|
96 { |
|
97 iModificationSet.Reset(); |
|
98 iCurrState = EEnd; |
|
99 ret = KErrEof; |
|
100 } |
|
101 break; |
|
102 |
|
103 case EEnd: |
|
104 return KErrEof; |
|
105 |
|
106 default: |
|
107 User::Leave( KErrGeneral ); |
|
108 } |
|
109 |
|
110 return ret; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CNSmlDSLUIDBuffer::CurrentUID |
|
115 // Returns the first UID in the buffer. |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CNSmlDSLUIDBuffer::CurrentUID( TSmlDbItemUid& aLocalUID ) const |
|
119 { |
|
120 if ( iModificationSet.ItemCount() > 0 ) |
|
121 { |
|
122 aLocalUID = iModificationSet.ItemAt( 0 ).ItemId(); |
|
123 } |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CNSmlDSLUIDBuffer::ClientItemCount |
|
128 // Returns the total number of UIDs (both those still in the buffer and those |
|
129 // already written). |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CNSmlDSLUIDBuffer::ClientItemCount() const |
|
133 { |
|
134 return iModificationSet.ItemCount() + iWrittenItems; |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CNSmlDSLUIDBuffer::SetCurrentItemWritten |
|
139 // Removes the current UID from the buffer. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CNSmlDSLUIDBuffer::SetCurrentItemWritten() |
|
143 { |
|
144 iModificationSet.RemoveItem( 0 ); |
|
145 ++iWrittenItems; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CNSmlDSLUIDBuffer::FetchModificationsL |
|
150 // Gets UIDs of all modified items from datastore to the buffer asynchronously. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CNSmlDSLUIDBuffer::FetchModificationsL( TInt& aResultCode ) |
|
154 { |
|
155 DBG_FILE(_S8("CNSmlDSLUIDBuffer::FetchModificationsL begins")); |
|
156 |
|
157 iModificationSet.Reset(); |
|
158 |
|
159 iHostClient.AllItemsL( iModificationSet, iContentItem.iImplementationUID, |
|
160 *iContentItem.iStoreName, aResultCode ); |
|
161 |
|
162 iCurrState = EModifications; |
|
163 |
|
164 DBG_FILE(_S8("CNSmlDSLUIDBuffer::FetchModificationsL ends")); |
|
165 } |
|
166 |
|
167 // End of File |