locationtriggering/ltcontainer/src/lbtramtriggersmanager.cpp
changeset 56 4e949f03ecc5
equal deleted inserted replaced
-1:000000000000 56:4e949f03ecc5
       
     1 /*
       
     2 * Copyright (c) 2006 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:  This header file describes the class that handles the storage
       
    15 *                of triggers in RAM Structures.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <lbttriggerfilterbyattribute.h>
       
    21 #include <lbtsessiontrigger.h>
       
    22 #include <lbtstartuptrigger.h>
       
    23 #include <lbttriggerfilterbyarea.h>
       
    24 #include <lbtgeorect.h>
       
    25 #include <lbttriggerfiltercomposite.h>
       
    26 #include <lbtgeocircle.h>
       
    27 #include <lbttriggerconditionarea.h>
       
    28 #include <lbtgeocell.h>
       
    29 #include <lbtgeohybrid.h>
       
    30 #include "lbttriggerstoreobserver.h"
       
    31 #include "lbtramtriggersmanager.h"
       
    32 #include "lbtramtriggeridtree.h"
       
    33 #include "lbtcontainerextendedtriggerinfo.h"
       
    34 #include "lbtcontainertriggerfilter.h"
       
    35 #include "lbtcontainerattrfilter.h"
       
    36 #include "lbtcontainerareafilter.h"
       
    37 #include "lbtcontainercompfilter.h"
       
    38 #include "lbtcontainerutilities.h"
       
    39 #include "lbtserverconsts.h"
       
    40 #include "lbtlogger.h"
       
    41 
       
    42 
       
    43 // CONSTANTS
       
    44 const TInt KStepCount(2); // The step for batch processing of triggers
       
    45 
       
    46 
       
    47 // ======== MEMBER FUNCTIONS ========
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // The Symbian 2 phase constructor
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CLbtRamTriggersManager* CLbtRamTriggersManager::NewL( )
       
    54     {
       
    55     CLbtRamTriggersManager* self = new( ELeave ) CLbtRamTriggersManager;
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61     
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Destructor
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CLbtRamTriggersManager::~CLbtRamTriggersManager()
       
    68     {
       
    69     delete iTriggerIdTree;
       
    70     delete iFilterBase;
       
    71     iIdArray.Close();
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CLbtRamTriggersManager::TriggersModified
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CLbtRamTriggersManager::TriggersModified(RArray<TLbtTriggerModifiedInfo>& aArray)
       
    79 	 {
       
    80 	 for( TInt i = 0;i<iIdArray.Count();i++ )
       
    81 		 {
       
    82 		 aArray.Append(iIdArray[i]);	
       
    83 	     }
       
    84 	 iIdArray.Reset();
       
    85 	 }	
       
    86 	 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Specify the types of triggers supported by the RAM Trigger Store
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 TTriggerTypeMask CLbtRamTriggersManager::SupportedTriggerTypes()
       
    92     {
       
    93     return ( CLbtTriggerEntry::ETypeSession );
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CLbtRamTriggersManager::CreateTriggerL
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CLbtRamTriggersManager::CreateTriggerL( CLbtContainerTriggerEntry &aEntry,
       
   101                     					     TRequestStatus& aStatus )
       
   102  	{
       
   103  	FUNC_ENTER("CLbtRamTriggersManager::CreateTriggerL");
       
   104  	aStatus = KRequestPending;
       
   105  	// Save client request objects
       
   106     iClientStatus = &aStatus;
       
   107     iCurrentTriggerId = aEntry.TriggerEntry()->Id();
       
   108     iCurrentOperation = EOperationCreate;
       
   109     
       
   110  	CLbtContainerTriggerEntry* tEntry = new(ELeave) CLbtContainerTriggerEntry(aEntry);
       
   111  	
       
   112  	TRAPD(error,iTriggerIdTree->AddToTreeL(tEntry));
       
   113  	
       
   114     if( error != KErrNone )
       
   115         {
       
   116         delete tEntry;
       
   117         CompleteClientRequest( error );
       
   118         }
       
   119     else
       
   120         {
       
   121         // Reliquish control to serve cancel request
       
   122         SelfComplete();
       
   123         }           
       
   124  	}
       
   125  	
       
   126 // ---------------------------------------------------------------------------
       
   127 // CreateEntryBasedOnType
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 CLbtTriggerEntry* CreateEntryBasedOnType(CLbtTriggerEntry* aEntry) 	
       
   131     {
       
   132      CLbtTriggerEntry* tEntry = NULL;
       
   133      switch(aEntry->Type())
       
   134         {
       
   135          case CLbtTriggerEntry::ETypeSession: 
       
   136          	{
       
   137          	TRAP_IGNORE(tEntry = CLbtSessionTrigger::NewL());
       
   138          	break;
       
   139          	}
       
   140          case CLbtTriggerEntry::ETypeStartup:
       
   141          	{
       
   142          	TRAP_IGNORE(tEntry = CLbtStartupTrigger::NewL());
       
   143          	break;
       
   144          	}
       
   145         }
       
   146     return tEntry; 
       
   147     }
       
   148  
       
   149 
       
   150 // ------------------------------------------------------------      
       
   151 // CLbtRamTriggersManager::GetTriggersL
       
   152 // ------------------------------------------------------------
       
   153 //
       
   154 void CLbtRamTriggersManager::GetTriggersL( RArray<TLbtTriggerId>& aTriggerIds,
       
   155 										   RPointerArray<CLbtContainerTriggerEntry>& aTriggers, 
       
   156 										   TLbtSecurityPolicy& aSecurityPolicy,
       
   157 										   TRequestStatus &aStatus )
       
   158 	{
       
   159 	FUNC_ENTER("CLbtRamTriggersManager::GetTriggersL");
       
   160 	iClientStatus = &aStatus;
       
   161     
       
   162     if( !aTriggerIds.Count() || 
       
   163     	iTriggerIdTree->IsEmpty() )
       
   164         {
       
   165         CompleteClientRequest(KErrNotFound);
       
   166         return;
       
   167         }
       
   168     
       
   169     // Copy trigger id array
       
   170     for( TInt i=0;i<aTriggerIds.Count();i++ )
       
   171         {
       
   172         TLbtTriggerModifiedInfo triggerInfo;
       
   173         triggerInfo.iTriggerId = aTriggerIds[i];
       
   174         iIdArray.Append( triggerInfo );
       
   175         }
       
   176     iIterator = 0;    
       
   177     iCurrentOperation = EOperationGetTriggers;
       
   178     iClientSecurityPolicy = aSecurityPolicy;
       
   179     iClientTriggerArray = &aTriggers;
       
   180     SelfComplete();
       
   181     }
       
   182 
       
   183 // ------------------------------------------------------------      
       
   184 // CLbtRamTriggersManager::HandleGetTriggersEventL
       
   185 // ------------------------------------------------------------
       
   186 //
       
   187 void CLbtRamTriggersManager::HandleGetTriggersEventL()
       
   188     {
       
   189     TInt count = 0;
       
   190     while( (iIterator < iIdArray.Count()) && 
       
   191            (count < KStepCount) )
       
   192        {
       
   193        CLbtContainerTriggerEntry *entry = iTriggerIdTree->FindEntryInTreeL( iIdArray[iIterator].iTriggerId );
       
   194        if( entry )
       
   195            {
       
   196            if( LbtContainerUtilities::RunSecurityPolicy( entry, iClientSecurityPolicy ) )
       
   197                {
       
   198                CLbtContainerTriggerEntry* clientEntry = new (ELeave) CLbtContainerTriggerEntry( *entry );
       
   199                iClientTriggerArray->Append( clientEntry );
       
   200                }
       
   201            }
       
   202        ++iIterator;
       
   203        ++count;
       
   204        }
       
   205     
       
   206     if( iIterator >= iIdArray.Count() )
       
   207         {
       
   208         // All triggers iteration done. Complete request                
       
   209         CompleteClientRequest( KErrNone );
       
   210         }
       
   211     else
       
   212         {
       
   213         SelfComplete();                
       
   214         }            
       
   215     }
       
   216 
       
   217 // ------------------------------------------------------------      
       
   218 // CLbtRamTriggersManager::ListTriggersL
       
   219 // ------------------------------------------------------------
       
   220 //
       
   221 void CLbtRamTriggersManager::ListTriggersL( CLbtContainerListOptions* aFilter,
       
   222 										    RPointerArray<CLbtContainerTriggerEntry>& aTriggers,
       
   223 										    TLbtSecurityPolicy& aSecurityPolicy,
       
   224 										    TRequestStatus &aStatus )
       
   225    {
       
   226    FUNC_ENTER("CLbtRamTriggersManager::ListTriggersL");
       
   227    iClientStatus = &aStatus;
       
   228     
       
   229    if(aFilter == NULL)
       
   230        {
       
   231        CompleteClientRequest( KErrArgument );
       
   232        return;
       
   233        }
       
   234    
       
   235    if( iTriggerIdTree->IsEmpty() )
       
   236     	{
       
   237     	CompleteClientRequest( KErrNotFound );
       
   238         return;
       
   239     	}
       
   240 
       
   241    // Store client data 
       
   242    iFilter = aFilter;   
       
   243    iClientSecurityPolicy = aSecurityPolicy;
       
   244    iClientTriggerArray = &aTriggers;
       
   245    iCurrentOperation = EOperationListing;
       
   246    
       
   247    iFilterBase = LbtContainerUtilities::GetContainerFilterFromListOptionsLC(aFilter);
       
   248    CleanupStack::Pop(1); // iFilterBase
       
   249 
       
   250    // Set the iterator to point to the first entry in the tree
       
   251    iTriggerIdTree->SetIteratorL();
       
   252    
       
   253    SelfComplete();
       
   254    }
       
   255 
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // CLbtRamTriggersManager::HandleListTriggerEventL
       
   259 // ---------------------------------------------------------------------------
       
   260 void CLbtRamTriggersManager::HandleListTriggerEventL()
       
   261     {    
       
   262     CLbtContainerTriggerEntry* tEntry = NULL;
       
   263     
       
   264     TInt count = 0;
       
   265     while( count < KStepCount )
       
   266         {
       
   267         tEntry = iTriggerIdTree->GetNextEntryL();
       
   268         
       
   269         if( tEntry == NULL )
       
   270             break;
       
   271         
       
   272         CLbtListTriggerOptions* listOptions = iFilter->ListOptions();
       
   273         CLbtExtendedTriggerInfo* contExtInfo = tEntry->ExtendedTriggerInfo();   
       
   274         TLbtTriggerDynamicInfoFieldsMask dynInfoMask;
       
   275         TLbtTriggerAttributeFieldsMask attrMask;
       
   276         listOptions->GetRetrievedFields(attrMask,dynInfoMask);
       
   277         TLbtTriggerDataMask dataMask = iFilter->DataMask();
       
   278         ++count;
       
   279         if( !LbtContainerUtilities::RunSecurityPolicy( tEntry, iClientSecurityPolicy ) )
       
   280             {
       
   281             continue;
       
   282             }
       
   283         
       
   284         CLbtContainerTriggerEntry* entry = NULL;
       
   285         CLbtTriggerEntry* clientEntry = NULL;       
       
   286         CLbtExtendedTriggerInfo* clientExtInfo = NULL;
       
   287         CLbtTriggerEntry* trigEntry = tEntry->TriggerEntry();
       
   288         TInt isFilterPresent = 0;
       
   289         TBool isEntryRequested = EFalse;
       
   290         iFilterBase->ProcessFilter(tEntry, isFilterPresent, isEntryRequested);
       
   291         
       
   292         if(isFilterPresent > 0 && isEntryRequested)
       
   293             {
       
   294             entry = CLbtContainerTriggerEntry::NewL();
       
   295             iClientTriggerArray->Append( entry );
       
   296 
       
   297             clientEntry = CLbtSessionTrigger::NewL();
       
   298             entry->SetTriggerEntry( clientEntry );
       
   299 
       
   300             if( attrMask & CLbtTriggerEntry::EAttributeId )
       
   301                 {
       
   302                 clientEntry->SetId(trigEntry->Id());
       
   303                 }              
       
   304                 
       
   305             if( attrMask & CLbtTriggerEntry::EAttributeName )
       
   306                 {
       
   307                 clientEntry->SetNameL(trigEntry->Name());
       
   308                 }
       
   309                 
       
   310             if( attrMask & CLbtTriggerEntry::EAttributeState )
       
   311                 {           
       
   312                 clientEntry->SetState(trigEntry->State());
       
   313                 }
       
   314             
       
   315             if( attrMask & CLbtTriggerEntry::EAttributeManagerUi )
       
   316                 {               
       
   317                 clientEntry->SetManagerUi(trigEntry->ManagerUi());              
       
   318                 }
       
   319             
       
   320             if( attrMask & CLbtTriggerEntry::EAttributeCondition )
       
   321                 {
       
   322                 CLbtTriggerConditionArea* cond = static_cast<CLbtTriggerConditionArea*>(trigEntry->GetCondition());
       
   323                 // Condition area to be sent back to client
       
   324                 CLbtTriggerConditionArea* condArea=CLbtTriggerConditionArea::NewLC();
       
   325                 CLbtGeoAreaBase* area = LbtContainerUtilities::CopyGeoAreaL( cond->TriggerArea() );
       
   326                 condArea->SetTriggerArea( area );
       
   327                 condArea->SetDirection( cond->Direction() );
       
   328                 CleanupStack::Pop( condArea );
       
   329                 clientEntry->SetCondition( condArea );
       
   330                 }
       
   331 
       
   332             TLbtTriggerDynamicInfo* info = new TLbtTriggerDynamicInfo;
       
   333             TBool isDynInfoPresent=EFalse;
       
   334                 
       
   335             if( dynInfoMask & TLbtTriggerDynamicInfo::EValidityStatus )
       
   336                 {
       
   337                 isDynInfoPresent=ETrue;
       
   338                 info->iValidity=tEntry->DynInfo()->iValidity;
       
   339                 }
       
   340             
       
   341             if( dynInfoMask & TLbtTriggerDynamicInfo::EDistanceToLatestLocation )
       
   342                 {               
       
   343                 isDynInfoPresent=ETrue; 
       
   344                 info->iDistanceToLatestLocation=tEntry->DynInfo()->iDistanceToLatestLocation;
       
   345                 }
       
   346             
       
   347             if( dynInfoMask & TLbtTriggerDynamicInfo::EFiredLocality )
       
   348                 {
       
   349                 isDynInfoPresent=ETrue; 
       
   350                 info->iFiredLocality=tEntry->DynInfo()->iFiredLocality;
       
   351                 }
       
   352                     
       
   353             if(isDynInfoPresent)
       
   354                 {
       
   355                 entry->SetDynInfo(info);
       
   356                 }
       
   357             else
       
   358                 {
       
   359                 delete info;
       
   360                 }
       
   361             
       
   362             
       
   363             if( dataMask & CLbtContainerTriggerEntry::EContainerAttributeHysteresisRadius )
       
   364                 {
       
   365                 if(clientExtInfo == NULL)
       
   366                     {
       
   367                     clientExtInfo=CLbtExtendedTriggerInfo::NewL();
       
   368                     }
       
   369                 clientExtInfo->SetHysteresisRadius(contExtInfo->HysteresisRadius());
       
   370                 }
       
   371                         
       
   372             if( dataMask & CLbtContainerTriggerEntry::EContainerAttributeIsFired )
       
   373                 {
       
   374                 if(clientExtInfo == NULL)
       
   375                     {
       
   376                     clientExtInfo = CLbtExtendedTriggerInfo::NewL();
       
   377                     }
       
   378                 clientExtInfo->SetTriggerFiredState(contExtInfo->IsTriggerFired());
       
   379                 }
       
   380                 
       
   381             if( dataMask & CLbtContainerTriggerEntry::EContainerAttributeOwnerSid )
       
   382                 {
       
   383                 if(clientExtInfo == NULL)
       
   384                     {
       
   385                     clientExtInfo = CLbtExtendedTriggerInfo::NewL();
       
   386                     }                  
       
   387                 clientExtInfo->SetOwnerSid(contExtInfo->OwnerSid()); 
       
   388                 }
       
   389                     
       
   390             if( dataMask & CLbtContainerTriggerEntry::EContainerAttributeRectTriggerArea )
       
   391                 {
       
   392                 if(clientExtInfo == NULL)
       
   393                     {
       
   394                     clientExtInfo = CLbtExtendedTriggerInfo::NewL();
       
   395                     }
       
   396                 clientExtInfo->SetTriggerRectangleArea(contExtInfo->TriggerReactangleArea()); 
       
   397                 }   
       
   398                 
       
   399             if( dataMask & CLbtContainerTriggerEntry::EContainerAttributeStrategyData )
       
   400                 {
       
   401                 if(clientExtInfo == NULL)                   
       
   402                     {
       
   403                     clientExtInfo = CLbtExtendedTriggerInfo::NewL();
       
   404                     }
       
   405                 clientExtInfo->SetStrategyDataL(contExtInfo->StategyData()); 
       
   406                 }
       
   407                 
       
   408             if( dataMask & CLbtContainerTriggerEntry::EContainerAttributeIsTriggerFireOnCreation )
       
   409                 {
       
   410                 if(clientExtInfo == NULL)
       
   411                     {
       
   412                     clientExtInfo = CLbtExtendedTriggerInfo::NewL();
       
   413                     }
       
   414                 clientExtInfo->SetTriggerFireOnCreation( contExtInfo->IsTriggerFireOnCreation()); 
       
   415                 }   
       
   416                         
       
   417             if( dataMask & CLbtContainerTriggerEntry::EContainerAttributeFireInfo )
       
   418                 {
       
   419                 if(clientExtInfo == NULL)                   
       
   420                     {
       
   421                     clientExtInfo = CLbtExtendedTriggerInfo::NewL();
       
   422                     }
       
   423                 clientExtInfo->SetFiredInfo( contExtInfo->GetFiredInfo()); 
       
   424                 }
       
   425             
       
   426             if(clientExtInfo!=NULL)
       
   427                 {
       
   428                 entry->SetExtendedTriggerInfo(clientExtInfo);
       
   429                 }
       
   430             }
       
   431         }
       
   432     
       
   433     if( tEntry == NULL )
       
   434         {
       
   435         if( iClientTriggerArray->Count() == 0 )
       
   436             {
       
   437             CompleteClientRequest( KErrNotFound );
       
   438             }
       
   439         else
       
   440             {
       
   441             CompleteClientRequest( KErrNone );
       
   442             }
       
   443         }
       
   444     else
       
   445         {
       
   446         SelfComplete();
       
   447         }
       
   448     }
       
   449 
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // CLbtRamTriggersManager::AppendTriggerInfo
       
   453 // ---------------------------------------------------------------------------
       
   454 void CLbtRamTriggersManager::AppendTriggerInfo(CLbtContainerTriggerEntry* aEntry)
       
   455 	{
       
   456 	FUNC_ENTER("CLbtRamTriggersManager::AppendTriggerInfo");
       
   457 	const CLbtTriggerConditionArea* conditionBase = 
       
   458 			static_cast<const CLbtTriggerConditionArea*>(aEntry->TriggerEntry()->GetCondition());
       
   459 	CLbtGeoAreaBase* areaBase = conditionBase->TriggerArea();
       
   460 		    
       
   461     TLbtTriggerModifiedInfo info;
       
   462     info.iTriggerId = aEntry->TriggerEntry()->Id();
       
   463     info.iAreaType = areaBase->Type();
       
   464     info.iManagerUi = aEntry->TriggerEntry()->ManagerUi();
       
   465     
       
   466     TSecureId sid = aEntry->ExtendedTriggerInfo()->OwnerSid();
       
   467     TUid ownerUid;
       
   468     ownerUid.iUid = (TInt)(sid.iId);
       
   469     info.iOwner = ownerUid;
       
   470     
       
   471     CLbtTriggerEntry* triggerEntry = aEntry->TriggerEntry();	
       
   472 	if( triggerEntry->Type() == CLbtTriggerEntry::ETypeStartup)
       
   473 		{
       
   474 		CLbtStartupTrigger* startupTrigger = static_cast<CLbtStartupTrigger*>(triggerEntry);
       
   475 		TSecureId secureId;
       
   476 		TBuf16<KMaxFileName> fileName;
       
   477 		startupTrigger->GetProcessId(fileName, secureId);
       
   478 		TUid startupUid;
       
   479 		startupUid.iUid = (TInt)(sid.iId);
       
   480 		info.iStartupProcess = startupUid;
       
   481 		}
       
   482 	else
       
   483 		{
       
   484 		info.iStartupProcess = KNullUid;
       
   485 		}
       
   486     
       
   487     iIdArray.Append(info);
       
   488 	}
       
   489 
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CLbtRamTriggersManager::SelfComplete
       
   493 // ---------------------------------------------------------------------------
       
   494 void CLbtRamTriggersManager::SelfComplete()
       
   495     {
       
   496     FUNC_ENTER("CLbtRamTriggersManager::SelfComplete");
       
   497     iStatus = KRequestPending;
       
   498     TRequestStatus* status = &iStatus;    
       
   499     SetActive();
       
   500     User::RequestComplete(status, KErrNone);    
       
   501     }
       
   502 
       
   503 // ---------------------------------------------------------------------------
       
   504 // CLbtRamTriggersManager::RunL
       
   505 // ---------------------------------------------------------------------------
       
   506 void CLbtRamTriggersManager::RunL()
       
   507     {
       
   508     FUNC_ENTER("CLbtRamTriggersManager::RunL");
       
   509     switch( iCurrentOperation )
       
   510         {
       
   511         case EOperationCreate:
       
   512             {
       
   513             // See if the trigger is a enabled and valid trigger
       
   514             CLbtContainerTriggerEntry *entry = iTriggerIdTree->FindEntryInTreeL( iCurrentTriggerId );
       
   515             CLbtTriggerEntry* trigger = entry->TriggerEntry();
       
   516             if((trigger->State() == CLbtTriggerEntry::EStateEnabled) &&
       
   517                (entry->DynInfo()->iValidity == TLbtTriggerDynamicInfo::EValid))
       
   518                 {
       
   519                 iCountOfEnabledAndValidTrigger++;
       
   520                 }
       
   521             CompleteClientRequest( KErrNone );
       
   522             break;
       
   523             }
       
   524         case EOperationUpdateTrigger:
       
   525             {
       
   526             HandleUpdateTriggerEventL();
       
   527             break;
       
   528             }
       
   529         case EOperationDelete:
       
   530             {
       
   531             HandleDeleteTriggersEventL();
       
   532             break;
       
   533             }
       
   534         case EOperationUpdatingState:
       
   535             {
       
   536             HandleUpdateTriggersStateEventL();
       
   537             break;
       
   538             }
       
   539     
       
   540         case EOperationListing:
       
   541             {
       
   542             HandleListTriggerEventL();
       
   543             break;
       
   544             }
       
   545             
       
   546         case EOperationGetTriggers:
       
   547             {
       
   548             HandleGetTriggersEventL();
       
   549             break;
       
   550             }
       
   551     
       
   552         default:
       
   553             {
       
   554             CompleteClientRequest( KErrGeneral );
       
   555             break;
       
   556             }
       
   557         }
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------------------------
       
   561 // CLbtRamTriggersManager::CompleteClientRequest
       
   562 // ---------------------------------------------------------------------------
       
   563 void CLbtRamTriggersManager::CompleteClientRequest(TInt aError)
       
   564     {
       
   565     FUNC_ENTER("CLbtRamTriggersManager::CompleteClientRequest");
       
   566     if( iClientStatus )
       
   567         User::RequestComplete( iClientStatus, aError );
       
   568     iCurrentOperation = EOperationNone;
       
   569     iClientStatus = NULL;
       
   570     iCurrentTriggerId = 0;    
       
   571     delete iFilterBase;
       
   572     iFilterBase = NULL;    
       
   573     iIterator = 0;
       
   574     iClientTriggerEntry = NULL;
       
   575     }
       
   576 
       
   577 // ---------------------------------------------------------------------------
       
   578 // CLbtRamTriggersManager::RunError
       
   579 // ---------------------------------------------------------------------------
       
   580 TInt CLbtRamTriggersManager::RunError( TInt aError  )
       
   581     {
       
   582     FUNC_ENTER("CLbtRamTriggersManager::RunError");
       
   583     CompleteClientRequest( aError );
       
   584     return KErrNone;
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------------------------
       
   588 // CLbtRamTriggersManager::DoCancel
       
   589 // ---------------------------------------------------------------------------
       
   590 void CLbtRamTriggersManager::DoCancel()
       
   591     {
       
   592     FUNC_ENTER("CLbtRamTriggersManager::DoCancel");
       
   593     // Nothing to do here. Only self complete events
       
   594     }
       
   595 
       
   596 
       
   597 // ---------------------------------------------------------------------------
       
   598 // CLbtRamTriggersManager::UpdateTriggerL
       
   599 // ---------------------------------------------------------------------------
       
   600 void CLbtRamTriggersManager::UpdateTriggerL( CLbtContainerTriggerEntry& aEntry,
       
   601     										 TLbtTriggerDataMask aDataMask,
       
   602     										 TLbtTriggerAttributeFieldsMask aAttrMask,
       
   603     										 TLbtSecurityPolicy& aSecurityPolicy,
       
   604     										 TRequestStatus& aStatus )
       
   605     {
       
   606     FUNC_ENTER("CLbtRamTriggersManager::UpdateTriggerL");
       
   607     iClientStatus = &aStatus;   
       
   608     iClientTriggerEntry = &aEntry;
       
   609     iClientSecurityPolicy = aSecurityPolicy;
       
   610     iDataMask = aDataMask;
       
   611     iAttrMask = aAttrMask;
       
   612     iIdArray.Reset();
       
   613     
       
   614     iCurrentOperation = EOperationUpdateTrigger;
       
   615     SelfComplete();
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------- 
       
   619 // CLbtRamTriggersManager::HandleUpdateTriggerEventL
       
   620 // ----------------------------------------------------------
       
   621 //
       
   622 void CLbtRamTriggersManager::HandleUpdateTriggerEventL()
       
   623     {
       
   624     // entry retrieved from the tree
       
   625     CLbtContainerTriggerEntry* entry = NULL;
       
   626     entry = iTriggerIdTree->FindEntryInTreeL( iClientTriggerEntry->TriggerEntry()->Id() );
       
   627     
       
   628     if( entry==NULL )
       
   629         {
       
   630         CompleteClientRequest(KErrNotFound);
       
   631         return;
       
   632         }
       
   633     
       
   634     if( !LbtContainerUtilities::RunSecurityPolicy( entry, iClientSecurityPolicy ) )
       
   635         {
       
   636         CompleteClientRequest(KErrAccessDenied);
       
   637         return;
       
   638         }    
       
   639     
       
   640     // Trigger Entry supplied by the client
       
   641     CLbtTriggerEntry* trigEntry = iClientTriggerEntry->TriggerEntry();
       
   642     CLbtExtendedTriggerInfo* trigExtInfo = iClientTriggerEntry->ExtendedTriggerInfo();
       
   643     TLbtTriggerDynamicInfo* trigDynInfo = iClientTriggerEntry->DynInfo();
       
   644     
       
   645     // Append the modification information
       
   646     MLbtTriggerStore::TLbtTriggerModifiedInfo info;
       
   647     info.iTriggerId = entry->TriggerEntry()->Id();   
       
   648     TSecureId sid = entry->ExtendedTriggerInfo()->OwnerSid();    
       
   649     info.iOwner.iUid= (TInt)(sid.iId);
       
   650     iIdArray.Append(info);
       
   651 
       
   652     /* contTrigEntry is the trigger entry which is a part of 
       
   653      * the container trigger entry retrieved from the tree 
       
   654      */     
       
   655     CLbtSessionTrigger* contTrigEntry = NULL;
       
   656     if( entry->TriggerEntry() )
       
   657         {
       
   658         contTrigEntry = static_cast <CLbtSessionTrigger*>(entry->TriggerEntry());
       
   659         
       
   660         CLbtTriggerConditionArea* condArea = static_cast <CLbtTriggerConditionArea*>(contTrigEntry->GetCondition());
       
   661         CLbtGeoAreaBase* geoArea = condArea->TriggerArea();    
       
   662         info.iAreaType = geoArea->Type();
       
   663         }
       
   664     else
       
   665         {
       
   666         contTrigEntry=CLbtSessionTrigger::NewL();
       
   667         entry->SetTriggerEntry( contTrigEntry );
       
   668         }
       
   669     
       
   670     /* Contextinfo is the extended information present in the entry 
       
   671      * retrieved from the tree 
       
   672      */
       
   673     CLbtExtendedTriggerInfo* contExtInfo = entry->ExtendedTriggerInfo();
       
   674     TLbtTriggerDynamicInfo* contDynInfo =  entry->DynInfo();
       
   675     
       
   676     if(trigEntry!=NULL)
       
   677         {
       
   678         if( iAttrMask & CLbtTriggerEntry::EAttributeId )
       
   679             {
       
   680              contTrigEntry->SetId(trigEntry->Id());
       
   681             }
       
   682                 
       
   683         if( iAttrMask & CLbtTriggerEntry::EAttributeName )
       
   684             {
       
   685             contTrigEntry->SetNameL(trigEntry->Name()); 
       
   686             }
       
   687                             
       
   688         if( iAttrMask & CLbtTriggerEntry::EAttributeState )
       
   689             {
       
   690             contTrigEntry->SetState(trigEntry->State());        
       
   691             }
       
   692         
       
   693         if( iAttrMask & CLbtTriggerEntry::EAttributeRearmTime )
       
   694             {
       
   695             contTrigEntry->SetTimeToRearm((trigEntry->TimeToRearm()));
       
   696             }
       
   697                             
       
   698         if( iAttrMask & CLbtTriggerEntry::EAttributeRequestor )
       
   699             {
       
   700             //clientEntry->SetRequestorL(trigEntry->GetRequestor());        
       
   701             }
       
   702                                 
       
   703         if( iAttrMask & CLbtTriggerEntry::EAttributeManagerUi )
       
   704             {
       
   705             contTrigEntry->SetManagerUi(trigEntry->ManagerUi());        
       
   706             }
       
   707                     
       
   708         if( iAttrMask & CLbtTriggerEntry::EAttributeCondition )
       
   709             {
       
   710             CLbtTriggerConditionArea* condArea = static_cast <CLbtTriggerConditionArea*>(contTrigEntry->GetCondition());
       
   711             CLbtGeoAreaBase* geoArea = condArea->TriggerArea();
       
   712             CLbtTriggerConditionArea* cond=static_cast <CLbtTriggerConditionArea*> (trigEntry->GetCondition());
       
   713             
       
   714             if(geoArea->Type() == CLbtGeoAreaBase::ECircle)
       
   715                 {
       
   716                 // Update the condition for cicular trigger specified in the trigger entry parameter
       
   717                 CLbtGeoCircle* containerCircle = static_cast<CLbtGeoCircle*>(geoArea);          
       
   718                 CLbtGeoCircle* geoCircle= static_cast <CLbtGeoCircle*> (cond->TriggerArea());
       
   719                 
       
   720                 containerCircle->SetCenter(geoCircle->Center());
       
   721                 containerCircle->SetRadius(geoCircle->Radius());
       
   722                 }
       
   723             else if(geoArea->Type() == CLbtGeoAreaBase::ECellular)
       
   724                 {
       
   725                 CLbtGeoCell* containerCell = static_cast<CLbtGeoCell*>(geoArea);
       
   726                 CLbtGeoCell* geoCell = static_cast <CLbtGeoCell*> (cond->TriggerArea());
       
   727                 
       
   728                 containerCell->SetNetworkType(geoCell->NetworkType());
       
   729                 containerCell->SetNetworkCountryCode(geoCell->NetworkCountryCode());
       
   730                 containerCell->SetNetworkIdentityCode(geoCell->NetworkIdentityCode());
       
   731                 containerCell->SetLocationAreaCode(geoCell->LocationAreaCode());
       
   732                 containerCell->SetCellId(geoCell->CellId());
       
   733                 }
       
   734             else if(geoArea->Type() == CLbtGeoAreaBase::EHybrid)
       
   735                 {
       
   736                 CLbtGeoHybrid* containerHybrid = static_cast<CLbtGeoHybrid*>(geoArea);
       
   737                 CLbtGeoHybrid* geoHybrid = static_cast <CLbtGeoHybrid*>( cond->TriggerArea() );
       
   738                 RPointerArray<CLbtGeoAreaBase> newHybridArea;
       
   739                 CleanupClosePushL( newHybridArea );
       
   740                 
       
   741                 const RPointerArray<CLbtGeoAreaBase>& hybridArray = geoHybrid->HybridArea();
       
   742                 for(TInt i=0;i<hybridArray.Count();++i)
       
   743                     {
       
   744                     CLbtGeoAreaBase* geoAreaToArray = NULL;
       
   745                     switch( hybridArray[i]->Type() )
       
   746                         {
       
   747                         case CLbtGeoAreaBase::ECircle:                              
       
   748                             {
       
   749                             // Update the condition for cicular trigger specified in the trigger entry parameter
       
   750                             CLbtGeoCircle* containerCircle = CLbtGeoCircle::NewL();           
       
   751                             CLbtGeoCircle* geoCircle= static_cast<CLbtGeoCircle*> ( hybridArray[i] );
       
   752                             
       
   753                             containerCircle->SetCenter(geoCircle->Center());
       
   754                             containerCircle->SetRadius(geoCircle->Radius());
       
   755                             
       
   756                             /*
       
   757                             // First clear the present additional geo area info array
       
   758                             RPointerArray<CLbtGeoAreaBase>& array = containerCircle->GetAdditionalGeoAreaInfo();
       
   759                             array.ResetAndDestroy();
       
   760                             
       
   761                             // copy from provided geo circle
       
   762                             array = geoCircle->GetAdditionalGeoAreaInfo();
       
   763                             for(TInt i=0;i<array.Count();++i)
       
   764                                 {
       
   765                                 containerCircle->SetAdditionalGeoAreaInfo( array[i] );
       
   766                                 }
       
   767                             geoAreaToArray = containerCircle;
       
   768                             */
       
   769                             break;
       
   770                             }
       
   771                         case CLbtGeoAreaBase::ECellular:
       
   772                             {
       
   773                             CLbtGeoCell* containerCell = CLbtGeoCell::NewL();
       
   774                             CLbtGeoCell* geoCell = static_cast<CLbtGeoCell*> ( hybridArray[i] );
       
   775                             
       
   776                             containerCell->SetNetworkType(geoCell->NetworkType());
       
   777                             containerCell->SetNetworkCountryCode(geoCell->NetworkCountryCode());
       
   778                             containerCell->SetNetworkIdentityCode(geoCell->NetworkIdentityCode());
       
   779                             containerCell->SetLocationAreaCode(geoCell->LocationAreaCode());
       
   780                             containerCell->SetCellId(geoCell->CellId());
       
   781                             geoAreaToArray = containerCell;
       
   782                             break;
       
   783                             }                           
       
   784                         }
       
   785                    newHybridArea.Append( geoAreaToArray );
       
   786                    }                
       
   787                 // The new hybrid array is ready. Now set the array into the geo area Hybrid
       
   788                 containerHybrid->SetHybridArea( newHybridArea );
       
   789                 CleanupStack::Pop(1); //newHybridArea
       
   790                 newHybridArea.Close();                 
       
   791                 }  
       
   792             
       
   793             CLbtTriggerConditionArea* newCond = 
       
   794                 static_cast <CLbtTriggerConditionArea*>(trigEntry->GetCondition());
       
   795             CLbtTriggerConditionArea::TDirection newTriggerDirection =
       
   796                 newCond->Direction();
       
   797             
       
   798             CLbtTriggerConditionArea* OldCond = 
       
   799                 static_cast <CLbtTriggerConditionArea*>(contTrigEntry->GetCondition());
       
   800             CLbtTriggerConditionArea::TDirection currentTriggerDirection =
       
   801                 OldCond->Direction();
       
   802             
       
   803             if( newTriggerDirection != currentTriggerDirection )
       
   804                 {
       
   805                 OldCond->SetDirection( newTriggerDirection );
       
   806                 }
       
   807             }
       
   808         }
       
   809                            
       
   810     if(trigExtInfo!=NULL)
       
   811         {
       
   812         if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeHysteresisRadius )
       
   813             {
       
   814             if(contExtInfo==NULL)
       
   815                 {
       
   816                 contExtInfo=CLbtExtendedTriggerInfo::NewL();
       
   817                 entry->SetExtendedTriggerInfo( contExtInfo );
       
   818                 }
       
   819             contExtInfo->SetHysteresisRadius(trigExtInfo->HysteresisRadius());
       
   820             }
       
   821                         
       
   822         if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeIsFired )
       
   823             {
       
   824             if(contExtInfo==NULL)
       
   825                 {
       
   826                 contExtInfo=CLbtExtendedTriggerInfo::NewL();
       
   827                 entry->SetExtendedTriggerInfo( contExtInfo );
       
   828                 }   
       
   829             contExtInfo->SetTriggerFiredState(trigExtInfo->IsTriggerFired());
       
   830             }
       
   831             
       
   832         if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeFireInfo )
       
   833             {
       
   834             if(contExtInfo==NULL)
       
   835                 {
       
   836                 contExtInfo=CLbtExtendedTriggerInfo::NewL();
       
   837                 entry->SetExtendedTriggerInfo( contExtInfo );
       
   838                 }   
       
   839             contExtInfo->SetFiredInfo( trigExtInfo->GetFiredInfo() );
       
   840             }
       
   841             
       
   842         if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeOwnerSid )
       
   843             {
       
   844             if(contExtInfo==NULL)
       
   845                 {
       
   846                 contExtInfo=CLbtExtendedTriggerInfo::NewL();
       
   847                 entry->SetExtendedTriggerInfo( contExtInfo );
       
   848                 }
       
   849             contExtInfo->SetOwnerSid(trigExtInfo->OwnerSid()); 
       
   850             }
       
   851                     
       
   852         if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeRectTriggerArea )
       
   853             {
       
   854             if(contExtInfo==NULL)
       
   855                 {
       
   856                 contExtInfo=CLbtExtendedTriggerInfo::NewL();
       
   857                 entry->SetExtendedTriggerInfo( contExtInfo );
       
   858                 }
       
   859             contExtInfo->SetTriggerRectangleArea(trigExtInfo->TriggerReactangleArea()); 
       
   860             }   
       
   861                         
       
   862         if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeStrategyData )
       
   863             {
       
   864             if(contExtInfo==NULL)
       
   865                 {
       
   866                 contExtInfo=CLbtExtendedTriggerInfo::NewL();
       
   867                 entry->SetExtendedTriggerInfo( contExtInfo );
       
   868                 }
       
   869             contExtInfo->SetStrategyDataL(trigExtInfo->StategyData()); 
       
   870             }
       
   871 
       
   872         if( iDataMask & CLbtContainerTriggerEntry::EContainerAttributeIsTriggerFireOnCreation )
       
   873             {
       
   874             if(contExtInfo==NULL)
       
   875                 {
       
   876                 contExtInfo=CLbtExtendedTriggerInfo::NewL();
       
   877                 entry->SetExtendedTriggerInfo( contExtInfo );
       
   878                 }
       
   879             contExtInfo->SetTriggerFireOnCreation(trigExtInfo->IsTriggerFireOnCreation()); 
       
   880             }   
       
   881         }
       
   882         
       
   883     if(trigDynInfo!=NULL)
       
   884         {
       
   885         if( iDataMask & CLbtContainerTriggerEntry::EContainerDynInfoAttributeValidity )
       
   886             {
       
   887             if(contDynInfo == NULL)
       
   888                 {
       
   889                 contDynInfo = new TLbtTriggerDynamicInfo;
       
   890                 entry->SetDynInfo( contDynInfo );
       
   891                 }
       
   892             contDynInfo->iValidity = trigDynInfo->iValidity;    
       
   893             }
       
   894         }
       
   895             
       
   896     CompleteClientRequest( KErrNone );
       
   897     }
       
   898 
       
   899 
       
   900 // ---------------------------------------------------------- 
       
   901 // CLbtRamTriggersManager::UpdateTriggersState
       
   902 // ----------------------------------------------------------
       
   903 //
       
   904 void CLbtRamTriggersManager::UpdateTriggersStateL( CLbtTriggerEntry::TLbtTriggerState aState,
       
   905                     							   CLbtContainerUpdateFilter* aFilter,
       
   906                     							   TLbtFireOnUpdate aFireOnUpdate,
       
   907                     							   TLbtSecurityPolicy& aSecurityPolicy,
       
   908                     							   TRequestStatus& aStatus )
       
   909     {
       
   910     FUNC_ENTER("CLbtRamTriggersManager::UpdateTriggersState");
       
   911     iClientStatus = &aStatus;
       
   912     
       
   913     if(aFilter==NULL)
       
   914         {
       
   915         CompleteClientRequest( KErrArgument );
       
   916         return;
       
   917         }
       
   918     
       
   919     /* Set the iterator to the beginning of the tree */
       
   920     //Set the iterator to the beginning of the tree
       
   921     iTriggerIdTree->SetIteratorL();
       
   922     iCurrentOperation = EOperationUpdatingState;
       
   923     iIterator = 0;  
       
   924     iState = aState;
       
   925     iFireOnUpdate = aFireOnUpdate;  
       
   926     
       
   927     /* Retrieve the first entry of the tree */
       
   928     CLbtContainerTriggerEntry* tEntry = NULL;
       
   929     tEntry=iTriggerIdTree->GetNextEntryL();
       
   930     
       
   931     if(tEntry == NULL)
       
   932         {
       
   933         CompleteClientRequest( KErrNotFound );    
       
   934         return;
       
   935         }
       
   936     
       
   937     CLbtContainerFilterBase* filter = LbtContainerUtilities::GetContainerFilterFromUpdateFilterLC(aFilter);    
       
   938     iIdArray.Reset();
       
   939     
       
   940     while(tEntry)
       
   941     	{
       
   942     	if( LbtContainerUtilities::RunSecurityPolicy( tEntry, aSecurityPolicy ) )
       
   943     		{
       
   944     		TInt isFilterPresent = 0;
       
   945 			TBool isEntryRequested = EFalse;		
       
   946 		
       
   947 			filter->ProcessFilter(tEntry,isFilterPresent,isEntryRequested);
       
   948 			if(isFilterPresent>0 && isEntryRequested)
       
   949 				{
       
   950 				AppendTriggerInfo(tEntry);
       
   951 				}
       
   952     		}		
       
   953 		tEntry=iTriggerIdTree->GetNextEntryL();		
       
   954     	}
       
   955 
       
   956     CleanupStack::PopAndDestroy(filter);
       
   957     if(iIdArray.Count() == 0)
       
   958         {
       
   959         CompleteClientRequest( KErrNotFound );                
       
   960         }
       
   961     else
       
   962         {
       
   963         SelfComplete();
       
   964         }       
       
   965     }
       
   966 
       
   967 // ---------------------------------------------------------- 
       
   968 // CLbtRamTriggersManager::HandleUpdateTriggersStateEventL
       
   969 // ----------------------------------------------------------
       
   970 //
       
   971 void CLbtRamTriggersManager::HandleUpdateTriggersStateEventL()
       
   972     {
       
   973     TInt count = 0;
       
   974     while( (iIterator < iIdArray.Count()) && 
       
   975            (count < KStepCount) )
       
   976        {
       
   977        CLbtContainerTriggerEntry *trigEntry = iTriggerIdTree->FindEntryInTreeL( iIdArray[iIterator].iTriggerId );
       
   978        CLbtTriggerEntry* trigger = trigEntry->TriggerEntry();
       
   979        
       
   980        if( trigger->State() == CLbtTriggerEntry::EStateDisabled && 
       
   981            iState == CLbtTriggerEntry::EStateEnabled && 
       
   982            trigEntry->DynInfo()->iValidity == TLbtTriggerDynamicInfo::EValid )
       
   983            {
       
   984            iCountOfEnabledAndValidTrigger++;
       
   985            }
       
   986        else if( trigger->State() == CLbtTriggerEntry::EStateEnabled && 
       
   987                iState == CLbtTriggerEntry::EStateDisabled && 
       
   988                trigEntry->DynInfo()->iValidity == TLbtTriggerDynamicInfo::EValid)
       
   989            {
       
   990            iCountOfEnabledAndValidTrigger--;
       
   991            }
       
   992        trigger->SetState(iState);   
       
   993        if( iFireOnUpdate == ELbtTrue )
       
   994            {
       
   995            CLbtExtendedTriggerInfo* extInfo = trigEntry->ExtendedTriggerInfo();
       
   996            extInfo->SetTriggerFireOnCreation( ETrue );
       
   997            }
       
   998        else 
       
   999            {
       
  1000            CLbtExtendedTriggerInfo* extInfo = trigEntry->ExtendedTriggerInfo();
       
  1001            extInfo->SetTriggerFireOnCreation( EFalse );
       
  1002            }                  
       
  1003        ++iIterator;
       
  1004        ++count;
       
  1005        }
       
  1006     
       
  1007     if( iIterator >= iIdArray.Count() )
       
  1008         {
       
  1009         // All triggers iteration done. Complete request                
       
  1010         CompleteClientRequest( KErrNone );
       
  1011         }
       
  1012     else
       
  1013         {
       
  1014         SelfComplete();                
       
  1015         }            
       
  1016     }
       
  1017 
       
  1018 //-----------------------------------------------------                    
       
  1019 // CLbtRamTriggersManager::UpdateTriggersValidity
       
  1020 //-----------------------------------------------------
       
  1021 //
       
  1022 void CLbtRamTriggersManager::UpdateTriggersValidityL( TLbtTriggerDynamicInfo::TLbtTriggerValidity aValidity,
       
  1023                     							 	  RArray<TLbtTriggerId>& aTriggerIds,
       
  1024                     							 	  TLbtSecurityPolicy& aSecurityPolicy,
       
  1025                     							 	  TRequestStatus& aStatus) 
       
  1026     {
       
  1027     FUNC_ENTER("CLbtRamTriggersManager::UpdateTriggersValidity");
       
  1028     aStatus = KRequestPending;
       
  1029     TRequestStatus* status = &aStatus;
       
  1030     iIdArray.Reset();
       
  1031     
       
  1032     if( iTriggerIdTree->IsEmpty() ||
       
  1033         !aTriggerIds.Count() )
       
  1034     	{
       
  1035     	User::RequestComplete(status, KErrNotFound);
       
  1036         return;
       
  1037     	}
       
  1038     
       
  1039     for(TInt i=0;i<aTriggerIds.Count();i++)
       
  1040         {
       
  1041         CLbtContainerTriggerEntry* entry = NULL;
       
  1042         entry = iTriggerIdTree->FindEntryInTreeL(aTriggerIds[i]);
       
  1043         if(entry == NULL)
       
  1044         	{
       
  1045         	// This trigger is not found. Continue to see if we can find other triggers
       
  1046         	continue;
       
  1047         	}
       
  1048         
       
  1049         if( !LbtContainerUtilities::RunSecurityPolicy( entry, aSecurityPolicy ) )
       
  1050         	{
       
  1051         	// Security check did not pass. Goto next trigger
       
  1052         	continue;
       
  1053         	}
       
  1054             	
       
  1055         if(entry != NULL)
       
  1056             {
       
  1057             if( entry->DynInfo()->iValidity == TLbtTriggerDynamicInfo::EInvalid &&
       
  1058 	    	    aValidity == TLbtTriggerDynamicInfo::EValid)
       
  1059 	    		{
       
  1060 	    		iCountOfEnabledAndValidTrigger++;
       
  1061 	    		}
       
  1062 	    	else if(entry->DynInfo()->iValidity == TLbtTriggerDynamicInfo::EValid &&
       
  1063 	    	    aValidity == TLbtTriggerDynamicInfo::EInvalid)
       
  1064 	    	    {
       
  1065 	    	    iCountOfEnabledAndValidTrigger--;
       
  1066 	    	    }
       
  1067 
       
  1068             if(entry->DynInfo() != NULL)
       
  1069                 {
       
  1070                 entry->DynInfo()->iValidity = aValidity;
       
  1071                 }
       
  1072             else
       
  1073                 {
       
  1074                 TLbtTriggerDynamicInfo * info = new TLbtTriggerDynamicInfo;
       
  1075                 info->iValidity = aValidity;
       
  1076                 entry->SetDynInfo(info);                
       
  1077                 }    
       
  1078             AppendTriggerInfo(entry);
       
  1079             }
       
  1080         }
       
  1081     User::RequestComplete(status,KErrNone);    
       
  1082     }
       
  1083 
       
  1084 // --------------------------------------------------------------------------------------------
       
  1085 // CLbtRamTriggersManager::UpdateTriggerFiredStateL
       
  1086 // --------------------------------------------------------------------------------------------
       
  1087 //    
       
  1088 void CLbtRamTriggersManager::UpdateTriggerFiredStateL( RArray<TLbtTriggerId>& aTriggerIds,
       
  1089 													   TBool aFireBool,
       
  1090 								                       TRequestStatus& aStatus )
       
  1091 	{
       
  1092 	FUNC_ENTER("CLbtRamTriggersManager::UpdateTriggerFiredStateL");
       
  1093 	TBool found = EFalse;
       
  1094     aStatus = KRequestPending;
       
  1095     TRequestStatus* status = &aStatus;
       
  1096     
       
  1097     if( aTriggerIds.Count() == 0 ||
       
  1098     	iTriggerIdTree->IsEmpty() )
       
  1099     	{
       
  1100     	User::RequestComplete(status, KErrNotFound);
       
  1101     	return;
       
  1102     	}
       
  1103     
       
  1104     iIdArray.Reset();
       
  1105     
       
  1106     for(TInt i=0;i<aTriggerIds.Count();i++)
       
  1107         {
       
  1108         CLbtContainerTriggerEntry* entry = NULL;
       
  1109         entry = iTriggerIdTree->FindEntryInTreeL(aTriggerIds[i]);
       
  1110         if(entry == NULL)
       
  1111         	{
       
  1112         	// This trigger is not found. Continue to see if we can find other triggers
       
  1113         	continue;
       
  1114         	}
       
  1115             
       
  1116         CLbtExtendedTriggerInfo* extInfo = entry->ExtendedTriggerInfo();
       
  1117         if(extInfo != NULL)
       
  1118         	{
       
  1119         	extInfo->SetTriggerFiredState(aFireBool);
       
  1120         	found = ETrue;
       
  1121         	}
       
  1122         }
       
  1123             
       
  1124     TInt error = KErrNone;
       
  1125     if( !found )
       
  1126     	{
       
  1127     	error = KErrNotFound;
       
  1128     	}
       
  1129     User::RequestComplete(status, error);
       
  1130 	}
       
  1131 
       
  1132 //------------------------------------------------------
       
  1133 // CLbtRamTriggersManager::DeleteTriggers
       
  1134 //------------------------------------------------------
       
  1135 //
       
  1136 void CLbtRamTriggersManager::DeleteTriggersL( CLbtContainerUpdateFilter* aFilter,
       
  1137 											  TLbtSecurityPolicy& aSecurityPolicy,
       
  1138 											  TRequestStatus& aStatus )
       
  1139     {
       
  1140     FUNC_ENTER("CLbtRamTriggersManager::DeleteTriggers");
       
  1141     iIdArray.Reset();
       
  1142     iClientStatus = &aStatus;
       
  1143  
       
  1144     if(aFilter==NULL)
       
  1145         {
       
  1146         User::RequestComplete(iClientStatus,KErrArgument);        
       
  1147         return;
       
  1148         }
       
  1149     
       
  1150     if( iTriggerIdTree->IsEmpty() )
       
  1151     	{
       
  1152     	User::RequestComplete(iClientStatus, KErrNotFound);
       
  1153         return;
       
  1154     	}
       
  1155 
       
  1156     /* Set the iterator to the beginning of the tree */
       
  1157     iTriggerIdTree->SetIteratorL();
       
  1158     iCurrentOperation = EOperationDelete;
       
  1159     iIterator = 0;  
       
  1160     
       
  1161     iFilterBase = LbtContainerUtilities::GetContainerFilterFromUpdateFilterLC(aFilter);
       
  1162     CleanupStack::Pop(1); // iFilterBase
       
  1163     
       
  1164     /* Retrieve the first entry of the tree */    
       
  1165     CLbtContainerTriggerEntry* tEntry=iTriggerIdTree->GetNextEntryL();
       
  1166         
       
  1167     while( tEntry )
       
  1168         {       
       
  1169         if( LbtContainerUtilities::RunSecurityPolicy( tEntry, aSecurityPolicy ) )
       
  1170             {
       
  1171             TInt isFilterPresent = 0;
       
  1172             TBool isEntryRequested = ETrue;
       
  1173             iFilterBase->ProcessFilter(tEntry,isFilterPresent,isEntryRequested);
       
  1174             if(isFilterPresent > 0 && isEntryRequested)
       
  1175                 {
       
  1176                 AppendTriggerInfo(tEntry);              
       
  1177                 }
       
  1178             }
       
  1179         tEntry = iTriggerIdTree->GetNextEntryL();
       
  1180         }
       
  1181     
       
  1182     if(iIdArray.Count() == 0)
       
  1183         {
       
  1184         CompleteClientRequest( KErrNotFound );                
       
  1185         }
       
  1186     else
       
  1187         {
       
  1188         SelfComplete();
       
  1189         }          
       
  1190     }   
       
  1191 
       
  1192 // ---------------------------------------------------------------------------
       
  1193 // CLbtRamTriggersManager::HandleDeleteTrigger()
       
  1194 // ---------------------------------------------------------------------------
       
  1195 //
       
  1196 void CLbtRamTriggersManager::HandleDeleteTriggersEventL()
       
  1197     {
       
  1198     TInt count = 0;
       
  1199     while( (iIterator < iIdArray.Count()) && 
       
  1200            (count < KStepCount) )
       
  1201        {
       
  1202        CLbtContainerTriggerEntry *entry = iTriggerIdTree->FindEntryInTreeL( iIdArray[iIterator].iTriggerId );
       
  1203        CLbtTriggerEntry* trigger = entry->TriggerEntry();
       
  1204        if( trigger->State() == CLbtTriggerEntry::EStateEnabled && 
       
  1205            entry->DynInfo()->iValidity == TLbtTriggerDynamicInfo::EValid )
       
  1206            {
       
  1207            iCountOfEnabledAndValidTrigger--;
       
  1208            }
       
  1209        DeleteTriggerL( iIdArray[iIterator].iTriggerId );
       
  1210        ++iIterator;
       
  1211        ++count;
       
  1212        }
       
  1213     
       
  1214     if( iIterator >= iIdArray.Count() )
       
  1215         {
       
  1216         // All triggers iteration done. Complete request                
       
  1217         CompleteClientRequest( KErrNone );
       
  1218         }
       
  1219     else
       
  1220         {
       
  1221         SelfComplete();                
       
  1222         }
       
  1223     }
       
  1224 
       
  1225 // ---------------------------------------------------------------------------
       
  1226 // CLbtRamTriggersManager::DeleteTriggerL
       
  1227 // ---------------------------------------------------------------------------
       
  1228 //
       
  1229 void CLbtRamTriggersManager::DeleteTriggerL(TLbtTriggerId aTriggerId)
       
  1230     {
       
  1231     FUNC_ENTER("CLbtRamTriggersManager::DeleteTriggerL");
       
  1232 
       
  1233 	CLbtContainerTriggerEntry* triggerEntry = iTriggerIdTree->FindEntryInTreeL(aTriggerId);
       
  1234 	if(triggerEntry == NULL)
       
  1235 		{
       
  1236 		User::Leave(KErrNotFound);
       
  1237 		}
       
  1238 
       
  1239 	CLbtGeoAreaBase::TGeoAreaType areaType = CLbtGeoAreaBase::ECircle;
       
  1240 	if(triggerEntry->TriggerEntry()->GetCondition()->Type() == CLbtTriggerConditionBase::ETriggerConditionArea)
       
  1241 		{
       
  1242 		// Get the condition area base
       
  1243 		CLbtTriggerConditionArea* conditionArea = 
       
  1244 				static_cast<CLbtTriggerConditionArea*>(triggerEntry->TriggerEntry()->GetCondition());
       
  1245 		areaType = conditionArea->TriggerArea()->Type();
       
  1246 		}
       
  1247 	
       
  1248 	if(iIdArray.Count() == 0)
       
  1249     	{
       
  1250     	MLbtTriggerStore::TLbtTriggerModifiedInfo info;
       
  1251     	info.iTriggerId = aTriggerId;
       
  1252     	info.iAreaType = areaType;
       
  1253     	iIdArray.Append(info);
       
  1254     	}
       
  1255     iTriggerIdTree->DeleteFromTreeL(aTriggerId);
       
  1256     }
       
  1257 
       
  1258 // ---------------------------------------------------------------------------
       
  1259 // Constructor
       
  1260 // ---------------------------------------------------------------------------
       
  1261 //
       
  1262 CLbtRamTriggersManager::CLbtRamTriggersManager():CActive( EPriorityStandard )
       
  1263     {
       
  1264     CActiveScheduler::Add( this );
       
  1265     iCountOfEnabledAndValidTrigger=0;
       
  1266     iIdArray.Reset();
       
  1267     }
       
  1268 
       
  1269 
       
  1270 // ---------------------------------------------------------------------------
       
  1271 // CLbtRamTriggersManager::GetCountOfEnabledAndValidTriggers
       
  1272 // ---------------------------------------------------------------------------
       
  1273 //
       
  1274 TInt CLbtRamTriggersManager::GetCountOfEnabledAndValidTriggers()
       
  1275 	{
       
  1276 	return iCountOfEnabledAndValidTrigger;
       
  1277 	}
       
  1278 
       
  1279 // ---------------------------------------------------------------------------
       
  1280 // The 2nd phase Symbian Constructor
       
  1281 // ---------------------------------------------------------------------------
       
  1282 //
       
  1283 void CLbtRamTriggersManager::ConstructL()
       
  1284     {
       
  1285 	iTriggerIdTree=CLbtRamTriggerIdTree::NewL();	
       
  1286     }
       
  1287 
       
  1288 //---------------------------------------------------------------------------
       
  1289 // CLbtDbTriggersManager::SetTimeTillCompaction
       
  1290 //---------------------------------------------------------------------------
       
  1291 //
       
  1292 void CLbtRamTriggersManager::SetTimeTillCompaction(TTime /*aTime*/)
       
  1293 	{
       
  1294 	// Do nothing here. No compaction required
       
  1295 	}
       
  1296 
       
  1297 //---------------------------------------------------------------------------
       
  1298 // CLbtRamTriggersManager::IsStoreBusy
       
  1299 //---------------------------------------------------------------------------
       
  1300 //
       
  1301 TBool CLbtRamTriggersManager::IsStoreBusy()
       
  1302 	{
       
  1303 	return EFalse;
       
  1304 	}
       
  1305 
       
  1306 //---------------------------------------------------------------------------
       
  1307 // CLbtRamTriggersManager::SetStoreChangeObserver
       
  1308 //---------------------------------------------------------------------------
       
  1309 //
       
  1310 void CLbtRamTriggersManager::SetStoreChangeObserver(MLbtTriggerStoreObserver* /*aObserver*/)
       
  1311 	{
       
  1312 	// Do nothing
       
  1313 	}
       
  1314 
       
  1315 //---------------------------------------------------------------------------
       
  1316 // CLbtRamTriggersManager::CancelCurrentOperation
       
  1317 //---------------------------------------------------------------------------
       
  1318 //
       
  1319 TInt CLbtRamTriggersManager::CancelCurrentOperation()
       
  1320     {
       
  1321     FUNC_ENTER("CLbtRamTriggersManager::CancelCurrentOperation");
       
  1322     TInt error = KErrCancel;
       
  1323     switch( iCurrentOperation )
       
  1324         {
       
  1325         case EOperationCreate:
       
  1326             {
       
  1327             TRAP_IGNORE( iTriggerIdTree->DeleteFromTreeL( iCurrentTriggerId ));
       
  1328             break;
       
  1329             }
       
  1330         case EOperationDelete:
       
  1331             {
       
  1332             // This information is required to update client about trigger change event.
       
  1333             if( iIterator > 0 &&
       
  1334                 iIterator < iIdArray.Count() )
       
  1335                 {
       
  1336                 error = KLbtErrPartial;
       
  1337                 }
       
  1338             break;
       
  1339             }
       
  1340         case EOperationUpdatingState:
       
  1341             {
       
  1342             // This information is required to update client about trigger change event.
       
  1343             if( iIterator > 0 &&
       
  1344                 iIterator < iIdArray.Count() )
       
  1345                 {
       
  1346                 error = KLbtErrPartial;
       
  1347                 }
       
  1348             }
       
  1349         case EOperationListing:
       
  1350         default:
       
  1351             {
       
  1352             break;
       
  1353             }
       
  1354         }
       
  1355     Cancel();
       
  1356     CompleteClientRequest( KErrCancel );
       
  1357     return error;
       
  1358     }