datasourcemodules/locationapesuplpsy/src/suplpsycellidhandler.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     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:  Cell Id implementaion in SUPL PSY.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <centralrepository.h> 
       
    22 #include <commdb.h>
       
    23 
       
    24 #include "suplpsylogging.h"
       
    25 #include "suplpsycellidhandler.h"
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS OF CSuplPsyCellIdHandler ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CSuplPsyCellIdHandler::CSuplPsyCellIdHandler,constuctor
       
    32 // (other items were commented in a header).
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 
       
    36 CSuplPsyCellIdHandler::CSuplPsyCellIdHandler( MBasicCellIDListener& aObserver ) 
       
    37 					    : CActive( EPriorityStandard ),
       
    38 					      iNetworkInfoPkg( iNetworkInfo ),
       
    39 					      iObserver( aObserver ),
       
    40 					      iNetworkType( EUnknown ),
       
    41 					      iCellIdInfo( NULL )
       
    42 	{
       
    43 	CActiveScheduler::Add( this );            
       
    44 	}
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CSuplPsyCellIdHandler::ConstructL,two phase constuctor
       
    48 // (other items were commented in a header).
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CSuplPsyCellIdHandler::ConstructL()
       
    52     {
       
    53     TRACESTRING( "CSuplPsyCellIdHandler::ConstructL start" )
       
    54     iIsInitilized = EFalse;
       
    55     User::LeaveIfError( ConnectToETelL() );
       
    56     iIsInitilized = ETrue;	
       
    57     TRACESTRING( "CSuplPsyCellIdHandler::ConstructL end" )
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CSuplPsyCellIdHandler::NewL,two phase constuctor
       
    62 // (other items were commented in a header).
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CSuplPsyCellIdHandler* CSuplPsyCellIdHandler::NewL( MBasicCellIDListener& aObserver )
       
    66     {
       
    67     CSuplPsyCellIdHandler* self = new( ELeave ) CSuplPsyCellIdHandler( aObserver );
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL();
       
    70     CleanupStack::Pop( self );
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CSuplPsyCellIdHandler::DoCancel
       
    77 // (other items were commented in a header).
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CSuplPsyCellIdHandler::DoCancel()
       
    81     {
       
    82 	TRACESTRING( "CSuplPsyCellIdHandler::DoCancel start" )
       
    83 	iPhone.CancelAsyncRequest( EMobilePhoneGetCurrentNetwork ); 
       
    84 	TRACESTRING( "CSuplPsyCellIdHandler::DoCancel end" )           
       
    85     }            
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSuplPsyCellIdHandler::~CSuplPsyCellIdHandler,Destructor
       
    89 // (other items were commented in a header).
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CSuplPsyCellIdHandler::~CSuplPsyCellIdHandler()
       
    93     {
       
    94 	TRACESTRING( "CSuplPsyCellIdHandler::~CSuplPsyCellIdHandler start" )
       
    95 	Cancel();
       
    96 	iPhone.Close(); 
       
    97 	if ( iIsInitilized )
       
    98 		{
       
    99 		iTelServer.UnloadPhoneModule(iTsyName);	
       
   100 		}
       
   101 			
       
   102 	iTelServer.Close();
       
   103 	
       
   104 	TRACESTRING( "CSuplPsyCellIdHandler::~CSuplPsyCellIdHandler end" )
       
   105     }
       
   106             
       
   107 // -----------------------------------------------------------------------------
       
   108 // CSuplPsyCellIdHandler::GetCellID,For retriving the cell id information
       
   109 // (other items were commented in a header).
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CSuplPsyCellIdHandler::GetCellID( TCellIdInfo& aCellIdInfo )
       
   113     {
       
   114 	TRACESTRING("CSuplPsyCellIdHandler::GetCellID start")
       
   115 	iCellIdInfo = &aCellIdInfo;
       
   116 	iPhone.GetCurrentNetwork( iStatus, iNetworkInfoPkg, iLocationInfo );
       
   117 	SetActive();            
       
   118     TRACESTRING("CSuplPsyCellIdHandler::GetCellID end")
       
   119     }  
       
   120       
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CSuplPsyCellIdHandler::NetworkType
       
   124 // (other items were commented in a header).
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 CSuplPsyCellIdHandler::TNetworkTypeInfo CSuplPsyCellIdHandler::NetworkType() const
       
   128 	{
       
   129 	return iNetworkType;
       
   130 	}
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CSuplPsyCellIdHandler::RunL
       
   134 // (other items were commented in a header).
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CSuplPsyCellIdHandler::RunL()
       
   138     {
       
   139 	TRACESTRING("CSuplPsyCellIdHandler::RunL start")
       
   140     
       
   141     TInt err = iStatus.Int();
       
   142     TRACESTRING2("Request Completed with Error Code: %d",err )
       
   143     	
       
   144 	if ( err == KErrNone )
       
   145 		{       
       
   146 		HandleCellInfoL();
       
   147 		}
       
   148 	else
       
   149 		{
       
   150 		iObserver.BasicCellIDRequestCompletedL( KErrNotFound );    
       
   151 		}
       
   152     TRACESTRING("CSuplPsyCellIdHandler::RunL end")
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CSuplPsyCellIdHandler::HandleCellInfoL(),
       
   157 // (other items were commented in a header).
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CSuplPsyCellIdHandler::HandleCellInfoL()
       
   161 	{
       
   162     TRACESTRING("CSuplPsyCellIdHandler::HandleCellInfoL start")
       
   163     
       
   164         
       
   165     switch (iNetworkInfo.iMode) 
       
   166     	{
       
   167         case RMobilePhone::ENetworkModeGsm:
       
   168         	{
       
   169         	TRACESTRING("GSM Network")
       
   170         	//For GSM Cell Information
       
   171 			iNetworkType = EGSM;
       
   172 			
       
   173 			TInt    MCC=0;
       
   174 			TInt64  MNC=0;
       
   175 			TLex LexMCC(iNetworkInfo.iCountryCode);
       
   176 			TLex LexMNC(iNetworkInfo.iNetworkId);
       
   177 
       
   178 			LexMCC.Val(MCC);
       
   179 			LexMNC.Val(MNC);
       
   180 			TUint   LAC = iLocationInfo.iLocationAreaCode;
       
   181 			TUint   CellId = iLocationInfo.iCellId;
       
   182 					
       
   183 			iCellIdInfo->iMCC = MCC;
       
   184 			iCellIdInfo->iMNC = MNC;
       
   185 			iCellIdInfo->iCid = CellId;
       
   186 			iCellIdInfo->iLac = LAC;
       
   187 								 
       
   188             TRACESTRING("Observers notified for GSM CellId information")
       
   189             iObserver.BasicCellIDRequestCompletedL(KErrNone);    
       
   190             break;                             
       
   191             }                    
       
   192         case RMobilePhone::ENetworkModeWcdma:
       
   193         	{
       
   194 			TRACESTRING("WCDMA Network")
       
   195 			//For WCDMA Cell Information
       
   196 			iNetworkType = EWCDMA;
       
   197 			
       
   198 			TInt    MCC=0;
       
   199 			TInt64  MNC=0;
       
   200 			TLex LexMCC(iNetworkInfo.iCountryCode);
       
   201 			TLex LexMNC(iNetworkInfo.iNetworkId);
       
   202 			LexMCC.Val(MCC);
       
   203 			LexMNC.Val(MNC);
       
   204 			TUint  CellId = iLocationInfo.iCellId;
       
   205 								
       
   206 			iCellIdInfo->iMNC = MNC;
       
   207 			iCellIdInfo->iMCC = MCC;
       
   208 			iCellIdInfo->iCid = CellId;
       
   209 														
       
   210 	        TRACESTRING("Observers notified for WCDMA CellId information")
       
   211 	        iObserver.BasicCellIDRequestCompletedL(KErrNone);    
       
   212             break;                             
       
   213             }                    
       
   214         default:            
       
   215         	{
       
   216                  
       
   217 #ifdef _WINS_ 
       
   218             
       
   219             iNetworkType = EGSM;
       
   220 			
       
   221 			TInt    MCC=0;
       
   222 			TInt64  MNC=0;
       
   223 			TLex LexMCC(iNetworkInfo.iCountryCode);
       
   224 			TLex LexMNC(iNetworkInfo.iNetworkId);
       
   225 
       
   226 			LexMCC.Val(MCC);
       
   227 			LexMNC.Val(MNC);
       
   228 			TUint   LAC = iLocationInfo.iLocationAreaCode;
       
   229 			TUint   CellId = iLocationInfo.iCellId;
       
   230 					
       
   231 			iCellIdInfo->iMCC = MCC;
       
   232 			iCellIdInfo->iMNC = MNC;
       
   233 			iCellIdInfo->iCid = CellId;
       
   234 			iCellIdInfo->iLac = LAC;
       
   235 								 
       
   236             TRACESTRING("Observers notified for GSM CellId information")
       
   237             iObserver.BasicCellIDRequestCompletedL(KErrNone);
       
   238 #else             
       
   239             
       
   240             TRACESTRING("Unknown Network")
       
   241             iNetworkType = EUnknown;
       
   242             
       
   243             TRACESTRING("Observers notified with error for unknown network")
       
   244             iObserver.BasicCellIDRequestCompletedL(KErrNotFound);    
       
   245 #endif	        
       
   246 	        break;        	
       
   247             }                     
       
   248 	    }
       
   249 	TRACESTRING("CSuplPsyCellIdHandler::HandleCellInfoL end")
       
   250 	}
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CSuplPsyCellIdHandler::RunError, Will be called by framework,if RunL leaves.
       
   254 // (other items were commented in a header).
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 TInt CSuplPsyCellIdHandler::RunError(TInt /*aError*/)
       
   258 	{
       
   259    	TRAP_IGNORE(iObserver.BasicCellIDRequestCompletedL(KErrNotFound));    
       
   260 	return KErrNone;
       
   261 	}
       
   262 	
       
   263 // -----------------------------------------------------------------------------
       
   264 // CSuplPsyCellIdHandler::ConnectToETelL
       
   265 // Connects to Telephony server & RMobilePhone
       
   266 // Returns System wide error,if any occurs
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 TInt CSuplPsyCellIdHandler::ConnectToETelL()
       
   270 	{
       
   271 	TInt err = iTelServer.Connect(); 
       
   272 	if(err != KErrNone)
       
   273 		{
       
   274 	    TRACESTRING2("Failed to connect with Error Code: %d",err )
       
   275         return err;
       
   276 		}
       
   277 
       
   278 	CCommsDatabase* const db = CCommsDatabase::NewL(EDatabaseTypeUnspecified); 
       
   279 	CleanupStack::PushL(db); 
       
   280 
       
   281 	TUint32 modemId = 0; 
       
   282 	db->GetGlobalSettingL(TPtrC(MODEM_PHONE_SERVICES_SMS), modemId); 
       
   283 	CCommsDbTableView* const view = db->OpenViewMatchingUintLC(TPtrC(MODEM), TPtrC(COMMDB_ID), 
       
   284 																modemId); 
       
   285 	err = view->GotoFirstRecord(); 
       
   286 	if(err != KErrNone)
       
   287 		{
       
   288 		CleanupStack::PopAndDestroy(2,db);			
       
   289 		return err;	
       
   290 		}
       
   291 	
       
   292 	view->ReadTextL(TPtrC(MODEM_TSY_NAME), iTsyName); 
       
   293 	err = iTelServer.LoadPhoneModule(iTsyName);
       
   294 	if(err != KErrNone)
       
   295 		{
       
   296 		CleanupStack::PopAndDestroy(2,db);		
       
   297 		return err;
       
   298 		}
       
   299 		
       
   300 
       
   301 	// For the phone information
       
   302 	RTelServer::TPhoneInfo info;
       
   303 
       
   304 	iTelServer.GetPhoneInfo(0, info); 
       
   305 	err = iPhone.Open(iTelServer, info.iName);
       
   306 	CleanupStack::PopAndDestroy(2,db);					
       
   307 	if(err != KErrNone)
       
   308 		{
       
   309 		return err;	
       
   310 		}
       
   311 	return err;
       
   312 	}	
       
   313 //  End of File