mmsharing/mmshmanagersrv/src/musapplicationmanager.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
    21 #include "musapplicationmanager.h"
    21 #include "musapplicationmanager.h"
    22 #include "musmanagercommon.h"
    22 #include "musmanagercommon.h"
    23 #include "musmanagerservercommon.h"
    23 #include "musmanagerservercommon.h"
    24 #include "mussessionproperties.h"
    24 #include "mussessionproperties.h"
    25 #include "musuid.hrh"
    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 
    26 
    32 #include <apacmdln.h>
    27 #include <apacmdln.h>
    33 #include <apgtask.h>
    28 #include <apgtask.h>
       
    29 //#include <badesca.h>
    34 #include <e32cmn.h>
    30 #include <e32cmn.h>
    35 #include <e32property.h>
    31 #include <e32property.h>
    36 #include <utf.h>
       
    37 #include <apadef.h>
       
    38 
       
    39 
    32 
    40 // CONSTANTS
    33 // CONSTANTS
    41 _LIT8( KDefaultEngineName, "MultimediaSharing" );
    34 
    42 _LIT( KMusUiProcessName, "musui.exe" );
       
    43 
    35 
    44 // -----------------------------------------------------------------------------
    36 // -----------------------------------------------------------------------------
    45 // CMusApplicationManager::NewL
    37 // CMusApplicationManager::NewL
    46 // -----------------------------------------------------------------------------
    38 // -----------------------------------------------------------------------------
    47 //
    39 //
    85 CMusApplicationManager::~CMusApplicationManager()
    77 CMusApplicationManager::~CMusApplicationManager()
    86     {
    78     {
    87     MUS_LOG( "mus: [MUSSRV] -> \
    79     MUS_LOG( "mus: [MUSSRV] -> \
    88     					CMusApplicationManager::~CMusApplicationManager()" );
    80     					CMusApplicationManager::~CMusApplicationManager()" );
    89 
    81 
       
    82     iApaSession.Close();
       
    83     iWsSession.Close();
       
    84 
    90     MUS_LOG( "mus: [MUSSRV] <- \
    85     MUS_LOG( "mus: [MUSSRV] <- \
    91     					CMusApplicationManager::~CMusApplicationManager()" );
    86     					CMusApplicationManager::~CMusApplicationManager()" );
    92     }
    87     }
    93 
    88 
    94 
    89 
    98 //
    93 //
    99 void CMusApplicationManager::ConstructL()
    94 void CMusApplicationManager::ConstructL()
   100     {
    95     {
   101     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ConstructL()" );
    96     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ConstructL()" );
   102 
    97 
   103     SetPropertyL( NMusSessionApi::KFastMode, MusSettingsKeys::EFastModeOff );
    98     User::LeaveIfError( iApaSession.Connect() );
       
    99     User::LeaveIfError( iWsSession.Connect() );
   104 
   100 
   105     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ConstructL()" );
   101     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ConstructL()" );
   106     }
   102     }
   107 
   103 
   108 
   104 
   120 // -----------------------------------------------------------------------------
   116 // -----------------------------------------------------------------------------
   121 //
   117 //
   122 TBool CMusApplicationManager::ApplicationRunning()
   118 TBool CMusApplicationManager::ApplicationRunning()
   123     {
   119     {
   124     MUS_LOG( "mus: [MUSSRV] <> CMusApplicationManager::ApplicationRunning()" );
   120     MUS_LOG( "mus: [MUSSRV] <> CMusApplicationManager::ApplicationRunning()" );
   125     
   121     return GetApaTask().Exists();
   126     TFindProcess findProcess( KMusUiProcessName );
       
   127     TFullName name;
       
   128     return ( findProcess.Next( name ) == KErrNone );
       
   129     }
   122     }
   130 
   123 
   131 
   124 
   132 // -----------------------------------------------------------------------------
   125 // -----------------------------------------------------------------------------
   133 // CMusApplicationManager::ApplicationRunning
   126 // CMusApplicationManager::ApplicationRunning
   141         {
   134         {
   142         ShowApplicationL();
   135         ShowApplicationL();
   143         }
   136         }
   144     else
   137     else
   145         {
   138         {
   146         MUS_LOG( "mus: [MUSSRV]     Starting app" );
   139         TUid appUid;
       
   140         appUid.iUid = KMusUiUid;
   147         
   141         
   148         RProcess process;
   142         TThreadId aThreadId;
   149         CleanupClosePushL( process );
   143         
   150         HBufC* args = CreateCommandLineArgsLC();
   144         User::LeaveIfError( 
   151         User::LeaveIfError( process.Create( KMusUiProcessName, *args ) );
   145                     iApaSession.StartDocument( KNullDesC, appUid, aThreadId) );
   152         process.Resume();
       
   153         CleanupStack::PopAndDestroy( args );
       
   154         CleanupStack::PopAndDestroy( &process );
       
   155         }
   146         }
   156 
   147 
   157     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::StartApplicationL()" );
   148     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::StartApplicationL()" );
   158     }
   149     }
   159 
   150 
   164 //
   155 //
   165 void CMusApplicationManager::StopApplicationL()
   156 void CMusApplicationManager::StopApplicationL()
   166     {
   157     {
   167     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::StopApplicationL()" );
   158     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::StopApplicationL()" );
   168 
   159 
   169     if( ApplicationRunning() )
   160     TApaTask task = GetApaTask();
       
   161     if( task.Exists() )
   170         {
   162         {
   171         SetPropertyL( NMusSessionApi::KStatus, 
   163         SetPropertyL( NMusSessionApi::KStatus, 
   172                       MultimediaSharing::EMultimediaSharingNotAvailable );
   164                       MultimediaSharing::EMultimediaSharingNotAvailable );
   173         }
   165         }
   174 
   166 
   182 //
   174 //
   183 void CMusApplicationManager::ShowApplicationL()
   175 void CMusApplicationManager::ShowApplicationL()
   184     {
   176     {
   185     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ShowApplicationL()" );
   177     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ShowApplicationL()" );
   186     
   178     
   187     // TODO: How to bring a QT application to foreground?
   179     // does a task for multimediasharing exist?
       
   180     TApaTask task = GetApaTask();
       
   181     if( task.Exists() )
       
   182         {
       
   183         task.BringToForeground();
       
   184         }
   188     
   185     
   189     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ShowApplicationL()" );
   186     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ShowApplicationL()" );
   190     }
   187     }
   191 
   188 
   192 
   189 
   200                         MDesCArray& aSessionParameters )
   197                         MDesCArray& aSessionParameters )
   201     {
   198     {
   202      MUS_LOG2( "mus: [MUSSRV] -> \
   199      MUS_LOG2( "mus: [MUSSRV] -> \
   203                CMusApplicationManager::WriteSessionPropertiesL( %d, %d )",
   200                CMusApplicationManager::WriteSessionPropertiesL( %d, %d )",
   204                ( TInt ) aUseCase, ( TInt ) aStatus );
   201                ( TInt ) aUseCase, ( TInt ) aStatus );
   205 	TRAPD( error,  		   
   202 
   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
   203     // set use case property
   219     SetPropertyL( NMusSessionApi::KUseCase, ( TInt ) aUseCase );
   204     SetPropertyL( NMusSessionApi::KUseCase,
       
   205                   ( TInt ) aUseCase );
   220 
   206 
   221     WriteSessionPropertiesL( aStatus, aSessionParameters );
   207     WriteSessionPropertiesL( aStatus, aSessionParameters );
   222 
   208 
   223 
   209 
   224     MUS_LOG( "mus: [MUSSRV] <- \
   210     MUS_LOG( "mus: [MUSSRV] <- \
   269 
   255 
   270     // contact name
   256     // contact name
   271     SetPropertyL( NMusSessionApi::KContactName,
   257     SetPropertyL( NMusSessionApi::KContactName,
   272                   aSessionParameters.MdcaPoint( KContactName ) );
   258                   aSessionParameters.MdcaPoint( KContactName ) );
   273 
   259 
   274     // fast mode  
   260     // set status property
   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 );
   261     SetStatusL( aStatus );
       
   262     
       
   263     // set privacy property
       
   264     lex.Assign( aSessionParameters.MdcaPoint( KPrivacyStatus ) );
       
   265     lex.Val( val );
       
   266 
       
   267     SetPropertyL( NMusSessionApi::KPrivacyStatus, val );
   292 
   268 
   293     MUS_LOG( "mus: [MUSSRV] <- \
   269     MUS_LOG( "mus: [MUSSRV] <- \
   294              CMusApplicationManager::WriteSessionPropertiesL()" );
   270              CMusApplicationManager::WriteSessionPropertiesL()" );
   295     }
   271     }
   296 
   272 
   390                                         aValue ) );
   366                                         aValue ) );
   391 
   367 
   392     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetPropertyL()" );
   368     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetPropertyL()" );
   393     }
   369     }
   394 
   370 
   395 // -----------------------------------------------------------------------------
   371 
   396 // Reads the callprovider description from the PS key
   372 // -----------------------------------------------------------------------------
   397 // return aProvider will have the proper callprovider name.
   373 //
   398 // -----------------------------------------------------------------------------
   374 // -----------------------------------------------------------------------------
   399 //
   375 //
   400 void CMusApplicationManager::CallProviderL(TDes8& aProvider)
   376 TApaTask CMusApplicationManager::GetApaTask() 
   401     {
   377     {
   402     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::CallProviderL");
   378     MUS_LOG( "mus: [MUSSRV] <> CMusApplicationManager::GetApaTask()" );
   403     const TInt KMusMgrMaxPluginNameLen = 256; 
   379     TUid appUid;
   404     TBuf<KMusMgrMaxPluginNameLen> pluginName;
   380     appUid.iUid = KMusUiUid;
   405     
   381     return TApaTaskList( iWsSession ).FindApp( appUid );
   406     User::LeaveIfError(RProperty::Get( 
   382     }
   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