locationtriggering/lbtmgmtui/src/lbtmgmtlbtadapter.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     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:  Location Triggering Management's Lbt adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // User Include
       
    20 #include "lbtmgmtlbtadapter.h"
       
    21 #include "lbtmgmtadapterobserver.h"
       
    22 #include "lbtmgmtdebug.h"
       
    23 #include <lbtstatuspskeys.h>
       
    24 #include <lbttriggerfilterbyattribute.h> 
       
    25 #include <lbttriggerchangeeventnotifier.h>
       
    26 
       
    27 // System Include
       
    28 #include <lbttriggeringsystemmanagementsettings.h> 
       
    29 #include <lbtcommon.h>
       
    30 #include <e32property.h>
       
    31 
       
    32 // Constant Definition
       
    33 
       
    34 // ========================= MEMBER FUNCTIONS ================================
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CLbtMgmtLbtAdapter::CLbtMgmtLbtAdapter
       
    39 // Overloaded Constructor
       
    40 //
       
    41 // ---------------------------------------------------------------------------
       
    42 //  
       
    43 CLbtMgmtLbtAdapter::CLbtMgmtLbtAdapter(  
       
    44                                 MLbtMgmtAdapterObserver& aAdapterObsrv )
       
    45     :CActive(EPriorityStandard),
       
    46     iObserver(aAdapterObsrv)
       
    47     {
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CLbtMgmtLbtAdapter::~CLbtMgmtLbtAdapter
       
    52 // Destructor
       
    53 //
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CLbtMgmtLbtAdapter::~CLbtMgmtLbtAdapter()
       
    57     {
       
    58     Cancel();
       
    59     delete iEventChangeObserver;
       
    60     iLbtMgrObserver.Close();
       
    61     iLbtMgr.Close();
       
    62     iLbtServ.Close();
       
    63     }
       
    64     
       
    65 // ---------------------------------------------------------------------------
       
    66 // CLbtMgmtLbtAdapter* CLbtMgmtLbtAdapter::NewL
       
    67 // Creates new Trigger Status adapter
       
    68 //
       
    69 // @param  aAdapterObsrv                        Observer to the Settings adapter
       
    70 // @return CLbtMgmtLbtAdapter& Reference to the Trigger Status adapter
       
    71 // ---------------------------------------------------------------------------
       
    72 //    
       
    73 CLbtMgmtLbtAdapter* CLbtMgmtLbtAdapter::NewL( 
       
    74                             MLbtMgmtAdapterObserver& aAdapterObsrv )
       
    75     {   
       
    76     CLbtMgmtLbtAdapter* self = 
       
    77                         CLbtMgmtLbtAdapter::NewLC( aAdapterObsrv );
       
    78     CleanupStack::Pop(self);
       
    79     return self;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CLbtMgmtLbtAdapter* CLbtMgmtLbtAdapter::NewLC
       
    84 // Creates new Trigger Status adapter. Leaves the object on the clean-up
       
    85 // stack
       
    86 //
       
    87 // @param  aAdapterObsrv                        Observer to the Settings adapter
       
    88 // @return CLbtMgmtLbtAdapter& Reference to the Trigger Status adapter
       
    89 // ---------------------------------------------------------------------------
       
    90 // 
       
    91 CLbtMgmtLbtAdapter* CLbtMgmtLbtAdapter::NewLC( 
       
    92                             MLbtMgmtAdapterObserver& aAdapterObsrv )
       
    93     {   
       
    94     CLbtMgmtLbtAdapter* self = 
       
    95                         new(ELeave) CLbtMgmtLbtAdapter( aAdapterObsrv );
       
    96     CleanupStack::PushL(self);
       
    97     self->ConstructL();
       
    98     return self;
       
    99     }
       
   100     
       
   101 // ---------------------------------------------------------------------------
       
   102 // void CLbtMgmtLbtAdapter::ConstructL
       
   103 // Second Phase Constructor
       
   104 //
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CLbtMgmtLbtAdapter::ConstructL()
       
   108     {  
       
   109     
       
   110     // Create the Central repository object for manipulating Avkon Central
       
   111     // repository for Co-ordinate display settings
       
   112     User::LeaveIfError( iLbtServ.Connect() );
       
   113 	User::LeaveIfError( iLbtMgr.Open(iLbtServ) );
       
   114 	User::LeaveIfError( iLbtMgrObserver.Open(iLbtServ) );
       
   115     
       
   116 	CActiveScheduler::Add( this );
       
   117     StartNotification();
       
   118     
       
   119     iEventChangeObserver = CLbtTriggerChangeEventNotifier::NewL( iLbtMgrObserver, *this );
       
   120     iEventChangeObserver->Start();
       
   121     
       
   122     iLbtMgr.GetTriggeringSystemSettingsL( iTriggerSettings );
       
   123     GetTotalActiveTriggersL();
       
   124     }
       
   125     
       
   126 // ---------------------------------------------------------------------------
       
   127 // CLbtMgmtLbtAdapter::TCordDisSetListPosition 
       
   128 //                CLbtMgmtLbtAdapter::GetCurrentDisplayFormatL
       
   129 // Returns the position of the Co-ordinate display format settings value.
       
   130 //
       
   131 // @return TCordDisSetListPosition Current postion of the Co-ordinate display
       
   132 //                                 settings value.
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 CLbtMgmtLbtAdapter::TTriggeringStatus 
       
   136                 CLbtMgmtLbtAdapter::GetCurrentTriggeringStatusL()
       
   137     {	
       
   138     LBTMGMTUIDEBUG("+ CLbtMgmtLbtAdapter::GetCurrentTriggeringStatusL()");
       
   139     CLbtMgmtLbtAdapter::TTriggeringStatus status = CLbtMgmtLbtAdapter::EOff;
       
   140     
       
   141     switch( iTriggerSettings.TriggeringMechanismState() )
       
   142     	{
       
   143     	case ETriggeringMechanismOn:
       
   144     		status = CLbtMgmtLbtAdapter::EOn;
       
   145     		break;
       
   146     	case ETriggeringMechanismOff:
       
   147     		status = CLbtMgmtLbtAdapter::EOff;
       
   148     		break;
       
   149     	default :
       
   150     		break;
       
   151     	}
       
   152     LBTMGMTUIDEBUG1("- CLbtMgmtLbtAdapter::GetCurrentTriggeringStatusL() - %d", status);
       
   153     
       
   154     return status;    
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // void CLbtMgmtLbtAdapter::SetCurrentDisplayFormatL
       
   159 // Sets the value of the Co-ordinate display format settings based on the
       
   160 // display position.
       
   161 //
       
   162 // @param aSettingsPos  Position of the new Co-ordinate display settings value
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CLbtMgmtLbtAdapter::SetCurrentTriggeringStatusL( 
       
   166         CLbtMgmtLbtAdapter::TTriggeringStatus aSettingsValue )
       
   167    {	
       
   168    LBTMGMTUIDEBUG1("+ CLbtMgmtLbtAdapter::SetCurrentTriggeringStatusL() - %d", aSettingsValue);
       
   169     switch( aSettingsValue )
       
   170     	{
       
   171     	case CLbtMgmtLbtAdapter::EOn:
       
   172     		iTriggerSettings.SetTriggeringMechanismState(ETriggeringMechanismOn);
       
   173 		    LBTMGMTUIDEBUG("Before SetTriggeringSystemSettingsL"); 
       
   174 			iLbtMgr.SetTriggeringSystemSettingsL(iTriggerSettings,ETriggeringMechanismState); 
       
   175     	    LBTMGMTUIDEBUG("After SetTriggeringSystemSettingsL"); 
       
   176     		break;
       
   177     	case CLbtMgmtLbtAdapter::EOff:
       
   178     		iTriggerSettings.SetTriggeringMechanismState(ETriggeringMechanismOff);
       
   179 		    LBTMGMTUIDEBUG("Before SetTriggeringSystemSettingsL"); 
       
   180 			iLbtMgr.SetTriggeringSystemSettingsL(iTriggerSettings,ETriggeringMechanismState); 
       
   181     	    LBTMGMTUIDEBUG("After SetTriggeringSystemSettingsL"); 
       
   182     		break;
       
   183     	default :
       
   184     		break;
       
   185     	}	
       
   186     LBTMGMTUIDEBUG("- CLbtMgmtLbtAdapter::SetCurrentTriggeringStatusL()");	
       
   187    }
       
   188     
       
   189 // --------------------------------------------------------------------------
       
   190 // void CLbtMgmtLbtAdapter::RunL
       
   191 // Inherited from CActive
       
   192 //
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CLbtMgmtLbtAdapter::RunL()
       
   196     {
       
   197     LBTMGMTUIDEBUG("+ CLbtMgmtLbtAdapter::RunL() - Settings Changed");  
       
   198     // Issue Notification
       
   199     iObserver.HandleSettingsChangeL();
       
   200     
       
   201     // Schedule for listening to change events again
       
   202     StartNotification();
       
   203 
       
   204     LBTMGMTUIDEBUG("- CLbtMgmtLbtAdapter::RunL()");  
       
   205     }
       
   206 
       
   207 // --------------------------------------------------------------------------
       
   208 // void CLbtMgmtLbtAdapter::DoCancel
       
   209 // Inherited from CActive
       
   210 //
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CLbtMgmtLbtAdapter::DoCancel()
       
   214     {
       
   215     // Cancel the outstanding CR notification request
       
   216     iLbtMgr.CancelNotifyTriggeringSystemSettingChange();
       
   217     }
       
   218     
       
   219 // --------------------------------------------------------------------------
       
   220 // void CLbtMgmtLbtAdapter::StartNotification
       
   221 // Start notification from the Central repository server for any changes in the
       
   222 // Co-ordinate display format key value
       
   223 //
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CLbtMgmtLbtAdapter::StartNotification()
       
   227     {
       
   228     if( !IsActive())
       
   229         {
       
   230         iStatus = KRequestPending;
       
   231         // Request for notification        
       
   232         iLbtMgr.NotifyTriggeringSystemSettingChange(iTriggerSettings, iStatus);
       
   233         SetActive(); 
       
   234         }  
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // void CLbtMgmtPluginEngine::ShowInfoDialog
       
   239 // It will return total active triggers
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 TInt CLbtMgmtLbtAdapter::ActiveTriggers()
       
   243     {
       
   244     return iTotalActiveTriggers;
       
   245     }
       
   246 
       
   247 // --------------------------------------------------------------------------
       
   248 // TInt CLbtMgmtLbtAdapter::GetTotalActiveTriggersL()
       
   249 // Gets all active triggers from Location Triggering Server. 
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CLbtMgmtLbtAdapter::GetTotalActiveTriggersL()
       
   253     {
       
   254     LBTMGMTUIDEBUG("+ CLbtMgmtLbtAdapter::GetTotalActiveTriggersL()");  
       
   255     RArray<TLbtTriggerId> triggerList;
       
   256     
       
   257     //Construct list options
       
   258     //XXX: should use NewLC() when it is available
       
   259     CLbtListTriggerOptions* listOptions = CLbtListTriggerOptions::NewL();
       
   260     CleanupStack::PushL(listOptions);
       
   261         
       
   262     //Construct an attribute filter
       
   263     CLbtTriggerFilterByAttribute* attribFilter = CLbtTriggerFilterByAttribute::NewLC();
       
   264 
       
   265     //Add trigger state to the filter. List only enabled triggers.
       
   266     attribFilter->AddTriggerStateL( CLbtTriggerEntry::EStateEnabled );
       
   267     
       
   268     //Add trigger validity to the filter. List only valid triggers.
       
   269     attribFilter->AddTriggerValidityL( TLbtTriggerDynamicInfo::EValid );
       
   270     
       
   271     listOptions->SetFilter(attribFilter);
       
   272     
       
   273     //List triggers
       
   274 
       
   275    LBTMGMTUIDEBUG("Before ListTriggerIdsL");  
       
   276    TRAPD( err, iLbtMgr.ListTriggerIdsL(triggerList, listOptions ) );
       
   277    LBTMGMTUIDEBUG("After ListTriggerIdsL"); 
       
   278    
       
   279    if( err == KErrNone )
       
   280        {
       
   281        iTotalActiveTriggers = triggerList.Count();
       
   282        }
       
   283     
       
   284     //Cleanup   
       
   285     triggerList.Close();
       
   286     CleanupStack::PopAndDestroy(2);//attribFilter, listOptions
       
   287 
       
   288     LBTMGMTUIDEBUG("- CLbtMgmtLbtAdapter::GetTotalActiveTriggersL()");  
       
   289     }
       
   290 
       
   291 // --------------------------------------------------------------------------
       
   292 // TInt CLbtMgmtLbtAdapter::DeleteActiveTriggersL()
       
   293 // Deletes all active triggers from Location Triggering Server. 
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CLbtMgmtLbtAdapter::DeleteActiveTriggersL()
       
   297     {
       
   298     LBTMGMTUIDEBUG("+ CLbtMgmtLbtAdapter::DeleteActiveTriggersL()");  
       
   299     //Construct an attribute filter
       
   300     CLbtTriggerFilterByAttribute* attribFilter = CLbtTriggerFilterByAttribute::NewLC();
       
   301 
       
   302     //Add trigger state to the filter. List only enabled triggers.
       
   303     attribFilter->AddTriggerStateL( CLbtTriggerEntry::EStateEnabled );
       
   304     
       
   305     //Add trigger validity to the filter. List only valid triggers.
       
   306     attribFilter->AddTriggerValidityL( TLbtTriggerDynamicInfo::EValid );   
       
   307 
       
   308     LBTMGMTUIDEBUG("Before DeleteTriggersL"); 
       
   309     iLbtMgr.DeleteTriggersL( attribFilter );
       
   310     LBTMGMTUIDEBUG("After DeleteTriggersL"); 
       
   311     
       
   312     CleanupStack::PopAndDestroy( attribFilter );
       
   313     LBTMGMTUIDEBUG("- CLbtMgmtLbtAdapter::DeleteActiveTriggersL()");  
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CLbtMgmtLbtAdapter::TriggerChangedL()
       
   318 // Gets the notification on Change in Trigger.
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 void CLbtMgmtLbtAdapter::TriggerChangedL(
       
   322 							const TLbtTriggerChangeEvent &aEvent)
       
   323 	{
       
   324     LBTMGMTUIDEBUG("+ CLbtMgmtLbtAdapter::TriggerChangedL()"); 
       
   325 	switch( aEvent.iEventType )
       
   326 		{
       
   327 		case ELbtTriggerChangeEventMultiple:
       
   328 		case ELbtTriggerChangeEventDeleted:
       
   329 		case ELbtTriggerChangeEventCreated:
       
   330 		case ELbtTriggerChangeEventUpdated:
       
   331 			GetTotalActiveTriggersL();
       
   332 		    // Issue Notification
       
   333 		    iObserver.HandleSettingsChangeL();
       
   334 			break;
       
   335 		default:
       
   336 			break;
       
   337 		}
       
   338     LBTMGMTUIDEBUG("- CLbtMgmtLbtAdapter::TriggerChangedL()"); 
       
   339 	}
       
   340