|
1 // Copyright (c) 2007-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 #include "ssmdebug.h" |
|
17 #include "ssmswppolicymap.h" |
|
18 |
|
19 |
|
20 // |
|
21 // The CSsmSwpPolicyMapping implementation |
|
22 // |
|
23 |
|
24 // Construction/destruction |
|
25 |
|
26 /** |
|
27 Create a mapping from an swp and a file name |
|
28 |
|
29 @param aSwpKey The swp key to set |
|
30 @param aFilename The file name associated with this swp key |
|
31 @return A new CSsmSwpPolicyMapping containing the swp and file name |
|
32 */ |
|
33 CSsmSwpPolicyMapping* CSsmSwpPolicyMapping::NewLC(TUint aSwpKey, const TDesC& aFilename) |
|
34 { |
|
35 CSsmSwpPolicyMapping* self = new (ELeave) CSsmSwpPolicyMapping(aSwpKey); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(aFilename); |
|
38 return self; |
|
39 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
40 |
|
41 /** |
|
42 Construct a mapping onbject |
|
43 |
|
44 @param aSwpKey swp key to set |
|
45 |
|
46 */ |
|
47 CSsmSwpPolicyMapping::CSsmSwpPolicyMapping(TUint aSwpKey) : |
|
48 iSwpKey(aSwpKey) |
|
49 { |
|
50 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
51 |
|
52 /** |
|
53 Set file on a constructed object |
|
54 |
|
55 @param aFile File name to set |
|
56 */ |
|
57 void CSsmSwpPolicyMapping::ConstructL(const TDesC& aFilename) |
|
58 { |
|
59 iFilename = aFilename.AllocL(); |
|
60 } |
|
61 |
|
62 /** |
|
63 Trivial destructor |
|
64 */ |
|
65 CSsmSwpPolicyMapping::~CSsmSwpPolicyMapping() |
|
66 { |
|
67 delete iFilename; |
|
68 } |
|
69 |
|
70 // Accessors |
|
71 |
|
72 /** |
|
73 Retrieve this mapping's swp key |
|
74 |
|
75 @return An swp key |
|
76 */ |
|
77 TUint CSsmSwpPolicyMapping::SwpKey() const |
|
78 { |
|
79 return iSwpKey; |
|
80 } |
|
81 |
|
82 /** |
|
83 Retrieve this mapping's file name |
|
84 |
|
85 @return A reference to a descriptor containing the file name |
|
86 */ |
|
87 const TDesC& CSsmSwpPolicyMapping::Filename() const |
|
88 { |
|
89 return *iFilename; |
|
90 } |
|
91 |
|
92 /** |
|
93 Method for comparing two mappings. |
|
94 Used by the map's sort and search functions |
|
95 */ |
|
96 TInt CSsmSwpPolicyMapping::CompareBySwp(const CSsmSwpPolicyMapping& aFirst, const CSsmSwpPolicyMapping& aSecond) |
|
97 { |
|
98 return aFirst.SwpKey() - aSecond.SwpKey(); |
|
99 } |
|
100 |
|
101 /** |
|
102 This linear order encapsulates the function used for sorting mappings by their swp as |
|
103 well as determining equivalence when searching |
|
104 |
|
105 @see TLinearOrder |
|
106 */ |
|
107 |
|
108 static TLinearOrder<CSsmSwpPolicyMapping> bySwp( CSsmSwpPolicyMapping::CompareBySwp ); |
|
109 |
|
110 |
|
111 // |
|
112 // The CSsmSwpPolicyMap implementation |
|
113 // |
|
114 |
|
115 // Construction/destruction |
|
116 |
|
117 /** |
|
118 Trivial factory methods |
|
119 */ |
|
120 CSsmSwpPolicyMap* CSsmSwpPolicyMap::NewLC() |
|
121 { |
|
122 CSsmSwpPolicyMap* self = new (ELeave) CSsmSwpPolicyMap(); |
|
123 CleanupStack::PushL(self); |
|
124 return self; |
|
125 } |
|
126 |
|
127 CSsmSwpPolicyMap* CSsmSwpPolicyMap::NewL() |
|
128 { |
|
129 CSsmSwpPolicyMap* self = NewLC(); |
|
130 CleanupStack::Pop(self); |
|
131 return self; |
|
132 } |
|
133 |
|
134 CSsmSwpPolicyMap::CSsmSwpPolicyMap() |
|
135 { |
|
136 } |
|
137 |
|
138 /** |
|
139 Destroy item list |
|
140 */ |
|
141 CSsmSwpPolicyMap::~CSsmSwpPolicyMap() |
|
142 { |
|
143 iItems.ResetAndDestroy(); |
|
144 } |
|
145 |
|
146 /** |
|
147 Add a mapping to the mapping list |
|
148 After this call, the map owns the mapping and the API user must pop the mapping |
|
149 from the cleanup stack |
|
150 |
|
151 @param aSwpKey The swp key to set |
|
152 @param aFilename The file name to be associated with this swp key |
|
153 @leave KErrAlreadyExists if this swp key is already in the list |
|
154 |
|
155 */ |
|
156 void CSsmSwpPolicyMap::AddL(TUint aSwpKey, const TDesC& aFilename) |
|
157 { |
|
158 CSsmSwpPolicyMapping* mapping = CSsmSwpPolicyMapping::NewLC(aSwpKey, aFilename); |
|
159 iItems.InsertInOrderL(mapping, bySwp); |
|
160 CleanupStack::Pop(mapping); |
|
161 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
162 |
|
163 /** |
|
164 * Delete a mapping from the mapping list |
|
165 * After this call the mapping corresponding to the key is deleted |
|
166 * @param aSwpKey The swp key to be deleted |
|
167 * @leave KErrNotFound if this swp key is not present in the list |
|
168 */ |
|
169 #ifdef _DEBUG |
|
170 void CSsmSwpPolicyMap::DeleteSwpMapL(TUint aSwpKey) |
|
171 { |
|
172 CSsmSwpPolicyMapping* mapping = CSsmSwpPolicyMapping::NewLC(aSwpKey, KNullDesC); |
|
173 TInt mappingarrayindex = iItems.FindInOrderL(mapping, bySwp); |
|
174 CleanupStack::PopAndDestroy(mapping); |
|
175 CSsmSwpPolicyMapping* found = iItems[mappingarrayindex]; |
|
176 delete found; |
|
177 iItems.Remove(mappingarrayindex); |
|
178 iItems.Compress(); |
|
179 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
180 #endif |
|
181 |
|
182 /** |
|
183 Find a file name for the supplied swp |
|
184 @param aSwpKey The swp key to search for in the mapping |
|
185 @return A descriptor containing the file name associated with the swp |
|
186 @leave KErrNotFound if there is no item matching this swp |
|
187 |
|
188 */ |
|
189 const TDesC& CSsmSwpPolicyMap::FilenameL(TUint aSwpKey) const |
|
190 { |
|
191 const CSsmSwpPolicyMapping* found = MappingL(aSwpKey); |
|
192 return found->Filename(); |
|
193 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
194 |
|
195 |
|
196 /** |
|
197 Find a mapping object for the supplied swp |
|
198 @param aSwp The swp key to search for |
|
199 @return The mapping object corresponding to the swp |
|
200 @leave KErrNotFound if there is no item matching this swp |
|
201 |
|
202 */ |
|
203 const CSsmSwpPolicyMapping* CSsmSwpPolicyMap::MappingL(TUint aSwpKey) const |
|
204 { |
|
205 CSsmSwpPolicyMapping* search = CSsmSwpPolicyMapping::NewLC(aSwpKey, KNullDesC); |
|
206 TInt pos = iItems.FindInOrderL(search, bySwp); |
|
207 CleanupStack::PopAndDestroy(search); |
|
208 const CSsmSwpPolicyMapping* const& found = iItems[pos]; |
|
209 return found; |
|
210 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
211 |
|
212 |