mmsharing/mmshmanagersrv/src/musapplicationmanager.cpp
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     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 
       
    27 #include <apacmdln.h>
       
    28 #include <apgtask.h>
       
    29 //#include <badesca.h>
       
    30 #include <e32cmn.h>
       
    31 #include <e32property.h>
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CMusApplicationManager::NewL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CMusApplicationManager* CMusApplicationManager::NewL()
       
    41     {
       
    42     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager* \
       
    43     				 CMusApplicationManager::NewL()" );
       
    44 
       
    45     CMusApplicationManager* self = CMusApplicationManager::NewLC();
       
    46     CleanupStack::Pop( self );
       
    47 
       
    48     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager* \
       
    49     				 CMusApplicationManager::NewL()" );
       
    50     return self;
       
    51     }
       
    52 
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CMusApplicationManager::NewLC
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CMusApplicationManager* CMusApplicationManager::NewLC()
       
    59     {
       
    60     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager* \
       
    61     				 CMusApplicationManager::NewLC()" );
       
    62 
       
    63     CMusApplicationManager* self = new( ELeave ) CMusApplicationManager();
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66 
       
    67     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager* \
       
    68     				 CMusApplicationManager::NewLC()" );
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CMusApplicationManager::~CMusApplicationManager
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CMusApplicationManager::~CMusApplicationManager()
       
    78     {
       
    79     MUS_LOG( "mus: [MUSSRV] -> \
       
    80     					CMusApplicationManager::~CMusApplicationManager()" );
       
    81 
       
    82     iApaSession.Close();
       
    83     iWsSession.Close();
       
    84 
       
    85     MUS_LOG( "mus: [MUSSRV] <- \
       
    86     					CMusApplicationManager::~CMusApplicationManager()" );
       
    87     }
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CMusApplicationManager::ConstructL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CMusApplicationManager::ConstructL()
       
    95     {
       
    96     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ConstructL()" );
       
    97 
       
    98     User::LeaveIfError( iApaSession.Connect() );
       
    99     User::LeaveIfError( iWsSession.Connect() );
       
   100 
       
   101     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ConstructL()" );
       
   102     }
       
   103 
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CMusApplicationManager::CMusApplicationManager
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CMusApplicationManager::CMusApplicationManager()
       
   110     {
       
   111     }
       
   112 
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CMusApplicationManager::ApplicationRunning
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 TBool CMusApplicationManager::ApplicationRunning()
       
   119     {
       
   120     MUS_LOG( "mus: [MUSSRV] <> CMusApplicationManager::ApplicationRunning()" );
       
   121     return GetApaTask().Exists();
       
   122     }
       
   123 
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CMusApplicationManager::ApplicationRunning
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CMusApplicationManager::StartApplicationL()
       
   130     {
       
   131     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::StartApplicationL()" );
       
   132 
       
   133     if( ApplicationRunning() )
       
   134         {
       
   135         ShowApplicationL();
       
   136         }
       
   137     else
       
   138         {
       
   139         TUid appUid;
       
   140         appUid.iUid = KMusUiUid;
       
   141         
       
   142         TThreadId aThreadId;
       
   143         
       
   144         User::LeaveIfError( 
       
   145                     iApaSession.StartDocument( KNullDesC, appUid, aThreadId) );
       
   146         }
       
   147 
       
   148     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::StartApplicationL()" );
       
   149     }
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CMusApplicationManager::ApplicationRunning
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CMusApplicationManager::StopApplicationL()
       
   157     {
       
   158     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::StopApplicationL()" );
       
   159 
       
   160     TApaTask task = GetApaTask();
       
   161     if( task.Exists() )
       
   162         {
       
   163         SetPropertyL( NMusSessionApi::KStatus, 
       
   164                       MultimediaSharing::EMultimediaSharingNotAvailable );
       
   165         }
       
   166 
       
   167     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::StopApplicationL()" );
       
   168     }
       
   169 
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CMusApplicationManager::ShowApplication
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CMusApplicationManager::ShowApplicationL()
       
   176     {
       
   177     MUS_LOG( "mus: [MUSSRV] -> CMusApplicationManager::ShowApplicationL()" );
       
   178     
       
   179     // does a task for multimediasharing exist?
       
   180     TApaTask task = GetApaTask();
       
   181     if( task.Exists() )
       
   182         {
       
   183         task.BringToForeground();
       
   184         }
       
   185     
       
   186     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::ShowApplicationL()" );
       
   187     }
       
   188 
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CMusApplicationManager::WriteSessionPropertiesL(
       
   195                         MultimediaSharing::TMusUseCase aUseCase,
       
   196                         MultimediaSharing::TMusAvailabilityStatus aStatus,
       
   197                         MDesCArray& aSessionParameters )
       
   198     {
       
   199      MUS_LOG2( "mus: [MUSSRV] -> \
       
   200                CMusApplicationManager::WriteSessionPropertiesL( %d, %d )",
       
   201                ( TInt ) aUseCase, ( TInt ) aStatus );
       
   202 
       
   203     // set use case property
       
   204     SetPropertyL( NMusSessionApi::KUseCase,
       
   205                   ( TInt ) aUseCase );
       
   206 
       
   207     WriteSessionPropertiesL( aStatus, aSessionParameters );
       
   208 
       
   209 
       
   210     MUS_LOG( "mus: [MUSSRV] <- \
       
   211              CMusApplicationManager::WriteSessionPropertiesL()" );
       
   212     }
       
   213 
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CMusApplicationManager::WriteSessionPropertiesL(
       
   220                         MultimediaSharing::TMusAvailabilityStatus aStatus,
       
   221                         MDesCArray& aSessionParameters )
       
   222     {
       
   223      MUS_LOG1( "mus: [MUSSRV] -> \
       
   224                CMusApplicationManager::WriteSessionPropertiesL( %d )",
       
   225                ( TInt ) aStatus );
       
   226 
       
   227     // set tel number property
       
   228     SetPropertyL( NMusSessionApi::KTelNumber,
       
   229                   aSessionParameters.MdcaPoint( KTelNumber ) );
       
   230 
       
   231     // set sip address property
       
   232     SetPropertyL( NMusSessionApi::KRemoteSipAddress,
       
   233                   aSessionParameters.MdcaPoint( KSipAddress ) );
       
   234 
       
   235     // set sip address proposal property
       
   236     SetPropertyL( NMusSessionApi::KRemoteSipAddressProposal,
       
   237                   aSessionParameters.MdcaPoint( KSipAddressProposal ) );
       
   238 
       
   239     // set video codec property
       
   240     SetPropertyL( NMusSessionApi::KVideoCodecs,
       
   241                   aSessionParameters.MdcaPoint( KVideoCodec ) );
       
   242 
       
   243     // set contact id property
       
   244     TLex lex( aSessionParameters.MdcaPoint( KContactId ) );
       
   245     TInt val;
       
   246     lex.Val( val );
       
   247 
       
   248     SetPropertyL( NMusSessionApi::KContactId, val );
       
   249 
       
   250     // set contact id property
       
   251     lex.Assign( aSessionParameters.MdcaPoint( KSipProfileId ) );
       
   252     lex.Val( val );
       
   253 
       
   254     SetPropertyL( NMusSessionApi::KSipProfileId, val );
       
   255 
       
   256     // contact name
       
   257     SetPropertyL( NMusSessionApi::KContactName,
       
   258                   aSessionParameters.MdcaPoint( KContactName ) );
       
   259 
       
   260     // set status property
       
   261     SetStatusL( aStatus );
       
   262     
       
   263     // set privacy property
       
   264     lex.Assign( aSessionParameters.MdcaPoint( KPrivacyStatus ) );
       
   265     lex.Val( val );
       
   266 
       
   267     SetPropertyL( NMusSessionApi::KPrivacyStatus, val );
       
   268 
       
   269     MUS_LOG( "mus: [MUSSRV] <- \
       
   270              CMusApplicationManager::WriteSessionPropertiesL()" );
       
   271     }
       
   272 
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CMusApplicationManager::SetStatusL( 
       
   279                         MultimediaSharing::TMusAvailabilityStatus aStatus )
       
   280     {
       
   281     MUS_LOG1( "mus: [MUSSRV] -> CMusApplicationManager::SetStatusL( %d )",
       
   282               ( TInt ) aStatus );
       
   283     SetPropertyL( NMusSessionApi::KStatus, ( TInt ) aStatus );
       
   284     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetStatusL()" );
       
   285     }
       
   286 
       
   287 	    
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CMusApplicationManager::SetIndicatorStatusL( TBool aLaunch )
       
   293     {
       
   294     TInt launch = aLaunch;
       
   295     MUS_LOG1( "mus: [MUSSRV] -> CMusApplicationManager::SetStatusL( %d )",
       
   296               launch );
       
   297               
       
   298     TInt indicatorStatus;
       
   299     TInt ret = RProperty::Get( NMusSessionApi::KCategoryUid, 
       
   300                                NMusSessionApi::KMusIndicatorStatus,
       
   301                                indicatorStatus );
       
   302 
       
   303     if ( ret != KErrNone && ret != KErrNotFound ) 
       
   304         {
       
   305         User::Leave( ret );
       
   306         }
       
   307 
       
   308     // set property only if not defined yet or if value changed
       
   309     if ( ret == KErrNotFound || indicatorStatus != launch )
       
   310         {
       
   311         SetPropertyL( NMusSessionApi::KMusIndicatorStatus, launch );    
       
   312         }
       
   313     
       
   314     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetStatusL()" );
       
   315     }
       
   316 
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CMusApplicationManager::SetPropertyL( TUint aProperty, 
       
   323                                            const TDesC& aValue )
       
   324     {
       
   325     MUS_LOG1( "mus: [MUSSRV] -> CMusApplicationManager::SetPropertyL( %d )",
       
   326                aProperty );
       
   327     MUS_LOG_TDESC( "mus: [MUSSRV]    New property value: ", aValue );
       
   328 
       
   329     // set tel number property
       
   330     TInt retval = RProperty::Define( NMusSessionApi::KCategoryUid,
       
   331                                      aProperty,
       
   332                                      RProperty::EText );
       
   333 
       
   334     if( retval != KErrAlreadyExists && retval != KErrNone )
       
   335         {
       
   336         User::Leave( retval );
       
   337         }
       
   338     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   339                                         aProperty,
       
   340                                         aValue ) );
       
   341 
       
   342     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetPropertyL()" );
       
   343     }
       
   344 
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CMusApplicationManager::SetPropertyL( TUint aProperty, TInt aValue )
       
   351     {
       
   352     MUS_LOG2( "mus: [MUSSRV] -> CMusApplicationManager::SetPropertyL( %d, %d )",
       
   353              ( TInt ) aProperty, aValue );
       
   354 
       
   355     // set tel number property
       
   356     TInt retval = RProperty::Define( NMusSessionApi::KCategoryUid,
       
   357                                      aProperty,
       
   358                                      RProperty::EInt );
       
   359     
       
   360     if( retval != KErrAlreadyExists && retval != KErrNone )
       
   361         {
       
   362         User::Leave( retval );
       
   363         }
       
   364     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   365                                         aProperty,
       
   366                                         aValue ) );
       
   367 
       
   368     MUS_LOG( "mus: [MUSSRV] <- CMusApplicationManager::SetPropertyL()" );
       
   369     }
       
   370 
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 TApaTask CMusApplicationManager::GetApaTask() 
       
   377     {
       
   378     MUS_LOG( "mus: [MUSSRV] <> CMusApplicationManager::GetApaTask()" );
       
   379     TUid appUid;
       
   380     appUid.iUid = KMusUiUid;
       
   381     return TApaTaskList( iWsSession ).FindApp( appUid );
       
   382     }