mmsharing/mmshmanagersrv/src/musapplicationmanager.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     1 /*
       
     2 * Copyright (c) 2006 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "musunittesting.h"
       
    20 #include "muslogger.h"
       
    21 #include "musapplicationmanager.h"
       
    22 #include "musmanagercommon.h"
       
    23 #include "musmanagerservercommon.h"
       
    24 #include "mussessionproperties.h"
       
    25 #include "musuid.hrh"
       
    26 #include "mussettings.h"
       
    27 /* PS keys related to NMusSessionInformationApi defined here */
       
    28 #include "mussesseioninformationapi.h"
       
    29 #include "muscleanupresetanddestroy.h"
       
    30 #include "lcengine.h"
       
    31 
       
    32 #include <apacmdln.h>
       
    33 #include <apgtask.h>
       
    34 #include <e32cmn.h>
       
    35 #include <e32property.h>
       
    36 #include <utf.h>
       
    37 #include <apadef.h>
       
    38 
       
    39 
       
    40 // CONSTANTS
       
    41 _LIT8( KDefaultEngineName, "MultimediaSharing" );
       
    42 _LIT( KMusUiProcessName, "musui.exe" );
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CMusApplicationManager::NewL
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CMusApplicationManager* CMusApplicationManager::NewL()
       
    49     {
       
    50     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager* \
       
    51     				 CMusApplicationManager::NewL()" );
       
    52 
       
    53     CMusApplicationManager* self = CMusApplicationManager::NewLC();
       
    54     CleanupStack::Pop( self );
       
    55 
       
    56     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager* \
       
    57     				 CMusApplicationManager::NewL()" );
       
    58     return self;
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CMusApplicationManager::NewLC
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CMusApplicationManager* CMusApplicationManager::NewLC()
       
    67     {
       
    68     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager* \
       
    69     				 CMusApplicationManager::NewLC()" );
       
    70 
       
    71     CMusApplicationManager* self = new( ELeave ) CMusApplicationManager();
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL();
       
    74 
       
    75     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager* \
       
    76     				 CMusApplicationManager::NewLC()" );
       
    77     return self;
       
    78     }
       
    79 
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CMusApplicationManager::~CMusApplicationManager
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CMusApplicationManager::~CMusApplicationManager()
       
    86     {
       
    87     MUS_LOG( "mus: [MUSSRV] -> \
       
    88     					CMusApplicationManager::~CMusApplicationManager()" );
       
    89 
       
    90     MUS_LOG( "mus: [MUSSRV] <- \
       
    91     					CMusApplicationManager::~CMusApplicationManager()" );
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CMusApplicationManager::ConstructL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CMusApplicationManager::ConstructL()
       
   100     {
       
   101     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ConstructL()" );
       
   102 
       
   103     SetPropertyL( NMusSessionApi::KFastMode, MusSettingsKeys::EFastModeOff );
       
   104 
       
   105     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ConstructL()" );
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CMusApplicationManager::CMusApplicationManager
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CMusApplicationManager::CMusApplicationManager()
       
   114     {
       
   115     }
       
   116 
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CMusApplicationManager::ApplicationRunning
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 TBool CMusApplicationManager::ApplicationRunning()
       
   123     {
       
   124     MUS_LOG( "mus: [MUSSRV] <> CMusApplicationManager::ApplicationRunning()" );
       
   125     
       
   126     TFindProcess findProcess( KMusUiProcessName );
       
   127     TFullName name;
       
   128     return ( findProcess.Next( name ) == KErrNone );
       
   129     }
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CMusApplicationManager::ApplicationRunning
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CMusApplicationManager::StartApplicationL()
       
   137     {
       
   138     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::StartApplicationL()" );
       
   139 
       
   140     if( ApplicationRunning() )
       
   141         {
       
   142         ShowApplicationL();
       
   143         }
       
   144     else
       
   145         {
       
   146         MUS_LOG( "mus: [MUSSRV]     Starting app" );
       
   147         
       
   148         RProcess process;
       
   149         CleanupClosePushL( process );
       
   150         HBufC* args = CreateCommandLineArgsLC();
       
   151         User::LeaveIfError( process.Create( KMusUiProcessName, *args ) );
       
   152         process.Resume();
       
   153         CleanupStack::PopAndDestroy( args );
       
   154         CleanupStack::PopAndDestroy( &process );
       
   155         }
       
   156 
       
   157     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::StartApplicationL()" );
       
   158     }
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CMusApplicationManager::ApplicationRunning
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CMusApplicationManager::StopApplicationL()
       
   166     {
       
   167     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::StopApplicationL()" );
       
   168 
       
   169     if( ApplicationRunning() )
       
   170         {
       
   171         SetPropertyL( NMusSessionApi::KStatus, 
       
   172                       MultimediaSharing::EMultimediaSharingNotAvailable );
       
   173         }
       
   174 
       
   175     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::StopApplicationL()" );
       
   176     }
       
   177 
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CMusApplicationManager::ShowApplication
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CMusApplicationManager::ShowApplicationL()
       
   184     {
       
   185     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ShowApplicationL()" );
       
   186     
       
   187     // TODO: How to bring a QT application to foreground?
       
   188     
       
   189     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ShowApplicationL()" );
       
   190     }
       
   191 
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CMusApplicationManager::WriteSessionPropertiesL(
       
   198                         MultimediaSharing::TMusUseCase aUseCase,
       
   199                         MultimediaSharing::TMusAvailabilityStatus aStatus,
       
   200                         MDesCArray& aSessionParameters )
       
   201     {
       
   202      MUS_LOG2( "mus: [MUSSRV] -> \
       
   203                CMusApplicationManager::WriteSessionPropertiesL( %d, %d )",
       
   204                ( TInt ) aUseCase, ( TInt ) aStatus );
       
   205 	TRAPD( error,  		   
       
   206     if ( aUseCase == MultimediaSharing::EMusLiveVideo &&
       
   207             MultimediaSharingSettings::VideoDirectionL() == 
       
   208                                             MusSettingsKeys::ETwoWayVideo )
       
   209         {
       
   210 		MUS_LOG( "mus: [MUSSRV]  UseCase MultimediaSharing::EMusTwoWayVideo" );
       
   211         aUseCase = MultimediaSharing::EMusTwoWayVideo;
       
   212         }
       
   213 		)
       
   214 	if ( error == KErrNoMemory )
       
   215 		{
       
   216 		User::Leave( error );
       
   217 		}
       
   218     // set use case property
       
   219     SetPropertyL( NMusSessionApi::KUseCase, ( TInt ) aUseCase );
       
   220 
       
   221     WriteSessionPropertiesL( aStatus, aSessionParameters );
       
   222 
       
   223 
       
   224     MUS_LOG( "mus: [MUSSRV] <- \
       
   225              CMusApplicationManager::WriteSessionPropertiesL()" );
       
   226     }
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CMusApplicationManager::WriteSessionPropertiesL(
       
   234                         MultimediaSharing::TMusAvailabilityStatus aStatus,
       
   235                         MDesCArray& aSessionParameters )
       
   236     {
       
   237      MUS_LOG1( "mus: [MUSSRV] -> \
       
   238                CMusApplicationManager::WriteSessionPropertiesL( %d )",
       
   239                ( TInt ) aStatus );
       
   240 
       
   241     // set tel number property
       
   242     SetPropertyL( NMusSessionApi::KTelNumber,
       
   243                   aSessionParameters.MdcaPoint( KTelNumber ) );
       
   244 
       
   245     // set sip address property
       
   246     SetPropertyL( NMusSessionApi::KRemoteSipAddress,
       
   247                   aSessionParameters.MdcaPoint( KSipAddress ) );
       
   248 
       
   249     // set sip address proposal property
       
   250     SetPropertyL( NMusSessionApi::KRemoteSipAddressProposal,
       
   251                   aSessionParameters.MdcaPoint( KSipAddressProposal ) );
       
   252 
       
   253     // set video codec property
       
   254     SetPropertyL( NMusSessionApi::KVideoCodecs,
       
   255                   aSessionParameters.MdcaPoint( KVideoCodec ) );
       
   256 
       
   257     // set contact id property
       
   258     TLex lex( aSessionParameters.MdcaPoint( KContactId ) );
       
   259     TInt val;
       
   260     lex.Val( val );
       
   261 
       
   262     SetPropertyL( NMusSessionApi::KContactId, val );
       
   263 
       
   264     // set contact id property
       
   265     lex.Assign( aSessionParameters.MdcaPoint( KSipProfileId ) );
       
   266     lex.Val( val );
       
   267 
       
   268     SetPropertyL( NMusSessionApi::KSipProfileId, val );
       
   269 
       
   270     // contact name
       
   271     SetPropertyL( NMusSessionApi::KContactName,
       
   272                   aSessionParameters.MdcaPoint( KContactName ) );
       
   273 
       
   274     // fast mode  
       
   275     TInt fastMode;
       
   276     User::LeaveIfError( RProperty::Get( NMusSessionApi::KCategoryUid, 
       
   277                                         NMusSessionApi::KFastMode, 
       
   278                                         fastMode ) );  
       
   279     if ( fastMode != MusSettingsKeys::EFastModeDisabled )
       
   280         {
       
   281         lex.Assign( aSessionParameters.MdcaPoint( KFastMode ) );
       
   282         lex.Val( val );
       
   283         SetPropertyL( NMusSessionApi::KFastMode, val );
       
   284         }
       
   285     else
       
   286         {        
       
   287         MUS_LOG( "mus: [MUSSRV]  fast mode disabled, do not update it" );
       
   288         }
       
   289     
       
   290    // set status property
       
   291     SetStatusL( aStatus );
       
   292 
       
   293     MUS_LOG( "mus: [MUSSRV] <- \
       
   294              CMusApplicationManager::WriteSessionPropertiesL()" );
       
   295     }
       
   296 
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 void CMusApplicationManager::SetStatusL( 
       
   303                         MultimediaSharing::TMusAvailabilityStatus aStatus )
       
   304     {
       
   305     MUS_LOG1( "mus: [MUSSRV] -> CMusApplicationManager::SetStatusL( %d )",
       
   306               ( TInt ) aStatus );
       
   307     SetPropertyL( NMusSessionApi::KStatus, ( TInt ) aStatus );
       
   308     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetStatusL()" );
       
   309     }
       
   310 
       
   311 	    
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 void CMusApplicationManager::SetIndicatorStatusL( TBool aLaunch )
       
   317     {
       
   318     TInt launch = aLaunch;
       
   319     MUS_LOG1( "mus: [MUSSRV] -> CMusApplicationManager::SetStatusL( %d )",
       
   320               launch );
       
   321               
       
   322     TInt indicatorStatus;
       
   323     TInt ret = RProperty::Get( NMusSessionApi::KCategoryUid, 
       
   324                                NMusSessionApi::KMusIndicatorStatus,
       
   325                                indicatorStatus );
       
   326 
       
   327     if ( ret != KErrNone && ret != KErrNotFound ) 
       
   328         {
       
   329         User::Leave( ret );
       
   330         }
       
   331 
       
   332     // set property only if not defined yet or if value changed
       
   333     if ( ret == KErrNotFound || indicatorStatus != launch )
       
   334         {
       
   335         SetPropertyL( NMusSessionApi::KMusIndicatorStatus, launch );    
       
   336         }
       
   337     
       
   338     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetStatusL()" );
       
   339     }
       
   340 
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CMusApplicationManager::SetPropertyL( TUint aProperty, 
       
   347                                            const TDesC& aValue )
       
   348     {
       
   349     MUS_LOG1( "mus: [MUSSRV] -> CMusApplicationManager::SetPropertyL( %d )",
       
   350                aProperty );
       
   351     MUS_LOG_TDESC( "mus: [MUSSRV]    New property value: ", aValue );
       
   352 
       
   353     // set tel number property
       
   354     TInt retval = RProperty::Define( NMusSessionApi::KCategoryUid,
       
   355                                      aProperty,
       
   356                                      RProperty::EText );
       
   357 
       
   358     if( retval != KErrAlreadyExists && retval != KErrNone )
       
   359         {
       
   360         User::Leave( retval );
       
   361         }
       
   362     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   363                                         aProperty,
       
   364                                         aValue ) );
       
   365 
       
   366     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetPropertyL()" );
       
   367     }
       
   368 
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 void CMusApplicationManager::SetPropertyL( TUint aProperty, TInt aValue )
       
   375     {
       
   376     MUS_LOG2( "mus: [MUSSRV] -> CMusApplicationManager::SetPropertyL( %d, %d )",
       
   377              ( TInt ) aProperty, aValue );
       
   378 
       
   379     // set tel number property
       
   380     TInt retval = RProperty::Define( NMusSessionApi::KCategoryUid,
       
   381                                      aProperty,
       
   382                                      RProperty::EInt );
       
   383     
       
   384     if( retval != KErrAlreadyExists && retval != KErrNone )
       
   385         {
       
   386         User::Leave( retval );
       
   387         }
       
   388     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   389                                         aProperty,
       
   390                                         aValue ) );
       
   391 
       
   392     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetPropertyL()" );
       
   393     }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // Reads the callprovider description from the PS key
       
   397 // return aProvider will have the proper callprovider name.
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 void CMusApplicationManager::CallProviderL(TDes8& aProvider)
       
   401     {
       
   402     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::CallProviderL");
       
   403     const TInt KMusMgrMaxPluginNameLen = 256; 
       
   404     TBuf<KMusMgrMaxPluginNameLen> pluginName;
       
   405     
       
   406     User::LeaveIfError(RProperty::Get( 
       
   407                                 NMusSessionInformationApi::KCategoryUid,
       
   408                                 NMusSessionInformationApi::KMUSCallProvider,
       
   409                                 pluginName ));
       
   410     User::LeaveIfError( 
       
   411             CnvUtfConverter::ConvertFromUnicodeToUtf8( aProvider, pluginName ));
       
   412     
       
   413     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::CallProviderL");
       
   414     }
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // Resolves name of the ecom plugin which implements the livecomms engine api
       
   418 // by using the callprovider
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 void CMusApplicationManager::ResolvePluginNameL(TDes8& aPluginName)
       
   422     {
       
   423     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ResolvePluginNameL");
       
   424     
       
   425     TBuf8<RProperty::KMaxPropertySize> providerName ;
       
   426 
       
   427     // Read the call provider name 
       
   428     CallProviderL( providerName );
       
   429 
       
   430     RImplInfoPtrArray pluginArray;
       
   431     MusCleanupResetAndDestroy<RImplInfoPtrArray>::PushL( pluginArray );
       
   432 
       
   433     TEComResolverParams resolverParams;
       
   434     
       
   435     resolverParams.SetDataType ( providerName );
       
   436     resolverParams.SetWildcardMatch (ETrue);
       
   437     
       
   438     // Use default plugin even if listing fails
       
   439     TRAPD( err, 
       
   440        REComSession::ListImplementationsL(KLcEngineInterfaceUid, resolverParams, pluginArray) );
       
   441     MUS_LOG1( "mus: [MUSSRV]    List implementations compl:%d", err );
       
   442     if ( err == KErrNoMemory )
       
   443         {
       
   444         User::Leave( err );
       
   445         }
       
   446     
       
   447     if( pluginArray.Count() > 0 )
       
   448         {
       
   449         CImplementationInformation* info = pluginArray[ 0 ];
       
   450         __ASSERT_ALWAYS( aPluginName.MaxLength() >= info->DataType().Length(), 
       
   451                          User::Leave( KErrArgument ) );
       
   452         aPluginName.Copy( info->DataType() );
       
   453         }
       
   454     else
       
   455         {
       
   456         __ASSERT_ALWAYS( aPluginName.MaxLength() >= KDefaultEngineName().Length(), 
       
   457                                  User::Leave( KErrArgument ) );
       
   458         aPluginName.Copy( KDefaultEngineName() );
       
   459         }
       
   460     CleanupStack::PopAndDestroy();//pluginArray
       
   461     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ResolvePluginNameL");
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // Creates command line used when starting application.
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 HBufC* CMusApplicationManager::CreateCommandLineArgsLC()
       
   469     {
       
   470     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::CreateCommandLineLC");
       
   471     
       
   472     TBuf8<KMusMgrMaxPluginNameLen> pluginNameUtf8;
       
   473     ResolvePluginNameL( pluginNameUtf8 );
       
   474     
       
   475     MUS_LOG_TDESC8( "mus: [MUSSRV]     Plugin name:", pluginNameUtf8 );
       
   476     
       
   477     HBufC* commandLineArgs = HBufC::NewLC( KMusMgrMaxPluginNameLen );
       
   478     TPtr commandLineArgsPtr( commandLineArgs->Des() );
       
   479     User::LeaveIfError( 
       
   480         CnvUtfConverter::ConvertToUnicodeFromUtf8( 
       
   481             commandLineArgsPtr, pluginNameUtf8 ) );
       
   482     
       
   483     MUS_LOG_TDESC( "mus: [MUSSRV] <- command line args:", commandLineArgsPtr );
       
   484     
       
   485     return commandLineArgs;
       
   486     }
       
   487 
       
   488 // End of File