datacommsserver/networkcontroller/src/asynwrap.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2003-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 /**
       
    17  @file ASYNWRAP.CPP
       
    18 */
       
    19 
       
    20 #include "asynwrap.h"
       
    21 
       
    22 CASyncEtelRequestWrapper* CASyncEtelRequestWrapper::NewL(MAsyncRequestsObserver* aObserver)
       
    23 /**
       
    24 This function is constructing an object of class CASyncEtelRequestWrapper,pushing it to the cleanup stack
       
    25 and popping it back.
       
    26 
       
    27 @param aObserver,a pointer to class MAsyncRequestsObserver to register the asyncronous requests
       
    28 @return self, make asyncronous requests synchronous whilst not blocking the thread and thus allowing other 
       
    29 active objects to run as normal
       
    30 */
       
    31 	{
       
    32 	CASyncEtelRequestWrapper* self = new (ELeave) CASyncEtelRequestWrapper();
       
    33 	CleanupStack::PushL(self);
       
    34 	self->iObserver = aObserver;
       
    35 	self->ConstructL();
       
    36 	CleanupStack::Pop();
       
    37 	return self;
       
    38 	}
       
    39 
       
    40 CASyncEtelRequestWrapper::CASyncEtelRequestWrapper()
       
    41 	: CActive(CActive::EPriorityStandard)
       
    42 	{
       
    43 	CActiveScheduler::Add(this);
       
    44 	}
       
    45 
       
    46 void CASyncEtelRequestWrapper::ConstructL()
       
    47 	{
       
    48 	iAsyncRequestState = ENoRequests;
       
    49 	iAsyncRequestData.iETelAsynError.iError = KErrNone;
       
    50 	iAsyncRequestData.iETelAsynError.iFailedRequest = 0x00;
       
    51 	iAsyncRequestData.iMSClass = RPacketService::EMSClassUnknown;
       
    52 	iAsyncRequestData.iRegistrationStatus = RPacketService::ENotRegisteredNotSearching;
       
    53 	}
       
    54 
       
    55 CASyncEtelRequestWrapper::~CASyncEtelRequestWrapper()
       
    56 /**
       
    57 Destructor
       
    58 */
       
    59 	{
       
    60 	Cancel();
       
    61 	iPacket.Close();
       
    62 	}
       
    63 
       
    64 void CASyncEtelRequestWrapper::StartAsyncRequests(RTelServer&, RMobilePhone& aMmPhone)
       
    65 /**
       
    66 Pass the object on which the request was made and the request id - 
       
    67 this is needed to cancel the request if necessary
       
    68 
       
    69 @param aTelServer, establish a root telephony server session.
       
    70 @param aMmPhone, encapsulates access to a mobile phone
       
    71 */
       
    72 	{
       
    73 	// Open PacketService
       
    74 	TInt ret = iPacket.Open(aMmPhone);
       
    75 	if(ret == KErrNone)
       
    76 		{
       
    77 		// The first request to be made is GetMSClass from packet session
       
    78 		iAsyncRequestState = EGetMSClass;
       
    79 		iReqToCancel = EPacketGetMSClass;
       
    80 		iPacket.GetMSClass(iStatus,iAsyncRequestData.iMSClass,iMaxMSClass);
       
    81 		// Set active and start to wait for the request response
       
    82 		if(!IsActive())
       
    83 			SetActive();
       
    84 		}
       
    85 	// Error, complete to the observer
       
    86 	else
       
    87 		{
       
    88 		// Save the error into iError and pass it to GenConn
       
    89 		iAsyncRequestData.iETelAsynError.iError = ret;
       
    90 		iAsyncRequestData.iETelAsynError.iFailedRequest = 0x00;
       
    91 		iObserver->ETelAsyncRequestsComplete(iAsyncRequestData);
       
    92 		}
       
    93 	}
       
    94 
       
    95 void CASyncEtelRequestWrapper::DoCancel()
       
    96 	{
       
    97 	// If the state is not ENoRequests, then we are requesting 
       
    98 	// something from ETel
       
    99 	if(iAsyncRequestState != ENoRequests)
       
   100 		{
       
   101 		// Cancel the current packet service request, it is saved
       
   102 		// in the iReqToCancel member. 
       
   103 		iPacket.CancelAsyncRequest(iReqToCancel);
       
   104 		}
       
   105 
       
   106 	iAsyncRequestState = ENoRequests;
       
   107 	iAsyncRequestData.iMSClass = RPacketService::EMSClassUnknown;
       
   108 	iAsyncRequestData.iRegistrationStatus = RPacketService::ENotRegisteredNotSearching;
       
   109 	}
       
   110 
       
   111 void CASyncEtelRequestWrapper::RunL()
       
   112 	{
       
   113 	if(iStatus != KRequestPending)
       
   114 		{
       
   115 		TInt err = iStatus.Int();
       
   116 		// If the request was not cancelled, start requesting the next one
       
   117 		if(err!=KErrCancel)
       
   118 			{
       
   119 			// MSClass information received
       
   120 			if(iAsyncRequestState == EGetMSClass)
       
   121 				{
       
   122 				// If error is not KErrNone and KErrNotSupported, then this state failed. 
       
   123 				// Save the error and report it to GenConn when the last state is handled.
       
   124 				if(err!=KErrNone && err!= KErrNotSupported)
       
   125 					{
       
   126 					iAsyncRequestData.iETelAsynError.iError = err;
       
   127 					iAsyncRequestData.iETelAsynError.iFailedRequest = EPacketGetMSClass;
       
   128 					}
       
   129 				// Get current network registration status
       
   130 				iAsyncRequestState = EGetNwRegStatus;
       
   131 				iReqToCancel = EPacketGetNtwkRegStatus;
       
   132 				iAsyncRequestData.iRegistrationStatus = RPacketService::EUnknown;
       
   133 				iPacket.GetNtwkRegStatus(iStatus, iAsyncRequestData.iRegistrationStatus);
       
   134 				// Start the next request
       
   135 				if(!IsActive())
       
   136 					{
       
   137 					SetActive();
       
   138 					}
       
   139 				}
       
   140 			else if(iAsyncRequestState == EGetNwRegStatus)
       
   141 				{
       
   142 				// If error is not KErrNone and KErrNotSupported, then this state failed. 
       
   143 				// Save the error and report it to GenConn when the last state is handled.
       
   144 				if(err!=KErrNone && err!= KErrNotSupported)
       
   145 					{
       
   146 					iAsyncRequestData.iETelAsynError.iError = err;
       
   147 					iAsyncRequestData.iETelAsynError.iFailedRequest = EPacketGetNtwkRegStatus;
       
   148 					}
       
   149 				// This is the last request
       
   150 				iAsyncRequestState = ENoRequests;
       
   151 				// All done, move the data to observer
       
   152 				iObserver->ETelAsyncRequestsComplete(iAsyncRequestData);
       
   153 				}
       
   154 			else
       
   155 				{
       
   156 				// When there is going to be more requests, add them here.
       
   157 				iAsyncRequestState = ENoRequests;
       
   158 				}
       
   159 			}
       
   160 		}
       
   161 	}
       
   162