multimediacommsengine/mmcesrv/mmcemediamanager/src/mcenatpluginmanager.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 #include <e32def.h>
       
    21 #include <badesca.h>
       
    22 #include <ecom/ecom.h>
       
    23 #include <in_pkt.h>
       
    24 #include <sdpdocument.h>
       
    25 #include "mcenatpluginmanager.h"
       
    26 #include "mcemmlogs.h"
       
    27 #include "mcecomsession.h"
       
    28 #include "mceloglineparser.h"
       
    29 
       
    30 const TUint KProtocolUdp = 2;
       
    31     
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMceNatPluginManager::NewL
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CMceNatPluginManager* CMceNatPluginManager::NewL()
       
    37     {
       
    38     CMceNatPluginManager* self = new (ELeave) CMceNatPluginManager();
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CMceNatPluginManager::ConstructL
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void CMceNatPluginManager::ConstructL()
       
    50     {
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMceNatPluginManager::CMceNatPluginManager
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CMceNatPluginManager::CMceNatPluginManager()
       
    58     {
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CMceNatPluginManager::~CMceNatPluginManager
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CMceNatPluginManager::~CMceNatPluginManager()
       
    66     {
       
    67     if( iPlugin )
       
    68         {
       
    69         delete iPlugin;
       
    70         }
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CMceNatPluginManager::GetPluginL
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CMceNatPluginManager::GetPluginL()
       
    78     {
       
    79     MCEMM_DEBUG( "********* CMceNatPluginManager::GetPluginL, Entry" );
       
    80     
       
    81     if ( NULL == iPlugin )
       
    82         {
       
    83         MCEMM_DEBUG( "********* CMceNatPluginManager::GetPluginL, INIT" )
       
    84 
       
    85 	    RImplInfoPtrArray infoArray;
       
    86 	    CleanupStack::PushL( TCleanupItem( ResetAndDestroyInfo, &infoArray ) );
       
    87 	    REComSession::ListImplementationsL( KNSPPluginIFUid, infoArray );    
       
    88 
       
    89 	    if ( infoArray.Count() > 0 && infoArray[ 0 ] )
       
    90 	        {
       
    91 		    iPlugin = reinterpret_cast< CNSPPlugin* >(
       
    92 			    REComSession::CreateImplementationL(
       
    93 				    infoArray[0]->ImplementationUid(),
       
    94 				    _FOFF( CNSPPlugin, iDtor_ID_Key ) ) );
       
    95 	        }
       
    96 	    else
       
    97 	        {
       
    98 	        User::Leave( KErrNotFound );
       
    99 	        }
       
   100 	    CleanupStack::Pop(); // TCleanupItem
       
   101 	    infoArray.ResetAndDestroy();
       
   102         }
       
   103     
       
   104     MCEMM_DEBUG( "********* CMceNatPluginManager::GetPluginL, Exit" );
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CMceNatPluginManager::NewSessionL
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TInt CMceNatPluginManager::NewSessionL( MNSPSessionObserver& aNatSessionObserver,
       
   112         TUint32 aIapId, const TDesC8& aDomain )
       
   113     {
       
   114     MCEMM_DEBUG( "********* CMceNatPluginManager::NewSessionL, Entry" );
       
   115     
       
   116     TUint sessionId( 0 );
       
   117     
       
   118     if ( NULL != iPlugin )
       
   119         {
       
   120         sessionId = iPlugin->NewSessionL( aNatSessionObserver,
       
   121                 aIapId, aDomain, KProtocolUdp );
       
   122         }
       
   123     else
       
   124         {
       
   125         User::Leave( KErrNotFound );
       
   126         }
       
   127     
       
   128     MCEMM_DEBUG_DVALUE( "********* CMceNatPluginManager::NewSessionL, Exit, sessionId", 
       
   129                         sessionId );
       
   130     
       
   131     return sessionId;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CMceNatPluginManager::CloseSessionL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CMceNatPluginManager::CloseSessionL( TUint aSessionId )
       
   139     {
       
   140     MCEMM_DEBUG( "********* CMceNatPluginManager::CloseSessionL, Entry" );
       
   141     
       
   142     if ( NULL != iPlugin )
       
   143         {
       
   144         iPlugin->CloseSessionL( aSessionId );
       
   145         }
       
   146     else
       
   147         {
       
   148         User::Leave( KErrNotFound );
       
   149         }
       
   150     
       
   151     MCEMM_DEBUG( "********* CMceNatPluginManager::CloseSessionL, Exit" );
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CMceNatPluginManager::CreateOfferL
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 TNatReturnStatus CMceNatPluginManager::CreateOfferL( 
       
   159     TUint aSessionId,
       
   160     CSdpDocument*& aOffer )
       
   161     {
       
   162     MCEMM_DEBUG( "********* CMceNatPluginManager::CreateOfferL, Entry" );
       
   163    
       
   164     WriteSdpToLog( _L("Offer on entry"), aOffer );
       
   165     
       
   166     TNatReturnStatus status = KErrNotFound;
       
   167     
       
   168     if ( NULL != iPlugin )
       
   169         {
       
   170         status = iPlugin->CreateOfferL( aSessionId, aOffer );
       
   171         }
       
   172     else
       
   173         {
       
   174         User::Leave( KErrNotFound );
       
   175         }
       
   176     
       
   177     WriteSdpToLog( _L("Offer on exit"), aOffer );
       
   178     
       
   179     MCEMM_DEBUG_DVALUE( "********* CMceNatPluginManager::CreateOfferL, Exit(status)=", status );
       
   180     
       
   181     return status;
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CMceNatPluginManager::ResolveL
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 TNatReturnStatus CMceNatPluginManager::ResolveL( 
       
   189     TUint aSessionId,
       
   190     CSdpDocument*& aOffer,
       
   191     CSdpDocument*& aAnswer )
       
   192     {
       
   193     MCEMM_DEBUG( "********* CMceNatPluginManager::ResolveL, Entry" );
       
   194     
       
   195     WriteSdpToLog( _L("Offer on entry"), aOffer );
       
   196     
       
   197     WriteSdpToLog( _L("Answer on entry"), aAnswer );
       
   198     
       
   199     TNatReturnStatus status = KErrNotFound;
       
   200     
       
   201     if ( NULL != iPlugin )
       
   202         {
       
   203         status = iPlugin->ResolveL( aSessionId, aOffer, aAnswer );
       
   204         }
       
   205     else
       
   206         {
       
   207         User::Leave( KErrNotFound );
       
   208         }
       
   209     
       
   210     WriteSdpToLog( _L("Offer on exit"), aOffer );
       
   211     
       
   212     WriteSdpToLog( _L("Answer on exit"), aAnswer );    
       
   213     
       
   214     MCEMM_DEBUG_DVALUE( "********* CMceNatPluginManager::ResolveL, Exit(status)=", status );
       
   215     
       
   216     return status;
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CMceNatPluginManager::DecodeAnswerL
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 TNatReturnStatus CMceNatPluginManager::DecodeAnswerL( 
       
   224     TUint aSessionId,
       
   225     CSdpDocument*& aAnswer )
       
   226     {
       
   227     MCEMM_DEBUG( "********* CMceNatPluginManager::DecodeAnswerL, Entry" );
       
   228     
       
   229     WriteSdpToLog( _L("Answer on entry"), aAnswer );    
       
   230     
       
   231     TNatReturnStatus status = KErrNotFound;
       
   232     
       
   233     if ( NULL != iPlugin )
       
   234         {
       
   235         status = iPlugin->DecodeAnswerL( aSessionId, aAnswer );
       
   236         }
       
   237     else
       
   238         {
       
   239         User::Leave( KErrNotFound );
       
   240         }
       
   241     
       
   242     WriteSdpToLog( _L("Answer on exit"), aAnswer );
       
   243     
       
   244     MCEMM_DEBUG_DVALUE( "********* CMceNatPluginManager::DecodeAnswerL, Exit(status)=", status );
       
   245     
       
   246     return status;
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CMceNatPluginManager::UpdateL
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CMceNatPluginManager::UpdateL( TUint aSessionId, CSdpDocument*& aOffer )
       
   254     {
       
   255     MCEMM_DEBUG( "********* CMceNatPluginManager::UpdateL, Entry" );
       
   256     
       
   257     WriteSdpToLog( _L("Offer on entry"), aOffer );
       
   258     
       
   259     if ( NULL != iPlugin )
       
   260         {
       
   261         iPlugin->UpdateL( aSessionId, aOffer );
       
   262         }
       
   263     else
       
   264         {
       
   265         User::Leave( KErrNotFound );
       
   266         }
       
   267     
       
   268     WriteSdpToLog( _L("Offer on exit"), aOffer );
       
   269     
       
   270     MCEMM_DEBUG( "********* CMceNatPluginManager::UpdateL, Exit" );
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CMceNatPluginManager::RestartL
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 TNatReturnStatus CMceNatPluginManager::RestartL( TUint aSessionId )
       
   278     {
       
   279     MCEMM_DEBUG( "********* CMceNatPluginManager::RestartL, Entry" );
       
   280     
       
   281     TNatReturnStatus status = KErrNotFound;
       
   282     
       
   283     if ( NULL != iPlugin )
       
   284         {
       
   285         status = iPlugin->RestartL( aSessionId );
       
   286         }
       
   287     else
       
   288         {
       
   289         User::Leave( KErrNotFound );
       
   290         }
       
   291     
       
   292     MCEMM_DEBUG_DVALUE( "********* CMceNatPluginManager::RestartL, Exit(status)=", status );
       
   293     
       
   294     return status;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CMceNatPluginManager::NatEnabled
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 TBool CMceNatPluginManager::NatEnabledL()
       
   302     {
       
   303     TRAPD( error, GetPluginL() );
       
   304     if(KErrNoMemory == error)
       
   305     	{
       
   306     	User::Leave( KErrNoMemory );
       
   307     	}
       
   308     if ( KErrNone == error )
       
   309         {
       
   310         if ( NULL != iPlugin )
       
   311             {
       
   312             MCEMM_DEBUG( "********* CMceNatPluginManager::NatEnabled: TRUE" );
       
   313             return ETrue;
       
   314             }
       
   315         else
       
   316             {
       
   317             MCEMM_DEBUG( "********* CMceNatPluginManager::NatEnabled: FALSE" );
       
   318             return EFalse;
       
   319             }
       
   320         }
       
   321     else
       
   322         {
       
   323         MCEMM_DEBUG( "********* CMceNatPluginManager::NatEnabled: FALSE(ELeave)" );
       
   324         return EFalse;
       
   325         }
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CMceNatPluginManager::SetSessionParam
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 TInt CMceNatPluginManager::SetSessionParam( 
       
   333     TUint aSessionId,
       
   334     CNSPPlugin::TNSPSessionParamKey aParamKey,
       
   335     TUint aParamValue )
       
   336 	{
       
   337 	MCEMM_DEBUG( "********* CMceNatPluginManager::SetSessionParam, Entry" );
       
   338 	
       
   339 	TInt status = KErrNone;
       
   340 	
       
   341 	if( iPlugin == NULL)
       
   342 		{
       
   343 		status = KErrNotFound;
       
   344 		}
       
   345 	else
       
   346 		{
       
   347 		status = iPlugin->SetSessionParam( aSessionId, aParamKey, aParamValue );
       
   348 		}
       
   349 	
       
   350 	MCEMM_DEBUG_DVALUE( "********* CMceNatPluginManager::SetSessionParam, Exit(status)=", status );
       
   351 	
       
   352 	return status;
       
   353    	}
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CMceNatPluginManager::GetSessionParam 
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 TInt CMceNatPluginManager::GetSessionParam( 
       
   360     TUint aSessionId,
       
   361     CNSPPlugin::TNSPSessionParamKey aParamKey )
       
   362 	{
       
   363 	MCEMM_DEBUG( "********* CMceNatPluginManager::GetSessionParam, Entry" );
       
   364 	
       
   365 	TInt status = KErrNone;
       
   366 	
       
   367 	if( iPlugin == NULL)
       
   368 		{
       
   369 		status = KErrNotFound;
       
   370 		}
       
   371 	else
       
   372 		{
       
   373 		status = iPlugin->GetSessionParam( aSessionId, aParamKey );
       
   374 		}
       
   375 	
       
   376 	MCEMM_DEBUG_DVALUE( "********* CMceNatPluginManager::GetSessionParam, Exit(status)=", status );
       
   377 	
       
   378 	return status;
       
   379    	}
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CMceNatPluginManager::WriteSdpToLog 
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 #ifdef _DEBUG
       
   386 void CMceNatPluginManager::WriteSdpToLog( 
       
   387     const TDesC& aMsg,
       
   388 	CSdpDocument* aSdp )
       
   389 	{
       
   390 	if ( aSdp )
       
   391 		{
       
   392 		MCEMM_DEBUG_SVALUE( "", aMsg )
       
   393 		CBufBase* buf = NULL;
       
   394 		TRAPD( err, buf = EncodeSdpL( *aSdp ) )
       
   395 
       
   396 		if ( err == KErrNone && buf != NULL )
       
   397 			{
       
   398 			TMceLogLineParser lineParser( buf->Ptr( 0 ), 80 );
       
   399 
       
   400 			while ( !lineParser.End() )
       
   401 				{
       
   402 				MCEMM_DEBUG_SVALUE( "", lineParser.GetLine() )
       
   403 				} 
       
   404 			}
       
   405 		delete buf;
       
   406 		}
       
   407 	else
       
   408 		{
       
   409 		MCEMM_DEBUG( "SDP document NULL" );
       
   410 		}
       
   411     }
       
   412 #else
       
   413 void CMceNatPluginManager::WriteSdpToLog( const TDesC& /* aMsg */,
       
   414 	CSdpDocument* /* aSdp */ )
       
   415 	{
       
   416 
       
   417 	}
       
   418 #endif
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CMceNatPluginManager::EncodeSdpL 
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 CBufBase* CMceNatPluginManager::EncodeSdpL( 
       
   425     CSdpDocument& aSdp )
       
   426     {
       
   427     CBufFlat* buf = CBufFlat::NewL( 100 );
       
   428     CleanupStack::PushL( buf );
       
   429     RBufWriteStream writeStream;
       
   430     writeStream.Open( *buf, 0 );
       
   431     aSdp.EncodeL( writeStream );
       
   432     writeStream.Close();
       
   433     CleanupStack::Pop( buf );
       
   434     return buf;
       
   435     }
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CMceNatPluginManager::ResetAndDestroyInfo
       
   439 // -----------------------------------------------------------------------------
       
   440 //   
       
   441 void CMceNatPluginManager::ResetAndDestroyInfo(TAny* aArray)
       
   442     {
       
   443     RPointerArray< CImplementationInformation >* array =
       
   444     	static_cast< RPointerArray< CImplementationInformation >* >( aArray );
       
   445     array->ResetAndDestroy();
       
   446     }  
       
   447    
       
   448 // end of file