telephonyserverplugins/multimodetsy/Multimode/gprs/atgprsntwkregstatuschange.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <et_phone.h>		// For CTelObject
       
    17 
       
    18 #include "atgprsntwkregstatuschange.h"		// Header file for this source file
       
    19 #include "mSLOGGER.H"					// For LOGTEXT macros
       
    20 #include "ATIO.H"							// For CATIO class
       
    21 #include "Matstd.h"						// For AT command strings and timeout values
       
    22 #include "gprs.h"							// for CGprs class
       
    23 #include "NOTIFY.H"						// for CNotifications
       
    24 
       
    25 // Macro for logging text to the log file using the local class name and a simpler 
       
    26 // call style.
       
    27 #ifdef __LOGDEB__
       
    28 _LIT8(KLogEntry,"CATGprsNtwkRegStatusChange::%S\t%S");
       
    29 #define LOCAL_LOGTEXT(function,text) {_LIT8(F,function);_LIT8(T,text);LOGTEXT3(KLogEntry,&F,&T);}
       
    30 #else
       
    31 #define LOCAL_LOGTEXT(function,text)
       
    32 #endif
       
    33 
       
    34 
       
    35 CATGprsNtwkRegStatusChange* CATGprsNtwkRegStatusChange::NewL(CATIO* aIo,CTelObject* aTelObject, CPhoneGlobals* aGlobals)
       
    36 /**
       
    37  * Standard class factory function
       
    38  */
       
    39  	{
       
    40 	return (new(ELeave) CATGprsNtwkRegStatusChange(aIo,aTelObject,aGlobals));
       
    41 	// Currently no need for a ConstructL call, maybe we'll need one in the future...
       
    42 	}
       
    43 
       
    44 CATGprsNtwkRegStatusChange::CATGprsNtwkRegStatusChange(CATIO* aIo, CTelObject* aTelObject,CPhoneGlobals* aGlobals)
       
    45 	:CATBase(aIo,aTelObject,aGlobals)
       
    46  	{
       
    47 	Enable();
       
    48 	}
       
    49 
       
    50 CATGprsNtwkRegStatusChange::~CATGprsNtwkRegStatusChange()
       
    51 	{
       
    52 	Disable();
       
    53 	}
       
    54 
       
    55 void CATGprsNtwkRegStatusChange::Enable()
       
    56 /** 
       
    57  * Adds the all important +CGREG:* expect string so that our ::EventSignal is called when 
       
    58  * we get an unsolicited network registration status changes.
       
    59  */
       
    60 	{
       
    61 	LOCAL_LOGTEXT("Enable","Adding +CGREG:* expect string");
       
    62 	
       
    63 	// Ensure +CRING is not on the expect string stack before we add it.
       
    64 	// (Doing things this way means we do not have to maintain an expect string in our
       
    65 	// member data)
       
    66 	iIo->RemoveExpectStrings(this);		
       
    67 
       
    68 	// Add +CRING expect string
       
    69 	__ASSERT_ALWAYS(iIo->AddExpectString(this,KCGREGMatchString) != NULL, Panic(EGeneral));
       
    70 	}
       
    71 
       
    72 void CATGprsNtwkRegStatusChange::Disable()
       
    73 /** 
       
    74  * Removes all expect strings added by this object. 
       
    75  * This object will not process +CRING until ::Enable() is called.
       
    76  */
       
    77 	{
       
    78 	LOCAL_LOGTEXT("Disable","Removing all CATGprsNtwkRegStatusCchange expect strings");
       
    79 	iIo->RemoveExpectStrings(this);		
       
    80 	}
       
    81 
       
    82 void CATGprsNtwkRegStatusChange::EventSignal(TEventSource aSource)
       
    83 /**
       
    84  * Called when a '+CGREG:' is received.
       
    85  * Parses the +CGREG:... string which we recieved from the phone and then triggers
       
    86  * the EPacketNtwkRegStatusChange notification as appropriate.
       
    87  */
       
    88 	{
       
    89 	LOCAL_LOGTEXT("EventSignal","Enter function");
       
    90 
       
    91 	TInt ret(KErrNone);
       
    92 	RPacketService::TRegistrationStatus regStatus(RPacketService::EUnknown);
       
    93 		
       
    94 	__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
    95 	TRAP(ret,ParseResponseL(regStatus));
       
    96 	if(ret!=KErrNone)
       
    97 		{
       
    98 		LOCAL_LOGTEXT("EventSignal","Unable to parse CGREG response");
       
    99 		}
       
   100 	else
       
   101 		{
       
   102 		//
       
   103 		// Trigger the notificaiton mechanism
       
   104 		LOCAL_LOGTEXT("EventSignal","Triggering EPacketNtwkRegStatusChange notification");
       
   105 		((CGprs*)iTelObject)->SetRegistrationStatus(regStatus);
       
   106 		iPhoneGlobals->iNotificationStore->CheckNotification(iTelObject, EPacketNtwkRegStatusChange);
       
   107 
       
   108 		// We are done, but there is no client request to complete
       
   109 		// we just return and wait until we get our next +CGREG:* command
       
   110 		}
       
   111 	}
       
   112 
       
   113 void CATGprsNtwkRegStatusChange::ParseResponseL(RPacketService::TRegistrationStatus& aRegStatus)
       
   114 /**
       
   115  * Parses the +CGREG unsolicited string from the modem.
       
   116  * An example response woulf be '+CGREG: 2' where the value denotes the
       
   117  * current registration status.
       
   118  * If parsing succeeds then aRegStatus is updated.
       
   119  */
       
   120 	{
       
   121 	ParseBufferLC();
       
   122 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
   123 	CATParamListEntry* entry=iter++;
       
   124 	
       
   125 	// Validate we have +CGREG at the start 
       
   126 	if((entry==NULL) ||(entry->iResultPtr!=KCGREGResponseString))
       
   127 		{
       
   128 		LOCAL_LOGTEXT("ParseResponseL","Failed to find +CGREG:");
       
   129 		User::Leave(KErrNotSupported);
       
   130 		}
       
   131 	
       
   132 	// Read in value
       
   133 	entry=iter++;
       
   134 	if(!entry)
       
   135 		{
       
   136 		LOCAL_LOGTEXT("ParseResponseL","Failed to find 1st parameter");
       
   137 		User::Leave(KErrNotFound);
       
   138 		}		
       
   139 	TInt etsiVal;
       
   140 	CATParamListEntry::EntryValL(entry,etsiVal);
       
   141 
       
   142 	// Convert value to equivalent EtelMM enum
       
   143 	switch(etsiVal)
       
   144 		{
       
   145 	case 0:		// ETSI value as defined in ETSI 07.07 section 10.1.14
       
   146 		aRegStatus=RPacketService::ENotRegisteredNotSearching;
       
   147 		break;
       
   148 	case 1:		// ETSI value as defined in ETSI 07.07 section 10.1.14
       
   149 		aRegStatus=RPacketService::ERegisteredOnHomeNetwork;
       
   150 		break;
       
   151 	case 2:		// ETSI value as defined in ETSI 07.07 section 10.1.14
       
   152 		aRegStatus=RPacketService::ENotRegisteredSearching;
       
   153 		break;
       
   154 	case 3:		// ETSI value as defined in ETSI 07.07 section 10.1.14
       
   155 		aRegStatus=RPacketService::ERegistrationDenied;
       
   156 		break;
       
   157 	case 4:		// ETSI value as defined in ETSI 07.07 section 10.1.14
       
   158 		aRegStatus=RPacketService::EUnknown;
       
   159 		break;
       
   160 	case 5:		// ETSI value as defined in ETSI 07.07 section 10.1.14
       
   161 		aRegStatus=RPacketService::ERegisteredRoaming;
       
   162 		break;
       
   163 	default:
       
   164 		aRegStatus=RPacketService::EUnknown;
       
   165 		break;
       
   166 		}
       
   167 	CleanupStack::PopAndDestroy();	// Pop and destroy the object pushed by ParseBufferLC()
       
   168 	}
       
   169 
       
   170 
       
   171 void CATGprsNtwkRegStatusChange::CompleteWithIOError(TEventSource /*aSource*/,TInt /*aStatus*/)
       
   172 	{
       
   173 	LOCAL_LOGTEXT("CATGprsNtwkRegStatusChange","CompleteWithIOError");
       
   174 	// CATIO removes expect strings in event of IO error so don't do it here
       
   175 	// Also, CATErrorHandler::CleanUp completes notification with error
       
   176 	}
       
   177 
       
   178 
       
   179 
       
   180 
       
   181