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