telephonyutils/etel3rdpartyapi/src/TelephonyActLine.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 /*
       
     2 * Copyright (c) 2009 Sony Ericsson Mobile Communications AB
       
     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 * Sony Ericsson Mobile Communications AB - initial contribution.
       
    11 * Nokia Corporation - additional changes.
       
    12 * 
       
    13 * Contributors:
       
    14 * 
       
    15 * Description:
       
    16 * Code for TelephonyActPhone class, used by CTelephonyFunctions class.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "TelephonyFunctions.h"
       
    26 #include "TelephonyActLine.h"
       
    27 #include "TelephonyActCall.h"
       
    28 
       
    29 /**
       
    30 Public constructor which can Leave().
       
    31 
       
    32 @param	aTelephonyFunctions Object that constructs this object.
       
    33 @param  aIncomingCallNameSubject Reference to an active object owned by CTelephonyFunctions which implements the MIncomingCallNameSubject interface. Used by this object to reset the call name when the line is no longer ringing.
       
    34 @leave	Leaves if no memory.
       
    35 @return Pointer to the newly created CNotifyLineStatusAct object.
       
    36 */
       
    37 CNotifyLineStatusAct* CNotifyLineStatusAct::NewL(CTelephonyFunctions* aTelephonyFunctions, CTelephonyFunctions::TOperations aPendingOperation, MIncomingCallNameSubject& aIncomingCallNameSubject)
       
    38 	{
       
    39 	CNotifyLineStatusAct* self = new(ELeave) CNotifyLineStatusAct(aTelephonyFunctions, aPendingOperation, aIncomingCallNameSubject);
       
    40 	CActiveScheduler::Add(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 /**
       
    45 Default destructor.
       
    46 */
       
    47 CNotifyLineStatusAct::~CNotifyLineStatusAct()
       
    48 	{
       
    49 	iState = ENotifyLineStatusActCleanUp;
       
    50 	Cancel();
       
    51 	Complete();
       
    52 	}
       
    53 
       
    54 /**
       
    55 Issue Request.
       
    56 
       
    57 The request for notification of line status can be either an internal
       
    58 request or an external one.
       
    59 
       
    60 1. Internal Request
       
    61 An internal request can either come from the CTelephonyFunctions
       
    62 object that owns this AO when it is initialised or from this AO
       
    63 itself when the line status change event has completed and the
       
    64 request is reposted. For internal requests, the aLineStatus pointer
       
    65 is NULL.
       
    66 
       
    67 2. External Request
       
    68 An external request is one from a client using the CTelephony 3rd
       
    69 Party API. In external requests, the aLineStatus parameter points
       
    70 to a TCallStatusV1 object specified by the client to store the
       
    71 resulting line status.
       
    72 
       
    73 @param aLineStatus Package descriptor containing TCallStatus object which will hold the resulting line status.
       
    74 */
       
    75 void CNotifyLineStatusAct::NotifyLineStatus(TDes8* aLineStatus)
       
    76 	{
       
    77 	// aLineStatus is NULL except when a client is interested
       
    78 	// in the line status change.
       
    79 	if(aLineStatus)
       
    80 		{
       
    81 		iLineStatusRequestedByClient = ETrue;
       
    82 		__ASSERT_DEBUG(iISVCallStatus==NULL, User::Invariant());
       
    83 		iISVCallStatus = reinterpret_cast<CTelephony::TCallStatusV1*> ( const_cast<TUint8*> (aLineStatus->Ptr()));
       
    84 		}
       
    85 
       
    86 	// At present only voice supported
       
    87 	if(!IsActive())
       
    88 		{
       
    89 		iTelephonyFunctions->Line(CTelephony::EVoiceLine)->NotifyMobileLineStatusChange(iStatus,iMMCallStatus);
       
    90 		SetActive();
       
    91 		}
       
    92 	}
       
    93 
       
    94 /**
       
    95 Called from CTelephonyFunctions::CancelAsync() to
       
    96 notify this AO that the client is no longer interested in
       
    97 the line status change.
       
    98 Resets the iLineStatusRequestedByClient flag because client
       
    99 is no longer interested in the line status change, however,
       
   100 the AO still continues to monitor for the line status change
       
   101 for notifications of an incoming call.
       
   102 */
       
   103 void CNotifyLineStatusAct::CancelFromClient()
       
   104 	{
       
   105 	iLineStatusRequestedByClient = EFalse;
       
   106 	iISVCallStatus = NULL;
       
   107 	if(iTelephonyFunctions->IsRequestPending(iPendingOperation))
       
   108 		{
       
   109 		iTelephonyFunctions->CompleteRequest(iPendingOperation, KErrCancel);
       
   110 		}
       
   111 	}
       
   112 
       
   113 /**
       
   114 Service completed request.
       
   115 
       
   116 This method copies the resulting line status change back to the
       
   117 TCallStatusV1 variable supplied by the client and completes the
       
   118 request back to the client if the client requested
       
   119 notification of line status changes.
       
   120 
       
   121 If the line is not ringing, then there is no incoming call and
       
   122 the call name stored in the MIncomingCallNameSubject object
       
   123 is reset. This prevents an old call from being answered.
       
   124 
       
   125 The iLineStatusRequestedByClient flag is reset and the request
       
   126 to listen for line status changes is then reposted except on
       
   127 object destruction.
       
   128 */
       
   129 void CNotifyLineStatusAct::Complete()
       
   130 	{
       
   131 	if(iStatus==KErrNone)
       
   132 		{
       
   133 
       
   134 		// If a client is interested in the line status change
       
   135 		// (i.e. the  iLineStatusRequestedByClient flag is set),
       
   136 		// the resulting line status change is copied back to the
       
   137 		// parameter supplied by the client.
       
   138 		if(iLineStatusRequestedByClient && iISVCallStatus)
       
   139 			{
       
   140 			CTelephonyFunctions::GetCallStatus(iMMCallStatus, iISVCallStatus->iStatus);
       
   141 			}
       
   142 
       
   143 		// Reset the call name if the line is no longer ringing.
       
   144 		// This will ensure that the CAnswerIncomingCallAct AO will
       
   145 		// only answer an incoming call when the notification of an
       
   146 		// incoming call has been received
       
   147 		// (CNotifyIncomingCallAct has completed) and will
       
   148 		// also prevent CAnswerIncomingCallAct from attempting to
       
   149 		// open an incoming call using an old call name.
       
   150 		if (iMMCallStatus != RMobileCall::EStatusRinging)
       
   151 			{
       
   152 			iIncomingCallNameSubject.ResetCallName();
       
   153 			}
       
   154 		}
       
   155 
       
   156 	if(iTelephonyFunctions->IsRequestPending(iPendingOperation))
       
   157 		{
       
   158 		iTelephonyFunctions->CompleteRequest(iPendingOperation, iStatus.Int());
       
   159 		}
       
   160 
       
   161     // Reset iISVCallStatus to NULL since we don't need the pointer anymore
       
   162 	iISVCallStatus = NULL;
       
   163 	iLineStatusRequestedByClient = EFalse;
       
   164 
       
   165 	// This object continuously listens for line status changes.
       
   166 	// The request is only ever cancelled on object destruction,
       
   167 	// do not repost the request in this case.
       
   168 	if ((iStatus!=KRequestPending) && (iStatus != KErrCancel) && (iState != ENotifyLineStatusActCleanUp))
       
   169 		{
       
   170 		NotifyLineStatus(NULL);
       
   171 		}
       
   172 	}
       
   173 
       
   174 
       
   175 /**
       
   176 Handle any Leave() from inside RunL().
       
   177 
       
   178 @param	aLeaveCode	passed in if RunL Leaves.
       
   179 @return	KErrNone.
       
   180 */
       
   181 TInt CNotifyLineStatusAct::RunError(TInt aLeaveCode)
       
   182 	{
       
   183 	if(iTelephonyFunctions->IsRequestPending(iPendingOperation))
       
   184 		{
       
   185 		iTelephonyFunctions->CompleteRequest(iPendingOperation, aLeaveCode);
       
   186 		}
       
   187 	iLineStatusRequestedByClient = EFalse;
       
   188     iISVCallStatus = NULL;
       
   189 	return KErrNone;
       
   190 	}
       
   191 
       
   192 /**
       
   193 Cancel request.
       
   194 
       
   195 Async request to be notified of line status changes is cancelled.
       
   196 */
       
   197 void CNotifyLineStatusAct::DoCancel()
       
   198 	{
       
   199 	iTelephonyFunctions->Line(CTelephony::EVoiceLine)->CancelAsyncRequest(EMobileLineNotifyMobileLineStatusChange);
       
   200 	iLineStatusRequestedByClient = EFalse;
       
   201     iISVCallStatus = NULL;
       
   202 	}
       
   203 
       
   204 
       
   205 /**
       
   206 First-phase constructor which cannot Leave().
       
   207 
       
   208 @param  aTelephonyFunctions object that constructs this object.
       
   209 @param  aPendingOperation The pending operation.
       
   210 @param  aIncomingCallNameSubject Reference to an active object owned by CTelephonyFunctions which implements the MIncomingCallNameSubject interface. Used by this object to reset the call name when the line is no longer ringing.
       
   211 */
       
   212 CNotifyLineStatusAct::CNotifyLineStatusAct(CTelephonyFunctions* aTelephonyFunctions, CTelephonyFunctions::TOperations aPendingOperation, MIncomingCallNameSubject& aIncomingCallNameSubject)
       
   213 : CAsyncRequestBaseAct(),
       
   214   iTelephonyFunctions(aTelephonyFunctions),
       
   215   iISVCallStatus(NULL),
       
   216   iPendingOperation(aPendingOperation),
       
   217   iIncomingCallNameSubject(aIncomingCallNameSubject),
       
   218   iLineStatusRequestedByClient(EFalse),
       
   219   iState(ENotifyLineStatusActOperating)
       
   220 	{
       
   221 	}