locationmgmt/networkgateway/src/netregstatusmonitor.cpp
changeset 60 9a7e3d5f461a
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
51:95c570bf4a05 60:9a7e3d5f461a
    67 
    67 
    68 /**
    68 /**
    69 */
    69 */
    70 void CNetworkRegistrationStatusMonitor::ConstructL()
    70 void CNetworkRegistrationStatusMonitor::ConstructL()
    71 	{	
    71 	{	
       
    72     LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor::ConstructL++");
    72 	iConfigurationProperty.Attach(KUidSystemCategory, RootServer::KUidC32StartPropertyKey.iUid); // needs the KEY
    73 	iConfigurationProperty.Attach(KUidSystemCategory, RootServer::KUidC32StartPropertyKey.iUid); // needs the KEY
    73 	TInt propertyValue = RootServer::EInitialising; // set to safe state
    74 	TInt propertyValue = RootServer::EInitialising; // set to safe state
    74 	TInt propertyResult = iConfigurationProperty.Get(propertyValue);
    75 	TInt propertyResult = iConfigurationProperty.Get(propertyValue);
    75 	
    76 	
    76 	if(propertyValue < RootServer::EConfigurationComplete)
    77 	if(propertyValue < RootServer::EConfigurationComplete)
    77 		{
    78 		{
    78 		//Attempt to connect to the ETel Server.  This will start C32Start if it has not already been started by the startup routine.
    79 		//Attempt to connect to the ETel Server.  This will start C32Start if it has not already been started by the startup routine.
    79 		User::LeaveIfError(iTelServer.Connect());
    80 		User::LeaveIfError(iTelServer.Connect());
       
    81 		LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor Connected to ETel");		
    80 		iConfigurationProperty.Subscribe(iStatus);
    82 		iConfigurationProperty.Subscribe(iStatus);
    81 		SetActive();
    83 		SetActive();
    82 		}
    84 		}
    83 	else
    85 	else
    84 		{
    86 		{
    85 		//Property already present, continue usual initialisation
    87 		//Property already present, continue usual initialisation
    86 		SetupPhoneL();
    88 		SetupPhoneL();
    87 		iInitialised = ETrue;
    89 		iInitialised = ETrue;
    88 		}
    90 		}
       
    91 	LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor::ConstructL++");
    89 	}
    92 	}
    90 
    93 
    91 void CNetworkRegistrationStatusMonitor::SetupPhoneL()
    94 void CNetworkRegistrationStatusMonitor::SetupPhoneL()
    92 	{
    95 	{
       
    96     LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor::SetupPhoneL++");
    93 	// Connect to the Network Registration Status internal LBS bus
    97 	// Connect to the Network Registration Status internal LBS bus
    94 	iLbsNetRegStatus.OpenL();
    98 	iLbsNetRegStatus.OpenL();
    95 		
    99 	LBSLOG(ELogP1, "attached to NetworkRegistrationStatus property");	
    96 	TRAPD(err, InitialisePhoneL());
   100 	TRAPD(err, InitialisePhoneL());
    97 	if (err == KErrNone)
   101 	if (err == KErrNone)
    98 		{
   102 		{
    99 		// Connected to ETel successfully, now get the network 
   103 		// Connected to ETel successfully, now get the network 
   100 		// registration status.
   104 		// registration status.
   101 		iPhone.GetNetworkRegistrationStatus(iStatus, iPhoneNetRegStatus);
   105 		iPhone.GetNetworkRegistrationStatus(iStatus, iPhoneNetRegStatus);
       
   106 		LBSLOG2(ELogP2, "Current network registration status: %S", &NetRegStatusToDesC(iPhoneNetRegStatus)); 
   102 		SetActive();
   107 		SetActive();
   103 		}
   108 		}
   104 	else
   109 	else
   105 		{		
   110 		{		
       
   111 	    LBSLOG(ELogP2, "couldn't connect to ETEL, setting network reg status to ENotRegistered");    
   106 		// Couldn't connect to ETel; publish a default value.
   112 		// Couldn't connect to ETel; publish a default value.
   107 		iLbsNetRegStatus.SetNetworkRegistrationStatus(RLbsNetworkRegistrationStatus::ENotRegistered);
   113 		iLbsNetRegStatus.SetNetworkRegistrationStatus(RLbsNetworkRegistrationStatus::ENotRegistered);
   108 		}
   114 		}
       
   115 	LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor::SetupPhoneL--");
   109 	}
   116 	}
   110 
   117 
   111 /**
   118 /**
   112 */
   119 */
   113 void CNetworkRegistrationStatusMonitor::RunL()
   120 void CNetworkRegistrationStatusMonitor::RunL()
   114 	{
   121 	{
       
   122     LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor::RunL++");
   115 	User::LeaveIfError(iStatus.Int());
   123 	User::LeaveIfError(iStatus.Int());
   116 	
   124 	
   117 	//Check to see whether the initialisation has finished
   125 	//Check to see whether the initialisation has finished
   118 	if(iInitialised == EFalse)
   126 	if(iInitialised == EFalse)
   119 		{
   127 		{
   177 		LBSLOG2(ELogP5, "Network registration status broadcast to LBS: %S", &LbsNetRegStatusToDesC(iCurrentNetRegStatus));
   185 		LBSLOG2(ELogP5, "Network registration status broadcast to LBS: %S", &LbsNetRegStatusToDesC(iCurrentNetRegStatus));
   178 		LBSLOG2(ELogP5, "Last Good Network registration status: %S", &LbsNetRegStatusToDesC(iLastGoodNetRegStatus));
   186 		LBSLOG2(ELogP5, "Last Good Network registration status: %S", &LbsNetRegStatusToDesC(iLastGoodNetRegStatus));
   179 		
   187 		
   180 		iObserver.OnNetworkRegistrationStatusChange(iCurrentNetRegStatus);
   188 		iObserver.OnNetworkRegistrationStatusChange(iCurrentNetRegStatus);
   181 		}
   189 		}
       
   190 	LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor::RunL--");
   182 	}
   191 	}
   183 
   192 
   184 /**
   193 /**
   185 */	
   194 */	
   186 void CNetworkRegistrationStatusMonitor::DoCancel()
   195 void CNetworkRegistrationStatusMonitor::DoCancel()
   260 @leave	Leaves if underlying ETEL.DLL returns error,
   269 @leave	Leaves if underlying ETEL.DLL returns error,
   261 or if we can't find a suitable Phone or can't open it.
   270 or if we can't find a suitable Phone or can't open it.
   262 */
   271 */
   263 void CNetworkRegistrationStatusMonitor::InitialisePhoneL()
   272 void CNetworkRegistrationStatusMonitor::InitialisePhoneL()
   264 	{	
   273 	{	
       
   274     LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor::InitialisePhoneL++");
   265 	TInt err(KErrNone);
   275 	TInt err(KErrNone);
   266 	
   276 	
   267 	User::LeaveIfError(iTelServer.Connect());
   277 	User::LeaveIfError(iTelServer.Connect());
   268 	
   278 	LBSLOG(ELogP1, "connected to RTelServer");
   269 	// Read the name of the .tsy to load from CommDB
   279 	// Read the name of the .tsy to load from CommDB
   270 	TBuf<KCommsDbSvrMaxFieldLength> tsyName;
   280 	TBuf<KCommsDbSvrMaxFieldLength> tsyName;
   271 	GetCommDbTSYnameL(tsyName);
   281 	GetCommDbTSYnameL(tsyName);
   272 
   282 	
   273 	// Load .tsy into ETel
   283 	// Load .tsy into ETel
   274 	User::LeaveIfError(iTelServer.LoadPhoneModule(tsyName));
   284 	err = iTelServer.LoadPhoneModule(tsyName);
   275 
   285 	
       
   286 	LBSLOG2(ELogP2, "TSY Name: %S", &tsyName);
       
   287 	User::LeaveIfError(err);
       
   288 	LBSLOG(ELogP2, "TSY loaded");
   276 	// Find available phones; check that the one we requested 
   289 	// Find available phones; check that the one we requested 
   277 	// to be loaded is there.
   290 	// to be loaded is there.
   278 	TInt phoneIndex(0);
   291 	TInt phoneIndex(0);
   279 	User::LeaveIfError(iTelServer.EnumeratePhones(phoneIndex));
   292 	User::LeaveIfError(iTelServer.EnumeratePhones(phoneIndex));
       
   293 	LBSLOG2(ELogP2, "phones enumerated. There are %d", phoneIndex);
   280 	while(phoneIndex-->0)
   294 	while(phoneIndex-->0)
   281 		{
   295 		{
   282 		TName searchTsyName;
   296 		TName searchTsyName;
   283 		// Check whether this phone belongs to loaded TSY
   297 		// Check whether this phone belongs to loaded TSY
   284 		if ((iTelServer.GetTsyName(phoneIndex, searchTsyName) == KErrNone) 
   298 		if ((iTelServer.GetTsyName(phoneIndex, searchTsyName) == KErrNone) 
   285 			&& (searchTsyName.CompareF(tsyName) == KErrNone)) 
   299 			&& (searchTsyName.CompareF(tsyName) == KErrNone)) 
       
   300 		    {
       
   301 		    LBSLOG(ELogP2, "Found phone belonging to the loaded TSY");
   286 			break;
   302 			break;
       
   303 		    }
   287 		}
   304 		}
   288 		
   305 		
   289 	// Open a phone to be used for monitoring the network registration status.
   306 	// Open a phone to be used for monitoring the network registration status.
   290 	RTelServer::TPhoneInfo phoneInfo;
   307 	RTelServer::TPhoneInfo phoneInfo;
   291 	User::LeaveIfError(iTelServer.GetPhoneInfo(phoneIndex, phoneInfo));	
   308 	User::LeaveIfError(iTelServer.GetPhoneInfo(phoneIndex, phoneInfo));	
   292 	User::LeaveIfError(iPhone.Open(iTelServer, phoneInfo.iName));
   309 	LBSLOG(ELogP2, "Got phone info from RTelServer");
   293 	
   310 	err = iPhone.Open(iTelServer, phoneInfo.iName);
       
   311 	if(KErrNone != err)
       
   312 	    {
       
   313 	    LBSLOG2(ELogP2, "error %d returned from RMobilePhone::Open()", err);
       
   314 	    }
       
   315 	User::LeaveIfError(err);
       
   316 	LBSLOG2(ELogP2, "%S phone opened", &phoneInfo.iName);
   294 	// Check that the phone is ready to be used.	
   317 	// Check that the phone is ready to be used.	
   295 	RPhone::TStatus status;
   318 	RPhone::TStatus status;
   296 	User::LeaveIfError(iPhone.GetStatus(status));
   319 	User::LeaveIfError(iPhone.GetStatus(status));
       
   320 	LBSLOG3(ELogP2, "Phone status: modem detected = %d, mode = %d", status.iModemDetected, status.iMode);
   297 	if(status.iModemDetected != RPhone::EDetectedPresent)
   321 	if(status.iModemDetected != RPhone::EDetectedPresent)
   298 		{		
   322 		{		
       
   323 	    
   299 		err = iPhone.Initialise();
   324 		err = iPhone.Initialise();
   300 		if(err != KErrNone)
   325 		if(err != KErrNone)
   301 			{
   326 			{
       
   327 		    LBSLOG2(ELogP2, "Error %d on initialising phone", err);
   302 			iPhone.Close();
   328 			iPhone.Close();
   303 			User::Leave(err);
   329 			User::Leave(err);
   304 			}
   330 			}
   305 		}	
   331 		}	
   306 
   332 
   307 	// Check that we can access the info we want
   333 	// Check that we can access the info we want
   308 	TUint32 networkCaps;
   334 	TUint32 networkCaps;
   309 	User::LeaveIfError(iPhone.GetNetworkCaps(networkCaps));
   335 	err = iPhone.GetNetworkCaps(networkCaps);
       
   336 	if(KErrNone != err)
       
   337 	    {
       
   338 	    LBSLOG2(ELogP2, "Error %d on getting network caps", err);
       
   339 	    }
       
   340 	User::LeaveIfError(err);
       
   341 	LBSLOG2(ELogP2, "Network caps = 0x%x", networkCaps);
   310 	if (!(networkCaps & RMobilePhone::KCapsGetRegistrationStatus
   342 	if (!(networkCaps & RMobilePhone::KCapsGetRegistrationStatus
   311 		  && networkCaps & RMobilePhone::KCapsNotifyRegistrationStatus))
   343 		  && networkCaps & RMobilePhone::KCapsNotifyRegistrationStatus))
   312 		{
   344 		{
       
   345 	    LBSLOG(ELogP2, "Leaving with KErrNotSupported (registration status not supported by phone)");
   313 		err = KErrNotSupported;
   346 		err = KErrNotSupported;
   314 		}
   347 		}
   315 	
   348 	
   316 	User::LeaveIfError(err);
   349 	User::LeaveIfError(err);
       
   350 	LBSLOG(ELogP1, "CNetworkRegistrationStatusMonitor::InitialisePhoneL--");
   317 	}
   351 	}
   318 
   352 
   319 #ifdef ENABLE_LBS_DEV_LOGGER
   353 #ifdef ENABLE_LBS_DEV_LOGGER
   320 /** Logging-only function to return a meaningful description of an enum value.
   354 /** Logging-only function to return a meaningful description of an enum value.
   321 */
   355 */