mmsharing/mmshmanagersrv/src/musmanagerserversession.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 <e32base.h>
       
    20 
       
    21 #include "muslogger.h"
       
    22 #include "musmanageripccommon.h"
       
    23 #include "musmanagerserveritcutility.h"
       
    24 #include "musmanagerserversession.h"
       
    25 #include "musmanagerserversessionobserver.h"
       
    26 #include "musmanagerserver.h"
       
    27 
       
    28 
       
    29 const TInt KServerRequestPending = 1;
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // Second phase constructor.
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CMusManagerServerSession::CMusManagerServerSession(
       
    38     CMusManagerServer& aServer,
       
    39     MMusManagerServerSessionObserver& aObserver )
       
    40     : CSession2(), iServer( aServer ), iServerCore( aObserver )
       
    41     {
       
    42     iServer.IncrementSessions();
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Second phase constructor.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void CMusManagerServerSession::ConstructL()
       
    50     {
       
    51  
       
    52     }
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // First phase constructor.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CMusManagerServerSession* CMusManagerServerSession::NewL(
       
    60     CMusManagerServer& aServer,
       
    61     MMusManagerServerSessionObserver& aObserver )
       
    62     {
       
    63     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServerSession::NewL()" );
       
    64     CMusManagerServerSession* self = CMusManagerServerSession::NewLC(
       
    65         aServer,
       
    66         aObserver );
       
    67     CleanupStack::Pop( self );
       
    68     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServerSession::NewL()" );
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // First phase constructor.
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CMusManagerServerSession* CMusManagerServerSession::NewLC(
       
    78     CMusManagerServer& aServer,
       
    79     MMusManagerServerSessionObserver& aObserver )
       
    80     {
       
    81     CMusManagerServerSession* self = new( ELeave ) CMusManagerServerSession(
       
    82         aServer,
       
    83         aObserver );
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     return self;
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // Standard destructor.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CMusManagerServerSession::~CMusManagerServerSession()
       
    95     {
       
    96     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServerSession::~CMusManagerServerSession()" );
       
    97     iServer.DecrementSessions();
       
    98     iServerCore.CancelMonitoring( this );
       
    99     iAvailabilityStatus.Close();
       
   100     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServerSession::~CMusManagerServerSession()" );
       
   101     }
       
   102     
       
   103 // -----------------------------------------------------------------------------
       
   104 // Start to monitor availability states for this session.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CMusManagerServerSession::MonitorAvailabilityL()
       
   108     {
       
   109     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServerSession::MonitorAvailabilityL" );			
       
   110     if ( iAvailabilityStatus.Count() )
       
   111     	{
       
   112     	MusManagerServerItcUtility::WriteAvailabilityReportL( 
       
   113 		iMessage, iAvailabilityStatus[0] );                         
       
   114 	    iAvailabilityStatus.Remove( 0 );
       
   115 	    MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServerSession::\
       
   116 	    	MonitorAvailabilityL" );
       
   117 	    return KErrNone;	
       
   118     	}
       
   119    	else
       
   120    		{
       
   121    		MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServerSession::\
       
   122    			MonitorAvailabilityL" );
       
   123    		return KServerRequestPending;	
       
   124    		}
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Receives incoming messages.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CMusManagerServerSession::ServiceL( const RMessage2& aMessage )
       
   132     {
       
   133     MUS_LOG1( "mus: [MUSSRV]     -> CMusManagerServerSession::ServiceL( %d )",
       
   134               ( TInt ) aMessage.Function() );
       
   135     TMusManagerIpcFunctions function
       
   136         = ( TMusManagerIpcFunctions )aMessage.Function();
       
   137 
       
   138     TInt retVal( KErrNone );
       
   139 
       
   140     switch ( function )
       
   141         {
       
   142     case EMusManagerIpcAvailabilityQuery:
       
   143         {
       
   144         TInt capability = iServerCore.AvailabilityQueryL();
       
   145         MusManagerServerItcUtility::WriteAvailabilityL(
       
   146             aMessage,
       
   147             capability );
       
   148 
       
   149         iLastReport = ( MultimediaSharing::TMusAvailabilityStatus )capability;
       
   150         break;
       
   151         }
       
   152     case EMusManagerIpcInvestigateAvailability:
       
   153         {
       
   154         TRAP( retVal, iServerCore.InvestigateAvailabilityL() );
       
   155         break;
       
   156         }
       
   157     case EMusManagerIpcInvitationReceived:
       
   158         {
       
   159         TUid channelId
       
   160             = MusManagerServerItcUtility::ReadChannelIdL( aMessage );
       
   161 
       
   162         TRAP( retVal, iServerCore.InvitationReceivedL( channelId ) );
       
   163 
       
   164         break;
       
   165         }
       
   166     case EMusManagerIpcOptionsReceived:
       
   167         {
       
   168         TUid channelId
       
   169             = MusManagerServerItcUtility::ReadChannelIdL( aMessage );
       
   170 
       
   171         TRAP( retVal, iServerCore.OptionsReceivedL( channelId ) );
       
   172         break;
       
   173         }
       
   174     case EMusManagerIpcStartMultimediaSharing:
       
   175         {
       
   176         TInt useCase
       
   177             = MusManagerServerItcUtility::ReadUseCaseL( aMessage );
       
   178 
       
   179         TRAP( retVal, iServerCore.StartMultimediaSharingL(
       
   180                         (MultimediaSharing::TMusUseCase) useCase ) );
       
   181         break;
       
   182         }
       
   183     case EMusManagerIpcStopMultimediaSharing:
       
   184         {
       
   185         TRAP( retVal, iServerCore.StopMultimediaSharingL() );
       
   186         break;
       
   187         }
       
   188      case EMusManagerIpcStartObservingAvailability:
       
   189         {
       
   190         iServerCore.RegisterObserverL( this ); 
       
   191         break;
       
   192         }    
       
   193      
       
   194     case EMusManagerIpcMonitorAvailability:
       
   195         {
       
   196         iMessage = aMessage;
       
   197         retVal = MonitorAvailabilityL(); 
       
   198         }
       
   199         break;
       
   200     case EMusManagerIpcCancelMonitoring:
       
   201         {
       
   202         iServerCore.CancelMonitoring( this );
       
   203         }
       
   204         break;
       
   205     case EMusManagerIpcHandleCommand:
       
   206         {
       
   207         TInt command
       
   208             = MusManagerServerItcUtility::ReadCommandL( aMessage );
       
   209 
       
   210         TRAP( retVal, iServerCore.CommandL(
       
   211                         ( MultimediaSharing::TCommandType ) command ) );
       
   212         }
       
   213         break;
       
   214 
       
   215     default:
       
   216         break;
       
   217         }
       
   218 	
       
   219     MUS_LOG1( "mus: [MUSSRV]  - Message compleated with code  %d", retVal );
       
   220   	aMessage.Complete( retVal );	
       
   221 
       
   222 	MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServerSession::ServiceL()" );
       
   223     }
       
   224 
       
   225 void CMusManagerServerSession::AvailabilityChangedL(
       
   226     					MultimediaSharing::TMusAvailabilityStatus aAvailability )
       
   227     {
       
   228     MUS_LOG1( "mus: [MUSSRV]  -> CMusManagerServerCore::AvailabilityChangedL( %d )",
       
   229               aAvailability );
       
   230     // inform ui via application manager (via session api)
       
   231     if( iAvailabilityStatus.Count() && !iMessage.IsNull()  )
       
   232     	{
       
   233     	iAvailabilityStatus.AppendL( aAvailability );	
       
   234     	MusManagerServerItcUtility::WriteAvailabilityReportL( 
       
   235 			iMessage, iAvailabilityStatus[0] );                         
       
   236 	    iAvailabilityStatus.Remove( 0 );
       
   237 	    iMessage.Complete( KErrNone );
       
   238     	}
       
   239     else if ( iMessage.IsNull() )
       
   240     	{
       
   241     	iAvailabilityStatus.AppendL( aAvailability );	                      
       
   242     	}
       
   243     else
       
   244     	{
       
   245     	MusManagerServerItcUtility::WriteAvailabilityReportL( 
       
   246 			iMessage, aAvailability );  
       
   247 		iMessage.Complete( KErrNone ); 	
       
   248     	}
       
   249     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServerSession::AvailabilityChangedL()" );
       
   250     }
       
   251 
       
   252 void CMusManagerServerSession::RequestComplete()
       
   253 	{
       
   254 	MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServerSession::RequestComplete()" );
       
   255  	iMessage.Complete( KErrCancel );
       
   256   	MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServerSession::RequestComplete()" );	
       
   257 	}
       
   258