locationtriggering/ltstrategyengine/src/lbtcellchangehandler.cpp
changeset 0 667063e416a2
child 20 2b4ea9893b66
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/locationtriggering/ltstrategyengine/src/lbtcellchangehandler.cpp	Tue Feb 02 01:06:48 2010 +0200
@@ -0,0 +1,172 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Class definition of cell change handler.
+*
+*/
+
+
+#include "lbtcellchangehandler.h"
+#include "lbtlogger.h"
+
+// ======== MEMBER FUNCTIONS ========
+
+// --------------------------------------------------------------------------
+// CLbtCellChangeHandler::NewL
+// CLbtCellChangeHandler instantiation method
+// --------------------------------------------------------------------------
+//
+CLbtCellChangeHandler* CLbtCellChangeHandler::NewL(RMobilePhone& aMPhone)
+    {
+    FUNC_ENTER("CLbtCellChangeHandler::NewL");
+    CLbtCellChangeHandler* self = new (ELeave) CLbtCellChangeHandler(aMPhone);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop();
+    return self;
+    }
+
+// -----------------------------------------------------------------------------
+// CLbtCellChangeHandler::CLbtCellChangeHandler
+// 
+// -----------------------------------------------------------------------------
+//
+CLbtCellChangeHandler::CLbtCellChangeHandler(RMobilePhone& aMPhone):
+    CActive(EPriorityStandard), iMPhone(aMPhone),
+    iCommandId(-1), iNwInfo(), iNwInfoPckg(iNwInfo), iLocArea()
+    {
+    CActiveScheduler::Add(this);
+    }
+
+// -----------------------------------------------------------------------------
+// CLbtCellChangeHandler::~CLbtCellChangeHandler
+// 
+// -----------------------------------------------------------------------------
+//
+CLbtCellChangeHandler::~CLbtCellChangeHandler()
+    {
+    FUNC_ENTER("CLbtCellChangeHandler::~CLbtCellChangeHandler");
+    if (IsActive())
+        {
+        Cancel();
+        }
+    iObserverArray.Close();
+    }
+
+
+// -----------------------------------------------------------------------------
+// CLbtCellChangeHandler::ConstructL
+// 
+// -----------------------------------------------------------------------------
+//
+void CLbtCellChangeHandler::ConstructL()
+    {
+   
+    }
+        
+
+// -----------------------------------------------------------------------------
+// CLbtCellChangeHandler::RunL
+// 
+// -----------------------------------------------------------------------------
+//
+void CLbtCellChangeHandler::RunL()
+    {
+    FUNC_ENTER("CLbtCellChangeHandler::RunL");
+    if( iStatus.Int() == KErrNone )
+        {
+        for( TInt i=0;i<iObserverArray.Count();i++ )
+            {
+            iObserverArray[i]->HandleCellChangeEvent( KErrNone, iNwInfo, iLocArea );
+            }
+        }
+    iLastStatusInfo = iStatus.Int();
+    
+    if( !IsActive() )
+        {
+        iMPhone.NotifyCurrentNetworkChange( iStatus, iNwInfoPckg, iLocArea );
+	    SetActive();
+	    iCommandId = EMobilePhoneNotifyCurrentNetworkChange;   
+        }
+	}
+
+// -----------------------------------------------------------------------------
+// CLbtCellChangeHandler::DoCancel
+// 
+// -----------------------------------------------------------------------------
+//
+void CLbtCellChangeHandler::DoCancel()
+    {
+    FUNC_ENTER("CLbtCellChangeHandler::DoCancel");
+    iMPhone.CancelAsyncRequest( iCommandId );
+    }
+
+// -----------------------------------------------------------------------------
+// CLbtCellChangeHandler::GetNetworkInfo
+// 
+// -----------------------------------------------------------------------------
+//
+void CLbtCellChangeHandler::GetNetworkInfo()
+    {
+    FUNC_ENTER("CLbtCellChangeHandler::GetNetworkInfo");
+    if(!IsActive())
+        {
+        iMPhone.GetCurrentNetwork( iStatus,iNwInfoPckg,iLocArea );
+        SetActive();
+        iCommandId = EMobilePhoneGetCurrentNetwork;
+        }
+    }
+
+// -----------------------------------------------------------------------------
+// CLbtCellChangeHandler::SetObserver
+// 
+// -----------------------------------------------------------------------------
+//
+void CLbtCellChangeHandler::SetObserver( MCellChangeObserver* aObserver )
+    {
+    FUNC_ENTER("CLbtCellChangeHandler::SetObserver");
+    iObserverArray.Append( aObserver );
+    // If cell change handler already has cell information,update it to the observer
+    if( iLocArea.iCellId && iLastStatusInfo == KErrNone )
+        {
+        aObserver->HandleCellChangeEvent( iLastStatusInfo ,iNwInfo, iLocArea );
+        }
+    if( !IsActive() )
+        {
+        GetNetworkInfo();
+        }
+    }
+
+// -----------------------------------------------------------------------------
+// CLbtCellChangeHandler::Remove
+// 
+// -----------------------------------------------------------------------------
+//
+void CLbtCellChangeHandler::Remove( MCellChangeObserver* aObserver )
+	{
+	FUNC_ENTER("CLbtCellChangeHandler::Remove");
+	if( iObserverArray.Count() )
+	    {
+	    TInt position = iObserverArray.Find( aObserver );	
+    	if( position != KErrNotFound )
+    		{
+        	iObserverArray.Remove( position );
+        	if( !iObserverArray.Count() )
+        	    {
+        	    Cancel();
+        		}
+    	    }
+	    }
+	}	
+// End of File
+