|
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: Utilities for DS Loader Framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #ifndef __HOST_SERVER_MTEST__ |
|
21 #include <SmlDataProvider.h> |
|
22 #endif |
|
23 |
|
24 #include "nsmldsitemmodificationset.h" |
|
25 |
|
26 // ================================= MEMBER FUNCTIONS ============================================= |
|
27 |
|
28 // ------------------------------------------------------------------------------------------------ |
|
29 // RNSmlDbItemModificationSet::AddItem |
|
30 // Adds item to modification set. |
|
31 // ------------------------------------------------------------------------------------------------ |
|
32 EXPORT_C TInt RNSmlDbItemModificationSet::AddItemL(const TNSmlDbItemModification& aItem ) |
|
33 { |
|
34 if ( iItemSet.Find( aItem ) != KErrNotFound ) |
|
35 { |
|
36 return KErrAlreadyExists; |
|
37 } |
|
38 else |
|
39 { |
|
40 iItemSet.AppendL( aItem ); |
|
41 } |
|
42 |
|
43 return KErrNone; |
|
44 } |
|
45 |
|
46 // ------------------------------------------------------------------------------------------------ |
|
47 // RNSmlDbItemModificationSet::RemoveItem |
|
48 // Removes the item at a specified position from the modification set. |
|
49 // ------------------------------------------------------------------------------------------------ |
|
50 EXPORT_C void RNSmlDbItemModificationSet::RemoveItem( TInt aIndex ) |
|
51 { |
|
52 iItemSet.Remove( aIndex ); |
|
53 } |
|
54 |
|
55 // ------------------------------------------------------------------------------------------------ |
|
56 // RNSmlDbItemModificationSet::AddGroup |
|
57 // Adds group of items to modification set. |
|
58 // ------------------------------------------------------------------------------------------------ |
|
59 EXPORT_C void RNSmlDbItemModificationSet::AddGroupL( const MSmlDataItemUidSet& aUidSet, TNSmlDbItemModification::TNSmlDbItemModificationType aModType ) |
|
60 { |
|
61 for ( TInt i = 0; i < aUidSet.ItemCount(); i++ ) |
|
62 { |
|
63 TNSmlDbItemModification tempItem( aUidSet.ItemAt( i ), aModType ); |
|
64 if ( iItemSet.Find( tempItem ) == KErrNotFound ) |
|
65 { |
|
66 iItemSet.AppendL( tempItem ); |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 // ------------------------------------------------------------------------------------------------ |
|
72 // RNSmlDbItemModificationSet::ItemCount |
|
73 // Returns the number of items in the set. |
|
74 // ------------------------------------------------------------------------------------------------ |
|
75 EXPORT_C TInt RNSmlDbItemModificationSet::ItemCount() const |
|
76 { |
|
77 return iItemSet.Count(); |
|
78 } |
|
79 |
|
80 // ------------------------------------------------------------------------------------------------ |
|
81 // RNSmlDbItemModificationSet::ItemIndex |
|
82 // Returns the index of modification item. |
|
83 // ------------------------------------------------------------------------------------------------ |
|
84 EXPORT_C TInt RNSmlDbItemModificationSet::ItemIndex( const TSmlDbItemUid aItemId ) const |
|
85 { |
|
86 for ( TInt i = 0; i < iItemSet.Count(); i++ ) |
|
87 { |
|
88 if ( iItemSet[i].ItemId() == aItemId ) |
|
89 { |
|
90 return i; |
|
91 } |
|
92 } |
|
93 return KErrNotFound; |
|
94 } |
|
95 |
|
96 // ------------------------------------------------------------------------------------------------ |
|
97 // RNSmlDbItemModificationSet::ItemAt |
|
98 // Retuns the modifcation item. |
|
99 // ------------------------------------------------------------------------------------------------ |
|
100 EXPORT_C TNSmlDbItemModification RNSmlDbItemModificationSet::ItemAt( TInt aIndex ) const |
|
101 { |
|
102 return iItemSet[aIndex]; |
|
103 } |
|
104 |
|
105 // ------------------------------------------------------------------------------------------------ |
|
106 // RNSmlDbItemModificationSet::Reset |
|
107 // Resets modification set. |
|
108 // ------------------------------------------------------------------------------------------------ |
|
109 EXPORT_C void RNSmlDbItemModificationSet::Reset() |
|
110 { |
|
111 iItemSet.Reset(); |
|
112 } |
|
113 |
|
114 // ------------------------------------------------------------------------------------------------ |
|
115 // RNSmlDbItemModificationSet::Reset |
|
116 // Closes modification set. |
|
117 // ------------------------------------------------------------------------------------------------ |
|
118 EXPORT_C void RNSmlDbItemModificationSet::Close() |
|
119 { |
|
120 Reset(); |
|
121 } |
|
122 |
|
123 // ------------------------------------------------------------------------------------------------ |
|
124 // RNSmlDbItemModificationSet::ExternalizeL |
|
125 // This method externalizes class to stream. |
|
126 // ------------------------------------------------------------------------------------------------ |
|
127 EXPORT_C void RNSmlDbItemModificationSet::ExternalizeL( RWriteStream& aStream ) const |
|
128 { |
|
129 aStream.WriteInt32L( iItemSet.Count() ); |
|
130 for ( TInt i = 0; i < iItemSet.Count(); i++ ) |
|
131 { |
|
132 TPckgBuf<TSmlDbItemUid> b( ( iItemSet[i].ItemId() ) ); |
|
133 aStream << b; |
|
134 TPckgBuf<TNSmlDbItemModification::TNSmlDbItemModificationType> c( iItemSet[i].ModificationType() ); |
|
135 aStream << c; |
|
136 } |
|
137 } |
|
138 |
|
139 // ------------------------------------------------------------------------------------------------ |
|
140 // RNSmlDbItemModificationSet::InternalizeL |
|
141 // This method internalizes class from stream. |
|
142 // ------------------------------------------------------------------------------------------------ |
|
143 EXPORT_C void RNSmlDbItemModificationSet::InternalizeL( RReadStream& aStream ) |
|
144 { |
|
145 TInt count( aStream.ReadInt32L() ); |
|
146 for ( TInt i = 0; i < count; i++ ) |
|
147 { |
|
148 TPckgBuf<TSmlDbItemUid> packageA; |
|
149 aStream >> packageA; |
|
150 TSmlDbItemUid tempId = packageA(); |
|
151 |
|
152 TPckgBuf<TNSmlDbItemModification::TNSmlDbItemModificationType> packageB; |
|
153 aStream >> packageB; |
|
154 TNSmlDbItemModification::TNSmlDbItemModificationType tempModType = packageB(); |
|
155 |
|
156 TNSmlDbItemModification tempItem( tempId, tempModType ); |
|
157 AddItemL( tempItem ); |
|
158 } |
|
159 }; |
|
160 |
|
161 // ------------------------------------------------------------------------------------------------ |
|
162 // RNSmlDbItemModificationSet::StreamSize |
|
163 // calculates size needed for stream when externalized. |
|
164 // ------------------------------------------------------------------------------------------------ |
|
165 EXPORT_C TInt RNSmlDbItemModificationSet::StreamSize() const |
|
166 { |
|
167 return ( sizeof( TInt32 ) + ( sizeof( TNSmlDbItemModification ) + 2 ) * ItemCount() ); |
|
168 } |
|
169 |
|
170 // End of File |