multimediacommsengine/mmcesrv/mmcemediamanager/src/mcedtmfhandler.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mcedtmfhandler.h"
       
    22 #include "mcemmlogs.h"
       
    23 #include "mceevents.h"
       
    24 #include "mcesrvstream.h"
       
    25 #include "mcesrvsource.h"
       
    26 #include "mcecomsession.h"
       
    27 #include "mcecommediasource.h"
       
    28 #include "mcesrvstreamiterator.h"
       
    29 #include <mmccinterface.h>
       
    30 
       
    31 const TInt KMceDtmfToneMaxLen = 2;
       
    32 MCEIDS_DEFINE_SPARE_INDEX_1( KMceDtmfToneIndex );
       
    33 MCEIDS_DEFINE_SPARE_INDEX_2( KMceDtmfToneDurationIndex );
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CMceDtmfHandler::NewL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMceDtmfHandler* CMceDtmfHandler::NewL( 
       
    42     CMceSrvStream& aStream, 
       
    43     CMccInterface& aMccInterface )
       
    44     {
       
    45     CMceDtmfHandler* self = 
       
    46         new ( ELeave ) CMceDtmfHandler( aStream, aMccInterface );       
       
    47     return self;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMceDtmfHandler::DtmfL
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CMceDtmfHandler::DtmfL( 
       
    55     CMceComMediaSource& aSource,
       
    56     TMceComEvent& aEvent,
       
    57     const TDesC8& aSequence )
       
    58     {
       
    59     MCEMM_DEBUG( "CMceDtmfHandler::DtmfL, Entry" )
       
    60      
       
    61     // Store source and stream ids, since multiple sources can use the same
       
    62     // dtmf stream.Received dtmf events will be routed to last one who has
       
    63     // used the stream.
       
    64 
       
    65     TMceSrvStreamIterator streams( aSource.MediaStream()->Session()->MccStreams(), 
       
    66                                    *aSource.MediaStream() );
       
    67     CMceSrvStream* stream = NULL;
       
    68     __ASSERT_ALWAYS( streams.Next( stream ), User::Leave( KErrNotSupported ) );
       
    69     iCurrentUserStreamId = stream->Id();
       
    70     iCurrentUserSourceId = stream->Source().Id();
       
    71     
       
    72     MCEMM_DEBUG_DVALUE( "CMceDtmfHandler::DtmfL, current streamId", 
       
    73                         iCurrentUserStreamId )
       
    74     MCEMM_DEBUG_DVALUE( "CMceDtmfHandler::DtmfL, current sourceId", 
       
    75                         iCurrentUserSourceId )
       
    76     
       
    77     TMceIds& ids = aEvent.Id();
       
    78     
       
    79     switch( aEvent.Action() )
       
    80         {
       
    81         case EMceItcIsDtmfActive:
       
    82             {
       
    83             ids.iSpare1 = IsDtmfActive();
       
    84             break;
       
    85             }
       
    86         case EMceItcStartDtmfTone:
       
    87             {
       
    88             TBuf8<KMceDtmfToneMaxLen> tone;
       
    89             tone.Append( static_cast<TChar>( ids.Get( KMceDtmfToneIndex ) ) );
       
    90             SendDtmfStringL( KMccDtmfSigStartTone, tone );
       
    91             SetDtmfActive( ETrue );
       
    92             break;
       
    93             }
       
    94         case EMceItcStopDtmfTone:
       
    95             {
       
    96             StopDtmfL();
       
    97             break;
       
    98             }
       
    99         case EMceItcSendDtmfTone:
       
   100             {
       
   101             TUint32 duration = ids.Get( KMceDtmfToneDurationIndex );
       
   102             TMccDtmfEventType eventType = 
       
   103                 ( duration > 0 ) ? KMccDtmfSigStartTone : KMccDtmfSigSendString;
       
   104             TBuf8<KMceDtmfToneMaxLen> tone;
       
   105             tone.Append( static_cast<TChar>( ids.Get( KMceDtmfToneIndex ) ) );
       
   106             SendDtmfStringL( eventType, 
       
   107                              tone, 
       
   108                              duration );
       
   109             break;
       
   110             }
       
   111         case EMceItcSendDtmfToneSequence:
       
   112             {
       
   113             __ASSERT_ALWAYS( aSequence.Length() > 0, User::Leave( KErrArgument ) );
       
   114             SendDtmfStringL( KMccDtmfSigSendString, aSequence );
       
   115             break;
       
   116             }
       
   117         case EMceItcCancelSendDtmfToneSequence:
       
   118             {
       
   119             // Will need checking if some other actions need to be taken here.
       
   120             SendDtmfStringL( KMccDtmfSigCancelSending );
       
   121             break;
       
   122             }
       
   123         default:
       
   124             {
       
   125             break;
       
   126             }
       
   127         }
       
   128     
       
   129     MCEMM_DEBUG( "CMceDtmfHandler::DtmfL, Exit" )
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CMceDtmfHandler::DtmfReceivedL
       
   134 // -----------------------------------------------------------------------------
       
   135 //    
       
   136 void CMceDtmfHandler::DtmfReceivedL( 
       
   137     const TMccEvent& aMccEvent, 
       
   138     TMceMccComEvent& aEvent )
       
   139     {
       
   140     const TMccDtmfEventData& dtmfEvent = 
       
   141                     (*reinterpret_cast<const TMccDtmfEventDataPackage*>( 
       
   142                         &aMccEvent.iEventData ))();
       
   143     
       
   144     if ( dtmfEvent.iDtmfEventType == KMccDtmfSequenceStop )
       
   145         {
       
   146         // This event can be ignored, it just means that one tone of the
       
   147         // seuence was completed, KMccDtmfSendingComplete will tell that
       
   148         // whole sequence was completed (client will receive as many started
       
   149         // events as there is tones but only one completed event).
       
   150         aEvent.iEvent = KMccEventNone;
       
   151         }
       
   152     else
       
   153         {
       
   154         aEvent.iEventSubType = dtmfEvent.iDtmfEventType;
       
   155         aEvent.iStreamId = iCurrentUserStreamId;
       
   156         aEvent.iEndpointId = iCurrentUserSourceId;
       
   157         
       
   158         if ( aEvent.iEventSubType == KMccDtmfManualAbort ||
       
   159              aEvent.iEventSubType == KMccDtmfSequenceAbort )
       
   160             {
       
   161             // Error occured, no need to send stop dtmf event
       
   162             SetDtmfActive( EFalse );
       
   163             Cancel();
       
   164             }
       
   165                
       
   166         MCEMM_DEBUG_DVALUE( "CMceDtmfHandler::DtmfReceivedL, subtype:", aEvent.iEventSubType )
       
   167         }
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CMceDtmfHandler::RunL
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CMceDtmfHandler::RunL()
       
   175     {
       
   176     MCEMM_DEBUG( "CMceDtmfHandler::RunL, tone expired" )
       
   177     StopDtmfL();
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CMceDtmfHandler::DoCancel
       
   182 // -----------------------------------------------------------------------------
       
   183 //    
       
   184 void CMceDtmfHandler::DoCancel()
       
   185     {
       
   186     MCEMM_DEBUG( "CMceDtmfHandler::DoCancel, stopping dtmf sending" )
       
   187     iTimer.Cancel();
       
   188     if ( IsDtmfActive() )
       
   189         {
       
   190         SetDtmfActive( EFalse );
       
   191         TRAP_IGNORE( SendDtmfStringL( KMccDtmfSigStopTone ) )
       
   192         }
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CMceDtmfHandler::RunError
       
   197 // -----------------------------------------------------------------------------
       
   198 //     
       
   199 TInt CMceDtmfHandler::RunError( TInt aError )
       
   200     {
       
   201     MCEMM_DEBUG_DVALUE( "CMceDtmfHandler::RunError, error:", aError )
       
   202     if ( aError != KErrNoMemory )
       
   203         {
       
   204         aError = KErrNone;
       
   205         }
       
   206     return aError;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CMceDtmfHandler::SendDtmfStringL
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CMceDtmfHandler::SendDtmfStringL( 
       
   214     TMccDtmfEventType aDtmfEventType, 
       
   215     const TDesC8& aDtmfString,
       
   216     TUint32 aDurationInMicroSecs )
       
   217     {
       
   218     MCEMM_DEBUG_DVALUE( "CMceDtmfHandler::SendDtmfString, type:", aDtmfEventType )
       
   219     MCEMM_DEBUG_SVALUE( "CMceDtmfHandler::SendDtmfString, string:", aDtmfString )
       
   220     
       
   221     __ASSERT_ALWAYS( aDtmfString.Length() <= KMccMaxDtmfStringLength,
       
   222                      User::Leave( KErrArgument ) );
       
   223     __ASSERT_ALWAYS( !IsDtmfActive(), User::Leave( KErrInUse ) );
       
   224     
       
   225     TMccEvent* event = new ( ELeave ) TMccEvent;
       
   226     CleanupStack::PushL( event );
       
   227     
       
   228     event->iEventCategory = KMccEventCategoryDtmf;
       
   229     event->iEventType = KMccDtmfControl;
       
   230     event->iSessionId = iStream.SessionId();
       
   231     event->iLinkId = iStream.LinkId();
       
   232     event->iStreamId = iStream.Id();
       
   233     
       
   234     {       
       
   235     TMccDtmfEventData eventData;
       
   236     eventData.iDtmfEventType = aDtmfEventType;
       
   237     eventData.iDtmfString.Copy( aDtmfString );
       
   238     TMccDtmfEventDataPackage eventDataBuf( eventData );
       
   239     event->iEventData.Copy( eventDataBuf );
       
   240     }
       
   241     
       
   242     iMccInterface.SendMediaSignalL( *event );
       
   243     
       
   244     CleanupStack::PopAndDestroy( event );
       
   245     
       
   246     if ( aDurationInMicroSecs > 0 )
       
   247         {
       
   248         MCEMM_DEBUG( "CMceDtmfHandler::SendDtmfString, activate stop timer" )
       
   249         iTimer.After( iStatus, TTimeIntervalMicroSeconds32( aDurationInMicroSecs ) );
       
   250         SetActive();
       
   251         SetDtmfActive( ETrue );  
       
   252         }
       
   253     
       
   254     MCEMM_DEBUG( "CMceDtmfHandler::SendDtmfString, Exit" )
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CMceDtmfHandler::StopDtmfL
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void CMceDtmfHandler::StopDtmfL()
       
   262     {
       
   263     MCEMM_DEBUG( "CMceDtmfHandler::StopDtmfL" )
       
   264     
       
   265     Cancel();
       
   266     
       
   267     if ( IsDtmfActive() )
       
   268         {
       
   269         MCEMM_DEBUG( "CMceDtmfHandler::StopDtmfL, stopping dtmf sending" )
       
   270         
       
   271         SetDtmfActive( EFalse );
       
   272         SendDtmfStringL( KMccDtmfSigStopTone );
       
   273         } 
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CMceDtmfHandler::SetDtmfActive
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CMceDtmfHandler::SetDtmfActive( TBool aIsActive )
       
   281     {
       
   282     iSendingDtmf = aIsActive;
       
   283     }
       
   284     
       
   285 // -----------------------------------------------------------------------------
       
   286 // CMceDtmfHandler::IsDtmfActive
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 TBool CMceDtmfHandler::IsDtmfActive() const
       
   290     {
       
   291     return iSendingDtmf;
       
   292     }
       
   293     
       
   294 // -----------------------------------------------------------------------------
       
   295 // CMceDtmfHandler::~CMceDtmfHandler
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 CMceDtmfHandler::~CMceDtmfHandler()
       
   299     {
       
   300     MCEMM_DEBUG( "CMceDtmfHandler::~CMceDtmfHandler, Entry" )
       
   301     TRAP_IGNORE( StopDtmfL() );
       
   302     iTimer.Close();
       
   303     MCEMM_DEBUG( "CMceDtmfHandler::~CMceDtmfHandler, Exit" )
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CMceDtmfHandler::CMceDtmfHandler
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 CMceDtmfHandler::CMceDtmfHandler( 
       
   311     CMceSrvStream& aStream, 
       
   312     CMccInterface& aMccInterface ) : 
       
   313     CActive( EPriorityStandard ),
       
   314     iStream( aStream ),
       
   315     iMccInterface( aMccInterface )
       
   316     {
       
   317     CActiveScheduler::Add( this );
       
   318     
       
   319     iTimer.CreateLocal();
       
   320     }
       
   321     
       
   322 // End of file
       
   323