landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CCompositeSearchResult.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     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: 
       
    15 *   ?description_line
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  INCLUDES
       
    21 #include <e32math.h>
       
    22 #include <e32svr.h>
       
    23 #include <e32std.h>
       
    24 
       
    25 #include <EPos_CPosLmCompositeCriteria.h>
       
    26 #include <EPos_CPosLmCategoryCriteria.h>
       
    27 #include <EPos_CPosLmCatNameCriteria.h>
       
    28 #include <EPos_CPosLmTextCriteria.h>
       
    29 #include <EPos_CPosLmIdListCriteria.h>
       
    30 #include <EPos_CPosLmAreaCriteria.h>
       
    31 #include <EPos_CPosLmNearestCriteria.h>
       
    32 #include <LbsPosition.h>
       
    33 
       
    34 #include "FT_CCompositeSearchResult.h"
       
    35 
       
    36 #include <StifLogger.h>
       
    37 
       
    38 //CONSTANTS
       
    39 const TInt KMaxLineLength=255;
       
    40 
       
    41 // C++ Constructor 
       
    42 CCompositeSearchResult::CCompositeSearchResult() 
       
    43     {
       
    44     }
       
    45 
       
    46 CCompositeSearchResult* CCompositeSearchResult::NewL(CStifLogger* aLog) 
       
    47     {
       
    48     CCompositeSearchResult* self = new(ELeave) CCompositeSearchResult;
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL(aLog);
       
    51     CleanupStack::Pop();
       
    52     return self;
       
    53     }
       
    54 
       
    55 // C++ destructor 
       
    56 CCompositeSearchResult::~CCompositeSearchResult() 
       
    57     {
       
    58     iFile.Close();
       
    59     iFileSession.Close();
       
    60 
       
    61     iResultIds.Close();
       
    62     iIdList.Close();
       
    63     iPositionList.Close();
       
    64 
       
    65     delete iTextCriteria;
       
    66     iTextCriteria = NULL;
       
    67 
       
    68     delete iCategoryName;
       
    69     iCategoryName = NULL;
       
    70 
       
    71     }
       
    72 
       
    73 void CCompositeSearchResult::ConstructL(CStifLogger* aLog) 
       
    74     {
       
    75     iLog = aLog;
       
    76 
       
    77     _LIT(KFileTestValues, "c:\\system\\test\\testdata\\LmDbCompositeSearchResult.txt");
       
    78     
       
    79     User::LeaveIfError(iFileSession.Connect());
       
    80     User::LeaveIfError(iFile.Open(iFileSession, KFileTestValues,  EFileRead));
       
    81     iTextEnabled = EFalse;
       
    82     iAreaEnabled = EFalse;
       
    83     iNearestEnabled = EFalse;
       
    84     iCategoryEnabled = EFalse;
       
    85     iIdListEnabled = EFalse;
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // CCompositeSearchResult::GetCompositeSearchResultsL
       
    90 //
       
    91 // (other items were commented in a header).
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 
       
    95 TBool CCompositeSearchResult::GetCompositeSearchResultsL(CPosLmCompositeCriteria& aComposite)
       
    96     {
       
    97     TBuf<KMaxLineLength> line;
       
    98     TBool done = EFalse;
       
    99 
       
   100     iTextEnabled = EFalse;
       
   101     iAreaEnabled = EFalse;
       
   102     iNearestEnabled = EFalse;
       
   103     iCategoryEnabled = EFalse;
       
   104     iIdListEnabled = EFalse;
       
   105 
       
   106     iResultIds.Close();
       
   107     iIdList.Close();
       
   108     iPositionList.Close();
       
   109 
       
   110     delete iTextCriteria;
       
   111     iTextCriteria = NULL;
       
   112 
       
   113     delete iCategoryName;
       
   114     iCategoryName = NULL;
       
   115 
       
   116     iCategoryId = 0;
       
   117     iRedefined = 0;
       
   118     iUseCoverageRadius = EFalse;
       
   119     iMaxDistance = -1;
       
   120 
       
   121     iSouthLat=0;iNorthLat=0;iWestLong=0;iEastLong=0;
       
   122     iTestCounter++;
       
   123 
       
   124     TBuf<50> buf;
       
   125     buf.Format(_L(">>>>>>>>>>>>Test Round %d<<<<<<<<<<"), iTestCounter);
       
   126     iLog->Log(buf);
       
   127 
       
   128     aComposite.ClearArguments();
       
   129 
       
   130     while (ReadLn(iFile, line) != KErrEof && !done)
       
   131         {
       
   132         TLex lex(line);
       
   133         if (lex.Peek() != '#' && lex.Peek() != '\t')
       
   134             {
       
   135             // Found "# TEXT" line
       
   136             if (lex.Peek() == 'T')
       
   137                 {
       
   138                 ParseTextL(line);
       
   139                 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   140                 
       
   141                 textCriteria->SetTextL(*iTextCriteria);
       
   142                 textCriteria->SetAttributesToSearch(iTextAttributes);
       
   143                 textCriteria->SetPositionFieldsToSearchL(iPositionList); 
       
   144                 
       
   145                 aComposite.AddArgument(textCriteria);
       
   146                 CleanupStack::Pop(textCriteria);
       
   147                 iTextEnabled = ETrue;
       
   148                 }
       
   149             // Found "# AREA" line
       
   150             else if (lex.Peek() == 'A')
       
   151                 {
       
   152                 ParseAreaL(line);
       
   153                 CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(iSouthLat, 
       
   154                     iNorthLat, 
       
   155                     iWestLong, 
       
   156                     iEastLong
       
   157                     );
       
   158                 
       
   159                 aComposite.AddArgument(areaCriteria);
       
   160                 CleanupStack::Pop(areaCriteria);
       
   161                 iAreaEnabled = ETrue;
       
   162                 }
       
   163             // Found "# CATEGORY" line
       
   164             else if (lex.Peek() == 'C')
       
   165                 {
       
   166                 ParseCategoryL(line);
       
   167                 CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC();
       
   168                 if (iCategoryId>0)
       
   169                     {
       
   170                     iLog->Log(_L("SetCategoryItemId"));
       
   171                     catSearchCriteria->SetCategoryItemId(iCategoryId);
       
   172                     }
       
   173                 if (iCategoryName != NULL)
       
   174                     {
       
   175                     iLog->Log(_L("SetCategoryNameL"));
       
   176                     catSearchCriteria->SetCategoryNameL(*iCategoryName);
       
   177                     }
       
   178                 aComposite.AddArgument(catSearchCriteria);
       
   179                 CleanupStack::Pop(catSearchCriteria);
       
   180                 iCategoryEnabled = ETrue;
       
   181                 }
       
   182             // Found "# NEAREST" line
       
   183             else if (lex.Peek() == 'N')
       
   184                 {
       
   185                 ParseNearestL(line);
       
   186                 TCoordinate coord(iLatitude, iLongitude);
       
   187                 
       
   188                 CPosLmNearestCriteria* nearestCriteria = CPosLmNearestCriteria::NewLC(coord, iUseCoverageRadius);
       
   189                 if (iMaxDistance > 0)
       
   190                     {
       
   191                     nearestCriteria->SetMaxDistance(iMaxDistance);
       
   192                     }
       
   193                 nearestCriteria->SetUseCoverageRadius(iUseCoverageRadius);
       
   194                 aComposite.AddArgument(nearestCriteria);
       
   195                 CleanupStack::Pop(nearestCriteria);
       
   196 
       
   197                 iNearestEnabled = ETrue;
       
   198                 }
       
   199             // Found "# IDLIST" line
       
   200             else if (lex.Peek() == 'I')
       
   201                 {
       
   202                 ParseIdListL(line);
       
   203                 RArray<TPosLmItemId> list;
       
   204                 CleanupClosePushL(list);
       
   205                 
       
   206                 CPosLmIdListCriteria* idList = CPosLmIdListCriteria::NewLC();
       
   207                 
       
   208                 for (TInt i=0;i<iIdList.Count();i++)
       
   209                 {
       
   210                     list.Append(iIdList[i]);
       
   211                 }
       
   212                 idList->SetLandmarkIdsL(list);
       
   213                 
       
   214                 aComposite.AddArgument(idList);
       
   215                 CleanupStack::Pop(idList);
       
   216                 CleanupStack::PopAndDestroy(&list);
       
   217                 iIdListEnabled = ETrue;
       
   218                 }
       
   219             // Found "# RESULT" line
       
   220             else if (lex.Peek() == 'R')
       
   221                 {
       
   222                 ParseResultL(line);
       
   223                 }
       
   224             // Found "# SEPARATOR" line
       
   225             else if (lex.Peek() == 'S')
       
   226                 {
       
   227                 done = ETrue;
       
   228                 }
       
   229             }
       
   230         }
       
   231 
       
   232     if (done != EFalse) return EFalse;
       
   233     else return ETrue;
       
   234 
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------
       
   238 // CCompositeSearchResult::ReadLn
       
   239 // 
       
   240 // (other items were commented in a header).
       
   241 // ---------------------------------------------------------
       
   242 //
       
   243 TInt CCompositeSearchResult::ReadLn(RFile& aFile, TDes& aDes)
       
   244     {
       
   245     aDes = KNullDesC;
       
   246     TBuf8<KMaxLineLength> line;
       
   247 
       
   248 	TInt err = aFile.Read(line);
       
   249     if (line.Length() == 0)
       
   250         {
       
   251         return KErrEof;
       
   252         }
       
   253 	if (err)
       
   254 		{
       
   255 		return err;
       
   256 		}
       
   257 
       
   258     // Find line feed
       
   259     TInt i = 0;
       
   260 	TLex8 fileData;
       
   261 	fileData.Assign(line);
       
   262 	while (fileData.Peek() != '\n' && !(fileData.Peek()).Eos())
       
   263 		{
       
   264         fileData.Inc();
       
   265         if (++i == KMaxLineLength)
       
   266             {
       
   267             // In case no carriage return or end of string characters are present.
       
   268             break;
       
   269             }
       
   270         }
       
   271 
       
   272     // Update file position
       
   273     TInt diff = -(line.Length() - i - 1);
       
   274     aFile.Seek(ESeekCurrent, diff);
       
   275 
       
   276     // Convert to 16-bit
       
   277     line.SetLength(i);
       
   278     aDes.Copy(line);
       
   279 
       
   280     return KErrNone;
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------
       
   284 // CCompositeSearchResult::ParseAreaL
       
   285 //
       
   286 // (other items were commented in a header).
       
   287 // ---------------------------------------------------------
       
   288 //
       
   289 void CCompositeSearchResult::ParseAreaL(const TDesC& aDes) 
       
   290     {
       
   291     iLog->Log(_L("ParseAreaL")); 
       
   292     TLex line(aDes);
       
   293     line.Mark();
       
   294 
       
   295     if (line.Peek() != '#' && line.Peek() != '\t')
       
   296         { 
       
   297         TInt index=0;
       
   298         while (line.Peek() != '\n' && !(line.Peek()).Eos())
       
   299             {
       
   300             line.Inc();
       
   301             if (line.Peek() == '\t')
       
   302                 {
       
   303                 TPtrC token = line.MarkedToken();
       
   304                 TLex val(token);              
       
   305                 switch(index)
       
   306                     {
       
   307                     case ESouthLat:
       
   308                         val.Val(iSouthLat, TChar(','));
       
   309                         break;
       
   310                     case ENorthLat:
       
   311                         val.Val(iNorthLat, TChar(','));
       
   312                         break;
       
   313                     case EWestLong:
       
   314                         val.Val(iWestLong, TChar(','));
       
   315                         break;
       
   316                     case EEastLong:
       
   317                         val.Val(iEastLong, TChar(','));
       
   318                         break;
       
   319                     }    
       
   320                 line.Inc();
       
   321                 while (line.Peek() == '\t') // Empty value
       
   322                     {
       
   323                     line.Inc();
       
   324                     ++index;
       
   325                     }
       
   326                 line.Mark();
       
   327                 ++index;
       
   328                 }
       
   329             }
       
   330         }
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------
       
   334 // CCompositeSearchResult::ParseNearestL
       
   335 //
       
   336 // (other items were commented in a header).
       
   337 // ---------------------------------------------------------
       
   338 //
       
   339 void CCompositeSearchResult::ParseNearestL(const TDesC& aDes) 
       
   340     {
       
   341     iLog->Log(_L("ParseNearestL"));
       
   342     TLex line(aDes);
       
   343     line.Mark();
       
   344     TInt useCoverageRadius = 0;
       
   345 
       
   346     if (line.Peek() != '#' && line.Peek() != '\t')
       
   347         { 
       
   348         TInt index=0;
       
   349         while (line.Peek() != '\n' && !(line.Peek()).Eos())
       
   350             {
       
   351             line.Inc();
       
   352             if (line.Peek() == '\t')
       
   353                 {
       
   354                 TPtrC token = line.MarkedToken();
       
   355                 TLex val(token);              
       
   356                 switch(index)
       
   357                     {
       
   358                     case ELatitude:
       
   359                         val.Val(iLatitude, TChar(','));   
       
   360                         break;
       
   361                     case ELongitude:
       
   362                         val.Val(iLongitude, TChar(','));   
       
   363                         break;
       
   364                     case EUseCoverageRadius:  
       
   365                         val.Val(useCoverageRadius);
       
   366                         if (useCoverageRadius == 1)
       
   367                             {
       
   368                             iUseCoverageRadius = ETrue;
       
   369                             }
       
   370                         break;
       
   371                     case EMaxDistance:
       
   372                         val.Val(iMaxDistance);   
       
   373                         break;
       
   374                     }    
       
   375                 line.Inc();
       
   376                 while (line.Peek() == '\t') // Empty value
       
   377                     {
       
   378                     line.Inc();
       
   379                     ++index;
       
   380                     }
       
   381                 line.Mark();
       
   382                 ++index;
       
   383                 }
       
   384             }
       
   385         }
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------
       
   389 // CCompositeSearchResult::ParseTextL()
       
   390 //
       
   391 // (other items were commented in a header).
       
   392 // ---------------------------------------------------------
       
   393 //
       
   394 void CCompositeSearchResult::ParseTextL(const TDesC& aDes) 
       
   395     {
       
   396     iLog->Log(_L("ParseTextL"));
       
   397     TLex line(aDes);
       
   398     line.Mark();
       
   399 
       
   400     if (line.Peek() != '#' && line.Peek() != '\t')
       
   401         { 
       
   402         TInt index=0;
       
   403         while (line.Peek() != '\n' && !(line.Peek()).Eos())
       
   404             {
       
   405             line.Inc();
       
   406             if (line.Peek() == '\t')
       
   407                 {
       
   408                 TPtrC token = line.MarkedToken();
       
   409                 
       
   410                 switch(index)
       
   411                     {
       
   412                     case ETextCriteria:
       
   413                         iTextCriteria = token.AllocL();
       
   414                         break;
       
   415                     case EAttributes:
       
   416                         ParseAttributesL(token);
       
   417                         iTextAttributes = iAttributes;
       
   418                         break;
       
   419                     case EPositionFields:
       
   420                         ExtractIdFields(token, iPositionList);
       
   421                         break;
       
   422                     }    
       
   423                 line.Inc();
       
   424                 while (line.Peek() == '\t') // Empty value
       
   425                     {
       
   426                     line.Inc();
       
   427                     ++index;
       
   428                     }
       
   429                 line.Mark();
       
   430                 ++index;
       
   431                 }
       
   432             }  
       
   433         }
       
   434     }   
       
   435 
       
   436 // ---------------------------------------------------------
       
   437 // CCompositeSearchResult::ParseCategoryL()
       
   438 //
       
   439 // (other items were commented in a header).
       
   440 // ---------------------------------------------------------
       
   441 //
       
   442 void CCompositeSearchResult::ParseCategoryL(const TDesC& aDes) 
       
   443     {
       
   444     iLog->Log(_L("ParseCategoryL"));
       
   445     TLex line(aDes);
       
   446     line.Mark();
       
   447     TInt tmp;
       
   448 
       
   449     if (line.Peek() != '#' && line.Peek() != '\t')
       
   450         { 
       
   451         TInt index=0;
       
   452         while (line.Peek() != '\n' && !(line.Peek()).Eos())
       
   453             {
       
   454             line.Inc();
       
   455             if (line.Peek() == '\t')
       
   456                 {
       
   457                 TPtrC token = line.MarkedToken();
       
   458                 TLex val(token);
       
   459 
       
   460                 switch(index)
       
   461                     {
       
   462                     case ECategoryName:
       
   463                         iCategoryName = token.AllocL();
       
   464                         break;
       
   465                     case ECategoryId:
       
   466                         val.Val(tmp);
       
   467                         iCategoryId = tmp;
       
   468                         break;
       
   469                     }    
       
   470                 line.Inc();
       
   471                 while (line.Peek() == '\t') // Empty value
       
   472                     {
       
   473                     line.Inc();
       
   474                     ++index;
       
   475                     }
       
   476                 line.Mark();
       
   477                 ++index;
       
   478                 }
       
   479             }  
       
   480         }
       
   481     }   
       
   482 
       
   483 // ---------------------------------------------------------
       
   484 // CCompositeSearchResult::ParseIdListL()
       
   485 //
       
   486 // (other items were commented in a header).
       
   487 // ---------------------------------------------------------
       
   488 //
       
   489 void CCompositeSearchResult::ParseIdListL(const TDesC& aDes)
       
   490     {
       
   491     iLog->Log(_L("ParseIdListL"));
       
   492     TLex line(aDes);
       
   493     line.Mark();
       
   494     
       
   495     RArray<TUint> list;
       
   496     CleanupClosePushL(list);
       
   497     TInt i=0;
       
   498 
       
   499     if (line.Peek() != '#' && line.Peek() != '\t')
       
   500         { 
       
   501         TInt index=0;
       
   502         while (line.Peek() != '\n' && !(line.Peek()).Eos())
       
   503             {
       
   504             line.Inc();
       
   505             if (line.Peek() == '\t')
       
   506                 {
       
   507                 TPtrC token = line.MarkedToken();
       
   508                 //TLex val(token);              
       
   509 
       
   510                 switch(index)
       
   511                     {
       
   512                     case ELmIdList:
       
   513                         ExtractIdFields(token, list);
       
   514                         for (i=0;i<list.Count();i++)
       
   515                             {
       
   516                             iIdList.Append(list[i]);
       
   517                             }
       
   518                             break;
       
   519                     }    
       
   520                 line.Inc();
       
   521                 while (line.Peek() == '\t') // Empty value
       
   522                     {
       
   523                     line.Inc();
       
   524                     ++index;
       
   525                     }
       
   526                 line.Mark();
       
   527                 ++index;
       
   528                 }
       
   529             }  
       
   530         }
       
   531     CleanupStack::PopAndDestroy(&list);
       
   532     }  
       
   533 
       
   534 // ---------------------------------------------------------
       
   535 // CCompositeSearchResult::ParseResultL()
       
   536 //
       
   537 // (other items were commented in a header).
       
   538 // ---------------------------------------------------------
       
   539 //
       
   540 void CCompositeSearchResult::ParseResultL(const TDesC& aDes)
       
   541     {
       
   542     iLog->Log(_L("ParseResultL"));
       
   543     TLex line(aDes);
       
   544     line.Mark();
       
   545     TInt redefined=0;
       
   546     
       
   547     RArray<TUint> list;
       
   548     CleanupClosePushL(list);
       
   549     TInt i=0;
       
   550 
       
   551     if (line.Peek() != '#' && line.Peek() != '\t')
       
   552         { 
       
   553         TInt index=0;
       
   554         while (line.Peek() != '\n' && !(line.Peek()).Eos())
       
   555             {
       
   556             line.Inc();
       
   557             if (line.Peek() == '\t')
       
   558                 {
       
   559                 TPtrC token = line.MarkedToken();
       
   560                 TLex val(token);              
       
   561 
       
   562                 switch(index)
       
   563                     {
       
   564                     case ELmResultIdList:
       
   565                         ExtractIdFields(token, list);
       
   566                         for (i=0;i<list.Count();i++)
       
   567                             {
       
   568                             iResultIds.Append(list[i]);
       
   569                             }
       
   570                             break;
       
   571                     case ERedefined:
       
   572                         val.Val(redefined);
       
   573                         if (redefined == 1)
       
   574                             {
       
   575                             iLog->Log(_L("REDEFINED"));
       
   576                             iRedefined = ETrue;
       
   577                             }
       
   578                             break;
       
   579                     }    
       
   580                 line.Inc();
       
   581                 while (line.Peek() == '\t') // Empty value
       
   582                     {
       
   583                     line.Inc();
       
   584                     ++index;
       
   585                     }
       
   586                 line.Mark();
       
   587                 ++index;
       
   588                 }
       
   589             }  
       
   590         }
       
   591     CleanupStack::PopAndDestroy(&list);
       
   592     }  
       
   593 
       
   594 // ---------------------------------------------------------
       
   595 // CCompositeSearchResult::ExtractIdFields()
       
   596 //
       
   597 // (other items were commented in a header).
       
   598 // ---------------------------------------------------------
       
   599 //
       
   600 void CCompositeSearchResult::ExtractIdFields(const TDesC& aDes, RArray<TUint>& aList)
       
   601     {
       
   602     iLog->Log(_L("ExtractIdFields"));
       
   603     TLex line(aDes);
       
   604     line.Mark();
       
   605     TInt startValue=0;
       
   606     TInt endValue=0;
       
   607     while (!(line.Peek()).Eos())
       
   608         {
       
   609         line.Inc();
       
   610     
       
   611         if (line.Peek() == ',' || line.Peek() == '-' || (line.Peek()).Eos())
       
   612             {
       
   613             TPtrC token = line.MarkedToken();
       
   614             TLex val(token);
       
   615             val.Val(startValue);
       
   616             iSearchResult.Append(startValue);
       
   617             aList.Append(startValue);
       
   618 
       
   619             if (line.Peek() == '-')
       
   620                 {
       
   621                 line.Inc();
       
   622                 line.Mark();
       
   623                 while (line.Peek() != ',' && !(line.Peek()).Eos())
       
   624                     {
       
   625                     line.Inc();               
       
   626                     }
       
   627                 TPtrC endToken = line.MarkedToken();
       
   628                 TLex endVal(endToken);
       
   629                 endVal.Val(endValue);
       
   630                 for (TInt i=startValue+1; i<=endValue; i++)
       
   631                     {
       
   632                     aList.Append(i);
       
   633                     }
       
   634                 }
       
   635              if (line.Peek() == ',')
       
   636                 {
       
   637                 line.Inc();
       
   638                 line.Mark();
       
   639                 }
       
   640             }
       
   641         }
       
   642     }
       
   643 
       
   644 //  End of File