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