locationtriggering/ltserver/ltserverlogic/src/lbttriggermodifyaooperation.cpp
changeset 0 667063e416a2
child 13 19bff11d6c18
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Active Object operation for serving server logic requests
       
    15 *				 for modification or deletion of triggers.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <lbtstartuptrigger.h>
       
    23 #include <lbtsessiontrigger.h>
       
    24 #include <lbtstartuptrigger.h>
       
    25 #include <lbttriggerfilterbase.h>
       
    26 #include <lbttriggerfilterbyattribute.h>
       
    27 #include <lbttriggerfilterbyarea.h>
       
    28 #include <lbttriggerfiltercomposite.h>
       
    29 #include <lbttriggerconditionbase.h>
       
    30 #include <lbttriggerconditionarea.h>
       
    31 #include <lbtgeocircle.h>
       
    32 #include <s32mem.h>
       
    33 #include <e32cmn.h>
       
    34 #include "lbttriggermodifyaooperation.h"
       
    35 #include "lbtaoobserver.h"
       
    36 #include "lbtcontainer.h"
       
    37 #include "lbtglobal.h"
       
    38 #include "lbtserverconsts.h"
       
    39 #include "lbtcontainerextendedtriggerinfo.h"
       
    40 #include "lbtcontainerupdatefilter.h"
       
    41 #include "lbtcontainertriggerfilter.h"
       
    42 #include "lbtserverlogicbase.h"
       
    43 #include "lbtsettingsmanager.h"
       
    44 #include "lbtlogger.h"
       
    45 
       
    46 // ===================== MEMBER FUNCTIONS =====================
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CLbtTriggerModifyAOOperation::NewL
       
    50 // Symbian Two - phase constructor
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CLbtTriggerModifyAOOperation* CLbtTriggerModifyAOOperation::NewL( MLbtAOObserver& aObserver,
       
    54 															      const RMessage2& aMessage,
       
    55 															      CLbtContainer& aContainer,
       
    56 															      TInt aClientType,
       
    57 				    							                  CLbtSettingsManager& aSettingsManager )
       
    58 	{
       
    59 	FUNC_ENTER("CLbtTriggerModifyAOOperation::NewL");
       
    60 	CLbtTriggerModifyAOOperation* self = 
       
    61 					new (ELeave) CLbtTriggerModifyAOOperation(aObserver, aMessage, aContainer, aClientType,aSettingsManager);
       
    62 	CleanupStack::PushL(self);
       
    63 	self->ConstructL();
       
    64 	CleanupStack::Pop(); // self
       
    65 	return self;
       
    66 	}
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CLbtTriggerModifyAOOperation::~CLbtTriggerModifyAOOperation
       
    70 // Destructor
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CLbtTriggerModifyAOOperation::~CLbtTriggerModifyAOOperation()
       
    74 	{
       
    75 	FUNC_ENTER("CLbtTriggerModifyAOOperation::~CLbtTriggerModifyAOOperation");
       
    76 	// If the operation is not complete yet then complete the 
       
    77 	// message with server busy
       
    78 	iContainer.RemoveObserver(this);
       
    79 	if(IsActive())
       
    80 		{
       
    81 		Cancel();
       
    82 		}
       
    83 	delete iContainerEntry;
       
    84 	iUpdatedTriggerList.ResetAndDestroy();
       
    85 	}
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CLbtTriggerModifyAOOperation::CLbtTriggerModifyAOOperation
       
    89 // C++ Default constructor
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 CLbtTriggerModifyAOOperation::CLbtTriggerModifyAOOperation( MLbtAOObserver& aObserver,
       
    93 										 				    const RMessage2& aMessage,
       
    94 										 				    CLbtContainer& aContainer,
       
    95 										 				    TInt aClientType,
       
    96 										 				    CLbtSettingsManager& aSettingsManager )
       
    97 	: CLbtAOOperationBase(aObserver, aMessage, aContainer, aClientType),
       
    98 	  iState(ENone),iSettingsManager( aSettingsManager )
       
    99 	{
       
   100 	FUNC_ENTER("CLbtTriggerModifyAOOperation::CLbtTriggerModifyAOOperation");
       
   101 	}
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CLbtTriggerModifyAOOperation::ConstructL
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CLbtTriggerModifyAOOperation::ConstructL()
       
   108 	{
       
   109 	FUNC_ENTER("CLbtTriggerModifyAOOperation::ConstructL");
       
   110 	CActiveScheduler::Add(this);
       
   111 	iTriggerId = KLbtNullTriggerId;
       
   112 	}
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CLbtTriggerModifyAOOperation::RunL
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CLbtTriggerModifyAOOperation::RunL()
       
   119 	{
       
   120 	FUNC_ENTER("CLbtTriggerModifyAOOperation::RunL");
       
   121 	switch ( iState )
       
   122 	    {
       
   123 	    case EListTriggers:
       
   124 	        {
       
   125 	        if ( iStatus.Int() == KErrNone &&
       
   126 	             iUpdatedTriggerList.Count() )
       
   127 	            {
       
   128 	            UpdateTriggersL();
       
   129 	            }
       
   130 	        else
       
   131 	            {
       
   132 	            LbtGlobal::RequestComplete(iMessage, iStatus.Int());
       
   133 	            iObserver.HandleOperationClosureL(this, iStatus.Int());
       
   134 	            }
       
   135 	        break;
       
   136 	        }
       
   137 	    case EUpdateTriggers: 
       
   138 	        {
       
   139 	        iState = ENone;
       
   140 	        // Complete the request with the return code of container
       
   141         	LbtGlobal::RequestComplete(iMessage, iStatus.Int());
       
   142         	iObserver.HandleOperationClosureL(this, iStatus.Int());
       
   143         	break;
       
   144 	        }
       
   145 	    default:
       
   146 	        break;
       
   147 	    }
       
   148 	}
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CLbtTriggerModifyAOOperation::DoCancel
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CLbtTriggerModifyAOOperation::DoCancel()
       
   155 	{
       
   156 	FUNC_ENTER("CLbtTriggerModifyAOOperation::DoCancel");
       
   157 	// Cancel container notifications
       
   158 	iContainer.CancelAsyncOperation(iAOIdentificationNum);
       
   159     if( iStatus.Int() == KLbtErrPartial )
       
   160       {
       
   161       LbtGlobal::RequestComplete(iMessage,KErrCancel);
       
   162       }
       
   163     else
       
   164       {
       
   165       LbtGlobal::RequestComplete(iMessage, iStatus.Int());
       
   166       }
       
   167 	}
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // CLbtTriggerModifyAOOperation::StartOperationL
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CLbtTriggerModifyAOOperation::StartOperationL()
       
   174 	{
       
   175 	FUNC_ENTER("CLbtTriggerModifyAOOperation::StartOperationL");
       
   176 	/* The Update Operation involves the following steps,
       
   177 	 * 1. First List Triggers has to be executed. This is necessary for 
       
   178 	 *    obtaining the owner SID of the trigger / triggers on whom the operation
       
   179 	 *    is to be performed. This is also needed to process the notification
       
   180 	 *    requests from clients and management ui.
       
   181 	 *
       
   182 	 * 2. The actual modification operation is then performed.
       
   183 	 *
       
   184 	 * 3. The pending Notification requests are performed.
       
   185 	 *
       
   186 	 * Following is a table of possible combination of actions
       
   187 	 * 
       
   188 	 *  Client Type       Operation Requested             Operations Performed
       
   189 	 *
       
   190 	 *  Client Library           update                           list, modify
       
   191 	 *  Client Library           delete                              modify
       
   192 	 *
       
   193 	 * Management Library    Update state of 1 trigger            list, modify
       
   194 	 * Management Library    Update other param of own trigger    list, modify
       
   195 	 * Management Library    Update other param of other trigger  none
       
   196 	 * Management Library    Update state of many triggers        list, modify
       
   197 	 * Management Library    Delete 1 trigger                     list, delete
       
   198 	 * Management Library    Delete many triggers                 list, delete
       
   199 	 */
       
   200     if ( CLbtServerLogicBase::TLbtClientLibrary == iClientType &&
       
   201          ELbtUpdateTrigger != iFunction )
       
   202         {
       
   203         // No need for list triggers in this case.
       
   204         TRAPD(error , UpdateTriggersL());
       
   205         
       
   206         if( error != KErrNone )
       
   207         	{
       
   208         	iObserver.HandleOperationClosureL(this, error);
       
   209         	}
       
   210         }
       
   211     else
       
   212         {
       
   213         ListTriggersL();
       
   214         }
       
   215 	}
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CLbtTriggerModifyAOOperation::CancelModifyOperation
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CLbtTriggerModifyAOOperation::CancelModifyOperation()
       
   222 	{
       
   223 	FUNC_ENTER("CLbtTriggerModifyAOOperation::CancelModifyOperation");
       
   224 	Cancel();
       
   225 	   
       
   226    if( iStatus.Int() == KLbtErrPartial )
       
   227        {
       
   228        LOG("Partial completion");  
       
   229        iObserver.HandleOperationClosureL( this,KErrNone );
       
   230        }
       
   231    else
       
   232        {
       
   233        iObserver.HandleOperationClosureL( this,iStatus.Int() );
       
   234        }
       
   235     }
       
   236 	
       
   237 // ---------------------------------------------------------------------------
       
   238 // CLbtTriggerModifyAOOperation::GetTriggerId
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 TLbtTriggerId CLbtTriggerModifyAOOperation::GetTriggerId()
       
   242 	{
       
   243 	FUNC_ENTER("CLbtTriggerModifyAOOperation::GetTriggerId");
       
   244 	return iTriggerId;
       
   245 	}
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // CLbtTriggerModifyAOOperation::ListTriggersL
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CLbtTriggerModifyAOOperation::ListTriggersL()
       
   252     {
       
   253     FUNC_ENTER("CLbtTriggerModifyAOOperation::ListTriggersL");
       
   254     // The List Triggers operation is called for 2 reasons
       
   255     //
       
   256     // 1. The Container UpdateTrigger method does not take a filter. Hence the
       
   257     //    check to ensure that only the owner can modify its triggers requires
       
   258     //    a call to List Triggers. During Listing we add the owner SID also to
       
   259     //    the filter. If the List Trigger call returns any triggers then the 
       
   260     //    update operation can be executed. 
       
   261     //
       
   262     // 2. The Notification requires informaiton all triggers that have been 
       
   263     //    modified and the owners of the triggers as well. This information
       
   264     //    is not available form the IPC. The IPC contains only the application
       
   265     //    that requests the modification. This could be through the LT 
       
   266     //    management API, in which case that will not indicate the owner of the
       
   267     //    trigger.
       
   268 
       
   269 	CLbtContainerListOptions* containerOptions = CLbtContainerListOptions::NewL();
       
   270 	CleanupStack::PushL(containerOptions);
       
   271 
       
   272 	CLbtListTriggerOptions* options = CLbtListTriggerOptions::NewL();
       
   273 	CleanupStack::PushL(options);
       
   274     TLbtSecurityPolicy securityPolicy;
       
   275     switch( iFunction )
       
   276         {
       
   277 		case ELbtUpdateTrigger:
       
   278 		    {
       
   279 		    CLbtTriggerEntry* trigger = 
       
   280 		        InternalizeTriggerFromIpcLC( iMessage, KParamTriggerEntry );
       
   281 
       
   282             // Add a filter for the trigger Id.
       
   283 			CLbtTriggerFilterByAttribute* filter = 
       
   284 			                CLbtTriggerFilterByAttribute::NewLC();
       
   285 			filter->AddTriggerIdL( trigger->Id() );
       
   286             options->SetFilter( filter );
       
   287 			CleanupStack::Pop(filter);
       
   288             CleanupStack::PopAndDestroy( trigger );
       
   289 
       
   290             // Only the update trigger requires this check. All other client API
       
   291             // requests are directly executed since the owner SID check can be done
       
   292             // through filters.
       
   293             // For all other requests from management API, the check is not 
       
   294             // required since the management API has the permission to execute
       
   295             // the request on any trigger in the system.
       
   296 
       
   297             if ( CLbtServerLogicBase::TLbtClientLibrary == iClientType ||
       
   298                  (CLbtServerLogicBase::TLbtManagementLibrary == iClientType &&
       
   299                  CLbtTriggerEntry::EAttributeState != iMessage.Int0()) )
       
   300                 {
       
   301     			securityPolicy.SetOwnerSecureId( iMessage.SecureId() );
       
   302                 }
       
   303 		    break;
       
   304 		    }
       
   305 		case ELbtDeleteTrigger:
       
   306 		case ELbtSetTriggerState:
       
   307 		    {
       
   308 			TPckg<TLbtTriggerId> id(iTriggerId);
       
   309 			LbtGlobal::Read(iMessage, KParamTriggerId, id);
       
   310 			// Create a filter for the trigger Id
       
   311 			CLbtTriggerFilterByAttribute* filter = 
       
   312 			                CLbtTriggerFilterByAttribute::NewLC();
       
   313 			filter->AddTriggerIdL( iTriggerId );
       
   314             options->SetFilter( filter );
       
   315 			CleanupStack::Pop(filter);
       
   316 			// ToDo : if msg from LT client API then add SID filter as well.
       
   317 			break;
       
   318 		    }
       
   319 		case ELbtDeleteTriggers:
       
   320 		case ELbtSetTriggersState:
       
   321 		    {
       
   322 			CLbtTriggerFilterBase* filter = 
       
   323 			    InternalizeFilterFromIpcLC( iMessage, KParamFilter );
       
   324             options->SetFilter( filter );
       
   325 			CleanupStack::Pop(filter);
       
   326 			// ToDo : if msg from LT client API then add SID filter as well.
       
   327 		    break;
       
   328 		    }
       
   329         }
       
   330 
       
   331     containerOptions->SetListOptions( options );
       
   332 	CleanupStack::Pop( options );
       
   333 	
       
   334 	containerOptions->SetDataMask(CLbtTriggerEntry::EAttributeId | 
       
   335 	    CLbtContainerTriggerEntry::EContainerAttributeOwnerSid);
       
   336 	CleanupStack::Pop(containerOptions);    
       
   337 						
       
   338 	// List the triggers that require modification.
       
   339 	iContainer.ListTriggers(containerOptions, iUpdatedTriggerList,iAOIdentificationNum,iStatus,securityPolicy);
       
   340     iState = EListTriggers;
       
   341 	SetActive();
       
   342     }
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // CLbtTriggerModifyAOOperation::CheckEnabledTriggerCap()
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 TBool CLbtTriggerModifyAOOperation::CheckEnabledTriggerCap()
       
   349 	{
       
   350 	TUint enabledValidTriggerCount = iContainer.GetCountOfEnabledAndValidTriggers();
       
   351 	
       
   352 	if( iSettingsManager.EnabledValidTriggerCount() > enabledValidTriggerCount )
       
   353 		{
       
   354 		// More triggers can be created. Return true
       
   355 		return ETrue;
       
   356 		}
       
   357 	return EFalse;
       
   358 	}
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // CLbtTriggerModifyAOOperation::UpdateTriggersL()
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CLbtTriggerModifyAOOperation::UpdateTriggersL()
       
   365     {
       
   366     FUNC_ENTER("CLbtTriggerModifyAOOperation::UpdateTriggersL");
       
   367 	switch(iFunction)
       
   368 		{
       
   369 		case ELbtUpdateTrigger:
       
   370 			{
       
   371 			HandleUpdateTriggerStateOpL();
       
   372 			break;
       
   373 			}
       
   374 		
       
   375 		case ELbtSetTriggerState:
       
   376 		case ELbtSetTriggersState:
       
   377 			{
       
   378 			HandleModifyTriggerStateOpL();
       
   379 			break;
       
   380 			}
       
   381 		case ELbtDeleteTrigger:
       
   382 		case ELbtDeleteTriggers:
       
   383 			{
       
   384 			HandleDeleteTriggerOpL();
       
   385 			break;
       
   386 			}
       
   387 		default:
       
   388 			{
       
   389 			User::Leave( KErrNotSupported );
       
   390 			break;
       
   391 			}
       
   392 		}
       
   393     iState = EUpdateTriggers;
       
   394     }
       
   395 
       
   396 // ---------------------------------------------------------------------------
       
   397 // CLbtTriggerModifyAOOperation::HandleUpdateTriggerStateOpL()
       
   398 // ---------------------------------------------------------------------------
       
   399 //		
       
   400 void CLbtTriggerModifyAOOperation::HandleUpdateTriggerStateOpL()
       
   401     {
       
   402     // Create the trigger entry object based on the type of trigger
       
   403     TLbtTriggerDataMask dataMask = 0;
       
   404 	CLbtTriggerEntry* trigger = 
       
   405 	    InternalizeTriggerFromIpcLC( iMessage, KParamTriggerEntry );
       
   406 	if( iMessage.Int0() & CLbtTriggerEntry::EAttributeState )
       
   407 		{
       
   408 		if( trigger->State() == CLbtTriggerEntry::EStateEnabled)
       
   409 			{
       
   410 			if( !CheckEnabledTriggerCap() )
       
   411 				{						
       
   412 				CleanupStack::PopAndDestroy( trigger );
       
   413 				LbtGlobal::RequestComplete(iMessage, KLbtErrMaxEnabledValidTriggersLimitExceeded);
       
   414 				iObserver.HandleOperationClosureL(this, KLbtErrMaxEnabledValidTriggersLimitExceeded);
       
   415 				return;
       
   416 				}
       
   417 			}
       
   418 		}
       
   419 	if( iMessage.Int0() & CLbtTriggerEntry::EAttributeCondition)
       
   420 	    {
       
   421 	    CLbtStartupTrigger* triggerEntry = static_cast<CLbtStartupTrigger*>
       
   422 	                                                    ( trigger );
       
   423 	      
       
   424 	    
       
   425 	    // Check whether the trigger radius is less than minimum 
       
   426 	    // trigger radius.
       
   427 	    if(triggerEntry->GetCondition()->Type() == CLbtTriggerConditionBase::ETriggerConditionArea)
       
   428     		{
       
   429     		// Get the condition area base
       
   430     		CLbtTriggerConditionArea* conditionArea = 
       
   431     				static_cast<CLbtTriggerConditionArea*>(triggerEntry->GetCondition());
       
   432     		
       
   433     		// Check if the area is a circle
       
   434     		if(conditionArea->TriggerArea()->Type() == CLbtGeoAreaBase::ECircle)
       
   435     			{
       
   436     			CLbtGeoCircle* circle = static_cast<CLbtGeoCircle*>(conditionArea->TriggerArea());
       
   437     			
       
   438     			// If the triggering area specified is less than the minimum triggering area
       
   439     			// the return KErrTriggerAreaTooSmall
       
   440     			if(circle->Radius() < iSettingsManager.MinimumTriggeringArea())
       
   441     				{
       
   442     				CleanupStack::PopAndDestroy( trigger );
       
   443     				LbtGlobal::RequestComplete(iMessage, KErrTriggerAreaTooSmall);
       
   444     				iObserver.HandleOperationClosureL(this, KErrTriggerAreaTooSmall);
       
   445     				return;
       
   446     				}
       
   447                 }
       
   448     		}
       
   449 	    }
       
   450 	    
       
   451 	LOG1("Trigger updated:%d",trigger->Id());
       
   452 	LOG1("State of updated trigger:%d",trigger->State());    
       
   453 	
       
   454 	
       
   455 	CLbtExtendedTriggerInfo* extendedTriggerInfo = 
       
   456 	                                            CLbtExtendedTriggerInfo::NewL();
       
   457 	CleanupStack::PushL( extendedTriggerInfo );
       
   458 	            
       
   459     if( iFireOnUpdate == ELbtTrue )
       
   460         {
       
   461         extendedTriggerInfo->SetTriggerFireOnCreation( ETrue );
       
   462         }
       
   463     else
       
   464         {
       
   465         extendedTriggerInfo->SetTriggerFireOnCreation( EFalse );
       
   466         }
       
   467     dataMask|= CLbtContainerTriggerEntry::EContainerAttributeIsTriggerFireOnCreation;
       
   468 	
       
   469 	// Create the container trigger entry for the update operation
       
   470 	iContainerEntry = CLbtContainerTriggerEntry::NewL(
       
   471 	                                        trigger, NULL, extendedTriggerInfo );
       
   472 	
       
   473 	
       
   474 	
       
   475 	// Pop trigger since ownership is transferred to iContainerEntry
       
   476     CleanupStack::Pop( 2 );// extendedTriggerInfo,trigger
       
   477     
       
   478     // Register for container change event observer
       
   479     TLbtTriggerEventMask eventMask = 0;
       
   480     eventMask|= CLbtContainer::ELbtConTriggerNameFieldChanged|
       
   481                 CLbtContainer::ELbtConTriggerStateFieldChanged|
       
   482                 CLbtContainer::ELbtConTriggerRequestorFieldChanged|
       
   483                 CLbtContainer::ELbtConTriggerManagerUiFieldChanged|        
       
   484                 CLbtContainer::ELbtConTriggerConditionFieldChanged|
       
   485                 CLbtContainer::ELbtConTriggerStartupFieldChanged;
       
   486                 
       
   487     iContainer.SetChangeObserver( this ,eventMask );
       
   488     
       
   489     TLbtSecurityPolicy securityPolicy;
       
   490 	// Change the state of the trigger owned by only the requesting 
       
   491 	// client in case this is a req through LT client API.
       
   492 	if ( iClientType == CLbtServerLogicBase::TLbtClientLibrary )
       
   493 	    {
       
   494         securityPolicy.SetOwnerSecureId( iMessage.SecureId() );
       
   495 	    }
       
   496     
       
   497 	// The attribute field mask for updated fields is 
       
   498 	// stores in IPC slot 0 ( 3 param).
       
   499 	iContainer.UpdateTriggerL(*iContainerEntry, 
       
   500 	                          dataMask,
       
   501 	                          iMessage.Int0(),iAOIdentificationNum,
       
   502 	                          iStatus,securityPolicy);
       
   503 	SetActive();
       
   504     }
       
   505 
       
   506     
       
   507 // ---------------------------------------------------------------------------
       
   508 // CLbtTriggerModifyAOOperation::HandleModifyTriggerStateOpL()
       
   509 // ---------------------------------------------------------------------------
       
   510 //
       
   511 void CLbtTriggerModifyAOOperation::HandleModifyTriggerStateOpL()
       
   512     {
       
   513     FUNC_ENTER("CLbtTriggerModifyAOOperation::HandleModifyTriggerStateOpL");
       
   514 	CLbtTriggerFilterBase* filter = NULL;
       
   515 	CLbtTriggerEntry::TLbtTriggerState triggerState;
       
   516 	
       
   517 	switch ( iFunction )
       
   518 	    {
       
   519 	    case ELbtSetTriggerState:
       
   520     	    {
       
   521     		// Read trigger id from IPC msg and create a filter
       
   522     		TPckg<TLbtTriggerId> id( iTriggerId );
       
   523     		LbtGlobal::Read( iMessage, KParamTriggerId, id );
       
   524     		
       
   525     		TPckg<TLbtFireOnUpdate> fireUpdatePckg( iFireOnUpdate );
       
   526     		LbtGlobal::Read( iMessage, KParamFireOnUpdate, fireUpdatePckg );
       
   527     		filter = CLbtTriggerFilterByAttribute::NewLC();
       
   528     		static_cast<CLbtTriggerFilterByAttribute *>(filter)->AddTriggerIdL( iTriggerId );
       
   529     		
       
   530     		TPckg<CLbtTriggerEntry::TLbtTriggerState> state(triggerState);
       
   531     		LbtGlobal::Read(iMessage, KTriggerState, state);
       
   532     		break;
       
   533     	    }
       
   534 	    case ELbtSetTriggersState:
       
   535 	        {
       
   536 	        TLbtTriggerStateInfo triggerStateInfo;
       
   537 	        TPckg<TLbtTriggerStateInfo> triggerStateInfoPckg(triggerStateInfo);
       
   538 	        LbtGlobal::Read(iMessage,KParamTriggerStateInfo,triggerStateInfoPckg);
       
   539 	        triggerState = triggerStateInfo.iState;
       
   540 	        iFireOnUpdate = triggerStateInfo.iFireOnUpdate;
       
   541     	    filter = InternalizeFilterFromIpcLC( iMessage, KParamFilter );
       
   542     		break;
       
   543 	        }
       
   544 	    }
       
   545 
       
   546 	CLbtContainerUpdateFilter* updOptions = 
       
   547         CLbtContainerUpdateFilter::NewL( filter, NULL );
       
   548 	
       
   549 	// Since ownership of filter is transferred to updOptions, 
       
   550 	// pop it from the cleanup stack.
       
   551 	CleanupStack::Pop( filter );
       
   552 
       
   553     TLbtSecurityPolicy securityPolicy;
       
   554 	// Change the state of the trigger owned by only the requesting 
       
   555 	// client in case this is a req through LT client API.
       
   556 	if ( iClientType == CLbtServerLogicBase::TLbtClientLibrary )
       
   557 	    {
       
   558         securityPolicy.SetOwnerSecureId( iMessage.SecureId() );
       
   559 	    }
       
   560 	
       
   561 	// Register for container change event observer
       
   562     TLbtTriggerEventMask eventMask = 0;
       
   563     eventMask|= CLbtContainer::ELbtConTriggerStateFieldChanged;
       
   564                 
       
   565     iContainer.SetChangeObserver( this ,eventMask );
       
   566     
       
   567 	// Update the trigger state in container
       
   568 	iContainer.UpdateTriggersState(triggerState, updOptions,iAOIdentificationNum,iFireOnUpdate,
       
   569 									 iStatus,securityPolicy);
       
   570 	SetActive();
       
   571     }
       
   572 
       
   573 // ---------------------------------------------------------------------------
       
   574 // CLbtTriggerModifyAOOperation::HandleDeleteTriggerOpL()
       
   575 // ---------------------------------------------------------------------------
       
   576 //
       
   577 void CLbtTriggerModifyAOOperation::HandleDeleteTriggerOpL()
       
   578     {
       
   579     FUNC_ENTER("CLbtTriggerModifyAOOperation::HandleDeleteTriggerOpL");
       
   580 	CLbtTriggerFilterBase* filter = NULL;
       
   581 	switch( iFunction )
       
   582 	    {
       
   583 	    case ELbtDeleteTrigger:
       
   584 	        {
       
   585     		TPckg<TLbtTriggerId> id(iTriggerId);
       
   586     		// Read the trigger id to be deleted
       
   587     		LbtGlobal::Read(iMessage, KParamTriggerId, id);
       
   588     		
       
   589     		// Create a Filter based on the trigger Id.
       
   590     		filter = CLbtTriggerFilterByAttribute::NewLC();
       
   591     		static_cast<CLbtTriggerFilterByAttribute *>(filter)->AddTriggerIdL(iTriggerId);
       
   592             break;	        
       
   593 	        }
       
   594 	    case ELbtDeleteTriggers:
       
   595 	        {
       
   596             filter = InternalizeFilterFromIpcLC( iMessage, KParamFilter );
       
   597             break;	        
       
   598 	        }
       
   599 	    }
       
   600 
       
   601 	CLbtContainerUpdateFilter* updOptions = 
       
   602     			    CLbtContainerUpdateFilter::NewL(filter,
       
   603     			                                    NULL);
       
   604 	// Since ownership of filter is transferred to updOptions, 
       
   605 	// pop it from the cleanup stack.
       
   606 	CleanupStack::Pop( filter );
       
   607 
       
   608     TLbtSecurityPolicy securityPolicy;
       
   609     // Add the SID of the requester client as a filter.
       
   610     // This prevents the client from changing the state of any trigger
       
   611     // that does not belong to it.
       
   612 	if ( iClientType == CLbtServerLogicBase::TLbtClientLibrary )
       
   613 	    {
       
   614         securityPolicy.SetOwnerSecureId( iMessage.SecureId() );
       
   615 	    }
       
   616     // Register for container change event observer
       
   617     TLbtTriggerEventMask eventMask = 0;
       
   618     eventMask|= CLbtContainer::ELbtConTriggerDeleted;
       
   619                 
       
   620     iContainer.SetChangeObserver( this ,eventMask );
       
   621     
       
   622 	// Delete trigger from container
       
   623 	iContainer.DeleteTriggers(updOptions,iAOIdentificationNum,iStatus,securityPolicy);
       
   624 	SetActive();
       
   625     }
       
   626 
       
   627 // ---------------------------------------------------------------------------
       
   628 // CLbtTriggerModifyAOOperation::GetUpdatedTriggerList
       
   629 // ---------------------------------------------------------------------------
       
   630 //
       
   631 RPointerArray<CLbtContainerTriggerEntry>& CLbtTriggerModifyAOOperation::GetUpdatedTriggerList()
       
   632 	{
       
   633 	FUNC_ENTER("CLbtTriggerModifyAOOperation::GetUpdatedTriggerList");
       
   634 	return iUpdatedTriggerList;
       
   635 	}
       
   636 
       
   637 // ---------------------------------------------------------------------------
       
   638 // CLbtTriggerModifyAOOperation::CreateTriggerEntryLC()
       
   639 // ---------------------------------------------------------------------------
       
   640 //
       
   641 CLbtTriggerEntry* CLbtTriggerModifyAOOperation::CreateTriggerEntryLC( TInt aType )
       
   642     {
       
   643     FUNC_ENTER("CLbtTriggerModifyAOOperation::CreateTriggerEntryLC");
       
   644     CLbtTriggerEntry* trigger = NULL;
       
   645     switch( aType )
       
   646         {
       
   647         case CLbtTriggerEntry::ETypeSession:
       
   648     		trigger = CLbtSessionTrigger::NewLC();
       
   649     		break;
       
   650         case CLbtTriggerEntry::ETypeStartup:
       
   651     		trigger = CLbtStartupTrigger::NewLC();
       
   652     		break;
       
   653         default:
       
   654             User::Leave( KErrArgument );
       
   655         }
       
   656 	return trigger;
       
   657     }
       
   658 
       
   659 // ---------------------------------------------------------------------------
       
   660 // CLbtTriggerModifyAOOperation::CreateTriggerFilterLC()
       
   661 // ---------------------------------------------------------------------------
       
   662 //
       
   663 CLbtTriggerFilterBase* CLbtTriggerModifyAOOperation::CreateTriggerFilterLC( TInt aType )
       
   664     {
       
   665     FUNC_ENTER("CLbtTriggerModifyAOOperation::CreateTriggerFilterLC");
       
   666     CLbtTriggerFilterBase* filter = NULL;
       
   667 	switch( aType )
       
   668 		{
       
   669 		case CLbtTriggerFilterBase::EFilterByAttribute:
       
   670 			{
       
   671 			filter = CLbtTriggerFilterByAttribute::NewLC();
       
   672 			break;
       
   673 			}	
       
   674 		case CLbtTriggerFilterBase::EFilterByArea:
       
   675 			{
       
   676 			filter = CLbtTriggerFilterByArea::NewLC();
       
   677 			break;
       
   678 			}
       
   679 		case CLbtTriggerFilterBase::EFilterComposite:
       
   680 			{
       
   681 			filter = CLbtTriggerFilterComposite::NewLC();
       
   682 			break;
       
   683 			}
       
   684 		default:
       
   685 		    User::Leave(KErrArgument);
       
   686 		}
       
   687     return filter;
       
   688     }
       
   689 
       
   690 // ---------------------------------------------------------------------------
       
   691 // CLbtTriggerModifyAOOperation::InternalizeFilterFromIpcLC()
       
   692 // ---------------------------------------------------------------------------
       
   693 //
       
   694 CLbtTriggerFilterBase* CLbtTriggerModifyAOOperation::InternalizeFilterFromIpcLC( 
       
   695     const RMessage2& aMessage, 
       
   696     const TInt aIpcSlot )
       
   697     {
       
   698     FUNC_ENTER("CLbtTriggerModifyAOOperation::InternalizeFilterFromIpcLC");
       
   699 	CLbtTriggerFilterBase* filter = CreateTriggerFilterLC( aMessage.Int0() );
       
   700 				
       
   701 	// Copy the filter object descriptor from the client IPC message
       
   702 	HBufC8* filterBuffer = LbtGlobal::CopyClientBuffer8LC( aMessage, aIpcSlot );
       
   703 	
       
   704 	if( filterBuffer == NULL )
       
   705 		{
       
   706 		CleanupStack::PopAndDestroy( filter );
       
   707 		User::Leave(KErrBadDescriptor);
       
   708 		}
       
   709 		
       
   710 	// Read the buffer into a stream
       
   711 	RDesReadStream stream( *filterBuffer );
       
   712 	CleanupClosePushL( stream );
       
   713 	filter->InternalizeL( stream );
       
   714 	CleanupStack::PopAndDestroy(2, filterBuffer); // filterBuffer,stream
       
   715 	return filter;
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------------------------
       
   719 // CLbtTriggerModifyAOOperation::InternalizeTriggerFromIpcLC()
       
   720 // ---------------------------------------------------------------------------
       
   721 //
       
   722 CLbtTriggerEntry* CLbtTriggerModifyAOOperation::InternalizeTriggerFromIpcLC( 
       
   723     const RMessage2& aMessage, 
       
   724     const TInt aIpcSlot )
       
   725     {
       
   726     FUNC_ENTER("CLbtTriggerModifyAOOperation::InternalizeTriggerFromIpcLC");
       
   727     // Create the trigger entry object based on the type of trigger
       
   728     
       
   729     TLbtTriggerUpdationInfo triggerUpdateInfo;
       
   730     TPckg<TLbtTriggerUpdationInfo> triggerUpdateInfoPckg( triggerUpdateInfo );
       
   731     LbtGlobal::Read( aMessage,KParamTriggerUpdationInfo,triggerUpdateInfoPckg );
       
   732     iFireOnUpdate = triggerUpdateInfo.iFireOnUpdate;
       
   733 	CLbtTriggerEntry* trigger = CreateTriggerEntryLC( triggerUpdateInfo.iTriggerType );
       
   734 	
       
   735 	// Copy the trigger entry object descriptor from the client IPC message
       
   736 	HBufC8* triggerEntryBuffer = LbtGlobal::CopyClientBuffer8LC( aMessage, aIpcSlot );
       
   737 	
       
   738 	if( triggerEntryBuffer == NULL )
       
   739 		{
       
   740 		CleanupStack::PopAndDestroy(trigger);
       
   741 		User::Leave(KErrBadDescriptor);
       
   742 		}
       
   743 	
       
   744 	// Create a Read Stream over the descriptor
       
   745 	RDesReadStream stream(*triggerEntryBuffer);
       
   746 	CleanupClosePushL(stream);
       
   747 	// Internalize the trigger entry class since it is a "C" class
       
   748 	trigger->InternalizeL(stream);	
       
   749 	CleanupStack::PopAndDestroy(2, triggerEntryBuffer); //triggerEntryBuffer, stream
       
   750     return trigger;
       
   751     }
       
   752 
       
   753 
       
   754 // end of file
       
   755