locationtriggering/ltstrategyengine/src/lbtcellchangehandler.cpp
author hgs
Wed, 03 Nov 2010 23:28:39 +0530
changeset 56 4e949f03ecc5
child 39 3efc7a0e8755
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) 2008 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:  Class definition of cell change handler.
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 "lbtcellchangehandler.h"
hgs
parents:
diff changeset
    20
#include "lbtlogger.h"
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    25
// CLbtCellChangeHandler::NewL
hgs
parents:
diff changeset
    26
// CLbtCellChangeHandler instantiation method
hgs
parents:
diff changeset
    27
// --------------------------------------------------------------------------
hgs
parents:
diff changeset
    28
//
hgs
parents:
diff changeset
    29
CLbtCellChangeHandler* CLbtCellChangeHandler::NewL(RMobilePhone& aMPhone)
hgs
parents:
diff changeset
    30
    {
hgs
parents:
diff changeset
    31
    FUNC_ENTER("CLbtCellChangeHandler::NewL");
hgs
parents:
diff changeset
    32
    CLbtCellChangeHandler* self = new (ELeave) CLbtCellChangeHandler(aMPhone);
hgs
parents:
diff changeset
    33
    CleanupStack::PushL(self);
hgs
parents:
diff changeset
    34
    self->ConstructL();
hgs
parents:
diff changeset
    35
    CleanupStack::Pop();
hgs
parents:
diff changeset
    36
    return self;
hgs
parents:
diff changeset
    37
    }
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    40
// CLbtCellChangeHandler::CLbtCellChangeHandler
hgs
parents:
diff changeset
    41
// 
hgs
parents:
diff changeset
    42
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    43
//
hgs
parents:
diff changeset
    44
CLbtCellChangeHandler::CLbtCellChangeHandler(RMobilePhone& aMPhone):
hgs
parents:
diff changeset
    45
    CActive(EPriorityStandard), iMPhone(aMPhone),
hgs
parents:
diff changeset
    46
    iCommandId(-1), iNwInfo(), iNwInfoPckg(iNwInfo), iLocArea()
hgs
parents:
diff changeset
    47
    {
hgs
parents:
diff changeset
    48
    CActiveScheduler::Add(this);
hgs
parents:
diff changeset
    49
    }
hgs
parents:
diff changeset
    50
hgs
parents:
diff changeset
    51
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    52
// CLbtCellChangeHandler::~CLbtCellChangeHandler
hgs
parents:
diff changeset
    53
// 
hgs
parents:
diff changeset
    54
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    55
//
hgs
parents:
diff changeset
    56
CLbtCellChangeHandler::~CLbtCellChangeHandler()
hgs
parents:
diff changeset
    57
    {
hgs
parents:
diff changeset
    58
    FUNC_ENTER("CLbtCellChangeHandler::~CLbtCellChangeHandler");
hgs
parents:
diff changeset
    59
    if (IsActive())
hgs
parents:
diff changeset
    60
        {
hgs
parents:
diff changeset
    61
        Cancel();
hgs
parents:
diff changeset
    62
        }
hgs
parents:
diff changeset
    63
    iObserverArray.Close();
hgs
parents:
diff changeset
    64
    }
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    68
// CLbtCellChangeHandler::ConstructL
hgs
parents:
diff changeset
    69
// 
hgs
parents:
diff changeset
    70
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    71
//
hgs
parents:
diff changeset
    72
void CLbtCellChangeHandler::ConstructL()
hgs
parents:
diff changeset
    73
    {
hgs
parents:
diff changeset
    74
   
hgs
parents:
diff changeset
    75
    }
hgs
parents:
diff changeset
    76
        
hgs
parents:
diff changeset
    77
hgs
parents:
diff changeset
    78
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    79
// CLbtCellChangeHandler::RunL
hgs
parents:
diff changeset
    80
// 
hgs
parents:
diff changeset
    81
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    82
//
hgs
parents:
diff changeset
    83
void CLbtCellChangeHandler::RunL()
hgs
parents:
diff changeset
    84
    {
hgs
parents:
diff changeset
    85
    FUNC_ENTER("CLbtCellChangeHandler::RunL");
hgs
parents:
diff changeset
    86
    if( iStatus.Int() == KErrNone )
hgs
parents:
diff changeset
    87
        {
hgs
parents:
diff changeset
    88
        for( TInt i=0;i<iObserverArray.Count();i++ )
hgs
parents:
diff changeset
    89
            {
hgs
parents:
diff changeset
    90
            iObserverArray[i]->HandleCellChangeEvent( KErrNone, iNwInfo, iLocArea );
hgs
parents:
diff changeset
    91
            }
hgs
parents:
diff changeset
    92
        }
hgs
parents:
diff changeset
    93
    iLastStatusInfo = iStatus.Int();
hgs
parents:
diff changeset
    94
    
hgs
parents:
diff changeset
    95
    if( !IsActive() )
hgs
parents:
diff changeset
    96
        {
hgs
parents:
diff changeset
    97
        iMPhone.NotifyCurrentNetworkChange( iStatus, iNwInfoPckg, iLocArea );
hgs
parents:
diff changeset
    98
	    SetActive();
hgs
parents:
diff changeset
    99
	    iCommandId = EMobilePhoneNotifyCurrentNetworkChange;   
hgs
parents:
diff changeset
   100
        }
hgs
parents:
diff changeset
   101
	}
