locationtriggering/ltclientlib/src/lbtcelloperation.cpp
changeset 0 667063e416a2
child 20 2b4ea9893b66
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Class definition of Cell data handler 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <commdb.h>
       
    20 #include <etel.h>
       
    21 #include "lbtcelloperation.h"
       
    22 #include "lbtgeogsmcell.h"
       
    23 #include "lbtgeowcdmacell.h"
       
    24 #include "lbtlogger.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CLbtCellOperation::NewL
       
    28 // 
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CLbtCellOperation* CLbtCellOperation::NewL( TRequestStatus& aStatus, CLbtGeoAreaBase ** aArea )
       
    32     {
       
    33     CLbtCellOperation* self = new (ELeave) CLbtCellOperation(aStatus, aArea);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL( );
       
    36     CleanupStack::Pop();    
       
    37     return self;
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CLbtCellOperation::CLbtCellOperation
       
    42 // 
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CLbtCellOperation::CLbtCellOperation(TRequestStatus& aStatus, CLbtGeoAreaBase ** aArea):iCommandId(-1),
       
    46 																						      iNwInfo(),
       
    47                                             												  iNwInfoPckg(iNwInfo), 
       
    48                                             												  iLocArea(),iCellInfo(), 
       
    49                                             												  iCellPckg(iCellInfo),
       
    50                                             												  iClientStatus(aStatus),
       
    51 												                                              iArea(aArea)
       
    52     {
       
    53     CActiveScheduler::Add( this );
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CLbtCellOperation::~CLbtCellOperation
       
    58 // 
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CLbtCellOperation::~CLbtCellOperation()
       
    62     {
       
    63     iMmApi.Close();
       
    64     iMPhone.Close();
       
    65     iTelServer.Close();    
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CLbtCellOperation::ConstructL
       
    70 // 
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CLbtCellOperation::ConstructL(  )
       
    74     {    
       
    75     InitialiseEtelL();
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CLbtCellOperation::Cancel
       
    80 // 
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CLbtCellOperation::DoCancel()
       
    84     {
       
    85     if( iCommandId == EMobilePhoneGetCurrentNetwork )
       
    86         {
       
    87         iMPhone.CancelAsyncRequest( iCommandId );
       
    88         }
       
    89     else if( iCommandId == ECustomGetCellInfoIPC )
       
    90         {
       
    91         iMmApi.CancelAsyncRequest( iCommandId );
       
    92         }
       
    93     }
       
    94     
       
    95 // -----------------------------------------------------------------------------
       
    96 // CLbtCellOperation::RunL
       
    97 // 
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CLbtCellOperation::RunL()
       
   101     {
       
   102     LBT_TRACE( KLbtLogClientLib|KLbtLogVerbose, __FILE__, __LINE__, "CLbtCellOperation::RunL", iStatus.Int() );
       
   103     if( iStatus.Int() == KErrNone )
       
   104         {
       
   105         if( iCommandId == EMobilePhoneGetCurrentNetwork )
       
   106             {
       
   107             LBT_TRACE( KLbtLogClientLib|KLbtLogVerbose, __FILE__, __LINE__, "First RunL");
       
   108             iMmApi.GetCellInfo(iStatus, iCellPckg);
       
   109             iCommandId = ECustomGetCellInfoIPC;
       
   110             SetActive();
       
   111             return; // TODO: Test code remove it
       
   112             }
       
   113         else
       
   114             {
       
   115             LBT_TRACE( KLbtLogClientLib|KLbtLogVerbose, __FILE__, __LINE__, "Second time RunL");
       
   116             CLbtGeoCell* geoCell = NULL;
       
   117                         
       
   118             if(iCellInfo.iMode == RMmCustomAPI::TMmCellInfo::EGSM)
       
   119             	{
       
   120             	geoCell = CLbtGeoGsmCell::NewL();
       
   121             	}
       
   122             else
       
   123             	{
       
   124             	geoCell = CLbtGeoWcdmaCell::NewL();
       
   125             	}
       
   126             geoCell->SetNetworkType( iNetworkMode );
       
   127             geoCell->SetNetworkCountryCode( iNwInfo.iCountryCode );
       
   128             geoCell->SetNetworkIdentityCode( iNwInfo.iNetworkId );
       
   129             geoCell->SetLocationAreaCode( iLocArea.iLocationAreaCode );
       
   130             geoCell->SetCellId( iLocArea.iCellId );
       
   131             
       
   132             if( iNetworkMode == RMobilePhone::ENetworkModeGsm )
       
   133             	{
       
   134                 CLbtGeoGsmCell* gsmCell = static_cast<CLbtGeoGsmCell*>(geoCell);
       
   135                 RArray<TInt> bsicArray;                
       
   136                 for( TInt i=0;i<15;i++ ) // 15 is  max available Nmr value
       
   137                     {
       
   138                     if( iCellInfo.iGsmCellInfo.iNmr[i].iBSIC != -1 )
       
   139                         {
       
   140                         bsicArray.Append( iCellInfo.iGsmCellInfo.iNmr[i].iBSIC );
       
   141                         }
       
   142                     }                
       
   143                 gsmCell->SetBsic( bsicArray );
       
   144                 geoCell = gsmCell;
       
   145             	}
       
   146             else if( iNetworkMode == RMobilePhone::ENetworkModeWcdma )
       
   147             	{
       
   148             	LBT_TRACE( KLbtLogClientLib|KLbtLogVerbose, __FILE__, __LINE__, "WCDMA Network");
       
   149             	// Create WCDMA cell
       
   150             	CLbtGeoWcdmaCell* wcdmaCell = static_cast<CLbtGeoWcdmaCell*>(geoCell);
       
   151             	
       
   152             	TLbtWcdmaCellInfo wcdmaCellInfo;
       
   153             	
       
   154             	// Copy the serving cell parameters
       
   155             	wcdmaCellInfo.iCell.iCarrierRssi = iCellInfo.iWcdmaCellInfo.iNwkMeasureReport[0].iCarrierRSSI;
       
   156             	wcdmaCellInfo.iCell.iRscp = iCellInfo.iWcdmaCellInfo.iNwkMeasureReport[0].iCellMeasuredResult[0].iFddInfo.iCpichRscp;
       
   157             	wcdmaCellInfo.iCell.iEcNo = iCellInfo.iWcdmaCellInfo.iNwkMeasureReport[0].iCellMeasuredResult[0].iFddInfo.iCpichEcN0;
       
   158             	wcdmaCellInfo.iCell.iPathLoss = iCellInfo.iWcdmaCellInfo.iNwkMeasureReport[0].iCellMeasuredResult[0].iFddInfo.iPathloss;
       
   159             	
       
   160             	// Copy the Rscp and Ecno values of the adjacent cells
       
   161             	for(TInt i=1;i<KMaxNetworkMeasureReports;++i)
       
   162             		{
       
   163             		for(TInt j=0;j<KMaxCellMeasuredResults;++j)
       
   164             			{
       
   165             			TInt8 rscp = iCellInfo.iWcdmaCellInfo.iNwkMeasureReport[i].iCellMeasuredResult[j].iFddInfo.iCpichRscp;
       
   166             			TInt8 ecNo = iCellInfo.iWcdmaCellInfo.iNwkMeasureReport[i].iCellMeasuredResult[j].iFddInfo.iCpichEcN0;
       
   167             			if( (rscp != -1) && (ecNo != -1) )
       
   168             				{
       
   169             				TLbtWcdmaCellInfo::TLbtCellMeasuredResult cellMsr;
       
   170             				cellMsr.iEcNo = ecNo;
       
   171             				cellMsr.iRscp = rscp;
       
   172             				wcdmaCellInfo.iMeasurementResult.Append(cellMsr);
       
   173             				}
       
   174             			}
       
   175             		}
       
   176             	wcdmaCell->SetWcdmaCellInfo(wcdmaCellInfo);
       
   177             	geoCell = wcdmaCell;
       
   178             	}
       
   179             *(iArea) = geoCell;
       
   180             TRequestStatus* status = &iClientStatus;
       
   181             User::RequestComplete( status, iStatus.Int() );
       
   182             }   
       
   183         }
       
   184     else
       
   185         {
       
   186         /*
       
   187         // -------------------------------------------------------------------------------------------------------
       
   188         // ----------- TEST CODE ----------------------------
       
   189         CLbtGeoCell* geoCell = NULL;
       
   190         CLbtGeoWcdmaCell* wcdmaCell = CLbtGeoWcdmaCell::NewL();
       
   191         wcdmaCell->SetNetworkType( RMobilePhone::ENetworkModeWcdma );
       
   192         RMobilePhone::TMobilePhoneNetworkCountryCode countryCode(_L("5"));
       
   193         wcdmaCell->SetNetworkCountryCode( countryCode );
       
   194         RMobilePhone::TMobilePhoneNetworkIdentity nid(_L("5"));
       
   195         wcdmaCell->SetNetworkIdentityCode( nid );
       
   196         wcdmaCell->SetLocationAreaCode( 5 );
       
   197         wcdmaCell->SetCellId( 5 );
       
   198         TLbtWcdmaCellInfo wcdmaCellInfo;
       
   199         	
       
   200     	// Copy the serving cell parameters
       
   201     	wcdmaCellInfo.iCell.iCarrierRssi = 5;
       
   202     	wcdmaCellInfo.iCell.iRscp = 5;
       
   203     	wcdmaCellInfo.iCell.iEcNo = 5;
       
   204     	wcdmaCellInfo.iCell.iPathLoss = 5;
       
   205     	
       
   206     	// Copy the Rscp and Ecno values of the adjacent cells
       
   207     	for(TInt i=0;i<1;++i)
       
   208     		{
       
   209     		for(TInt j=0;j<5;++j)
       
   210     			{
       
   211     			TInt8 rscp = 5;
       
   212     			TInt8 ecNo = 5;
       
   213     			if( (rscp != -1) && (ecNo != -1) )
       
   214     				{
       
   215     				TLbtWcdmaCellInfo::TLbtCellMeasuredResult cellMsr;
       
   216     				cellMsr.iEcNo = 5;
       
   217     				cellMsr.iRscp = 5;
       
   218     				wcdmaCellInfo.iMeasurementResult.Append(cellMsr);
       
   219     				}
       
   220     			}
       
   221     		}
       
   222     	wcdmaCell->SetWcdmaCellInfo(wcdmaCellInfo);
       
   223     	geoCell = wcdmaCell;
       
   224     	*(iArea) = geoCell;
       
   225         // ----------- TEST CODE END----------------------------
       
   226         // -------------------------------------------------------------------------------------------------------
       
   227         */
       
   228         TRequestStatus* status = &iClientStatus;
       
   229         User::RequestComplete( status, iStatus.Int() );        
       
   230         }    
       
   231     }    
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CLbtCellOperation::GetCurrentCellInformation
       
   235 // 
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 void CLbtCellOperation::GetCurrentCellInformation( )
       
   239     {
       
   240     iClientStatus = KRequestPending;
       
   241     TInt error = iMPhone.GetCurrentMode( iNetworkMode );
       
   242     if( KErrNone != error )
       
   243         {
       
   244         TRequestStatus* status = &iClientStatus;
       
   245         User::RequestComplete( status, error );        
       
   246         return;  
       
   247         }
       
   248     iMPhone.GetCurrentNetwork(iStatus, iNwInfoPckg, iLocArea);
       
   249     iCommandId = EMobilePhoneGetCurrentNetwork;
       
   250     SetActive();
       
   251     }
       
   252     
       
   253 // -----------------------------------------------------------------------------
       
   254 // CLbtCellOperation::InitialiseEtelL
       
   255 // 
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CLbtCellOperation::InitialiseEtelL()
       
   259     {
       
   260 	CCommsDatabase* const db = CCommsDatabase::NewL(ETrue); 
       
   261 	CleanupStack::PushL(db); 
       
   262 
       
   263 	TUint32 modemId = 0; 
       
   264 	db->GetGlobalSettingL(TPtrC(MODEM_PHONE_SERVICES_SMS), modemId); 
       
   265 	CCommsDbTableView* const view =
       
   266 	    db->OpenViewMatchingUintLC(TPtrC(MODEM), TPtrC(COMMDB_ID), modemId); 
       
   267 
       
   268 	TInt err = view->GotoFirstRecord();
       
   269 	if(err != KErrNone)
       
   270 	    {
       
   271         User::Leave(err);
       
   272 	    }
       
   273 
       
   274     HBufC* nameBuf = NULL;
       
   275     nameBuf = view->ReadLongTextLC(TPtrC(MODEM_TSY_NAME));
       
   276 
       
   277     User::LeaveIfError(iTelServer.Connect());
       
   278 	err = iTelServer.LoadPhoneModule(*nameBuf);
       
   279 	
       
   280 	if(err != KErrNone)
       
   281 	      {
       
   282         User::Leave(err);
       
   283 	    }
       
   284 		
       
   285 	// For the phone information
       
   286 	RTelServer::TPhoneInfo info;
       
   287 
       
   288 	iTelServer.GetPhoneInfo(0, info); 
       
   289 	err = iMPhone.Open(iTelServer, info.iName);
       
   290 	
       
   291 	if(err != KErrNone)
       
   292 	    {
       
   293         User::Leave(err);
       
   294 	    }
       
   295 	    
       
   296 	// initialise etel multimode custom api
       
   297     err = iMmApi.Open(iMPhone);
       
   298 
       
   299 	if(err != KErrNone)
       
   300 	    {
       
   301         User::Leave(err);
       
   302 	    }    
       
   303 
       
   304   	CleanupStack::PopAndDestroy(3); // nameBuf, view and db 
       
   305     }    
       
   306     
       
   307 
       
   308 // End of File
       
   309