mmsharing/mmshengine/src/musengtelephoneutils.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
    17 
    17 
    18 
    18 
    19 // USER
    19 // USER
    20 #include "musengtelephoneutils.h"
    20 #include "musengtelephoneutils.h"
    21 #include "musengaudioroutingobserver.h"
    21 #include "musengaudioroutingobserver.h"
       
    22 #include "musengmcesession.h"
       
    23 #include "musengvolumechangeobserver.h"
    22 #include "muslogger.h"
    24 #include "muslogger.h"
    23 
    25 
    24 // SYSTEM
    26 // SYSTEM
    25 #include <centralrepository.h>
    27 #include <centralrepository.h>
    26 #include <telincallvolcntrlcrkeys.h>
    28 #include <telephonydomaincrkeys.h>
    27 #include <e32property.h>
    29 #include <e32property.h>
    28 #include <telephonydomainpskeys.h>
    30 #include <telephonydomainpskeys.h>
    29 #include <CPhCltCommandHandler.h> // for CPhCltCommandHandler
    31 #include <CPhCltCommandHandler.h> // for CPhCltCommandHandler
    30 
    32 
    31 // Constants
    33 
    32 const TInt KMusEngMaxVolume = 10;
    34 // -----------------------------------------------------------------------------
    33 const TInt KMusEngMinVolume = 0;
    35 //
    34 
    36 // -----------------------------------------------------------------------------
    35 
    37 //
    36 
    38 CMusEngTelephoneUtils* CMusEngTelephoneUtils::NewL()
    37 
    39     {
    38 // -----------------------------------------------------------------------------
    40     CMusEngTelephoneUtils* self = new( ELeave ) CMusEngTelephoneUtils();
    39 //
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CMusEngTelephoneUtils* CMusEngTelephoneUtils::NewL( 
       
    43     MMusEngAudioRoutingObserver& aAudioRoutingObserver )
       
    44     {
       
    45     CMusEngTelephoneUtils* self = 
       
    46         new( ELeave )CMusEngTelephoneUtils( aAudioRoutingObserver );
       
    47     CleanupStack::PushL( self );
    41     CleanupStack::PushL( self );
    48     self->ConstructL();
    42     self->ConstructL();
    49     CleanupStack::Pop( self );
    43     CleanupStack::Pop( self );
    50     return self;
    44     return self;
    51     }
    45     }
    52 
    46 
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CMusEngTelephoneUtils::CMusEngTelephoneUtils( 
       
    58     MMusEngAudioRoutingObserver& aAudioRoutingObserver ) 
       
    59     : CActive( CActive::EPriorityStandard ),
       
    60       iAudioRoutingObserver( aAudioRoutingObserver )
       
    61     {
       
    62     iAudioOutputAtStartup = CTelephonyAudioRouting::ENotActive;
       
    63     }
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CMusEngTelephoneUtils::ConstructL()
       
    71     {
       
    72     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::ConstructL()" )
       
    73 
       
    74     // Volume control
       
    75     iRepository = CRepository::NewL( KCRUidInCallVolume );
       
    76 
       
    77     // Audio routing control
       
    78     iTelephonyAudioRouting = CTelephonyAudioRouting::NewL( *this );
       
    79 
       
    80     iAudioOutputAtStartup = iTelephonyAudioRouting->Output();
       
    81     
       
    82     // Phone
       
    83     MUS_LOG( "mus: [ENGINE]     Use static DLL" )
       
    84     iPhoneCommandHandler = CPhCltCommandHandler::NewL();
       
    85         
       
    86     CActiveScheduler::Add( this );
       
    87 
       
    88     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::ConstructL()" )
       
    89     }
       
    90 
    47 
    91 // -----------------------------------------------------------------------------
    48 // -----------------------------------------------------------------------------
    92 //
    49 //
    93 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
    94 //
    51 //
   102     
    59     
   103     if( iTelephonyAudioRouting ) // If 2nd phase construction has succeeded 
    60     if( iTelephonyAudioRouting ) // If 2nd phase construction has succeeded 
   104         {
    61         {
   105         CTelephonyAudioRouting::TAudioOutput currentMode =
    62         CTelephonyAudioRouting::TAudioOutput currentMode =
   106                                             iTelephonyAudioRouting->Output();
    63                                             iTelephonyAudioRouting->Output();
   107         if( currentMode != iAudioOutputAtStartup )
    64         MUS_LOG1( "mus: [ENGINE] iAudioOutputAtStartup: %d", iAudioOutputAtStartup );
       
    65         MUS_LOG1( "mus: [ENGINE] currentMode: %d", currentMode );
       
    66         // When active call is dropped, audio output is set to ENotActive,
       
    67         // but in some cases Mush engine get deleted before OutputChanged()
       
    68         // notification comes. In that case we shouldn't touch output. 
       
    69         if( currentMode != iAudioOutputAtStartup && 
       
    70             currentMode != CTelephonyAudioRouting::ENotActive )
   108             {
    71             {
   109             // As going down, let audiorouting api to show notification
    72             // As going down, let audiorouting api to show notification
   110             iTelephonyAudioRouting->SetShowNote( ETrue );
    73             iTelephonyAudioRouting->SetShowNote( ETrue );
   111             TRAPD( err, 
    74             TRAPD( err, DoSetOutputL( iAudioOutputAtStartup ) );
   112                 iTelephonyAudioRouting->SetOutputL( iAudioOutputAtStartup ) )
       
   113             MUS_LOG1( "mus: [ENGINE]    final route change completed: %d", err )
    75             MUS_LOG1( "mus: [ENGINE]    final route change completed: %d", err )
   114             err++;
    76             err++;
   115         	}
    77             }
   116         }
    78         }
       
    79 
       
    80     if ( iNotifier )
       
    81         {
       
    82         iNotifier->StopListening();
       
    83         delete iNotifier;
       
    84         }    
   117 
    85 
   118     delete iRepository;
    86     delete iRepository;
   119     delete iTelephonyAudioRouting;
    87     delete iTelephonyAudioRouting;
   120     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::~CMusEngTelephoneUtils()" )
    88     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::~CMusEngTelephoneUtils()" )
   121     }
    89     }
   122 
    90 
   123 // -----------------------------------------------------------------------------
    91 
   124 //
    92 // -----------------------------------------------------------------------------
   125 // -----------------------------------------------------------------------------
    93 //
   126 //
    94 // -----------------------------------------------------------------------------
   127 TBool CMusEngTelephoneUtils::AudioRoutingCanBeChanged()
    95 //
       
    96 TBool CMusEngTelephoneUtils::AudioRoutingCanBeChanged() const
   128     {
    97     {
   129     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::AudioRoutingCanBeChanged" )
    98     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::AudioRoutingCanBeChanged" )
   130     
    99     
   131     TBool retValue = ( iTelephonyAudioRouting->Output() !=
   100     TBool retValue = ( 
   132                        CTelephonyAudioRouting::EWiredAudioAccessory &&
       
   133                        iTelephonyAudioRouting->Output() !=
       
   134                        CTelephonyAudioRouting::EBTAudioAccessory &&
       
   135                        iTelephonyAudioRouting->Output() !=
   101                        iTelephonyAudioRouting->Output() !=
   136                        CTelephonyAudioRouting::ETTY );
   102                        CTelephonyAudioRouting::ETTY );
   137     
   103     
   138     MUS_LOG1( "mus: [ENGINE]  <- CMusEngTelephoneUtils::AudioRoutingCanBeChanged: %d",
   104     MUS_LOG1( "mus: [ENGINE]  <- CMusEngTelephoneUtils::AudioRoutingCanBeChanged: %d",
   139               retValue )
   105               retValue )
   140               
   106               
   141     return retValue;
   107     return retValue;
   142     }
   108     }
   143 
   109 
   144 // -----------------------------------------------------------------------------
   110 
   145 //
   111 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   112 //
   147 //
   113 // -----------------------------------------------------------------------------
   148 void CMusEngTelephoneUtils::LoudspeakerL( TBool aEnable )
   114 //
       
   115 TBool CMusEngTelephoneUtils::IsAudioRoutingHeadset() const
       
   116     {
       
   117     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::IsAudioRoutingHeadset" )
       
   118 	    
       
   119     TBool retValue = ( iTelephonyAudioRouting->Output() ==
       
   120                        CTelephonyAudioRouting::EBTAudioAccessory ||
       
   121                        iTelephonyAudioRouting->Output() ==
       
   122                        CTelephonyAudioRouting::EWiredAudioAccessory );
       
   123 	    
       
   124     MUS_LOG1( "mus: [ENGINE]  <- CMusEngTelephoneUtils::IsAudioRoutingHeadset: %d",
       
   125                retValue )
       
   126 	              
       
   127     return retValue;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TBool CMusEngTelephoneUtils::IsAudioRoutingLoudSpeaker() const
       
   135     {
       
   136     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::IsAudioRoutingLoudSpeaker" )
       
   137     TBool retValue = EFalse;
       
   138     
       
   139     CTelephonyAudioRouting::TAudioOutput currentMode =
       
   140                                             iTelephonyAudioRouting->Output();
       
   141     MUS_LOG1( "mus: [ENGINE] iAudioOutputAtStartup: %d", iAudioOutputAtStartup );
       
   142     MUS_LOG1( "mus: [ENGINE] currentMode: %d", currentMode );
       
   143     
       
   144     if( currentMode != iAudioOutputAtStartup && 
       
   145         currentMode == CTelephonyAudioRouting::ELoudspeaker )
       
   146     	{
       
   147     
       
   148          retValue = ETrue;
       
   149     
       
   150     	}
       
   151     	
       
   152     MUS_LOG1( "mus: [ENGINE]  <- CMusEngTelephoneUtils::IsAudioRoutingLoudSpeaker: %d",
       
   153                retValue )
       
   154 	              
       
   155     return retValue;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CMusEngTelephoneUtils::LoudspeakerL( TBool aEnable, TBool aShowDialog )
   149     {
   163     {
   150     MUS_LOG1( "mus: [ENGINE]  -> CMusEngTelephoneUtils::LoudspeakerL(%d)",
   164     MUS_LOG1( "mus: [ENGINE]  -> CMusEngTelephoneUtils::LoudspeakerL(%d)",
   151               aEnable )
   165               aEnable )
   152     
   166     
   153     // Disable note shown by audiorouting api as it causes
       
   154     // application going to background for a while. Instead, display
       
   155     // note by ourselves once setting output completes. This mechanism
       
   156     // is needed only for loudspeaker enabling as going to background
       
   157     // causes problems only at beginning of sharing session.
       
   158     iTelephonyAudioRouting->SetShowNote( EFalse );              
       
   159     if ( aEnable )
   167     if ( aEnable )
   160         {
   168         {
   161         if ( iTelephonyAudioRouting->Output() == 
   169         if ( iTelephonyAudioRouting->Output() == 
   162              CTelephonyAudioRouting::EHandset )
   170              CTelephonyAudioRouting::EHandset || 
   163             {
   171              iTelephonyAudioRouting->Output() == 
   164             iTelephonyAudioRouting->SetOutputL( 
   172              CTelephonyAudioRouting::EBTAudioAccessory|| 
   165                 CTelephonyAudioRouting::ELoudspeaker );
   173              iTelephonyAudioRouting->Output() == 
       
   174              CTelephonyAudioRouting::EWiredAudioAccessory )  
       
   175             {
       
   176             // Disable note shown by audiorouting api as it causes
       
   177             // application going to background for a while. Instead, display
       
   178             // note by ourselves once setting output completes. This mechanism
       
   179             // is needed only for loudspeaker enabling as going to background
       
   180             // causes problems only at beginning of sharing session.
       
   181             if ( aShowDialog )
       
   182                 {   
       
   183                 iTelephonyAudioRouting->SetShowNote( EFalse );
       
   184                 
       
   185                 iShowDialog = aShowDialog;
       
   186                 }
       
   187     
       
   188             DoSetOutputL( CTelephonyAudioRouting::ELoudspeaker );
   166             }
   189             }
   167         }
   190         }
   168     else
   191     else
   169         {        
   192         {
       
   193         iTelephonyAudioRouting->SetShowNote( aShowDialog );
       
   194         
   170         if ( iAudioOutputAtStartup == CTelephonyAudioRouting::ELoudspeaker )
   195         if ( iAudioOutputAtStartup == CTelephonyAudioRouting::ELoudspeaker )
   171             {
   196             {
   172             iTelephonyAudioRouting->SetOutputL( 
   197             DoSetOutputL( CTelephonyAudioRouting::EHandset );
   173                 CTelephonyAudioRouting::EHandset );
       
   174             }
   198             }
   175         else
   199         else
   176             {
   200             {
   177             iTelephonyAudioRouting->SetOutputL( iAudioOutputAtStartup );
   201             DoSetOutputL( iAudioOutputAtStartup );
   178             }
   202             }
   179         }
   203         }
       
   204 
       
   205     
   180                                 
   206                                 
   181     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::LoudspeakerL(...)" )
   207     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::LoudspeakerL(...)" )
   182     }
   208     }
   183 
   209 
       
   210 
   184 // -----------------------------------------------------------------------------
   211 // -----------------------------------------------------------------------------
   185 //
   212 //
   186 // -----------------------------------------------------------------------------
   213 // -----------------------------------------------------------------------------
   187 //
   214 //
   188 TBool CMusEngTelephoneUtils::IsLoudSpeakerEnabled() const
   215 TBool CMusEngTelephoneUtils::IsLoudSpeakerEnabled() const
   190     return ( iTelephonyAudioRouting->Output() ==
   217     return ( iTelephonyAudioRouting->Output() ==
   191              CTelephonyAudioRouting::ELoudspeaker );
   218              CTelephonyAudioRouting::ELoudspeaker );
   192     }
   219     }
   193 
   220 
   194 // -----------------------------------------------------------------------------
   221 // -----------------------------------------------------------------------------
   195 // Gets the CS call volume level.
   222 // Returns locally cached the CS call volume level.
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 TInt CMusEngTelephoneUtils::GetVolume() const
       
   226     {
       
   227     return iCurrentVolume;
       
   228     }
       
   229         
       
   230 // -----------------------------------------------------------------------------
       
   231 // Gets the CS call volume level from central repository.
   196 // Leaves if error occurs when accessing central repository.
   232 // Leaves if error occurs when accessing central repository.
   197 // -----------------------------------------------------------------------------
   233 // -----------------------------------------------------------------------------
   198 //
   234 //
   199 TInt CMusEngTelephoneUtils::GetVolumeL() const
   235 TInt CMusEngTelephoneUtils::GetVolumeL() const
   200     {
   236     {
   207     else
   243     else
   208         {
   244         {
   209         User::LeaveIfError( iRepository->Get( KTelIncallEarVolume,
   245         User::LeaveIfError( iRepository->Get( KTelIncallEarVolume,
   210                                               currentVolume ) );
   246                                               currentVolume ) );
   211         }
   247         }
       
   248 
   212     return ValidateVolume( currentVolume );
   249     return ValidateVolume( currentVolume );
   213     }
   250     }
       
   251 
   214 
   252 
   215 // -----------------------------------------------------------------------------
   253 // -----------------------------------------------------------------------------
   216 // Sets the CS call volume level.
   254 // Sets the CS call volume level.
   217 // Leaves if error occurs when accessing central repository.
   255 // Leaves if error occurs when accessing central repository.
   218 // -----------------------------------------------------------------------------
   256 // -----------------------------------------------------------------------------
   219 //
   257 //
   220 void CMusEngTelephoneUtils::SetVolumeL( TInt aVolume )
   258 void CMusEngTelephoneUtils::SetVolumeL( TInt aVolume )
   221     {
   259     {
   222     TInt newVolume = ValidateVolume( aVolume );
   260     TInt newVolume = ValidateVolume( aVolume );
   223 
   261     MUS_LOG1( "mus: [ENGINE]  -> CMusEngTelephoneUtils::SetVolumeL(), %d", newVolume )
   224     if ( GetVolumeL() != newVolume )
   262     if ( iCurrentVolume != newVolume )
   225         {
   263         {
   226         if ( IsLoudSpeakerEnabled() )
   264         if ( IsLoudSpeakerEnabled() )
   227             {
   265             {
   228             User::LeaveIfError( iRepository->Set( KTelIncallLoudspeakerVolume,
   266             User::LeaveIfError( iRepository->Set( KTelIncallLoudspeakerVolume,
   229                                                   newVolume ) );
   267                                                   newVolume ) );
   231         else
   269         else
   232             {
   270             {
   233             User::LeaveIfError( iRepository->Set( KTelIncallEarVolume, 
   271             User::LeaveIfError( iRepository->Set( KTelIncallEarVolume, 
   234                                                   newVolume ) );
   272                                                   newVolume ) );
   235             }
   273             }
   236         }
   274         iCurrentVolume = newVolume;
   237     }
   275         }
       
   276     }
       
   277 
   238 
   278 
   239 // -----------------------------------------------------------------------------
   279 // -----------------------------------------------------------------------------
   240 //
   280 //
   241 // -----------------------------------------------------------------------------
   281 // -----------------------------------------------------------------------------
   242 //
   282 //
   253     iPhoneCommandHandler->MuteMicrophone( iStatus, aMute );
   293     iPhoneCommandHandler->MuteMicrophone( iStatus, aMute );
   254     SetActive();
   294     SetActive();
   255     
   295     
   256     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::MuteMicL()" )
   296     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::MuteMicL()" )
   257     }
   297     }
       
   298 
   258 
   299 
   259 // -----------------------------------------------------------------------------
   300 // -----------------------------------------------------------------------------
   260 //
   301 //
   261 // -----------------------------------------------------------------------------
   302 // -----------------------------------------------------------------------------
   262 //
   303 //
   273     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::IsMicMutedL()" )
   314     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::IsMicMutedL()" )
   274 
   315 
   275     return ( psVal == EPSTelMicMuteOn );
   316     return ( psVal == EPSTelMicMuteOn );
   276     }
   317     }
   277 
   318 
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void CMusEngTelephoneUtils::SetAudioRoutingObserver( 
       
   325                                     MMusEngAudioRoutingObserver* aObserver )
       
   326     {
       
   327     iAudioRoutingObserver = aObserver;
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 void CMusEngTelephoneUtils::SetVolumeChangeObserver( 
       
   335                                     MMusEngVolumeChangeObserver* aObserver )
       
   336     {
       
   337     iVolumeObserver = aObserver;
       
   338     }
       
   339 
   278 // -----------------------------------------------------------------------------
   340 // -----------------------------------------------------------------------------
   279 // 
   341 // 
   280 // -----------------------------------------------------------------------------
   342 // -----------------------------------------------------------------------------
   281 //
   343 //
   282 void CMusEngTelephoneUtils::RunL()
   344 void CMusEngTelephoneUtils::RunL()
   288              iStatus.Int() )
   350              iStatus.Int() )
   289 
   351 
   290     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::RunL()" )
   352     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::RunL()" )
   291     }
   353     }
   292 
   354 
       
   355 // -------------------------------------------------------------------------
       
   356 //  If RunL() leaves,It should be handled here.
       
   357 // -------------------------------------------------------------------------
       
   358 //
       
   359 TInt CMusEngTelephoneUtils::RunError( TInt aError )
       
   360     {
       
   361     MUS_LOG1( "mus: [ENGINE]     -> CMusEngTelephoneUtils::\
       
   362               RunError() return #%d", aError )
       
   363     
       
   364     // Nothing can be done here.
       
   365     aError = KErrNone;
       
   366 
       
   367     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::RunError()" )
       
   368     return aError;
       
   369     }
       
   370 
       
   371 
   293 // -----------------------------------------------------------------------------
   372 // -----------------------------------------------------------------------------
   294 // 
   373 // 
   295 // -----------------------------------------------------------------------------
   374 // -----------------------------------------------------------------------------
   296 //
   375 //
   297 void CMusEngTelephoneUtils::DoCancel()
   376 void CMusEngTelephoneUtils::DoCancel()
   302         {
   381         {
   303         iPhoneCommandHandler->CancelAsyncRequest( EPhCltCommandMuteMic );
   382         iPhoneCommandHandler->CancelAsyncRequest( EPhCltCommandMuteMic );
   304         }
   383         }
   305         
   384         
   306     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::DoCancel()" )
   385     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::DoCancel()" )
   307     } 
   386     }
       
   387     
   308 
   388 
   309 // -----------------------------------------------------------------------------
   389 // -----------------------------------------------------------------------------
   310 //
   390 //
   311 // -----------------------------------------------------------------------------
   391 // -----------------------------------------------------------------------------
   312 //
   392 //
   313 void CMusEngTelephoneUtils::AvailableOutputsChanged( 
   393 void CMusEngTelephoneUtils::AvailableOutputsChanged( 
   314     CTelephonyAudioRouting& /*aTelephonyAudioRouting*/ )
   394                         CTelephonyAudioRouting& /*aTelephonyAudioRouting*/ )
   315     {
   395     {
   316     // NOP
   396     // NOP
   317     }
   397     }
   318 
   398 
       
   399 
   319 // -----------------------------------------------------------------------------
   400 // -----------------------------------------------------------------------------
   320 //
   401 //
   321 // -----------------------------------------------------------------------------
   402 // -----------------------------------------------------------------------------
   322 //
   403 //
   323 void CMusEngTelephoneUtils::OutputChanged( 
   404 void CMusEngTelephoneUtils::OutputChanged( 
   324     CTelephonyAudioRouting& aTelephonyAudioRouting )
   405                 CTelephonyAudioRouting& aTelephonyAudioRouting )
   325     {
   406     {
   326     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::OutputChanged()" )
   407     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::OutputChanged()" )
   327 
   408 
   328     // Some other application has changed audio output routing. We consider
   409     // Some other application has changed audio output routing. We consider
   329     // this as a last will of a user and return to this state after sharing
   410     // this as a last will of a user and return to this state after sharing
   330     
   411     
   331     iAudioOutputAtStartup = aTelephonyAudioRouting.Output();
   412     iAudioOutputAtStartup = aTelephonyAudioRouting.Output();
   332     
   413     
   333     MUS_LOG1( "mus: [ENGINE]     New audio routing is %d", iAudioOutputAtStartup )
   414     MUS_LOG1( "mus: [ENGINE]     New audio routing is %d", iAudioOutputAtStartup )
   334     
   415     
   335     iAudioRoutingObserver.AudioRoutingChanged();
   416     if ( iAudioRoutingObserver )
       
   417         {
       
   418         iAudioRoutingObserver->AudioRoutingChanged( EFalse );
       
   419         }
       
   420     
       
   421     UpdateCurrentVolume(ETrue);
       
   422     
       
   423     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::OutputChanged()" )
       
   424     }
       
   425     
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 void CMusEngTelephoneUtils::SetOutputComplete( 
       
   432                     CTelephonyAudioRouting& /*aTelephonyAudioRouting*/,
       
   433                     TInt aError )
       
   434     {
       
   435     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::SetOutputComplete()" )
       
   436 
       
   437     if ( aError == KErrNone )
       
   438         {
       
   439         if ( iAudioRoutingObserver )
       
   440             {
       
   441             // If audio routing api didn't shown note and show dialog mode is on,
       
   442             // we know that this completion is for such setoutput call for which
       
   443             // we need to show the note. Show note mode is turned off only in that
       
   444             // case.
       
   445             TBool dialogShownByUs( EFalse );
       
   446             TBool dialogShownByAudioRouting( EFalse );     
       
   447             aError = iTelephonyAudioRouting->GetShowNote( dialogShownByAudioRouting );
       
   448             if ( aError == KErrNone && !dialogShownByAudioRouting && iShowDialog )
       
   449                 {
       
   450                 dialogShownByUs = iShowDialog;
       
   451                 iShowDialog = EFalse;
       
   452                 }
   336         
   453         
   337     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::OutputChanged()" )
   454             iAudioRoutingObserver->AudioRoutingChanged( dialogShownByUs );
   338     }
   455             }
   339     
   456 
   340 
   457         UpdateCurrentVolume(ETrue);
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CMusEngTelephoneUtils::SetOutputComplete( 
       
   346     CTelephonyAudioRouting& /*aTelephonyAudioRouting*/,
       
   347     TInt aError )
       
   348     {
       
   349     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::SetOutputComplete()" )
       
   350 
       
   351     if ( aError == KErrNone )
       
   352         {
       
   353         iAudioRoutingObserver.AudioRoutingChanged();
       
   354         }
   458         }
   355     
   459     
   356     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::SetOutputComplete()" )
   460     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::SetOutputComplete()" )
   357     }
   461     }
       
   462                             
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 //
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CMusEngTelephoneUtils::UpdateCurrentVolume( TBool aAudioRouteChanged )
       
   469     {
       
   470     TInt volume(0);
       
   471     TRAPD(error, volume = GetVolumeL() );
       
   472     if( (KErrNone == error) && (iCurrentVolume != volume) )
       
   473          {
       
   474          iCurrentVolume = volume;
       
   475          if ( iVolumeObserver )
       
   476              {
       
   477              iVolumeObserver->VolumeChanged( volume, aAudioRouteChanged );
       
   478              }
       
   479          }
       
   480     }
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 CMusEngTelephoneUtils::CMusEngTelephoneUtils() 
       
   487 	: CActive( CActive::EPriorityStandard )
       
   488     {
       
   489     iAudioOutputAtStartup = CTelephonyAudioRouting::ENotActive;
       
   490     }
       
   491 
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 void CMusEngTelephoneUtils::ConstructL()
       
   498     {
       
   499     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::ConstructL()" )
       
   500 
       
   501     // Volume control
       
   502     iRepository = CRepository::NewL( KCRUidInCallVolume );
       
   503     
       
   504     iNotifier = CCenRepNotifyHandler::NewL( *this, *iRepository );
       
   505     iNotifier->StartListeningL();
       
   506     
       
   507     // Audio routing control
       
   508     iTelephonyAudioRouting = CTelephonyAudioRouting::NewL( *this );
       
   509 
       
   510     iAudioOutputAtStartup = iTelephonyAudioRouting->Output();
       
   511     MUS_LOG1( "mus: [ENGINE] iAudioOutputAtStartup: %d", iAudioOutputAtStartup );
       
   512     // Phone
       
   513     MUS_LOG( "mus: [ENGINE]     Use static DLL" )
       
   514     iPhoneCommandHandler = CPhCltCommandHandler::NewL();
       
   515      
       
   516     iCurrentVolume = GetVolumeL();
       
   517     
       
   518     CActiveScheduler::Add( this );
       
   519 
       
   520     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::ConstructL()" )
       
   521     }
       
   522 
   358 
   523 
   359 // -----------------------------------------------------------------------------
   524 // -----------------------------------------------------------------------------
   360 // Validates that requested volume level is valid (between 1-10) and if it is
   525 // Validates that requested volume level is valid (between 1-10) and if it is
   361 // not, modifies requested volume level to be valid.  Returns validated volume.
   526 // not, modifies requested volume level to be valid.  Returns validated volume.
   362 // -----------------------------------------------------------------------------
   527 // -----------------------------------------------------------------------------
   376         // NOP, to keep PC-Lint happy
   541         // NOP, to keep PC-Lint happy
   377         }
   542         }
   378         
   543         
   379     return aVolume;
   544     return aVolume;
   380     }
   545     }
       
   546 
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // Set output if setting is currently allowed.
       
   550 // -----------------------------------------------------------------------------
       
   551 //
       
   552 void CMusEngTelephoneUtils::DoSetOutputL( 
       
   553     CTelephonyAudioRouting::TAudioOutput aAudioOutput )
       
   554     {
       
   555     MUS_LOG( "mus: [ENGINE]  -> CMusEngTelephoneUtils::DoSetOutputL()" )
       
   556     if ( iAudioRoutingObserver && !iAudioRoutingObserver->AudioRouteChangeAllowed() )
       
   557         {
       
   558         MUS_LOG( "mus: [ENGINE]     change not allowed!" )
       
   559         User::Leave( KErrAccessDenied );
       
   560         }
       
   561     iTelephonyAudioRouting->SetOutputL( aAudioOutput );
       
   562     MUS_LOG( "mus: [ENGINE]  <- CMusEngTelephoneUtils::DoSetOutputL()" )
       
   563     }
       
   564 
       
   565 
       
   566 // ---------------------------------------------------------------------------
       
   567 // CMusEngTelephoneUtils::HandleNotifyGeneric
       
   568 // ---------------------------------------------------------------------------
       
   569 //
       
   570 void CMusEngTelephoneUtils::HandleNotifyGeneric( TUint32 aId )
       
   571     {
       
   572     MUS_LOG( "mus: [ENGINE] -> CMusEngTelephoneUtils::HandleNotifyGeneric()" )
       
   573     TInt error = KErrArgument;
       
   574     TInt volume = 0;
       
   575     if ( KTelIncallEarVolume == aId )
       
   576         {
       
   577         error = iRepository->Get( KTelIncallEarVolume, volume );        
       
   578         MUS_LOG1( "mus: [ENGINE] EAR volume: %d", volume );
       
   579         }
       
   580     else if ( KTelIncallLoudspeakerVolume == aId )
       
   581         {
       
   582         error = iRepository->Get( KTelIncallLoudspeakerVolume, volume );        
       
   583         MUS_LOG1( "mus: [ENGINE] Loudspeakers volume: %d", volume );
       
   584         }
       
   585     
       
   586     volume = ValidateVolume(volume);
       
   587     if ( (KErrNone == error) && (iCurrentVolume != volume) )
       
   588         {
       
   589         MUS_LOG1( "mus: [ENGINE] volume changed: %d!, notifying UI...", volume )
       
   590         iCurrentVolume = volume;
       
   591         if( iVolumeObserver  )
       
   592             {
       
   593             iVolumeObserver->VolumeChanged( volume, EFalse );
       
   594             }
       
   595         }
       
   596     else
       
   597         {
       
   598         MUS_LOG( "mus: [ENGINE] volume hasn't changed!, do nothing..." )    
       
   599         }
       
   600         
       
   601     MUS_LOG1( "mus: [ENGINE] <- CMusEngTelephoneUtils::HandleNotifyGeneric(), error:%d",
       
   602             error );
       
   603     }