locationmanager/locationtrail/src/cnetworkinfo.cpp
branchRCL_3
changeset 63 e538444823de
parent 47 b73252188534
equal deleted inserted replaced
57:2872ae438bf7 63:e538444823de
    18 #include <etel3rdparty.h>
    18 #include <etel3rdparty.h>
    19 
    19 
    20 #include "cnetworkinfo.h"
    20 #include "cnetworkinfo.h"
    21 #include "locationmanagerdebug.h"
    21 #include "locationmanagerdebug.h"
    22 
    22 
    23 
       
    24 
       
    25 
       
    26 // --------------------------------------------------------------------------
    23 // --------------------------------------------------------------------------
    27 // CNetworkInfo::NewL
    24 // CNetworkInfo::NewL
    28 // --------------------------------------------------------------------------
    25 // --------------------------------------------------------------------------
    29 //
    26 //
    30 EXPORT_C CNetworkInfo* CNetworkInfo::NewL( MNetworkInfoObserver* aTrail )
    27 EXPORT_C CNetworkInfo* CNetworkInfo::NewL( MNetworkInfoObserver* aTrail )
    32     LOG( "CNetworkInfo::NewL(), begin" );
    29     LOG( "CNetworkInfo::NewL(), begin" );
    33     CNetworkInfo* self = new (ELeave) CNetworkInfo( aTrail );
    30     CNetworkInfo* self = new (ELeave) CNetworkInfo( aTrail );
    34     CleanupStack::PushL( self );
    31     CleanupStack::PushL( self );
    35     self->ConstructL();
    32     self->ConstructL();
    36     CleanupStack::Pop( self );
    33     CleanupStack::Pop( self );
       
    34     LOG( "CNetworkInfo::NewL(), end" );
    37     return self;
    35     return self;
    38     }
    36     }
    39         
    37         
    40 // --------------------------------------------------------------------------
    38 // --------------------------------------------------------------------------
    41 // CNetworkInfo::CNetworkInfo
    39 // CNetworkInfo::CNetworkInfo
    42 // --------------------------------------------------------------------------
    40 // --------------------------------------------------------------------------
    43 //  
    41 //  
    44 CNetworkInfo::CNetworkInfo( MNetworkInfoObserver* aTrail ) 
    42 CNetworkInfo::CNetworkInfo( MNetworkInfoObserver* aTrail ) 
    45     : CActive( CActive::EPriorityStandard ),
    43     : CActive( CActive::EPriorityStandard ),
    46     iTrail ( aTrail ),
    44     iFirstTime( EFalse ),
    47     iMobilePhone(aTrail->GetMobilePhone4NwInfo()),
    45     iTelephony( NULL ),
    48     iState( ENetworkInfoNoOptState ),
    46     iNetworkInfoV1Pckg( iNetworkInfoV1 ) 
    49     
       
    50     iMMNetworkInfoPckg( iMMNetworkInfo ) 
       
    51     {
    47     {
    52     CActiveScheduler::Add( this );
    48     CActiveScheduler::Add( this );
       
    49     iTrail = aTrail;
    53     }
    50     }
    54 
    51 
    55 // --------------------------------------------------------------------------
    52 // --------------------------------------------------------------------------
    56 // CNetworkInfo::ConstructL
    53 // CNetworkInfo::ConstructL
    57 // --------------------------------------------------------------------------
    54 // --------------------------------------------------------------------------
    58 //    
    55 //    
    59 void CNetworkInfo::ConstructL()
    56 void CNetworkInfo::ConstructL()
    60     {
    57     {
    61 	LOG( "CNetworkInfo::ConstructL(), begin" );
    58 	LOG( "CNetworkInfo::ConstructL(), begin" );
    62     StartNwInfoChangeNotifier();
    59 	iFirstTime = ETrue;
       
    60     iTelephony = CTelephony::NewL();
       
    61     iTelephony->GetCurrentNetworkInfo(iStatus, iNetworkInfoV1Pckg);
       
    62     LOG( "CNetworkInfo::ConstructL(), iTelephony->GetCurrentNetworkInfo called" );
       
    63     
       
    64    	if ( IsActive() )
       
    65     	{
       
    66     	Cancel();
       
    67         }    
       
    68     SetActive();
       
    69     
    63     LOG( "CNetworkInfo::ConstructL(), end" );
    70     LOG( "CNetworkInfo::ConstructL(), end" );
    64     }
    71     }
    65     
    72     
    66 // --------------------------------------------------------------------------
    73 // --------------------------------------------------------------------------
    67 // CNetworkInfo::~CNetworkInfo
    74 // CNetworkInfo::~CNetworkInfo
    68 // --------------------------------------------------------------------------
    75 // --------------------------------------------------------------------------
    69 //    
    76 //    
    70 EXPORT_C CNetworkInfo::~CNetworkInfo()
    77 EXPORT_C CNetworkInfo::~CNetworkInfo()
    71     {
    78     {
    72     // we are not owning RMobilePhone obj.. DON'T CLOSE it.
       
    73     Cancel();
    79     Cancel();
       
    80     delete iTelephony;
    74     }
    81     }
    75 
    82 
    76 // --------------------------------------------------------------------------
    83 // --------------------------------------------------------------------------
    77 // CNetworkInfo::RunError
    84 // CNetworkInfo::RunError
    78 // --------------------------------------------------------------------------
    85 // --------------------------------------------------------------------------
    81     {
    88     {
    82     return KErrNone;
    89     return KErrNone;
    83     }    
    90     }    
    84 
    91 
    85 // --------------------------------------------------------------------------
    92 // --------------------------------------------------------------------------
    86 // CNetworkInfo::StartNwInfoChangeNotifier
       
    87 // --------------------------------------------------------------------------
       
    88 //    
       
    89 EXPORT_C void CNetworkInfo::StartNwInfoChangeNotifier()
       
    90     { 
       
    91 	LOG( "CNetworkInfo::StartNwInfoChangeNotifier(), begin" );   
       
    92    	if ( !IsActive())
       
    93     	{
       
    94     	// get current n/w info first and from RunL start notifier
       
    95         iState = ENetworkInfoOptGetState; 
       
    96         
       
    97         iMobilePhone.GetCurrentNetwork(iStatus, iMMNetworkInfoPckg, iMMArea);
       
    98         SetActive();
       
    99         }
       
   100     
       
   101     LOG( "CNetworkInfo::StartNwInfoChangeNotifier(), end" ); 
       
   102     }    
       
   103 
       
   104 // --------------------------------------------------------------------------
       
   105 // CNetworkInfo::StopNwInfoChangeNotifier
       
   106 // --------------------------------------------------------------------------
       
   107 //    
       
   108 EXPORT_C void CNetworkInfo::StopNwInfoChangeNotifier()
       
   109     { 
       
   110 	LOG( "CNetworkInfo::StopNwInfoChangeNotifier(), begin" );   
       
   111     Cancel();
       
   112     iState = ENetworkInfoNoOptState;
       
   113     LOG( "CNetworkInfo::StopNwInfoChangeNotifier(), end" ); 
       
   114     }    
       
   115 
       
   116 // --------------------------------------------------------------------------
       
   117 // CNetworkInfo::RunL
    93 // CNetworkInfo::RunL
   118 // --------------------------------------------------------------------------
    94 // --------------------------------------------------------------------------
   119 //    
    95 //    
   120 void CNetworkInfo::RunL()
    96 void CNetworkInfo::RunL()
   121     { 
    97     { 
   122 	LOG( "CNetworkInfo::RunL(), begin" );   
    98 	LOG( "CNetworkInfo::RunL(), begin" );   
   123 	// reset the flag first
    99 	iFirstTime = EFalse; 
   124     iState = ENetworkInfoNoOptState;
   100     iTrail->NetworkInfo( iNetworkInfoV1, iStatus.Int() );
   125     if(iStatus == KErrNone)
   101     LOG( "CNetworkInfo::RunL(), iTrail->NetworkInfo called" );   
   126         {
   102     
   127         // convert the network info to CTelephony network info. just to give backward compatibility
   103     iTelephony->NotifyChange(iStatus, CTelephony::ECurrentNetworkInfoChange, iNetworkInfoV1Pckg);
   128         MapNetworkInfo(&iNetworkInfoV1, &iMMNetworkInfo, &iMMArea);
   104     LOG( "CNetworkInfo::RunL(), iTelephony->NotifyChange called" );
   129         }
   105       
   130     if(iTrail)
   106    	if ( IsActive() )
   131         {
       
   132         iTrail->NetworkInfo( iNetworkInfoV1, iStatus.Int() );
       
   133         }
       
   134     // listen to n/w info change
       
   135    	if ( !IsActive() )
       
   136     	{
   107     	{
   137     	iState = ENetworkInfoOptNotifyState;
   108     	Cancel();
   138         iMobilePhone.NotifyCurrentNetworkChange(iStatus,iMMNetworkInfoPckg, iMMArea);
   109         }    
   139         SetActive();
   110     SetActive();
   140         }
   111     
   141     LOG( "CNetworkInfo::RunL(), end" ); 
   112     LOG( "CNetworkInfo::RunL(), end" ); 
   142     }    
   113     }    
   143 
   114 
   144 // --------------------------------------------------------------------------
   115 // --------------------------------------------------------------------------
   145 // CNetworkInfo::DoCancel
   116 // CNetworkInfo::DoCancel
   146 // --------------------------------------------------------------------------
   117 // --------------------------------------------------------------------------
   147 // 
   118 // 
   148 void CNetworkInfo::DoCancel()
   119 void CNetworkInfo::DoCancel()
   149     {
   120     {
   150 	LOG1( "CNetworkInfo::DoCancel(), begin. State - %d", iState);
   121 	LOG( "CNetworkInfo::DoCancel(), begin" );
   151 	switch ( iState )    
   122 	if ( IsActive() )
   152         {   
   123 		{
   153         case ENetworkInfoOptGetState:
   124     	if ( iFirstTime )    
   154         	{
   125         	{
   155         	LOG( "Cancel get current n/w info change" );
   126 	    	LOG( "CNetworkInfo::DoCancel(), cancelling CTelephony::EGetCurrentNetworkInfoCancel" );
   156         	iMobilePhone.CancelAsyncRequest( EMobilePhoneGetCurrentNetwork);
   127         	iTelephony->CancelAsync( CTelephony::EGetCurrentNetworkInfoCancel );
   157             break;
       
   158         	}
   128         	}
   159         case ENetworkInfoOptNotifyState:
   129     	else
   160     		{
   130     		{
   161         	LOG( "Cancel current n/w info change" );
   131 	    	LOG( "CNetworkInfo::DoCancel(), cancelling CTelephony::ECurrentNetworkInfoChangeCancel" );
   162         	iMobilePhone.CancelAsyncRequest( EMobilePhoneNotifyCurrentNetworkChange);
   132 	    	iTelephony->CancelAsync( CTelephony::ECurrentNetworkInfoChangeCancel );	
   163             break;
   133     		}
   164         	}
   134 		}	
   165         default:
       
   166             break;
       
   167         }
       
   168     iState = ENetworkInfoNoOptState;
       
   169    	LOG( "CNetworkInfo::DoCancel(), end" );
   135    	LOG( "CNetworkInfo::DoCancel(), end" );
   170     }
   136     }
   171 
   137 
   172 // --------------------------------------------------------------------------
       
   173 // CNetworkInfo::MapNetworkInfo
       
   174 // --------------------------------------------------------------------------
       
   175 // 
       
   176 EXPORT_C void CNetworkInfo::MapNetworkInfo(CTelephony::TNetworkInfoV1* aTelNetworkInfo, 
       
   177     RMobilePhone::TMobilePhoneNetworkInfoV2* aMMNetworkInfo, 
       
   178     RMobilePhone::TMobilePhoneLocationAreaV1* aMMArea)
       
   179 	{
       
   180    	LOG( "CNetworkInfo::MapNetworkInfo(), begin" );
       
   181 	switch(aMMNetworkInfo->iMode)
       
   182 		{
       
   183 		case RMobilePhone::ENetworkModeUnknown: 
       
   184 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeUnknown;
       
   185 			break;
       
   186 		case RMobilePhone::ENetworkModeUnregistered:
       
   187 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeUnregistered;
       
   188 			break;
       
   189 		case RMobilePhone::ENetworkModeGsm:
       
   190 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeGsm;
       
   191 			break;
       
   192 		case RMobilePhone::ENetworkModeAmps:
       
   193 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeAmps;
       
   194 			break;			
       
   195 		case RMobilePhone::ENetworkModeCdma95:
       
   196 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeCdma95;
       
   197 			break;
       
   198 		case RMobilePhone::ENetworkModeCdma2000:
       
   199 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeCdma2000;
       
   200 			break;
       
   201 		case RMobilePhone::ENetworkModeWcdma:
       
   202 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeWcdma;
       
   203 			break;
       
   204 		case RMobilePhone::ENetworkModeTdcdma:
       
   205 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeTdcdma;
       
   206 			break;
       
   207 		default:
       
   208 			aTelNetworkInfo->iMode=CTelephony::ENetworkModeUnknown;
       
   209 		}	
       
   210 
       
   211 	switch(aMMNetworkInfo->iStatus)
       
   212 		{
       
   213 		case RMobilePhone::ENetworkStatusUnknown: 
       
   214 			aTelNetworkInfo->iStatus=CTelephony::ENetworkStatusUnknown;
       
   215 			break;
       
   216 		case RMobilePhone::ENetworkStatusAvailable:
       
   217 			aTelNetworkInfo->iStatus=CTelephony::ENetworkStatusAvailable;
       
   218 			break;
       
   219 		case RMobilePhone::ENetworkStatusCurrent:
       
   220 			aTelNetworkInfo->iStatus=CTelephony::ENetworkStatusCurrent;
       
   221 			break;
       
   222 		case RMobilePhone::ENetworkStatusForbidden:
       
   223 			aTelNetworkInfo->iStatus=CTelephony::ENetworkStatusForbidden;
       
   224 			break;			
       
   225 		default:
       
   226 			aTelNetworkInfo->iStatus=CTelephony::ENetworkStatusUnknown;
       
   227 		}	
       
   228 			
       
   229 	switch(aMMNetworkInfo->iBandInfo)
       
   230 		{
       
   231 		case RMobilePhone::EBandUnknown: 
       
   232 			aTelNetworkInfo->iBandInfo=CTelephony::EBandUnknown;
       
   233 			break;
       
   234 		case RMobilePhone::E800BandA:
       
   235 			aTelNetworkInfo->iBandInfo=CTelephony::E800BandA;
       
   236 			break;
       
   237 		case RMobilePhone::E800BandB:
       
   238 			aTelNetworkInfo->iBandInfo=CTelephony::E800BandB;
       
   239 			break;
       
   240 		case RMobilePhone::E800BandC:
       
   241 			aTelNetworkInfo->iBandInfo=CTelephony::E800BandC;
       
   242 			break;			
       
   243 		case RMobilePhone::E1900BandA:
       
   244 			aTelNetworkInfo->iBandInfo=CTelephony::E1900BandA;
       
   245 			break;
       
   246 		case RMobilePhone::E1900BandB:
       
   247 			aTelNetworkInfo->iBandInfo=CTelephony::E1900BandB;
       
   248 			break;
       
   249 		case RMobilePhone::E1900BandC:
       
   250 			aTelNetworkInfo->iBandInfo=CTelephony::E1900BandC;
       
   251 			break;
       
   252 		case RMobilePhone::E1900BandD:
       
   253 			aTelNetworkInfo->iBandInfo=CTelephony::E1900BandD;
       
   254 			break;
       
   255 		case RMobilePhone::E1900BandE:
       
   256 			aTelNetworkInfo->iBandInfo=CTelephony::E1900BandE;
       
   257 			break;
       
   258 		case RMobilePhone::E1900BandF:
       
   259 			aTelNetworkInfo->iBandInfo=CTelephony::E1900BandF;
       
   260 			break;
       
   261 		default:
       
   262 			aTelNetworkInfo->iBandInfo=CTelephony::EBandUnknown;
       
   263 		}			
       
   264 	
       
   265 	aTelNetworkInfo->iCountryCode.Copy(aMMNetworkInfo->iCountryCode);
       
   266 	aTelNetworkInfo->iNetworkId.Copy(aMMNetworkInfo->iNetworkId);
       
   267 	aTelNetworkInfo->iDisplayTag.Copy(aMMNetworkInfo->iDisplayTag);
       
   268 	
       
   269 	TInt maxLength = aTelNetworkInfo->iShortName.MaxLength();
       
   270 	if (aMMNetworkInfo->iShortName.Length() > maxLength)
       
   271 		{
       
   272 		aTelNetworkInfo->iShortName.Copy(aMMNetworkInfo->iShortName.Ptr(), maxLength);
       
   273 		}
       
   274 	else
       
   275 		{
       
   276 		aTelNetworkInfo->iShortName.Copy(aMMNetworkInfo->iShortName);		
       
   277 		}
       
   278 	
       
   279 	maxLength = aTelNetworkInfo->iLongName.MaxLength();
       
   280 
       
   281 	if (aMMNetworkInfo->iLongName.Length() > maxLength)
       
   282 		{
       
   283 		aTelNetworkInfo->iLongName.Copy(aMMNetworkInfo->iLongName.Ptr(), maxLength);
       
   284 		}
       
   285 	else
       
   286 		{
       
   287 		aTelNetworkInfo->iLongName.Copy(aMMNetworkInfo->iLongName);	
       
   288 		}
       
   289 	
       
   290 	aTelNetworkInfo->iCdmaSID.Copy(aMMNetworkInfo->iCdmaSID);
       
   291 	
       
   292 	if(aMMArea)
       
   293 		{
       
   294 		aTelNetworkInfo->iAreaKnown=aMMArea->iAreaKnown;
       
   295 		aTelNetworkInfo->iLocationAreaCode=aMMArea->iLocationAreaCode;
       
   296 		aTelNetworkInfo->iCellId=aMMArea->iCellId;	
       
   297 		}
       
   298 	else
       
   299 		{
       
   300 		aTelNetworkInfo->iAreaKnown=EFalse;
       
   301 		aTelNetworkInfo->iLocationAreaCode=0;
       
   302 		aTelNetworkInfo->iCellId=0;	
       
   303 		}
       
   304 	
       
   305 	//check which paramater class version this is.		
       
   306 	switch(aMMNetworkInfo->iAccess)
       
   307 		{
       
   308 		case RMobilePhone::ENetworkAccessUnknown: 
       
   309 			aTelNetworkInfo->iAccess=CTelephony::ENetworkAccessUnknown;
       
   310 			break;
       
   311 		case RMobilePhone::ENetworkAccessGsm:
       
   312 			aTelNetworkInfo->iAccess=CTelephony::ENetworkAccessGsm;
       
   313 			break;
       
   314 		case RMobilePhone::ENetworkAccessGsmCompact:
       
   315 			aTelNetworkInfo->iAccess=CTelephony::ENetworkAccessGsmCompact;
       
   316 			break;
       
   317 		case RMobilePhone::ENetworkAccessUtran:
       
   318 			aTelNetworkInfo->iAccess=CTelephony::ENetworkAccessUtran;
       
   319 			break;			
       
   320 		default:
       
   321 			aTelNetworkInfo->iAccess=CTelephony::ENetworkAccessUnknown;
       
   322 		}						
       
   323 		
       
   324    	LOG( "CNetworkInfo::MapNetworkInfo(), end" );
       
   325 	}
       
   326 
       
   327 // ----------------------------------------------------------------------------
       
   328 // CNetworkInfo::GetCurrentRegisterNw()
       
   329 // ---------------------------------------------------------------------------- 
       
   330 RMobilePhone::TMobilePhoneNetworkInfoV2& CNetworkInfo::GetCurrentRegisterNw()
       
   331     {
       
   332     return iMMNetworkInfo;
       
   333     }
       
   334 
       
   335 // End of file
   138 // End of file
   336