multimediacommsengine/mmcefloorctrlengine/src/fcsession.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:    The class provides the FC session information
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <badesca.h>
       
    24 #include <s32strm.h>
       
    25 
       
    26 #include "fcsession.h"
       
    27 #include "fcinterface.h"
       
    28 #include "sdporiginfield.h"
       
    29 #include "sdpconnectionfield.h"
       
    30 #include "sdpmediafield.h"
       
    31 #include "sdpfmtattributefield.h"
       
    32 #include "sdpattributefield.h"
       
    33 #include "sdpdocument.h"
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CFCSession::NewL
       
    39 // Two-phased constructor.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CFCSession* CFCSession::NewL( MFCPlugIn* aPlugIn, 
       
    43 		                      TUint32 aIapId, 
       
    44 		                      TUint32 aPort )
       
    45 	{
       
    46 	CFCSession* self = CFCSession::NewLC( aPlugIn, aIapId, aPort );
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CFCSession::NewLC
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CFCSession* CFCSession::NewLC( MFCPlugIn* aPlugIn, 
       
    57 		                       TUint32 aIapId, 
       
    58 		                       TUint32 aPort )
       
    59 	{
       
    60 	CFCSession* self = new (ELeave) CFCSession( aPort );
       
    61 	CleanupStack::PushL(self);
       
    62 	self->ConstructL( aPlugIn, aIapId );
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CFCSession::ConstructL
       
    68 // Symbian 2nd phase constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CFCSession::ConstructL( MFCPlugIn* aPlugIn, TUint32 aIapId )
       
    72 	{
       
    73 	User::LeaveIfNull( aPlugIn );
       
    74 	
       
    75 	iSdpFmtAttributeFields = 
       
    76 	    new (ELeave) RPointerArray<CSdpFmtAttributeField>(1);
       
    77 	
       
    78 	iPlugIn = ( CFCInterface* ) aPlugIn;	    
       
    79 	
       
    80 	iPlugIn->SetIapId( aIapId );
       
    81 	iPlugIn->SetLocalPort( iPort );
       
    82 	}
       
    83 	
       
    84 // -----------------------------------------------------------------------------
       
    85 // CFCSession::~CFCSession
       
    86 // destructor.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CFCSession::~CFCSession()
       
    90 	{		
       
    91 	if (iSdpFmtAttributeFields)
       
    92 		{
       
    93 		iSdpFmtAttributeFields->ResetAndDestroy();
       
    94 		iSdpFmtAttributeFields->Close();
       
    95 		delete iSdpFmtAttributeFields;
       
    96 		}
       
    97     delete iPlugIn;
       
    98 	}
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CFCSession::Port
       
   102 // 
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 TUint CFCSession::Port() const
       
   106 	{
       
   107 	return iPort;
       
   108 	}
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CFCSession::SetPort
       
   112 // 
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CFCSession::SetPort( const TUint aPort )
       
   116     {
       
   117     iPort = aPort;
       
   118 	iPlugIn->SetLocalPort(aPort);
       
   119 	iUpdateNeeded = ETrue;
       
   120     }
       
   121 
       
   122 void CFCSession::Update( TUint32 aPort )
       
   123     {
       
   124     SetPort( aPort );
       
   125     iIsReceiver = ( iPort != KFCDefaultPort );
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CFCSession::FormatAttributeFields
       
   130 // Gets all SipMediaFmtAttribute params defined for the FCSession
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 RPointerArray<CSdpFmtAttributeField>& CFCSession::FormatAttributeFields()
       
   134 	{
       
   135 	return *iSdpFmtAttributeFields;
       
   136 	}
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CFCSession::SetFormatAttributeFieldsL
       
   140 // Setting all SipMediaFmtAttribute params defined for the FCSession
       
   141 // -----------------------------------------------------------------------------
       
   142 //	
       
   143 void CFCSession::SetFormatAttributeFieldsL(
       
   144     RPointerArray<CSdpFmtAttributeField>* aAttributes )
       
   145 	{
       
   146 	DoSetFormatAttributeFieldsL( aAttributes );
       
   147 	iUpdateNeeded = ETrue;
       
   148 	}
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CFCSession::DoSetFormatAttributeFieldsL
       
   152 // Setting all SipMediaFmtAttribute params defined for the FCSession
       
   153 // -----------------------------------------------------------------------------
       
   154 //	
       
   155 void CFCSession::DoSetFormatAttributeFieldsL(
       
   156     RPointerArray<CSdpFmtAttributeField>* aAttributes )
       
   157 	{
       
   158 	if (iSdpFmtAttributeFields)
       
   159 		{
       
   160 		iSdpFmtAttributeFields->ResetAndDestroy();
       
   161 		iSdpFmtAttributeFields->Close();
       
   162 		delete iSdpFmtAttributeFields;	
       
   163 		iSdpFmtAttributeFields = NULL;
       
   164 		}
       
   165 		
       
   166 	if ( aAttributes )
       
   167 	    {
       
   168 	    iSdpFmtAttributeFields = aAttributes;    
       
   169 	    }
       
   170 	else
       
   171 	    {
       
   172 	    iSdpFmtAttributeFields = 
       
   173 	        new (ELeave) RPointerArray<CSdpFmtAttributeField>(1);
       
   174 		}
       
   175 	}
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CFCSession::IsFmtAttributeValid
       
   179 // validats all SipMediaFmtAttribute params defined for the FCSession
       
   180 // -----------------------------------------------------------------------------
       
   181 //	
       
   182 TBool CFCSession::IsFmtAttributeValid()
       
   183 	{
       
   184 	TBool validate= EFalse;
       
   185 	if (iSdpFmtAttributeFields)
       
   186 		{
       
   187 		TInt len=0;
       
   188 		CSdpFmtAttributeField* fmtatt = NULL;
       
   189 		for(TInt count=0; count < iSdpFmtAttributeFields->Count(); count++)
       
   190 	        {
       
   191 	        fmtatt = (*iSdpFmtAttributeFields)[count];
       
   192 	        len = fmtatt->Value().Length();
       
   193 	        if (len!=0)
       
   194 	        	{
       
   195 	            validate= ETrue;
       
   196 	        	}
       
   197 	        else
       
   198 	        	{
       
   199         		validate = EFalse;
       
   200         		return validate;	
       
   201         		}
       
   202         	return validate;
       
   203         	}
       
   204 		}
       
   205 	return validate;
       
   206 	}
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CFCSession::UpdateSDPL 
       
   210 // Adds/modifies the FC media line in the offer.
       
   211 // RStringPool should open before using this function
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CFCSession::UpdateSDPL( CSdpDocument& aSdpDocument )
       
   215     {
       
   216     __ASSERT_ALWAYS( iUpdateNeeded, User::Leave( KErrTotalLossOfPrecision ) );
       
   217     //m= application iPort udp NegotiatedPlugin()
       
   218     
       
   219     // Find the media field, and remove, if exists.
       
   220     RPointerArray< CSdpMediaField >& mediaFields = aSdpDocument.MediaFields();
       
   221     TInt ind = FindMediaField( aSdpDocument.MediaFields() );
       
   222     if ( ind != KErrNotFound )
       
   223         {
       
   224         delete mediaFields[ ind ];
       
   225         mediaFields.Remove( ind );
       
   226         }
       
   227     
       
   228     // create  and add new media field. 
       
   229 	RStringF mediaType = SdpCodecStringPool::StringPoolL().StringF(
       
   230                             SdpCodecStringConstants::EMediaApplication, 
       
   231                             SdpCodecStringPool::StringTableL() );
       
   232     CleanupClosePushL( mediaType );
       
   233     
       
   234     RStringF protocol = SdpCodecStringPool::StringPoolL().StringF(
       
   235                     SdpCodecStringConstants::EProtocolUdp, 
       
   236                     SdpCodecStringPool::StringTableL() );
       
   237     CleanupClosePushL( protocol );
       
   238     
       
   239 	CSdpMediaField* mediaField = CSdpMediaField::NewL( mediaType,
       
   240                                                        iPort,
       
   241                                                        protocol,
       
   242                                                        NegotiatedFCPlugIn() );
       
   243 	CleanupStack::PushL( mediaField );            
       
   244     	
       
   245 	if (IsFmtAttributeValid() )
       
   246     	{
       
   247     	for( TInt i = 0; i < iSdpFmtAttributeFields->Count(); i++ )
       
   248     		{
       
   249     		CSdpFmtAttributeField* newField = 
       
   250     		    ( ( *iSdpFmtAttributeFields )[i] )->CloneL();
       
   251     		CleanupStack::PushL( newField );
       
   252     		mediaField->FormatAttributeFields().AppendL( newField );
       
   253     		CleanupStack::Pop( newField );
       
   254     		}
       
   255     	}
       
   256     
       
   257     mediaFields.AppendL( mediaField);	
       
   258     
       
   259     iUpdateNeeded = EFalse; 
       
   260     
       
   261     CleanupStack::Pop( mediaField );  
       
   262 
       
   263     CleanupStack::PopAndDestroy( 2 ); // protocol, mediaType	
       
   264 	}
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CFCSession::DecodeSDPMediaPort
       
   268 // Get Port from the Sdpdoc
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 TUint CFCSession::DecodeSDPMediaPort( 
       
   272         const RPointerArray< CSdpMediaField >& aMediaFields ) const
       
   273 	{
       
   274 	TUint port = 0;
       
   275     
       
   276     TInt ind = FindMediaField( aMediaFields );
       
   277     
       
   278     if ( ind != KErrNotFound )
       
   279         {
       
   280         port = aMediaFields[ ind ]->Port();
       
   281         }
       
   282     
       
   283     return port;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CFCSession::DecodeConnectionAddrL
       
   288 // Get Port from the Sdpdoc
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 HBufC* CFCSession::DecodeConnectionAddrL( 
       
   292                             const CSdpConnectionField* aConnectionField ) const 
       
   293 	{
       
   294     HBufC* addr = NULL;
       
   295     // a connection field might not exist in session level
       
   296     // so do not leave here, if there is no c= in session level, return NULL
       
   297     if ( aConnectionField )
       
   298         {
       
   299         const TInetAddr* remoteAddr = aConnectionField->InetAddress();
       
   300         TBuf< KMaxAddressLength > addr16;
       
   301         remoteAddr->Output( addr16 );
       
   302         addr = addr16.AllocL();
       
   303         }
       
   304     return addr;
       
   305     }
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CFCSession::NegotiatedFCPlugIn
       
   309 // Gets the negotiated floor control plugIn
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 const TDesC8& CFCSession::NegotiatedFCPlugIn() const
       
   313 	{
       
   314 	return iPlugIn->Name();
       
   315 	}
       
   316 
       
   317 // ----------------------------------------------------------------------------
       
   318 // CFCPlugInEngine::StoreInfoL
       
   319 // Store the information
       
   320 // ----------------------------------------------------------------------------
       
   321 //
       
   322 void CFCSession::StoreInfoL( const CSdpDocument& aSdpDocument )
       
   323 	{
       
   324 	//Resolve the remote port and addr	   
       
   325 	HBufC* addr= DecodeConnectionAddrL( aSdpDocument.ConnectionField() );
       
   326 
       
   327 	RPointerArray<CSdpMediaField>& mediaDescriptions = 
       
   328 	    ( const_cast< CSdpDocument* >( &aSdpDocument ) )->MediaFields();
       
   329 	       
       
   330 	if ( addr )
       
   331     	{
       
   332     	CleanupStack::PushL( addr );
       
   333     
       
   334 	    TUint port = DecodeSDPMediaPort( mediaDescriptions );
       
   335 	
       
   336     	//Set the remote address for the specific plugin ex TBCP
       
   337     	iPlugIn->SetAddressL( *addr, port );
       
   338     	CleanupStack::PopAndDestroy( addr );    
       
   339     	}
       
   340 	
       
   341 	//Store the fmt attributes
       
   342 	RPointerArray<CSdpFmtAttributeField> *fmtFields =
       
   343 		new (ELeave) RPointerArray<CSdpFmtAttributeField>(1);
       
   344 		
       
   345     CleanupStack::PushL( TCleanupItem( ArrayCleanupAndDelete, fmtFields ) );
       
   346     		
       
   347 	TInt ind = FindMediaField( mediaDescriptions );
       
   348 	if ( ind != KErrNotFound )
       
   349 	    {
       
   350 	    CSdpMediaField* mediaAnnouncement = mediaDescriptions[ ind ];
       
   351 	    	    
       
   352     	RPointerArray<CSdpFmtAttributeField>& attributes = 
       
   353             mediaAnnouncement->FormatAttributeFields();
       
   354         		    
       
   355         for( TInt fmtCount = 0; fmtCount < attributes.Count(); fmtCount++ )
       
   356             {
       
   357             CSdpFmtAttributeField* fmtatt = attributes[ fmtCount ];
       
   358 			if ( iPlugIn->Name().Compare( fmtatt->Format() ) == 0)
       
   359 		        {
       
   360 		        CSdpFmtAttributeField* newField = fmtatt->CloneL();
       
   361 		        CleanupStack::PushL( newField );
       
   362 				fmtFields->AppendL( newField );
       
   363 				CleanupStack::Pop( newField );
       
   364 				}
       
   365 			}
       
   366 	    }
       
   367 	DoSetFormatAttributeFieldsL( fmtFields );
       
   368 	CleanupStack::Pop(); // cleanup item
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CFCSession::CFCSession
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CFCSession::ReleaseSession()
       
   376 	{
       
   377 	iPort=0;
       
   378 	//Stop the sending and reciving and socketserver. Socket is not close yet
       
   379 	iPlugIn->Stop();
       
   380 	}
       
   381 	
       
   382 // -----------------------------------------------------------------------------
       
   383 // CFCSession::ConnectionReadyL
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 void CFCSession::ConnectionReadyL()
       
   387 	{
       
   388 	iPlugIn->ConnectL( iIsReceiver );
       
   389 	}
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CFCSession::SendToNetL
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void CFCSession::SendToNetL(HBufC8* aData)
       
   396 	{
       
   397 	iPlugIn->SendToNetL(aData);
       
   398 	}
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CFCSession::CFCSession
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 CFCSession::CFCSession( TUint32 aPort ) : 
       
   405 		iPort( aPort ),
       
   406 		iUpdateNeeded( ETrue )
       
   407     {
       
   408 	iIsReceiver = ( iPort != KFCDefaultPort );
       
   409 	}
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CFCSession::PlugIn
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 MFCPlugIn* CFCSession::PlugIn() const
       
   416     {
       
   417     return iPlugIn;
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CFCSession::IsReceiver
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 TBool CFCSession::IsReceiver()
       
   425     {
       
   426     return iIsReceiver;
       
   427     }
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // CFCSession::FindMediaField
       
   431 // Search is done comparing media format to plugin name
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 TInt CFCSession::FindMediaField( 
       
   435                     const RPointerArray<CSdpMediaField>& aMediaFields ) const   
       
   436     {
       
   437 	TInt ind = KErrNotFound;
       
   438 	for ( TInt i = 0; ind == KErrNotFound && i < aMediaFields.Count(); i++ )
       
   439 	    {
       
   440 	    if ( aMediaFields[ i ]->FormatList().Compare( iPlugIn->Name() ) == 0 )
       
   441 	        {
       
   442 	        ind = i;
       
   443 	        }
       
   444 	    }
       
   445 	return ind;	        
       
   446     }
       
   447 		    
       
   448 // -----------------------------------------------------------------------------
       
   449 // CFCSession::ArrayCleanup
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CFCSession::ArrayCleanup(TAny* aArray)
       
   453 	{
       
   454     RPointerArray< CSdpFmtAttributeField >*  array = 
       
   455         reinterpret_cast< RPointerArray< CSdpFmtAttributeField >* >( aArray );
       
   456     if (array)
       
   457         {
       
   458         array->ResetAndDestroy();
       
   459         }
       
   460 	}
       
   461 	
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CFCSession::ArrayCleanupAndDelete
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 void CFCSession::ArrayCleanupAndDelete(TAny* aArray)
       
   468 	{
       
   469     RPointerArray< CSdpFmtAttributeField >*  array = 
       
   470         reinterpret_cast< RPointerArray< CSdpFmtAttributeField >* >( aArray );
       
   471     if (array)
       
   472         {
       
   473         array->ResetAndDestroy();
       
   474         delete array;
       
   475         }
       
   476 	}	
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CFCSession::UpdateNeeded
       
   480 // -----------------------------------------------------------------------------
       
   481 //
       
   482 TBool CFCSession::UpdateNeeded()
       
   483     {
       
   484     return iUpdateNeeded;
       
   485     }
       
   486     	
       
   487 //  End of File