|
1 /* |
|
2 * Copyright (c) 2002 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: Declaration of some common global functions. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef APENGINE_COMMONS_H |
|
20 #define APENGINE_COMMONS_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <commdb.h> |
|
24 #include <ApEngineVer.h> |
|
25 |
|
26 |
|
27 // CONSTANTS |
|
28 _LIT(KSqlSelectBase, "SELECT * from %s WHERE %s='%S'"); |
|
29 _LIT( KEmpty, "" ); |
|
30 _LIT( KFormat, "%S" ); |
|
31 _LIT8( KFormat8,"%S" ); |
|
32 |
|
33 |
|
34 LOCAL_C const TInt KR_ApEngineDefaultValue = 0; |
|
35 |
|
36 // DATA TYPES |
|
37 |
|
38 enum TApEnginePanicCodes |
|
39 { |
|
40 ENullPointer, |
|
41 EInvalidDbType, |
|
42 EWrongResourceFormat, |
|
43 EActiveApDbObserverNotFound, |
|
44 EInvalidColumn, |
|
45 EInvalidSpeed, |
|
46 ESqlError, |
|
47 ESanityCheckFailed, |
|
48 ENotSupported, |
|
49 EMenuCommandUnknown |
|
50 }; |
|
51 |
|
52 |
|
53 // CLASS DECLARATION |
|
54 /** |
|
55 * ApCommons is a collection of commonly used 'utility' functions. |
|
56 */ |
|
57 NONSHARABLE_CLASS( ApCommons ) |
|
58 { |
|
59 public: |
|
60 /** |
|
61 * Panics. |
|
62 */ |
|
63 static void Panic( TApEnginePanicCodes aPanic ); |
|
64 |
|
65 /** |
|
66 * Starts a transaction on the given database if not already in one. |
|
67 * In case of error, leaves with CommDb error codes. |
|
68 * In case of KErrLocked, if retry is asked, it retries the operation |
|
69 * after a short ( KRetryWait ) period. If still locked, leaves with it |
|
70 * to allow caller module to handle the situation |
|
71 * (e.g. giving up a Retry/Cancel query). |
|
72 * In case of successfull transaction starting, pushes |
|
73 * RollbackTransactionOnLeave to the CleanUpStack. |
|
74 * @param aDb A reference to a CCommsDatabase object to start |
|
75 * the transaction. |
|
76 * @param aRetry A TBool indicating whether it shall retry |
|
77 * the operation or not. |
|
78 * @return Boolean indicating whether it has started a |
|
79 * transaction or not (it also means whether it has pushed it or not.) |
|
80 * It is used after DB operations to decide whether we have to |
|
81 * commit or it is the caller's task. |
|
82 */ |
|
83 static TBool StartPushedTransactionLC( CCommsDatabase& aDb, |
|
84 TBool aRetry = ETrue ); |
|
85 |
|
86 |
|
87 /** |
|
88 * Rolls back transaction on leave; called in leave processing. |
|
89 * @param aDb The database (CCommsDatabase*) as TAny*. |
|
90 */ |
|
91 static void RollbackTransactionOnLeave( TAny* aDb ); |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 /** |
|
97 * Creates a valid name from the passed aName. |
|
98 * @param aDb A reference to a CCommsDatabase object |
|
99 * @param aChanged A reference to a boolean to hold whether the name |
|
100 * had been changed or not. |
|
101 * @param aUid The Uid of the access point whose name we are checking |
|
102 * to be able to handle updates and ignore self-match only situation |
|
103 * @param aIsNew a boolean specifying whether tha access point whose |
|
104 * name we are checking is new or not. |
|
105 * @return A valid name |
|
106 */ |
|
107 static HBufC* DoMakeValidNameL( CCommsDatabase& aDb, |
|
108 TBool& aChanged, |
|
109 HBufC* aName, |
|
110 TUint32 aUid, |
|
111 TBool aIsNew ); |
|
112 |
|
113 /** |
|
114 * Ensures that the passed name is valid, length > 0 & length < max. |
|
115 * If length == 0, leaves with KErrInvalidName |
|
116 * If name is only whitespace, leaves with KErrInvalidName |
|
117 * If name is longer than max, name is truncated |
|
118 * It copies the name, pushez it onto the CleanupStack and passes |
|
119 * ownership. |
|
120 * @param aName The name |
|
121 * @param aChanged A reference to a boolean to hold whether the name |
|
122 * had been changed or not. |
|
123 * @return The valid-length name |
|
124 */ |
|
125 static HBufC* EnsureMaxLengthLC( const TDesC* aName, TBool& aChanged ); |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 /** |
|
133 * If aName is constructed from aPrefix with a postfix, get the numeric |
|
134 * value of the postfix, e.g: |
|
135 * - GetPostfix( "Foo (3)", "Foo" ) == 3 |
|
136 * - GetPostfix( "Foo 23 (45)", "Foo 23" ) == 45 |
|
137 * If aName is the same as aPrefix, return 0, e.g.: |
|
138 * - GetPostfix( "Foo", "Foo" ) == 0 |
|
139 * If aName is not constructed from aPrefix, return -1, e.g.: |
|
140 * - GetPostfix( "Foobar", "Foo" ) == -1 |
|
141 * - GetPostfix( "Fo 23 45", "Foo" ) == -1 |
|
142 * @param aName The name to get the postfix from |
|
143 * @param aPrefix The prefix |
|
144 * @return The postfix |
|
145 */ |
|
146 static TInt GetPostfix( const TDesC& aName, const TDesC& aPrefix ); |
|
147 |
|
148 |
|
149 /** |
|
150 * Given aName in the format <prefix> or |
|
151 * <prefix><brace><integer><brace>, return a |
|
152 * pointer to the leading part. That is, if there is |
|
153 * trailing <space><integer>, then that is excluded; |
|
154 * if there is no trailing part, then the original |
|
155 * decriptor is returned. |
|
156 * Examples: |
|
157 * - "Foo" returns "Foo"; |
|
158 * - "Foo 12" returns "Foo 12"; |
|
159 * - "Foo(12)" returns "Foo"; |
|
160 * - "Foo 12 (34)" returns "Foo 12 "; |
|
161 * - "Foo bar" returns "Foo bar"; |
|
162 * - "Foo " returns "Foo ". |
|
163 * @param aName The name to get the prefix from |
|
164 * @return The prefix |
|
165 */ |
|
166 static TPtrC GetPrefix( const TDesC& aName ); |
|
167 |
|
168 |
|
169 /** |
|
170 * Reads up a TUint32 from the given tables given column. |
|
171 * Leaves in case of error. |
|
172 * Leave with KErrUnknown is captured and returned as |
|
173 * function return value. |
|
174 * The main aim is not to Leave if some value is not written to the DB. |
|
175 * @param atable The table to read from |
|
176 * @param aColumn The column to read |
|
177 * @param aValue A reference to hold the readed integer |
|
178 * @return Error code |
|
179 */ |
|
180 static TInt ReadUintL |
|
181 ( |
|
182 CCommsDbTableView* atable, |
|
183 const TDesC& aColumn, |
|
184 TUint32& aValue |
|
185 ); |
|
186 |
|
187 /** |
|
188 * Reads up a TBool from the given tables given column. |
|
189 * Leaves in case of error. |
|
190 * Leave with KErrUnknown is captured and returned as |
|
191 * function return value. |
|
192 * The main aim is not to Leave if some value is not written to the DB. |
|
193 * @param atable The table to read from |
|
194 * @param aColumn The column to read |
|
195 * @param aValue A reference to hold the readed boolean |
|
196 * @return Error code |
|
197 */ |
|
198 static TInt ReadBoolL |
|
199 ( |
|
200 CCommsDbTableView* atable, |
|
201 const TDesC& aColumn, |
|
202 TBool& aValue |
|
203 ); |
|
204 |
|
205 |
|
206 /** |
|
207 * Reads up a long text from the given tables given column. |
|
208 * Leaves in case of error. |
|
209 * Leave with KErrUnknown is captured and returned as |
|
210 * function return value. |
|
211 * Ownership of the returned text is passed to the caller. |
|
212 * The main aim is not to Leave if some value is not written to the DB. |
|
213 * @param atable The table to read from |
|
214 * @param aColumn The column to read |
|
215 * @param aValue A reference to hold the error code |
|
216 * @return The readed long text |
|
217 */ |
|
218 static HBufC* ReadLongTextLC |
|
219 ( |
|
220 CCommsDbTableView* atable, |
|
221 const TDesC& aColumn, |
|
222 TInt& aErrCode |
|
223 ); |
|
224 |
|
225 |
|
226 /** |
|
227 * Reads up a long text from the given tables given column. |
|
228 * Leaves in case of error. |
|
229 * Ownership of the returned text is passed to the caller. |
|
230 * Readed data is poped from the CleanuptStack to be able |
|
231 * to TRAP it in ReadLongTextLC (above) function... |
|
232 * @param atable The table to read from |
|
233 * @param aColumn The column to read |
|
234 * @return The readed long text |
|
235 */ |
|
236 static HBufC* ReadLongTextL( CCommsDbTableView* atable, |
|
237 const TDesC& aColumn ); |
|
238 |
|
239 |
|
240 /** |
|
241 * Returns the escaped aLiteral. |
|
242 * @param aLiteral The lietral to be escaped |
|
243 * @return the escaped aLiteral. |
|
244 */ |
|
245 static HBufC* EscapeTextLC( const TDesC& aLiteral ); |
|
246 |
|
247 |
|
248 /** |
|
249 * Reads up the specified text columns value from the database. |
|
250 * In case of error, leaves with CommDb error codes. |
|
251 */ |
|
252 static HBufC16* ReadText16ValueLC( CCommsDbTableView* atable, |
|
253 const TDesC& aCol ); |
|
254 |
|
255 /** |
|
256 * Reads up the specified text columns value from the database. |
|
257 * In case of error, leaves with CommDb error codes. |
|
258 * @param atable The table to read from |
|
259 * @param aColumn The column to read |
|
260 * @return The readed text |
|
261 */ |
|
262 static HBufC8* ReadText8ValueLC( CCommsDbTableView* atable, |
|
263 const TDesC& aCol ); |
|
264 |
|
265 /** |
|
266 * Reads up the read-only flag for the current record |
|
267 * in the passed table |
|
268 * In case of error, leaves with CommDb error codes. |
|
269 * The function expects the passed table to have a valid |
|
270 * current record, that is, after creating the table, |
|
271 * record cursor must be setted to the desired record... |
|
272 * @param aTable The table to read current records read-only flag. |
|
273 * @return The current records read-only flag |
|
274 */ |
|
275 static TBool DoGetReadOnlyL( CCommsDbTableView& aTable ); |
|
276 |
|
277 |
|
278 /** |
|
279 * Commits a transaction on the given database. |
|
280 * In case of error, returns the CommDb error codes. |
|
281 * @param aDb The database to commit the transaction on |
|
282 * @return Error code |
|
283 */ |
|
284 static TInt CommitTransaction( CCommsDatabase& aDb ); |
|
285 |
|
286 |
|
287 /** |
|
288 * Gets the local variant value |
|
289 * @return A TInt stating the variant |
|
290 */ |
|
291 static TInt GetVariantL(); |
|
292 |
|
293 |
|
294 /** |
|
295 * Gives back the TInt Value of the given shared data key for the given |
|
296 * UId. Does't use notify the given shared data, just gives back the |
|
297 * actual value. |
|
298 * @param aUid actual uid to identify the chunk of shared data |
|
299 * @param aKey actual shared data key |
|
300 * @return The actual value of the shared data |
|
301 */ |
|
302 static TInt IsGivenSharedDataSupportL( const TUid aUid, |
|
303 const TUint32 aKey ); |
|
304 |
|
305 }; |
|
306 |
|
307 #endif // CAPENGINE_COMMONS_H |
|
308 |
|
309 // End of File |