hgs
parents:
diff changeset
   102
hgs
parents:
diff changeset
   103
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   104
// CLbtCellChangeHandler::DoCancel
hgs
parents:
diff changeset
   105
// 
hgs
parents:
diff changeset
   106
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   107
//
hgs
parents:
diff changeset
   108
void CLbtCellChangeHandler::DoCancel()
hgs
parents:
diff changeset
   109
    {
hgs
parents:
diff changeset
   110
    FUNC_ENTER("CLbtCellChangeHandler::DoCancel");
hgs
parents:
diff changeset
   111
    iMPhone.CancelAsyncRequest( iCommandId );
hgs
parents:
diff changeset
   112
    }
hgs
parents:
diff changeset
   113
hgs
parents:
diff changeset
   114
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   115
// CLbtCellChangeHandler::GetNetworkInfo
hgs
parents:
diff changeset
   116
// 
hgs
parents:
diff changeset
   117
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   118
//
hgs
parents:
diff changeset
   119
void CLbtCellChangeHandler::GetNetworkInfo()
hgs
parents:
diff changeset
   120
    {
hgs
parents:
diff changeset
   121
    FUNC_ENTER("CLbtCellChangeHandler::GetNetworkInfo");
hgs
parents:
diff changeset
   122
    if(!IsActive())
hgs
parents:
diff changeset
   123
        {
hgs
parents:
diff changeset
   124
        iMPhone.GetCurrentNetwork( iStatus,iNwInfoPckg,iLocArea );
hgs
parents:
diff changeset
   125
        SetActive();
hgs
parents:
diff changeset
   126
        iCommandId = EMobilePhoneGetCurrentNetwork;
hgs
parents:
diff changeset
   127
        }
hgs
parents:
diff changeset
   128
    }
hgs
parents:
diff changeset
   129
hgs
parents:
diff changeset
   130
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   131
// CLbtCellChangeHandler::SetObserver
hgs
parents:
diff changeset
   132
// 
hgs
parents:
diff changeset
   133
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   134
//
hgs
parents:
diff changeset
   135
void CLbtCellChangeHandler::SetObserver( MCellChangeObserver* aObserver )
hgs
parents:
diff changeset
   136
    {
hgs
parents:
diff changeset
   137
    FUNC_ENTER("CLbtCellChangeHandler::SetObserver");
hgs
parents:
diff changeset
   138
    iObserverArray.Append( aObserver );
hgs
parents:
diff changeset
   139
    // If cell change handler already has cell information,update it to the observer
hgs
parents:
diff changeset
   140
    if( iLocArea.iCellId && iLastStatusInfo == KErrNone )
hgs
parents:
diff changeset
   141
        {
hgs
parents:
diff changeset
   142
        aObserver->HandleCellChangeEvent( iLastStatusInfo ,iNwInfo, iLocArea );
hgs
parents:
diff changeset
   143
        }
hgs
parents:
diff changeset
   144
    if( !IsActive() )
hgs
parents:
diff changeset
   145
        {
hgs
parents:
diff changeset
   146
        GetNetworkInfo();
hgs
parents:
diff changeset
   147
        }
hgs
parents:
diff changeset
   148
    }
hgs
parents:
diff changeset
   149
hgs
parents:
diff changeset
   150
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   151
// CLbtCellChangeHandler::Remove
hgs
parents:
diff changeset
   152
// 
hgs
parents:
diff changeset
   153
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   154
//
hgs
parents:
diff changeset
   155
void CLbtCellChangeHandler::Remove( MCellChangeObserver* aObserver )
hgs
parents:
diff changeset
   156
	{
hgs
parents:
diff changeset
   157
	FUNC_ENTER("CLbtCellChangeHandler::Remove");
hgs
parents:
diff changeset
   158
	if( iObserverArray.Count() )
hgs
parents:
diff changeset
   159
	    {
hgs
parents:
diff changeset
   160
	    TInt position = iObserverArray.Find( aObserver );	
hgs
parents:
diff changeset
   161
    	if( position != KErrNotFound )
hgs
parents:
diff changeset
   162
    		{
hgs
parents:
diff changeset
   163
        	iObserverArray.Remove( position );
hgs
parents:
diff changeset
   164
        	if( !iObserverArray.Count() )
hgs
parents:
diff changeset
   165
        	    {
hgs
parents:
diff changeset
   166
        	    Cancel();
hgs
parents:
diff changeset
   167
        		}
hgs
parents:
diff changeset
   168
    	    }
hgs
parents:
diff changeset
   169
	    }
hgs
parents:
diff changeset
   170
	}	
hgs
parents:
diff changeset
   171
// End of File
hgs
parents:
diff changeset
   172