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