locationtriggering/ltstrategyengine/src/lbtstrategyengine.cpp
changeset 0 667063e416a2
child 13 19bff11d6c18
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2006, 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:  Implementation Location Acquisition Strategy Engine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <commdb.h>
       
    20 #include "lbtlogger.h"
       
    21 #include "lbtstrategyengine.h"
       
    22 #include "lbtstrategyengineobserver.h"
       
    23 #include "lbtcellchangehandler.h"
       
    24 
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CLbtStrategyEngine::NewL
       
    30 // CLbtStrategyEngine instantiation method
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CLbtStrategyEngine* CLbtStrategyEngine::NewL( TAny* aConstructionParameters, 
       
    34                                           MLbtStrategyEngineObsrvr* aObserver )
       
    35     {
       
    36     FUNC_ENTER("CLbtStrategyEngine::NewL");
       
    37     
       
    38     CLbtStrategyEngine* self = new ( ELeave ) CLbtStrategyEngine();
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( aConstructionParameters, aObserver );
       
    41     CleanupStack::Pop();
       
    42     return self;
       
    43     
       
    44     }
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CLbtStrategyEngine::~CLbtStrategyEngine
       
    49 // Default destructor
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CLbtStrategyEngine::~CLbtStrategyEngine()
       
    53     {
       
    54     FUNC_ENTER("CLbtStrategyEngine::~CLbtStrategyEngine");
       
    55     
       
    56     // This is just done as a precautionary measure!
       
    57     StopSupervision();
       
    58     if( iView )
       
    59     	{
       
    60     	iView->RemContainerObserver();
       
    61     	}
       
    62     delete iView;
       
    63     
       
    64     iMPhone.Close();
       
    65     iTelServer.Close();
       
    66     
       
    67     
       
    68     delete iCoOrdinateSupervisor;
       
    69     delete iCellSupervisor;
       
    70     delete iCellChangeHandler;
       
    71     }	
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CLbtStrategyEngine::StartSupervision
       
    76 // 
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CLbtStrategyEngine::StartSupervision()
       
    80     {
       
    81     FUNC_ENTER("CLbtStrategyEngine::StartSupervision");
       
    82     
       
    83     if( iSupervisionInitiated && iViewInitialised )
       
    84         {
       
    85         iCoOrdinateSupervisor->StartSupervision();
       
    86         iCellSupervisor->StartSupervision();
       
    87         }
       
    88     iSupervisionInitiated = ETrue;
       
    89     }
       
    90 
       
    91     
       
    92 // -----------------------------------------------------------------------------
       
    93 // CLbtStrategyEngine::StopSupervision
       
    94 // 
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CLbtStrategyEngine::StopSupervision()
       
    98     {
       
    99     FUNC_ENTER("CLbtStrategyEngine::StopSupervision");
       
   100     
       
   101     iCellChangeHandler->Cancel();
       
   102     iCoOrdinateSupervisor->StopSupervision();
       
   103     iCellSupervisor->StopSupervision();
       
   104     }
       
   105     
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CLbtStrategyEngine::SettingsChanged
       
   109 // Handles notification of triggering settings change provided by server
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CLbtStrategyEngine::SettingsChanged()
       
   113     {
       
   114     FUNC_ENTER("CLbtStrategyEngine::SettingsChanged");
       
   115 
       
   116     iCoOrdinateSupervisor->SettingsChanged();
       
   117     iCellSupervisor->SettingsChanged();
       
   118     }
       
   119 
       
   120     
       
   121 // -----------------------------------------------------------------------------
       
   122 // CLbtStrategyEngine::OperationComplete
       
   123 // Handles notification from CLbtTriggerView when a refresh operation is  
       
   124 // completed
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CLbtStrategyEngine::OperationComplete( 
       
   128                             MLbtTriggerViewObserver::TOperation aOperation )
       
   129     {
       
   130     FUNC_ENTER("CLbtStrategyEngine::OperationComplete");
       
   131     if( MLbtTriggerViewObserver::EViewRefreshed == aOperation )
       
   132         {
       
   133         if( ( iChangedAreaType & 
       
   134               MLbtContainerChangeEventObserver::ETypeCircularTriggerChange ) || 
       
   135               ( iChangedAreaType & MLbtContainerChangeEventObserver::ETypeAll ) )
       
   136             {
       
   137             if( iView->CoordTriggerCount() )
       
   138                 {
       
   139                 iCoOrdinateSupervisor->Resume();
       
   140                 }
       
   141             else
       
   142                 {
       
   143                 iCoOrdinateSupervisor->Reset();
       
   144                 }
       
   145             }
       
   146             
       
   147         if( ( iChangedAreaType & 
       
   148               MLbtContainerChangeEventObserver::ETypeCellularTriggerChange ) ||
       
   149               ( iChangedAreaType & MLbtContainerChangeEventObserver::ETypeAll ) )
       
   150             {
       
   151             if( iView->CellTriggerCount() )
       
   152                 {
       
   153                 iCellSupervisor->Resume();
       
   154                 }
       
   155             else
       
   156                 {
       
   157                 iCellSupervisor->Reset();   // TODO: Check if this needed
       
   158                 }
       
   159             }
       
   160             
       
   161         iChangedAreaType = MLbtContainerChangeEventObserver::ETypeUnKnown;   
       
   162         }
       
   163         
       
   164     else if( MLbtTriggerViewObserver::EViewInitialized == aOperation )
       
   165         {
       
   166         iViewInitialised = ETrue;
       
   167         if( iSupervisionInitiated )
       
   168             {
       
   169             if( iView->CellTriggerCount() )
       
   170                 {
       
   171                 iCellSupervisor->StartSupervision();
       
   172                 }
       
   173             if( iView->CoordTriggerCount() )
       
   174                 {
       
   175                 iCoOrdinateSupervisor->StartSupervision();
       
   176                 }
       
   177             }
       
   178         }
       
   179         
       
   180     else
       
   181         {
       
   182         // TODO: Panic probably!
       
   183         }    
       
   184     }
       
   185 
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CLbtStrategyEngine::TriggerStoreChanged
       
   189 // Handles notification from Location Triggering Container for trigger 
       
   190 // creation / modification events
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CLbtStrategyEngine::TriggerStoreChanged( RArray<TLbtTriggerId>& aTriggerIds,
       
   194 		                                      TLbtTriggerEventMask aEventMask,
       
   195 		                                      TLbtContainerChangedAreaType aAreaType,
       
   196 		                                      RArray<TUid>& /*aManagerUids*/ )
       
   197 	{
       
   198 	FUNC_ENTER("CLbtStrategyEngine::TriggerStoreChanged");
       
   199     if( aAreaType & MLbtContainerChangeEventObserver::ETypeCircularTriggerChange )
       
   200         {
       
   201         iChangedAreaType = aAreaType;
       
   202         iCoOrdinateSupervisor->Suspend();
       
   203         }
       
   204         
       
   205     else if( aAreaType & MLbtContainerChangeEventObserver::ETypeCellularTriggerChange )
       
   206         {
       
   207         iChangedAreaType = aAreaType;
       
   208         iCellSupervisor->StopSupervision();
       
   209         }
       
   210         
       
   211     else if( aAreaType & MLbtContainerChangeEventObserver::ETypeAll )
       
   212         {
       
   213         iChangedAreaType = aAreaType;
       
   214         iCoOrdinateSupervisor->Suspend();
       
   215         iCellSupervisor->StopSupervision();
       
   216         }
       
   217     
       
   218     // Todo: Remove the dummy positionInfo
       
   219     TPositionInfo dummy;
       
   220     iView->Refresh( dummy, aEventMask, aTriggerIds );
       
   221     }
       
   222 
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CLbtStrategyEngine::CLbtStrategyEngine
       
   226 // C++ default constructor.
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 CLbtStrategyEngine::CLbtStrategyEngine()
       
   230     {
       
   231     
       
   232     }
       
   233 
       
   234     
       
   235 // -----------------------------------------------------------------------------
       
   236 // CLbtStrategyEngine::ConstructL
       
   237 // Symbian 2nd phase constructor.
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 void CLbtStrategyEngine::ConstructL( TAny* aConstructionParameters,
       
   241                                         MLbtStrategyEngineObsrvr* aObserver )
       
   242     {	
       
   243     FUNC_ENTER("CLbtStrategyEngine::ConstructL");
       
   244 	iView = CLbtTriggerView::NewL( this );
       
   245 	iView->SetTriggerStatusObserver( aObserver );
       
   246 	iView->SetContainerObserver( this );
       
   247 	
       
   248 	InitialiseEtelL();
       
   249 	iCellChangeHandler = CLbtCellChangeHandler::NewL( iMPhone );
       
   250 	
       
   251 	iCoOrdinateSupervisor = CLbtCoOrdinateSupervisor::NewL( aConstructionParameters,iView,aObserver,iCellChangeHandler );
       
   252 	
       
   253 	iCellSupervisor = CLbtCellSupervisor::NewL(  aConstructionParameters,iView,aObserver,iCellChangeHandler );
       
   254 	
       
   255 	iViewInitialised = EFalse;
       
   256     iSupervisionInitiated = EFalse;
       
   257 	}	
       
   258 
       
   259 
       
   260 // ----------------------------------------------------------------------------
       
   261 // CLbtStrategyEngine::InitialiseEtelL
       
   262 // ----------------------------------------------------------------------------
       
   263 //
       
   264 void CLbtStrategyEngine::InitialiseEtelL()
       
   265     {
       
   266     FUNC_ENTER("CLbtCellSupervisor::InitialiseEtelL");
       
   267     CCommsDatabase* const db = CCommsDatabase::NewL(ETrue); 
       
   268 	CleanupStack::PushL(db); 
       
   269 
       
   270 	TUint32 modemId = 0; 
       
   271 	db->GetGlobalSettingL(TPtrC(MODEM_PHONE_SERVICES_SMS), modemId); 
       
   272 	CCommsDbTableView* const view =
       
   273 	    db->OpenViewMatchingUintLC(TPtrC(MODEM), TPtrC(COMMDB_ID), modemId); 
       
   274 
       
   275 	TInt err = view->GotoFirstRecord();
       
   276 	if(err != KErrNone)
       
   277 	    {
       
   278 	    User::Leave(err);
       
   279 	    }
       
   280 
       
   281     HBufC* nameBuf = NULL;
       
   282     nameBuf = view->ReadLongTextLC(TPtrC(MODEM_TSY_NAME));
       
   283 
       
   284     User::LeaveIfError(iTelServer.Connect());
       
   285 	err = iTelServer.LoadPhoneModule(*nameBuf);
       
   286 	
       
   287 	if(err != KErrNone)
       
   288 	    {
       
   289 	    User::Leave(err);
       
   290 	    }
       
   291 		    
       
   292 	// For the phone information
       
   293 	RTelServer::TPhoneInfo info;
       
   294 
       
   295 	iTelServer.GetPhoneInfo(0, info); 
       
   296 	err = iMPhone.Open(iTelServer, info.iName);
       
   297 
       
   298 	if(err != KErrNone)
       
   299 	    {
       
   300 	    User::Leave(err);
       
   301 	    }
       
   302 
       
   303     CleanupStack::PopAndDestroy(3); // nameBuf, view and db 
       
   304 	}