telephonyserverplugins/common_tsy/commontsy/src/mmtsy/cmmdtmftsywithdispatcher.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
child 42 3adadc800673
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2008-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 #ifdef USING_CTSY_DISPATCHER
       
    17 
       
    18 /**
       
    19  * This file contains additional function definitions for the CMmDtmfTsy class
       
    20  * in CTSY for use when the CTSY is used with the CTSY Dispatcher.
       
    21  */
       
    22 
       
    23 #include "cmmdtmftsy.h"
       
    24 #include "cmmphonetsy.h"
       
    25 #include "cmmtsyreqhandlestore.h"
       
    26 #include "cmmcalllist.h"
       
    27 #include "cmmcalltsy.h"
       
    28 #include <ctsy/tflogger.h>
       
    29 
       
    30 /**
       
    31  * Starts sending a single DTMF digit.
       
    32  *
       
    33  * This version of StartDTMFToneL sends the call ID of the active call through
       
    34  * which the DTMF digit will be sent and hence relieves the LTSY of the
       
    35  * responsibility to track the call state and to locate the active call.
       
    36  *
       
    37  * @param aTsyReqHandle The TSY request handle.
       
    38  * @param aTone The tone to send.
       
    39  * @return Return value to the ETel Server.
       
    40  */
       
    41 TInt CMmDtmfTsy::StartDTMFToneL(const TTsyReqHandle aTsyReqHandle, TChar* aTone)
       
    42 	{
       
    43 	TFLOGSTRING("TSY: CMmDtmfTsy::StartDTMFToneL");
       
    44 
       
    45     TInt ret = KErrServerBusy;
       
    46 
       
    47     // Check if request handle already exists
       
    48     TTsyReqHandle startDtmftoneHandle =
       
    49         iMmPhone->iTsyReqHandleStore->GetTsyReqHandle(
       
    50             CMmPhoneTsy::EMultimodePhoneStartDTMFTone );
       
    51 
       
    52     if (CMmPhoneTsy::EMultimodePhoneReqHandleUnknown != startDtmftoneHandle)
       
    53         {
       
    54         iMmPhone->ReqCompleted(aTsyReqHandle, ret);
       
    55         }
       
    56     else
       
    57         {
       
    58         // DTMF can only be sent if there is a connected call
       
    59         // The call ID for the first connected call found is returned. If there
       
    60         // isn't an ongoing conference call, there will only be one active call.
       
    61         // If there is a conference call going, the DTMF will be sent using the
       
    62         // call ID of one of the active calls in the conference and will be
       
    63         // sent through to the conference call.
       
    64         TInt callId = -1;
       
    65         if (GetConnectedCallId(callId) != KErrNone)
       
    66         	{
       
    67         	iMmPhone->ReqCompleted(aTsyReqHandle, KErrEtelCallNotActive);
       
    68         	}
       
    69         else
       
    70         	{
       
    71 	        CMmDataPackage dataPackage;
       
    72 	        dataPackage.PackData(&callId, aTone);
       
    73 	        ret = iMmPhone->MessageManager()->HandleRequestL(
       
    74 	            EMobilePhoneStartDTMFTone,
       
    75 	            &dataPackage
       
    76 	            );
       
    77 
       
    78 	        if (ret != KErrNone)
       
    79 	        	{
       
    80 	        	iMmPhone->ReqCompleted(aTsyReqHandle, ret);
       
    81 	        	}
       
    82 	        else
       
    83 	            {
       
    84 	            // Save the type of the DTMF
       
    85 	            iDtmfType = EDtmfTypeDigit;
       
    86 
       
    87 	            iMmPhone->iReqHandleType =
       
    88 	                            CMmPhoneTsy::EMultimodePhoneStartDTMFTone;
       
    89 	            }
       
    90         	}
       
    91         }
       
    92 
       
    93     return KErrNone;
       
    94 	} // CMmDtmfTsy::StartDTMFToneL
       
    95 
       
    96 /**
       
    97  * Stops sending a single DTMF digit.
       
    98  *
       
    99  * @param aTsyReqHandle The TSY request handle.
       
   100  * @return Return value to the ETel Server.
       
   101  */
       
   102 TInt CMmDtmfTsy::StopDTMFToneL(const TTsyReqHandle aTsyReqHandle)
       
   103 	{
       
   104 	TFLOGSTRING("TSY: CMmDtmfTsy::StopDTMFToneL");
       
   105 
       
   106     TInt ret = KErrServerBusy;
       
   107 
       
   108     // Check if request handle already exists
       
   109     TTsyReqHandle stopDtmftoneHandle =
       
   110         iMmPhone->iTsyReqHandleStore->GetTsyReqHandle(
       
   111             CMmPhoneTsy::EMultimodePhoneStopDTMFTone );
       
   112 
       
   113     if ( CMmPhoneTsy::EMultimodePhoneReqHandleUnknown != stopDtmftoneHandle )
       
   114         {
       
   115         iMmPhone->ReqCompleted( aTsyReqHandle, ret );
       
   116         }
       
   117     else
       
   118         {
       
   119         // DTMF can only be stopped if there is a connected call
       
   120         TInt callId = -1;
       
   121         if (GetConnectedCallId(callId) != KErrNone)
       
   122         	{
       
   123         	iMmPhone->ReqCompleted(aTsyReqHandle, KErrEtelCallNotActive);
       
   124         	}
       
   125         else
       
   126         	{
       
   127 	        CMmDataPackage dataPackage;
       
   128 	        dataPackage.PackData(&callId);
       
   129 	        ret = iMmPhone->MessageManager()->HandleRequestL(
       
   130 	            EMobilePhoneStopDTMFTone,
       
   131 	            &dataPackage
       
   132 	            );
       
   133 
       
   134 	        if (ret != KErrNone)
       
   135 	        	{
       
   136 	        	iMmPhone->ReqCompleted(aTsyReqHandle, ret);
       
   137 	        	}
       
   138 	        else
       
   139 	            {
       
   140 	            // Save the type of the DTMF
       
   141 	            iDtmfType = EDtmfTypeDigit;
       
   142 
       
   143 	            iMmPhone->iReqHandleType =
       
   144 	                            CMmPhoneTsy::EMultimodePhoneStopDTMFTone;
       
   145 	            }
       
   146         	}
       
   147         }
       
   148 
       
   149     return KErrNone;
       
   150 	} // CMmDtmfTsy::StopDTMFToneL
       
   151 
       
   152 /**
       
   153  * Complete the Start DTMF Tone request.
       
   154  *
       
   155  * @param aResult Error code from LTSY.
       
   156  */
       
   157 void CMmDtmfTsy::CompleteStartDTMFTone(TInt aResult)
       
   158 	{
       
   159 	TFLOGSTRING2("TSY: CMmDtmfTsy::CompleteStartDTMFTone aResult=%d", aResult);
       
   160 
       
   161     TTsyReqHandle reqHandle
       
   162         = iMmPhone->iTsyReqHandleStore->ResetTsyReqHandle(
       
   163         		CMmPhoneTsy::EMultimodePhoneStartDTMFTone);
       
   164 
       
   165     if (CMmPhoneTsy::EMultimodePhoneReqHandleUnknown != reqHandle)
       
   166         {
       
   167         iMmPhone->ReqCompleted(reqHandle, aResult);
       
   168         }
       
   169 
       
   170 	} // CMmDtmfTsy::CompleteStartDTMFTone
       
   171 
       
   172 /**
       
   173  * Complete the Stop DTMF Tone request.
       
   174  *
       
   175  * @param aResult Error code from LTSY.
       
   176  */
       
   177 void CMmDtmfTsy::CompleteStopDTMFTone(TInt aResult)
       
   178 	{
       
   179 	TFLOGSTRING2("TSY: CMmDtmfTsy::CompleteStopDTMFTone aResult=%d", aResult);
       
   180 
       
   181     TTsyReqHandle reqHandle
       
   182         = iMmPhone->iTsyReqHandleStore->ResetTsyReqHandle(
       
   183         		CMmPhoneTsy::EMultimodePhoneStopDTMFTone);
       
   184 
       
   185     if (CMmPhoneTsy::EMultimodePhoneReqHandleUnknown != reqHandle)
       
   186         {
       
   187         iMmPhone->ReqCompleted(reqHandle, aResult);
       
   188         }
       
   189 
       
   190 	} // CMmDtmfTsy::CompleteStopDTMFTone
       
   191 
       
   192 /**
       
   193  * Send a DTMF string passing down the call ID of the connected call to LTSY.
       
   194  * @param aTsyReqHandle The TSY request handle.
       
   195  * @param aTones
       
   196  * @return
       
   197  */
       
   198 TInt CMmDtmfTsy::SendDTMFTonesL(const TTsyReqHandle aTsyReqHandle, const TDesC* aTones)
       
   199 	{
       
   200 	TFLOGSTRING("TSY: CMmDtmfTsy::SendDTMFTonesL");
       
   201 
       
   202     TTsyReqHandle sendDTMFTonesHandle = iMmPhone->iTsyReqHandleStore
       
   203         ->GetTsyReqHandle(CMmPhoneTsy::EMultimodePhoneSendDTMFTones);
       
   204 
       
   205     if (CMmPhoneTsy::EMultimodePhoneReqHandleUnknown == sendDTMFTonesHandle)
       
   206         {
       
   207         // DTMF can only be sent if there is a connected call
       
   208         TInt callId = -1;
       
   209         if (GetConnectedCallId(callId) != KErrNone)
       
   210         	{
       
   211         	iMmPhone->ReqCompleted(aTsyReqHandle, KErrEtelCallNotActive);
       
   212         	}
       
   213         else
       
   214         	{
       
   215 	        CMmDataPackage dataPackage;
       
   216 	        dataPackage.PackData(&callId, const_cast<TDesC*>(aTones));
       
   217 	        TInt ret = iMmPhone->MessageManager()->HandleRequestL(
       
   218 	            EMobilePhoneSendDTMFTones,
       
   219 	            &dataPackage
       
   220 	            );
       
   221 
       
   222 	        if (ret != KErrNone)
       
   223 	            {
       
   224 	            // DTMF string sending has failed
       
   225 	            iMmPhone->ReqCompleted(aTsyReqHandle, ret);
       
   226 	            }
       
   227 	        else
       
   228 	            {
       
   229     	        iDtmfType = EDtmfTypeString;
       
   230 	            iMmPhone->iReqHandleType = CMmPhoneTsy::EMultimodePhoneSendDTMFTones;
       
   231 	            }
       
   232         	}
       
   233         } // if (CMmPhoneTsy::EMultimodePhoneReqHandleUnknown == sendDTMFTonesHandle)
       
   234     else
       
   235     	{
       
   236     	iMmPhone->ReqCompleted(aTsyReqHandle, KErrServerBusy);
       
   237     	}
       
   238 
       
   239     return KErrNone;
       
   240 	} // CMmDtmfTsy::SendDTMFTonesL
       
   241 
       
   242 /**
       
   243  * Locate an active voice call.
       
   244  *
       
   245  * @param aCallId The call ID of an active call, if there is one.
       
   246  * @return KErrNone if it finds an active call, KErrNotFound otherwise.
       
   247  */
       
   248 TInt CMmDtmfTsy::GetConnectedCallId(TInt& aCallId)
       
   249 	{
       
   250 	CMmCallTsy* mmCall = iMmPhone->CallList()->GetMmCallByStatus(RMobileCall::EStatusConnected);
       
   251 
       
   252 	if (mmCall)
       
   253 		{
       
   254 		aCallId = mmCall->CallId();
       
   255 		return KErrNone;
       
   256 		}
       
   257 	else
       
   258 		{
       
   259 		return KErrNotFound;
       
   260 		}
       
   261 
       
   262 	} // CMmDtmfTsy::GetConnectedCallId
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CMmDtmfTsy::Complete
       
   266 // Completes the request due timer expiration. Adds a timeout for start
       
   267 // and stop of DTMF.
       
   268 // (other items were commented in a header).
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void CMmDtmfTsy::Complete(TInt aReqHandleType, TInt)
       
   272     {
       
   273     switch (aReqHandleType)
       
   274         {
       
   275         case CMmPhoneTsy::EMultimodePhoneSendDTMFTones:
       
   276             CompleteSendDTMFTones(KErrTimedOut);
       
   277             break;
       
   278         case CMmPhoneTsy::EMultimodePhoneStartDTMFTone:
       
   279         	CompleteStartDTMFTone(KErrTimedOut);
       
   280         	break;
       
   281         case CMmPhoneTsy::EMultimodePhoneStopDTMFTone:
       
   282         	CompleteStopDTMFTone(KErrTimedOut);
       
   283         	break;
       
   284         default:
       
   285             // Ignore
       
   286             break;
       
   287         }
       
   288     } // CMmDtmfTsy::Complete
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // CMmDtmfTsy::SendDTMFTonesCancelL
       
   292 // Cancels DTMF tone sending passing down the call ID.
       
   293 // (other items were commented in a header).
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 TInt CMmDtmfTsy::SendDTMFTonesCancelL()
       
   297     {
       
   298 TFLOGSTRING("TSY: CMmDtmfTsy::SendDTMFTonesCancel");
       
   299 
       
   300     TTsyReqHandle sendDTMFTonesHandle =
       
   301         iMmPhone->iTsyReqHandleStore->GetTsyReqHandle(
       
   302             CMmPhoneTsy::EMultimodePhoneSendDTMFTones );
       
   303 
       
   304     // There must be a pending Send to cancel
       
   305     if (CMmPhoneTsy::EMultimodePhoneReqHandleUnknown != sendDTMFTonesHandle)
       
   306         {
       
   307 		TInt callId = -1;
       
   308 
       
   309 		// There needs to be a connected call to send the cancel through
       
   310 		// If there isn't do nothing
       
   311 		if (GetConnectedCallId(callId) == KErrNone)
       
   312 			{
       
   313 			// no packed parameter for DOS call
       
   314 			CMmDataPackage dataPackage;
       
   315 			dataPackage.PackData(&callId);
       
   316 			TInt ret = iMmPhone->MessageManager()->HandleRequestL(
       
   317 					EMobilePhoneSendDTMFTonesCancel,
       
   318 					&dataPackage);
       
   319 
       
   320 			if ( KErrNone == ret )
       
   321 				{
       
   322 				// Set the DTMFTonesCancelFlag
       
   323 				iSendDTMFTonesCancelFlag = ETrue;
       
   324 				}
       
   325 			}
       
   326         }
       
   327 
       
   328     return KErrNone;
       
   329 	}
       
   330 
       
   331 #endif // USING_CTSY_DISPATCHER
       
   332