multimediacommsengine/mmcesrv/mmceserver/src/mcecssessionimplementation.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <badesca.h>
       
    22 #include <pathinfo.h>
       
    23 
       
    24 #include "mcecssessionimplementation.h"
       
    25 #include "mcecssession.h"
       
    26 #include "mcecssessionreceiver.h"
       
    27 #include "mcecomaudiocodec.h"
       
    28 #include "mcecomvideocodec.h"
       
    29 #include "mcecssubsession.h"
       
    30 #include "mcesipmanager.h"
       
    31 #include "mcemediamanager.h"
       
    32 #include "mcesipdefaults.h"
       
    33 #include "mcesrvlogs.h"
       
    34 #include "mceserial.h"
       
    35 #include "mcecommediasink.h"
       
    36 #include "mcefilesource.h"
       
    37 #include "mcecomcamerasource.h"
       
    38 
       
    39 
       
    40  
       
    41 #define MCE_WRITE( aType, aData )\
       
    42     aType writeBuf( aData );\
       
    43     aInfo.Copy( writeBuf );
       
    44     
       
    45     
       
    46 #define MCE_READ( aCastType, aType, aData )\
       
    47     aCastType readBuf;\
       
    48     readBuf.Copy( aInfo );\
       
    49     aType aData = readBuf();
       
    50 
       
    51 
       
    52 _LIT(KMceApplPrivatePath, "%3Sprivate\\%x\\");
       
    53 _LIT(KMceRootPath, "%3S");
       
    54  
       
    55 // -----------------------------------------------------------------------------
       
    56 // CMceCsSessionImplementation::NewL
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CMceCsSessionImplementation* CMceCsSessionImplementation::NewL(
       
    60                                                 CMceSipManager& aManager,
       
    61                                                 CMceCsSession* aITCProvider )
       
    62 	{
       
    63     CMceCsSessionImplementation* self = 
       
    64        CMceCsSessionImplementation::NewLC( aManager, aITCProvider );
       
    65     CleanupStack::Pop(self);
       
    66     return self;
       
    67 	}
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CMceCsSessionImplementation::NewLC
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CMceCsSessionImplementation* CMceCsSessionImplementation::NewLC(
       
    74                                                CMceSipManager& aManager,
       
    75                                                CMceCsSession* aITCProvider )
       
    76 	{
       
    77     CMceCsSessionImplementation* self = 
       
    78             new (ELeave) CMceCsSessionImplementation( aManager, *aITCProvider );
       
    79     CleanupStack::PushL(self);
       
    80     self->ConstructL();
       
    81     return self;
       
    82 	}
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CMceCsSessionImplementation::CMceCsSessionImplementation
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CMceCsSessionImplementation::CMceCsSessionImplementation(
       
    89                                                 CMceSipManager& aManager,
       
    90                                                 CMceCsSession& aITCProvider )
       
    91 : iManager( aManager ),
       
    92   iITCProvider( &aITCProvider )
       
    93 	{
       
    94 	}
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CMceCsSessionImplementation::ConstructL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CMceCsSessionImplementation::ConstructL ()
       
   101 	{
       
   102     MCESRV_DEBUG("CMceCsSessionImplementation::ConstructL, Entry");
       
   103     iDefaults = CMceSipDefaults::NewL();
       
   104     MCESRV_DEBUG("CMceCsSessionImplementation::ConstructL, Exit");
       
   105 	}
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CMceCsSessionImplementation::~CMceCsSessionImplementation
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CMceCsSessionImplementation::~CMceCsSessionImplementation()
       
   112 	{
       
   113 	delete iDefaults;
       
   114     iSubSessions.ResetAndDestroy();
       
   115     iSubSessions.Close();
       
   116 	}
       
   117 
       
   118     
       
   119 // -----------------------------------------------------------------------------
       
   120 // CMceCsSessionImplementation::ServerCore
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 RPointerArray<CMceCsSubSession>& CMceCsSessionImplementation::SubSessions()
       
   124     {
       
   125     return iSubSessions;
       
   126     }
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CMceCsSessionImplementation::SupportedAudioCodecsL
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 HBufC8* CMceCsSessionImplementation::SupportedAudioCodecsL()
       
   134 	{
       
   135 	
       
   136     MCESRV_DEBUG("CMceCsSessionImplementation::SupportedAudioCodecsL, Entry");
       
   137     CDesC8ArrayFlat* codecs = NULL;
       
   138     HBufC8* codecsAsString = NULL;
       
   139     
       
   140 	RPointerArray<CMceComAudioCodec> supportedCodecs;
       
   141 	CleanupStack::PushL( TCleanupItem( ArrayCleanup, &supportedCodecs ) );
       
   142 		
       
   143 	iManager.MediaManager().GetCapabilitiesL( supportedCodecs );
       
   144 
       
   145     codecs = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   146     CleanupStack::PushL( codecs );
       
   147     
       
   148 	for ( int i=0;i<supportedCodecs.Count();i++ )
       
   149 		{
       
   150 		CMceComAudioCodec* codec = supportedCodecs[i];
       
   151 		
       
   152 		CMceMsgObject<CMceComAudioCodec>* codecMsg = 
       
   153                     new (ELeave) CMceMsgObject<CMceComAudioCodec>
       
   154                     ( *codec, EMceItcMsgTypeCodec );
       
   155 		CleanupStack::PushL( codecMsg );
       
   156 
       
   157 		codecMsg->EncodeL();
       
   158 		codecs->AppendL( codecMsg->EncodeBuffer().Ptr(0) );
       
   159 		CleanupStack::PopAndDestroy( codecMsg );
       
   160 		}
       
   161     CMceMsgTextArray* msgCodecs = new (ELeave) CMceMsgTextArray( *codecs );
       
   162     CleanupStack::PushL( msgCodecs );
       
   163     msgCodecs->EncodeL();
       
   164     
       
   165     codecsAsString = msgCodecs->EncodeBufferCloneL();
       
   166     
       
   167     CleanupStack::PopAndDestroy( msgCodecs );
       
   168     CleanupStack::PopAndDestroy( codecs );
       
   169 	CleanupStack::PopAndDestroy( &supportedCodecs ); //TCleanupItem
       
   170     	
       
   171     MCESRV_DEBUG("CMceCsSessionImplementation::SupportedAudioCodecsL, Exit");
       
   172 	
       
   173 	return codecsAsString;
       
   174         	
       
   175 	}
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CMceCsSessionImplementation::SupportedVideoCodecsL
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 HBufC8* CMceCsSessionImplementation::SupportedVideoCodecsL()
       
   182 	{
       
   183 	
       
   184     MCESRV_DEBUG("CMceCsSessionImplementation::SupportedVideoCodecsL, Entry");
       
   185     CDesC8ArrayFlat* codecs = NULL;
       
   186     HBufC8* codecsAsString = NULL;
       
   187     
       
   188 	RPointerArray<CMceComVideoCodec> supportedCodecs;
       
   189 	CleanupStack::PushL( TCleanupItem( ArrayCleanup, &supportedCodecs ) );
       
   190 		
       
   191 	iManager.MediaManager().GetCapabilitiesL( supportedCodecs );
       
   192 
       
   193     codecs = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   194     CleanupStack::PushL( codecs );
       
   195     
       
   196 	for ( int i=0;i<supportedCodecs.Count();i++ )
       
   197 		{
       
   198 		CMceComVideoCodec* codec = supportedCodecs[i];
       
   199 		
       
   200 		CMceMsgObject<CMceComVideoCodec>* codecMsg = 
       
   201                     new (ELeave) CMceMsgObject<CMceComVideoCodec>
       
   202                     ( *codec, EMceItcMsgTypeCodec );
       
   203 		CleanupStack::PushL( codecMsg );
       
   204 
       
   205 		codecMsg->EncodeL();
       
   206 		codecs->AppendL( codecMsg->EncodeBuffer().Ptr(0) );
       
   207 		CleanupStack::PopAndDestroy( codecMsg );
       
   208 		}
       
   209     CMceMsgTextArray* msgCodecs = new (ELeave) CMceMsgTextArray( *codecs );
       
   210     CleanupStack::PushL( msgCodecs );
       
   211     msgCodecs->EncodeL();
       
   212     
       
   213     codecsAsString = msgCodecs->EncodeBufferCloneL();
       
   214     
       
   215     CleanupStack::PopAndDestroy( msgCodecs );
       
   216     CleanupStack::PopAndDestroy( codecs );
       
   217 	CleanupStack::PopAndDestroy( &supportedCodecs ); //TCleanupItem
       
   218     	
       
   219     MCESRV_DEBUG("CMceCsSessionImplementation::SupportedVideoCodecsL, Exit");
       
   220 	
       
   221 	return codecsAsString;
       
   222         	
       
   223 	}
       
   224 
       
   225 
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CMceCsSession::DoServiceL
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CMceCsSessionImplementation::DoServiceL( TMceIds& aIds, TInt aFunction, TPtr8& aInfo )
       
   232     {
       
   233 
       
   234     MCESRV_DEBUG("CMceCsSessionImplementation::DoServiceL( read ), Entry");
       
   235 
       
   236     switch( aFunction )
       
   237         {
       
   238         case EMceItcCameraInfo:
       
   239             {
       
   240     		MCESRV_DEBUG("getting camera info");
       
   241             MCE_READ( TMceItcArgTCameraInfo, TMceCameraInfo, cameraInfo );
       
   242             iManager.MediaManager().GetCameraInfoL( cameraInfo.iIndex,
       
   243                                                     cameraInfo.iInfo );
       
   244             MCE_WRITE( TMceItcArgTCameraInfo, cameraInfo ); 
       
   245             break;
       
   246             }
       
   247         case EMceItcCamerasAvailable:
       
   248             {
       
   249             TInt camerasAvailable = KErrNotFound;
       
   250             iManager.MediaManager().GetCamerasAvailableL( camerasAvailable );
       
   251     		MCESRV_DEBUG_DVALUE("getting available cameras. #", camerasAvailable );
       
   252             MCE_WRITE( TMceItcArgTInt, camerasAvailable ); 
       
   253             break;
       
   254             }
       
   255         case EMceItcDisplaysAvailable:
       
   256             {
       
   257             TInt displaysAvailable = KErrNotFound;
       
   258             iManager.MediaManager().GetDisplaysAvailableL( displaysAvailable );
       
   259     		MCESRV_DEBUG_DVALUE("getting displays available. value", displaysAvailable );
       
   260             MCE_WRITE( TMceItcArgTInt, displaysAvailable ); 
       
   261             break;
       
   262             }
       
   263         case EMceItcFileInfo:
       
   264             {
       
   265     		MCESRV_DEBUG("getting file info");
       
   266             TMceItcArgTFileInfo readBuf;
       
   267             readBuf.Copy( aInfo );
       
   268             TMceFileInfo& fileInfo = readBuf();
       
   269             GetFileInfoL( aIds, fileInfo );
       
   270             MCE_WRITE( TMceItcArgTFileInfo, fileInfo ); 
       
   271             break;
       
   272             }
       
   273         case EMceItcMaxVolume:
       
   274             {
       
   275             TInt maxVolume = KErrNotFound;
       
   276             iManager.MediaManager().GetMaxVolumeL( maxVolume );
       
   277     		MCESRV_DEBUG_DVALUE("getting max volume. value", maxVolume );
       
   278             MCE_WRITE( TMceItcArgTInt, maxVolume );  
       
   279             break;
       
   280             }
       
   281         case EMceItcMaxGain:
       
   282             {
       
   283             TInt maxGain = KErrNotFound;
       
   284             iManager.MediaManager().GetMaxGainL( maxGain );
       
   285     		MCESRV_DEBUG_DVALUE("getting max volume. value", maxGain );
       
   286             MCE_WRITE( TMceItcArgTInt, maxGain );  
       
   287             break;
       
   288             }
       
   289         default:
       
   290             {
       
   291         	#ifndef ALLOW_NOT_SUPPORTED_ITC
       
   292         	User::Leave(KErrNotSupported);
       
   293         	#endif
       
   294             }
       
   295         }
       
   296     
       
   297     MCESRV_DEBUG("CMceCsSessionImplementation::DoServiceL( read ), Exit");
       
   298     }
       
   299     
       
   300 // -----------------------------------------------------------------------------
       
   301 // CMceCsSessionImplementation::DoServiceL
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 HBufC8* CMceCsSessionImplementation::DoServiceL( TMceIds& /*aIds*/, TInt /*aFunction*/ )
       
   305     {
       
   306     MCESRV_DEBUG("CMceCsSessionImplementation::DoServiceL(no data), Entry");
       
   307     HBufC8* returnMessage = NULL;
       
   308     #ifndef ALLOW_NOT_SUPPORTED_ITC
       
   309     User::Leave(KErrNotSupported);
       
   310     #endif
       
   311     
       
   312     MCESRV_DEBUG("CMceCsSessionImplementation::DoServiceL(no data), Exit");
       
   313     
       
   314     return returnMessage;
       
   315     
       
   316     }
       
   317     
       
   318 // -----------------------------------------------------------------------------
       
   319 // CMceCsSessionImplementation::DoServiceL
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CMceCsSessionImplementation::DoServiceL( TMceIds& /*aIds*/, TInt aFunction, const TDesC8& aInfo )
       
   323     {
       
   324     MCESRV_DEBUG("CMceCsSessionImplementation::DoServiceL( write ), Entry");
       
   325     
       
   326     switch( aFunction )
       
   327         {
       
   328         case EMceItcCancelTranscode:
       
   329             {
       
   330     		MCESRV_DEBUG("cancelling transcode");
       
   331             MCE_READ( TMceItcArgTUint32, TUint32, sessionId );
       
   332             iManager.MediaManager().CancelTranscodeFileL( sessionId );
       
   333             break;
       
   334             }
       
   335         default:
       
   336             {
       
   337         	#ifndef ALLOW_NOT_SUPPORTED_ITC
       
   338         	User::Leave(KErrNotSupported);
       
   339         	#endif
       
   340             }
       
   341         }
       
   342     
       
   343     MCESRV_DEBUG("CMceCsSessionImplementation::DoServiceL( write ), Exit");
       
   344     }
       
   345     
       
   346 // -----------------------------------------------------------------------------
       
   347 // CMceCsSessionImplementation::DoServiceL
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CMceCsSessionImplementation::DoServiceL( TMceIds& aIds, TInt aFunction, 
       
   351                                               CMceMsgBase& aMessage )
       
   352     {
       
   353     MCESRV_DEBUG("CMceCsSessionImplementation::DoServiceL( message ), Entry");
       
   354     switch( aFunction )
       
   355         {
       
   356         case EMceItcTranscode:
       
   357             {
       
   358     		MCESRV_DEBUG("transcoding");
       
   359             CMceMsgObject<CMceComFileSource>* msg = 
       
   360                 static_cast<CMceMsgObject<CMceComFileSource>*>( &aMessage );
       
   361             
       
   362             CMceComFileSource* file = msg->Object();
       
   363             CleanupStack::PushL( file );
       
   364             file->iClient = this;
       
   365             TUint32 sessionId = iManager.MediaManager().TranscodeFileL( file );
       
   366             aIds.Set( KMceIdsIndexTCId, sessionId );
       
   367             CleanupStack::Pop( file );
       
   368             break;
       
   369             }
       
   370         case EMceItcTranscodeWithSession:
       
   371             {
       
   372            	MCESRV_DEBUG("transcoding with session");
       
   373            	
       
   374            	// Session structure is needed temporarily by mediamanager
       
   375            	// in order to find out output codec types. 
       
   376            	//
       
   377             CMceMsgObject<CMceComSession>* msg = 
       
   378                 static_cast<CMceMsgObject<CMceComSession>*>( &aMessage );
       
   379             
       
   380             CMceComSession* session = msg->Object();
       
   381             CleanupStack::PushL( session );
       
   382             
       
   383             CMceComFileSource* file = NULL;
       
   384             for( TInt i = 0; session && ( i < session->Streams().Count() ) && !file; i++ )
       
   385                 {
       
   386                 if ( session->Streams()[ i ]->Source() &&
       
   387                      session->Streams()[ i ]->Source()->Type() == KMceFileSource )
       
   388                     {
       
   389                     file = static_cast<CMceComFileSource*>( 
       
   390                             session->Streams()[ i ]->Source() );
       
   391                     file->iClient = this;
       
   392                     }
       
   393                 }
       
   394             __ASSERT_ALWAYS( file, User::Leave( KErrArgument ) );
       
   395             TUint32 sessionId = iManager.MediaManager().TranscodeFileL( file );
       
   396             aIds.Set( KMceIdsIndexTCId, sessionId );
       
   397             
       
   398             // Filesource was taken in use from session by mediamanager
       
   399             // (took ownership) and rest can be discarded. File is not deleted
       
   400             // while deleting session because of ref count increase.
       
   401             //
       
   402             file->ReferenceCount()++;
       
   403             CleanupStack::PopAndDestroy( session );
       
   404             break;
       
   405             }
       
   406         default:
       
   407             {
       
   408         	#ifndef ALLOW_NOT_SUPPORTED_ITC
       
   409         	User::Leave(KErrNotSupported);
       
   410         	#endif
       
   411             }
       
   412         }
       
   413     
       
   414     MCESRV_DEBUG("CMceCsSessionImplementation::DoServiceL( message ), Exit");
       
   415     
       
   416     }
       
   417 
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CMceCsSessionImplementation::GetFileInfoL
       
   421 // -----------------------------------------------------------------------------
       
   422 //
       
   423 void CMceCsSessionImplementation::GetFileInfoL( TMceIds& aIds, 
       
   424                                                 TMceFileInfo& aFileInfo )
       
   425     {
       
   426     MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Entry");
       
   427     
       
   428     // Save some stack
       
   429     {
       
   430     const RMessage2* itcContext = MCE_IDS_ITC_CONTEXT( aIds );
       
   431     const TDesC& fileName = aFileInfo.iFileName;
       
   432 	const TDesC& rootPath = PathInfo::PhoneMemoryRootPath(); 
       
   433     TFileName privatePath;
       
   434     TFileName realRootPath;
       
   435 
       
   436     __ASSERT_ALWAYS( MCE_NOT_NULL_PTR( itcContext ) , User::Leave( KErrArgument ) );
       
   437     	
       
   438     
       
   439     TUid clientUId = itcContext->SecureId();
       
   440 	privatePath.Format(KMceApplPrivatePath, &rootPath, clientUId.iUid );
       
   441 	realRootPath.Format(KMceRootPath, &rootPath );
       
   442     
       
   443     MCESRV_DEBUG_SVALUE16("CMceCsSessionImplementation::GetFileInfoL, file", fileName );
       
   444     MCESRV_DEBUG_SVALUE16("CMceCsSessionImplementation::GetFileInfoL, root", rootPath );    
       
   445     MCESRV_DEBUG_SVALUE16("CMceCsSessionImplementation::GetFileInfoL, private", privatePath );
       
   446 
       
   447 	if( itcContext->HasCapability( ECapabilityAllFiles ) )
       
   448 		{
       
   449     	MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Client has AllFiles capability");
       
   450 	    aFileInfo.iAccessRights = TMceFileInfo::EReadWrite;		
       
   451 		}
       
   452 	else if( fileName.FindF( rootPath ) == 0 )
       
   453 		{
       
   454     	MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Client accessing phone root(data)");
       
   455 	    aFileInfo.iAccessRights = TMceFileInfo::EReadWrite;		
       
   456 		}
       
   457 	else if( fileName.FindF( privatePath ) == 0 )
       
   458 		{
       
   459     	MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Client accessing private path");
       
   460 	    aFileInfo.iAccessRights = TMceFileInfo::EReadWrite;		
       
   461 		}
       
   462 	else if( fileName.FindF( privatePath ) == 0 )
       
   463 		{
       
   464     	MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Client accessing private path");
       
   465 	    aFileInfo.iAccessRights = TMceFileInfo::EReadWrite;		
       
   466 		}
       
   467 	else if( fileName.FindF( realRootPath ) == KErrNotFound )
       
   468 		{
       
   469     	MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Client accessing another drive");
       
   470 	    aFileInfo.iAccessRights = TMceFileInfo::EReadWrite;		
       
   471 		}
       
   472 	else
       
   473 		{
       
   474     	MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Permission denied");
       
   475 	    aFileInfo.iAccessRights = TMceFileInfo::EZero;				
       
   476 		}	
       
   477     }
       
   478     
       
   479     if ( aFileInfo.iDirection >= TMceFileInfo::ERead && 
       
   480     	 aFileInfo.iAccessRights > TMceFileInfo::EZero )
       
   481         {
       
   482     	MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Getting file info");
       
   483         iManager.MediaManager().GetFileInfoL( aFileInfo );
       
   484         }			
       
   485 
       
   486     MCESRV_DEBUG("CMceCsSessionImplementation::GetFileInfoL, Exit");
       
   487     }
       
   488 
       
   489             
       
   490 
       
   491 // -----------------------------------------------------------------------------
       
   492 // CMceCsSessionImplementation::StoreClientContent
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 void CMceCsSessionImplementation::StoreClientContent( HBufC8* aClientContent )
       
   496     {
       
   497     delete aClientContent;
       
   498     }
       
   499 
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CMceCsSessionImplementation::EventReceived
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 void CMceCsSessionImplementation::EventReceived( TMceMccComEvent& aEvent )
       
   506     {
       
   507     MCESRV_DEBUG("CMceCsSessionImplementation::EventReceived, Entry");
       
   508 
       
   509     TMceIds ids;
       
   510     ids.iManagerType = KMceCSSIPSession;
       
   511     ids.iCallbackID = aEvent.iItcEvent;
       
   512 	ids.iMediaID = aEvent.iStream ? aEvent.iStream->Id() : KMceMediaIdNotAssigned;
       
   513 	ids.iSinkID = aEvent.iSink ? aEvent.iSink->Id() : KMceMediaIdNotAssigned;
       
   514 	ids.iSourceID = aEvent.iSource ? aEvent.iSource->Id() : KMceMediaIdNotAssigned;
       
   515 	ids.iState = aEvent.iItcData;
       
   516 	ids.iStatus = aEvent.iError;
       
   517 
       
   518     TRAP_IGNORE( SendToClientL( ids, NULL, NULL ) );
       
   519         
       
   520     MCESRV_DEBUG("CMceCsSessionImplementation::EventReceived, Exit");
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // CMceCsSessionImplementation::ArrayCleanup
       
   525 // -----------------------------------------------------------------------------
       
   526 //
       
   527 void CMceCsSessionImplementation::ArrayCleanup(TAny* aArray)
       
   528 	{
       
   529     RPointerArray<CMceComAudioCodec>* array = 
       
   530         reinterpret_cast<RPointerArray<CMceComAudioCodec>*>(aArray);
       
   531     if (array)
       
   532         {
       
   533         array->ResetAndDestroy();
       
   534         }
       
   535 	}
       
   536 
       
   537 
       
   538 
       
   539 // -----------------------------------------------------------------------------
       
   540 // CMceCsSessionImplementation::SubSessionL
       
   541 // -----------------------------------------------------------------------------
       
   542 //
       
   543 CMceCsSubSession* CMceCsSessionImplementation::SubSessionL( TUint32 aSessionId )
       
   544     {
       
   545 	CMceCsSubSession* subSession = 
       
   546 	    reinterpret_cast<CMceCsSubSession*>( aSessionId );
       
   547     User::LeaveIfError( iSubSessions.Find( subSession ) );
       
   548     return subSession;
       
   549 	
       
   550     }
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // CMceCsSessionImplementation::FindSubSession
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 const CMceCsSubSession* 
       
   557     CMceCsSessionImplementation::FindSubSession( TUint32 aDialogId )
       
   558     {
       
   559     CMceCsSubSession* subSession = NULL;
       
   560     TInt i = 0;
       
   561     
       
   562     while ( !subSession && i < iSubSessions.Count() )
       
   563         {
       
   564         subSession = iSubSessions[i++];
       
   565         if ( subSession->DialogId() != aDialogId )
       
   566             {
       
   567             subSession = NULL;
       
   568             }
       
   569         }
       
   570     return subSession;
       
   571     }
       
   572 
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // CMceCsSessionImplementation::CreateSubSessionL
       
   576 // -----------------------------------------------------------------------------
       
   577 //
       
   578 void CMceCsSessionImplementation::CreateSubSessionL( TMceIds& aIds,
       
   579                                                      CDesC8Array& aParams )
       
   580     {
       
   581     MCESRV_DEBUG("CMceCsSessionImplementation::CreateSubSessionL, Entry");
       
   582 	User::LeaveIfNull( iITCProvider );
       
   583         
       
   584     CMceCsSubSession *subSession = 
       
   585         iManager.CreateSubSessionL( ClientSession(), aIds, aParams );
       
   586         
       
   587     CleanupStack::PushL( subSession );
       
   588     iSubSessions.AppendL(subSession);
       
   589     CleanupStack::Pop(subSession);
       
   590     
       
   591     aIds.iSessionID = MCE_SESSION_ID( subSession );
       
   592     aIds.iDialogID = subSession->DialogId();
       
   593     
       
   594     MCESRV_DEBUG("CMceCsSessionImplementation::CreateSubSessionL, Exit");
       
   595     }
       
   596 
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // CMceCsSessionImplementation::RemoveSubSessionL
       
   600 // -----------------------------------------------------------------------------
       
   601 //
       
   602 void CMceCsSessionImplementation::RemoveSubSessionL( TUint32 aSessionId )
       
   603     {
       
   604     MCESRV_DEBUG("CMceCsSessionImplementation::RemoveSubSessionL, Entry");
       
   605     MCESRV_DEBUG_DVALUE("id", aSessionId );
       
   606     
       
   607     
       
   608 	CMceCsSubSession* subSession = SubSessionL( aSessionId );
       
   609     TInt index = iSubSessions.Find( subSession );
       
   610     iSubSessions.Remove( index );
       
   611     
       
   612     if ( !subSession->CanDispose() && 
       
   613          !subSession->Terminate() )
       
   614         {
       
   615         MCESRV_DEBUG("RemoveSubSessionL: could not terminate -> to orphans");
       
   616         CleanupStack::PushL( subSession );
       
   617         iManager.AddOrphanSubSessionL( subSession );
       
   618         CleanupStack::Pop( subSession );
       
   619         }
       
   620     else
       
   621         {
       
   622         delete subSession;
       
   623         }
       
   624 
       
   625     MCESRV_DEBUG("CMceCsSessionImplementation::RemoveSubSessionL, Exit");
       
   626     
       
   627     }
       
   628 
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // CMceCsSessionImplementation::RemoveAllSubSessions
       
   632 // -----------------------------------------------------------------------------
       
   633 //
       
   634 void CMceCsSessionImplementation::RemoveAllSubSessions( TBool aMakeOrphan )
       
   635     {
       
   636     MCESRV_DEBUG("CMceCsSessionImplementation::RemoveAllSubSessions, Entry");
       
   637     
       
   638     while( iSubSessions.Count() > 0 )
       
   639         {
       
   640         TBool deleteSS = ETrue;
       
   641         
       
   642     	CMceCsSubSession* subSession = iSubSessions[ 0 ];
       
   643         iSubSessions.Remove( 0 );
       
   644     
       
   645         if ( !subSession->CanDispose() && 
       
   646              !subSession->Terminate() )
       
   647             {
       
   648             if ( aMakeOrphan )
       
   649                 {
       
   650                 TRAPD( error, iManager.AddOrphanSubSessionL( subSession ) );
       
   651                 deleteSS = error == KErrNone ? EFalse : ETrue;
       
   652                 }
       
   653             }
       
   654             
       
   655         if ( deleteSS )
       
   656             {
       
   657             delete subSession;
       
   658             }
       
   659         }
       
   660     MCESRV_DEBUG("CMceCsSessionImplementation::RemoveAllSubSessions, Exit");
       
   661     }
       
   662 
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CMceCsSessionImplementation::SendToClientL
       
   666 // -----------------------------------------------------------------------------
       
   667 //
       
   668 void CMceCsSessionImplementation::SendToClientL( TMceIds& aIds, 
       
   669                                                  HBufC8* aContext, 
       
   670                                                  HBufC8* aContent )
       
   671     {
       
   672     MCESRV_DEBUG("CMceCsSessionImplementation::SendToClientL, Entry");
       
   673     
       
   674     if ( !IsOrphan() )
       
   675         {
       
   676         CMceCsSessionReceiver* receiver = ClientSession().ReceiverL( aIds );
       
   677         TMceIds ids = receiver->Ids();
       
   678         ids.Copy( aIds );
       
   679 
       
   680         MCESRV_DEBUG_IDS("IDS", ids );
       
   681                         
       
   682         if ( aContent )
       
   683             {
       
   684             receiver->SendToClientL( ids, aContext, aContent );
       
   685             }
       
   686         else if( aContext )
       
   687             {
       
   688             receiver->SendToClientL( ids, aContext );
       
   689             }
       
   690         else
       
   691             {
       
   692             receiver->SendToClientL( ids );
       
   693             }
       
   694         }
       
   695     else
       
   696         {
       
   697         MCESRV_DEBUG("SendToClientL: orphan -> no recipient to send");
       
   698         delete aContext;
       
   699         delete aContent;
       
   700         }
       
   701         
       
   702     MCESRV_DEBUG("CMceCsSessionImplementation::SendToClientL, Exit");
       
   703     
       
   704     }
       
   705 
       
   706 // -----------------------------------------------------------------------------
       
   707 // CMceCsSessionImplementation::IsOrphan
       
   708 // -----------------------------------------------------------------------------
       
   709 //
       
   710 TBool CMceCsSessionImplementation::IsOrphan()
       
   711     {
       
   712     return MCE_IS_NULL_PTR( iITCProvider );
       
   713     }
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 // CMceCsSessionImplementation::ClientSession
       
   717 // -----------------------------------------------------------------------------
       
   718 //
       
   719 CMceCsSession& CMceCsSessionImplementation::ClientSession()
       
   720     {
       
   721     return *iITCProvider;
       
   722     }
       
   723 
       
   724 // -----------------------------------------------------------------------------
       
   725 // CMceCsSessionImplementation::StoreDefaultHeadersL
       
   726 // -----------------------------------------------------------------------------
       
   727 //
       
   728 void CMceCsSessionImplementation::StoreDefaultHeadersL( CDesC8Array& aMethods, 
       
   729                                                         CDesC8Array* aHeaders )
       
   730     {
       
   731     iDefaults->StoreDefaultHeadersL( aMethods, aHeaders );
       
   732     }
       
   733 
       
   734 // -----------------------------------------------------------------------------
       
   735 // CMceCsSessionImplementation::DefaultHeaders
       
   736 // -----------------------------------------------------------------------------
       
   737 //
       
   738 CDesC8Array& CMceCsSessionImplementation::DefaultHeaders( TInt aMethodInd )
       
   739     {
       
   740     return iDefaults->DefaultHeaders( aMethodInd );
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // CMceCsSessionImplementation::DefaultHeaders
       
   745 // -----------------------------------------------------------------------------
       
   746 //	
       
   747 HBufC8* CMceCsSessionImplementation::DefaultHeadersL( TDesC8& aMethod )
       
   748     {
       
   749     MCESRV_DEBUG("CMceCsSessionImplementation::DefaultHeadersL, Entry");
       
   750 	
       
   751 	CDesC8Array& headers = iDefaults->DefaultHeaders( aMethod );
       
   752     
       
   753 	CMceMsgTextArray* headersMsg = new (ELeave) CMceMsgTextArray( headers );
       
   754     CleanupStack::PushL( headersMsg );
       
   755     headersMsg->EncodeL();
       
   756     
       
   757     HBufC8* headersStr = headersMsg->EncodeBufferCloneL();
       
   758     
       
   759     CleanupStack::PopAndDestroy( headersMsg );
       
   760     
       
   761     MCESRV_DEBUG("CMceCsSessionImplementation::DefaultHeadersL, Exit");
       
   762 	
       
   763 	return headersStr;
       
   764     
       
   765 	
       
   766     }
       
   767 
       
   768 //  End of File