convergedcallengine/csplugin/src/cspdtmfprovider.cpp
branchRCL_3
changeset 20 987c9837762f
parent 0 ff3b6d0fd310
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Contains the implementation of class CSPDTMFProvider
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <etelmm.h>
       
    20 #include <mccpdtmfprovider.h>
       
    21 #include <mccpdtmfobserver.h>
       
    22 #include <rmmcustomapi.h>
       
    23 
       
    24 #include "cspdtmfprovider.h"
       
    25 #include "csplogger.h"
       
    26 #include "cspeteldtmfmonitor.h"
       
    27 #include "cspeteldtmfstopmonitor.h"
       
    28 
       
    29 CSPDTMFProvider* CSPDTMFProvider::NewL( RMobilePhone& aPhone,
       
    30                                         RMmCustomAPI& aMmCustom )
       
    31     {
       
    32     CSPDTMFProvider* self = new ( ELeave ) CSPDTMFProvider( aPhone,
       
    33                                                             aMmCustom );
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL( );
       
    36     CleanupStack::Pop( self );
       
    37     return self;
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Destructor of the object.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CSPDTMFProvider::~CSPDTMFProvider( )
       
    45     {
       
    46     CSPLOGSTRING(CSPOBJECT, "CSPDTMFProvider::~CSPDTMFProvider()" );
       
    47     Cancel();
       
    48     iObservers.Close();
       
    49     delete iMonitor;
       
    50     delete iStopMonitor;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Notifies observers about a DTMF event
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CSPDTMFProvider::NotifyDTMFEvent( const MCCPDTMFObserver::TCCPDtmfEvent aEvent,
       
    58                       const TInt aError,
       
    59                       const TChar aTone )
       
    60     {
       
    61     CSPLOGSTRING2(CSPINT, "CSPDTMFProvider::NotifyDTMFEvent %d", aEvent );
       
    62     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
    63         {
       
    64         MCCPDTMFObserver *obs = iObservers[i];
       
    65         if ( obs )
       
    66             {        
       
    67             iObservers[i]->HandleDTMFEvent( aEvent, aError, aTone );
       
    68             }
       
    69         }    
       
    70     }
       
    71 
       
    72     
       
    73 // ---------------------------------------------------------------------------
       
    74 // Cancel DTMF string sending
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 TInt CSPDTMFProvider::CancelDtmfStringSending()
       
    78     {
       
    79     CSPLOGSTRING(CSPREQIN, "CSPDTMFProvider::CancelDtmfStringSending" );
       
    80     if ( IsActive() )
       
    81         {
       
    82         Cancel();
       
    83         }
       
    84     else
       
    85         {
       
    86         return KErrAlreadyExists; // Is not active
       
    87         }
       
    88     
       
    89     return KErrNone;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // Starts DTMF string sending
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 TInt CSPDTMFProvider::StartDtmfTone( const TChar aTone )
       
    97     {
       
    98     CSPLOGSTRING(CSPREQIN, "CSPDTMFProvider::StartDtmfTone" );
       
    99     TInt ret(KErrAlreadyExists);
       
   100     if (!IsActive())
       
   101         {
       
   102         ret = iPhone.StartDTMFTone( aTone );
       
   103         }    
       
   104     return ret;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // Stop DTMF tone
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 TInt CSPDTMFProvider::StopDtmfTone()
       
   112     {
       
   113     CSPLOGSTRING(CSPREQIN, "CSPDTMFProvider::StopDtmfTone" );
       
   114     TInt ret(KErrAlreadyExists);
       
   115     if (!IsActive())
       
   116         {
       
   117         ret = iPhone.StopDTMFTone();
       
   118         }
       
   119     return ret;    
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // Send DTMF string
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TInt CSPDTMFProvider::SendDtmfToneString( const TDesC& aString )
       
   127     {
       
   128     CSPLOGSTRING(CSPREQIN, "CSPDTMFProvider::SendDtmfToneString" );
       
   129     TInt ret = KErrInUse;
       
   130     
       
   131     if ( !IsActive() )
       
   132         {            
       
   133         iPhone.SendDTMFTones( iStatus, aString );
       
   134         SetActive();
       
   135         ret = KErrNone;
       
   136         }
       
   137 
       
   138     return ret;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // Continue DTMF string sending
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 TInt CSPDTMFProvider::ContinueDtmfStringSending( const TBool aContinue )
       
   146     {
       
   147     CSPLOGSTRING(CSPREQIN, "CSPDTMFProvider::ContinueDtmfStringSending" );
       
   148     return iPhone.ContinueDTMFStringSending( aContinue );
       
   149     }
       
   150     
       
   151 // ---------------------------------------------------------------------------
       
   152 // Adds observer.
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CSPDTMFProvider::AddObserverL( const MCCPDTMFObserver& aObserver )
       
   156     {
       
   157     if ( iObservers.Find( &aObserver ) == KErrNotFound )
       
   158         {
       
   159         iObservers.Append( &aObserver );
       
   160         }
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // Removes given observer.
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 TInt CSPDTMFProvider::RemoveObserver( const MCCPDTMFObserver& aObserver )
       
   168     {
       
   169     TInt ret = KErrNotFound;
       
   170     
       
   171     TInt found = iObservers.Find( &aObserver );
       
   172     if ( found != KErrNotFound )
       
   173         {
       
   174         iObservers.Remove( found );
       
   175         ret = KErrNone;
       
   176         }
       
   177 
       
   178     return ret;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // From CActive.
       
   183 // Handles request completion.
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CSPDTMFProvider::RunL()
       
   187     {
       
   188     CSPLOGSTRING2( CSPREQIN, 
       
   189         "CSPDTMFProvider::RunL: status: %d", iStatus.Int() );
       
   190     
       
   191     if ( iStatus == KErrNone )
       
   192         {
       
   193         MCCPDTMFObserver::TCCPDtmfEvent event = 
       
   194             MCCPDTMFObserver::ECCPDtmfStringSendingCompleted;
       
   195         NotifyDTMFEvent( event, KErrNone, NULL );
       
   196         }
       
   197     else
       
   198         {
       
   199         TInt error = iStatus.Int();
       
   200         if ( error != KErrCancel )
       
   201             {
       
   202             MCCPDTMFObserver::TCCPDtmfEvent event = 
       
   203                 MCCPDTMFObserver::ECCPDtmfStringSendingCompleted;
       
   204             NotifyDTMFEvent( event, error, NULL );
       
   205             }
       
   206         else
       
   207             {
       
   208             // Cancel is not notified
       
   209             CSPLOGSTRING( CSPREQEND, "CSPDTMFProvider::RunL Cancel." );
       
   210             }
       
   211         }
       
   212                 
       
   213     CSPLOGSTRING( CSPREQEND, "CSPDTMFProvider::RunL End of RunL." );
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // From CActive
       
   218 // Canceling functionality.
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CSPDTMFProvider::DoCancel()
       
   222     {
       
   223     if ( iStatus == KRequestPending )
       
   224         {
       
   225         CSPLOGSTRING( CSPINT, 
       
   226             "CSPDTMFProvider::DoCancel Canceling pending request.." );
       
   227         iPhone.CancelAsyncRequest( EMobilePhoneSendDTMFTones );
       
   228         }
       
   229     }
       
   230             
       
   231 // ---------------------------------------------------------------------------
       
   232 // Constructs the requester.
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 CSPDTMFProvider::CSPDTMFProvider( RMobilePhone& aPhone, 
       
   236                                   RMmCustomAPI& aMmCustom ):
       
   237                     CActive( EPriorityStandard ),
       
   238                     iPhone( aPhone ),
       
   239                     iMmCustom( aMmCustom )
       
   240     {
       
   241     CSPLOGSTRING(CSPOBJECT, "CSPDTMFProvider::CSPDTMFProvider()" );
       
   242     CActiveScheduler::Add( this );
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // Constructs the requester in the second phase.
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void CSPDTMFProvider::ConstructL( ) 
       
   250     {
       
   251     if ( !iPhone.SubSessionHandle() || !iMmCustom.SubSessionHandle() )
       
   252         {
       
   253         User::Leave( KErrArgument );
       
   254         }
       
   255     iMonitor = CSPEtelDtmfMonitor::NewL( *this, iMmCustom );
       
   256     iMonitor->StartMonitoring();
       
   257     iStopMonitor = CSPEtelDtmfStopMonitor::NewL( *this, iPhone );
       
   258     iStopMonitor->StartMonitoring();
       
   259     }
       
   260 
       
   261 //  End of File