2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: CPosLmMultiDbSearch class used to perform searches for landmarks or
15 * landmark categories in multiple databases.
21 #ifndef CPOSLMMULTIDBSEARCH_H
22 #define CPOSLMMULTIDBSEARCH_H
26 #include <EPos_CPosLandmarkSearch.h>
27 #include <EPos_CPosLmCategoryManager.h>
29 class CPosLmSearchCriteria;
30 class CPosLmDisplayData;
31 class CPosLmMultiDbSearchOperation;
32 class CPosLmMultiDbSortPref;
33 class CPosLmMultiDbSearchItem;
36 * @ref CPosLmMultiDbSearch is used to perform searches for landmarks or
37 * landmark categories in multiple databases.
39 * The client can specify which databases to search.
41 * Some criterion classes are used for searching for landmarks (e.g.
42 * @ref CPosLmCategoryCriteria is used for searching for landmarks which
43 * contain a certain category) and some are used
44 * to search for landmark categories (e.g. @ref CPosLmCatNameCriteria is used
45 * to search for landmark categories by specifying a category name).
47 * Searches can be run in incremental mode.
48 * @ref StartLandmarkSearchL and @ref StartCategorySearchL both return a
49 * @p CPosLmOperation object which is used to execute the search. If it is
50 * sufficient to run the search synchronously, the client only has to
51 * call @p CPosLmOperation::ExecuteL. If it is run incrementally the client can
52 * supervise the progress of the operation. The @p CPosLmOperation::NextStep
53 * function in the search operations cannot be executed synchronously using
54 * @p User::WaitForRequest. Doing so may cause the operation to hang.
55 * @p CPosLmOperation::NextStep must be run using an active object. The client
56 * can cancel the search by deleting the @p CPosLmOperation object.
58 * By default, these functions start a new search, but the client can specify
59 * that only previous matches should be searched. This can be used to refine
60 * the search when there are many matches.
62 * It is not allowed to search by category item ID in
63 * @ref CPosLmCategoryCriteria since an item ID is only valid in one landmark
66 * It is only allowed to specify a named category, a global category,
67 * or no category. It is not allowed to search with @ref CPosLmIdListCriteria
68 * since an item ID is only valid in one landmark database. In both cases
69 * the search functions leave with error code @p KErrArgument.
71 * During the search execution, a read-lock is acquired for each database.
72 * Only one search can be performed at a time by the single instance of
73 * the class. If a search is already running, the search function leaves
74 * with error code @p KErrInUse.
76 * After search completion, the client can make a second search and specify
77 * that only the matches from the previous search shall be considered.
79 * The client can also set a limit on how many search matches should be
80 * returned (see @ref SetMaxNumOfMatches).
82 * The client retrieves the matches from the search by requesting an iterator
83 * (see @ref MatchIteratorL) or by using display data (see
84 * @ref SetDisplayData).
86 * If @ref CPosLmMultiDbSearch is used, the client must call the global
87 * function @ref ReleaseLandmarkResources before terminating in order to
88 * release all used landmark resources, otherwise the client may receive
91 * @p NetworkServices capability is required for remote databases.
93 * @lib eposlmmultidbsearch.lib
95 * @version $Revision: 1.17 $, $Date: 2005/07/07 13:40:10 $
97 class CPosLmMultiDbSearch : public CBase
102 * Struct containing a search error.
106 TUint iDatabaseIndex; /**<
107 The index of the database where the search has failed. The
108 database URI can be retrieved by calling @ref DatabaseUriPtr.*/
109 TInt iErrorCode; /**<
110 The search error code for the database. */
113 public: // Constructors and destructor
116 * Two-phased constructor.
118 * Leaves with @p KErrArgument if the database list is empty.
120 * @param[in] aDatabaseList An array containing the URIs of the landmark
121 * databases to be used in the search.
122 * @return A new instance of this class.
124 IMPORT_C static CPosLmMultiDbSearch* NewL( const CDesCArray& aDatabaseList );
129 IMPORT_C virtual ~CPosLmMultiDbSearch();
131 public: // New functions
134 * Specifies the list of databases that should be used in the search.
136 * If this function is called and then @ref StartLandmarkSearchL or
137 * @ref StartCategorySearchL is called with the flag
138 * aSearchOnlyPreviousMatches set, new databases that were not a part
139 * of the previous search will generate no matches.
141 * If the client specifies database(s) that do not exist,
142 * @ref GetSearchError will report error code @p KErrNotFound for those
143 * databases after the search is started.
145 * This function will leave with @p KErrInUse if called during a
148 * If this function is called after a search has completed,
149 * database indexes in the results may become invalid.
151 * If a database is removed from a previously set list, the search
152 * result of that database is unavailable after this function
153 * is called. Search errors are reset after this function is called.
155 * Leaves with @p KErrArgument if the database list is empty.
158 * @param[in] aDatabaseList An array containing the URIs of the landmark
159 * databases to be used in the search.
161 IMPORT_C void SetDatabasesToSearchL( const CDesCArray& aDatabaseList );
164 * Returns the list of databases to search. Ownership is transferred
167 * @return The list of databases to search.
169 IMPORT_C CDesCArray* DatabasesToSearchL();
172 * Sets the maximum number of search matches limit for each database.
174 * This function is used to limit the number of matches retrieved from
175 * each database in the search operation. If the limit is set, the
176 * search operation will stop when this limit is reached. By default
177 * the maximum number of matches is unlimited.
179 * If a new value for maximum number of matches is set when a search is
180 * ongoing, it will not affect the current search. The new maximum will
181 * be utilized in the next search.
184 * @param[in] aMaxNumOfMatches The maximum number of search matches for
185 * each landmark database involved in the search.
187 IMPORT_C void SetMaxNumOfMatches( TInt aMaxNumOfMatches = KPosLmMaxNumOfMatchesUnlimited );
190 * Starts a landmark search.
192 * If there are no previous matches and the client specifies that
193 * previous matches should be used, this function leaves with error
194 * code @p KErrArgument.
196 * If a search is already running, this function leaves with error
199 * If the search criterion is not valid for landmark searching, this
200 * function leaves with error code @p KErrArgument.
202 * If the search criterion is not supported, this function leaves
203 * with error code @p KErrNotSupported.
205 * If @ref CPosLmIdListCriteria is used or @ref CPosLmCategoryCriteria
206 * with item ID set, this function leaves with error code
209 * The client takes ownership of the returned operation object.
211 * This function requires @p ReadUserData capability.
214 * @param[in] aCriteria The search criterion.
215 * @param[in] aSearchOnlyPreviousMatches This flag may be used to perform a
216 * search within the results of previous search.
217 * @returns A handle to the search operation.
219 IMPORT_C CPosLmOperation* StartLandmarkSearchL(
220 const CPosLmSearchCriteria& aCriteria,
221 TBool aSearchOnlyPreviousMatches = EFalse );
224 * Starts a landmark search.
226 * This overload of the @ref StartLandmarkSearchL function lets the
227 * client define the sort order for the search matches.
229 * Only sorting by landmark name is supported. If the client tries to
230 * sort by another attribute, this function leaves with error code
231 * @p KErrNotSupported.
233 * If there are no previous matches and the client specifies that
234 * previous matches should be used, this function leaves with error
235 * code @p KErrArgument.
237 * If a search is already running, this function will leave with error
240 * If the search criterion is not valid for landmark searching, this
241 * function leaves with error code @p KErrArgument.
243 * If the search criterion is not supported, this function will leave
244 * with error code @p KErrNotSupported.
246 * If @ref CPosLmIdListCriteria is used or @ref CPosLmCategoryCriteria
247 * with item ID set, this function leaves with error code
250 * The client takes ownership of the returned operation object.
252 * This function requires @p ReadUserData capability.
255 * @param[in] aCriteria The search criterion.
256 * @param[in] aSortPref A sort preference object.
257 * @param[in] aSearchOnlyPreviousMatches This flag may be used to perform a
258 * search within the results of previous search.
259 * @returns A handle to the search operation.
261 IMPORT_C CPosLmOperation* StartLandmarkSearchL(
262 const CPosLmSearchCriteria& aCriteria,
263 const TPosLmSortPref& aSortPref,
264 TBool aSearchOnlyPreviousMatches = EFalse );
267 * Starts a search for landmark categories.
269 * If there are no previous matches and the client specifies that
270 * previous matches should be used, this function leaves with error
271 * code @p KErrArgument...
273 * The criterion, which defines if a landmark category is a match,
274 * is passed as input to this function.
276 * If a search is already running, this function leaves with error
279 * If the search criterion is not valid for landmark category searching,
280 * this function leaves with error code @p KErrArgument.
282 * If the search criterion is not supported, this function leaves
283 * with error code @p KErrNotSupported.
285 * The client takes ownership of the returned operation object.
287 * This function requires @p ReadUserData capability.
289 * @param[in] aCriteria The search criteria.
290 * @param[in] aSortPref Sort preference for the search results.
291 * @param[in] aSearchOnlyPreviousMatches This flag may be used to perform a
292 * search within the results of previous search.
293 * @returns A handle to the search operation.
295 IMPORT_C CPosLmOperation* StartCategorySearchL(
296 const CPosLmSearchCriteria& aCriteria,
297 CPosLmCategoryManager::TCategorySortPref aSortPref,
298 TBool aSearchOnlyPreviousMatches = EFalse );
301 * Returns the number of errors encountered during the search. This is
302 * the same as number of databases in which the search has failed.
305 * @return The number of errors encountered during the search.
307 IMPORT_C TUint NumOfSearchErrors() const;
310 * Returns errors encountered in the search.
312 * The client specifies an index of the error to retrieve. The index must
313 * be strictly less than @ref NumOfSearchErrors, otherwise this function
314 * panics with code @p EPosInvalidIndex. Whenever a new search is started
315 * this function must be called again to retrieve error codes, if any.
318 * @param[in] aErrorIndex The index of the error to retrieve.
319 * @param[out] aSearchError On return, contains the search error.
321 IMPORT_C void GetSearchError(
323 TSearchError& aSearchError ) const;
326 * Returns the total number of matches so far in the search.
328 * This function can also be called during a search operation.
331 * @return The number of search matches.
333 IMPORT_C TUint TotalNumOfMatches() const;
336 * Returns the number of matches so far in the search for a
337 * database specified by index.
339 * The index must be strictly less than @ref NumOfDatabasesToSearch,
340 * otherwise this function will panic with code @p EPosInvalidIndex.
341 * The URI of the database can be retrieved by calling
342 * @ref DatabaseUriPtr.
344 * This function can also be called during a search operation.
346 * @param[in] aDatabaseIndex The index of the database to get number
347 * of search matches for.
348 * @return The number of matches per database.
350 IMPORT_C TUint NumOfMatches( TUint aDatabaseIndex ) const;
353 * Returns the number of databases involved in the search.
356 * @return The number of databases involved in the search.
358 IMPORT_C TUint NumOfDatabasesToSearch() const;
361 * Returns the URI of a database involved in the search.
363 * The client specifies an index of the database URI to retrieve. The
364 * index must be strictly less than @ref NumOfDatabasesToSearch,
365 * otherwise this function will panic with code @p EPosInvalidIndex.
368 * @param[in] aDatabaseIndex The index of the database URI to retrieve.
369 * @return A pointer to the database URI descriptor. This pointer is
370 * only valid until @ref SetDatabasesToSearch is called, or the
371 * @ref CPosLmMultiDbSearch object is destroyed, whichever happens
374 IMPORT_C TPtrC DatabaseUriPtr( TUint aDatabaseIndex ) const;
377 * Creates an iterator object to iterate the matching landmarks or
378 * categories from one of the databases involved in the search.
380 * The database to get search matches for is specified by index. The
381 * index must be strictly less than @ref NumOfDatabasesToSearch,
382 * otherwise this function will panic with code @p EPosInvalidIndex.
383 * The URI of the database can be retrieved by calling
384 * @ref DatabaseUriPtr.
386 * This function can also be called during a search in order to read the
387 * matches encountered so far. Note that the iterator will not iterate
388 * any new matches. If new matches are found, a new iterator needs to be
389 * created to retrieve them. The previous matches will also be included.
391 * If the client has started a search, but no matches have been found
392 * yet in the database, an empty iterator is returned.
394 * If a sort preference was specified when the search was started, the
395 * landmarks or categories will be sorted when the search is complete
396 * but the items are not necessarily sorted if this function is
397 * called during a search.
399 * The client takes ownership of the returned iterator object.
401 * Note: The iterator iterates matches in @ref CPosLmMultiDbSearch.
402 * It cannot be used after the search object has been deleted.
405 * @param aDatabaseIndex The index of the database to get search matches
407 * @return A search results iterator.
409 IMPORT_C CPosLmItemIterator* MatchIteratorL( TUint aDatabaseIndex );
412 * Display data can be used as an alternative way to get result
413 * from a database search. Landmarks or categories are added to the
414 * display data collection during a search depending on the search type.
416 * This function may replace the combination of using
417 * @ref MatchIteratorL and reading landmark or category data.
418 * Result data is read already during the search and no duplicate
419 * access to database is needed.
421 * The display data object will be reset each time a new search is
422 * started. No items during the search are removed from the
423 * collection. New found matches can be added every time next
424 * search step is completed, see @ref CPosLmDisplayData::NewItemIndex.
426 * If the client sets display data during an ongoing search, this
427 * function panics with code @p EPosSearchOperationInUse.
429 * The client owns the display data object. If the client deletes it
430 * during a search, this may lead to unexpected errors. The client must
431 * call @ref UnsetDisplayData before it deletes the display data object.
433 * Search results from all databases are collected in the same
434 * displayable data collection. The @ref CPosLmDisplayItem::DatabaseIndex
435 * may be used to know which database every displayable item belongs to.
436 * The database index matches databases specified in this object,
437 * see @ref DatabaseUriPtr.
439 * @param[in,out] aData The displayable data.
441 IMPORT_C void SetDisplayData( CPosLmDisplayData& aData );
444 * Unsets display data. No further data will be added to the display
445 * data set with @ref SetDisplayData.
447 * If the client unsets display data during an ongoing search, this
448 * function panics with code @p EPosSearchOperationInUse.
450 IMPORT_C void UnsetDisplayData();
453 * Retrieves the maximum number of search matches limit for each
456 * By default the maximum number of matches is unlimited.
458 * @return The maximum number of search matches for each landmark
459 * database involved in the search or
460 * @p KPosLmMaxNumOfMatchesUnlimited if unlimited.
462 IMPORT_C TInt MaxNumOfMatches() const;
465 * Tells if the database with the specified database index is to be
468 * @param aDatabaseIndex The index of the database.
469 * @return ETrue if the database is to be searched, otherwise EFalse.
471 TBool ToBeSearched( TUint aDatabaseIndex ) const;
474 * Gets a pointer to the database with the specified database index.
476 * @param aDatabaseIndex The index of the database.
477 * @return A pointer to the landmark database.
479 CPosLandmarkDatabase* DatabaseL( TUint aDatabaseIndex );
482 * Gets a pointer to the single search class for the database with the
483 * specified database index.
485 * @param aDatabaseIndex The index of the database.
486 * @return A pointer to the single search class.
488 CPosLandmarkSearch* SearcherL( TUint aDatabaseIndex );
491 * This method must be called to notify this class when a search has
492 * been started in the single search class corresponding to the
493 * specified database index.
495 * @param aDatabaseIndex The index of the database.
497 void SearchStarted( TUint aDatabaseIndex );
500 * This method must be called to notify this class when a search has
501 * been executed (partly or completely) in the single search class
502 * corresponding to the specified database index.
504 * @param[in] aDatabaseIndex The index of the database.
505 * @param[in] aSortPref The sort pref for the search.
507 void SearchExecutedL(
508 TUint aDatabaseIndex,
509 const CPosLmMultiDbSortPref& aSortPref );
512 * Adds a search error for the specified database index.
514 * @param aDatabaseIndex The index of the database.
515 * @param aErrorCode The error code.
517 void AddSearchError( TUint aDatabaseIndex, TInt aErrorCode );
520 * This function must be called by the CPosLmMultiDbSearchOperation
521 * when the search operation has completed or has been cancelled.
523 void HandleSearchOperationCompleted();
528 * C++ default constructor.
530 CPosLmMultiDbSearch();
533 * By default Symbian 2nd phase constructor is private.
535 void ConstructL(const CDesCArray& aDatabaseList);
537 void CloseDbsNotToSearch(const CDesCArray& aDatabaseList);
539 CPosLmOperation* StartSearchL(
540 const CPosLmSearchCriteria& aCriteria,
541 CPosLmMultiDbSortPref* aSortPref,
542 TBool aSearchOnlyPreviousMatches );
546 TInt iMaxNumOfMatches;
547 TInt iNewMaxNumOfMatches;
549 CPosLmMultiDbSearchOperation* iMultiSearchOperation; // No ownership
551 RPointerArray<CPosLmMultiDbSearchItem> iSearchItems;
553 RArray<TSearchError> iSearchErrors; // Can contain dummy errors.
554 TUint iNoOfSearchErrors; // Number of valid errors.
556 CPosLmDisplayData* iClientDisplayData; // No ownership
560 #endif // CPOSLMMULTIDBSEARCH_H