multimediacommsengine/tsrc/testdriver/siptester/ttcnresolverplugin/src/CTTCNResolverPluginBase.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CTTCNResolverPluginBase.h"
       
    19 #include <apacmdln.h>
       
    20 
       
    21 
       
    22 // -----------------------------------------------------------------------------
       
    23 // CTTCNResolverPluginBase::ConstructL
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 void CTTCNResolverPluginBase::ConstructL()
       
    27 	{
       
    28 	TBool found = EFalse;
       
    29 	
       
    30 	const TUid KMyImplementationUid = { MyUid() };
       
    31 	
       
    32 	TFileName uidFileName;
       
    33     ConstructUidFileNameL( _L("c:\\ttcnresolverpluginuid"), 
       
    34                            MyUid(), 
       
    35                            _L(".txt"),
       
    36                            uidFileName );
       
    37 	
       
    38 	HBufC8* uidText = ReadFileContentsL( uidFileName );
       
    39 	if ( uidText )
       
    40 	    {
       
    41 	    found = ETrue;
       
    42 	    }
       
    43     else
       
    44         {
       
    45     	RImplInfoPtrArray infoArray;
       
    46     	REComSession::ListImplementationsL( KSIPResolvedClientIFUid, 
       
    47     	                                    infoArray );
       
    48     	CleanupStack::PushL( TCleanupItem( ResetAndDestroy, &infoArray ) );
       
    49     	
       
    50     	for (TInt i=0; !found && i<infoArray.Count(); i++)
       
    51     		{
       
    52     		CImplementationInformation* info = infoArray[ i ];
       
    53     		if ( info->ImplementationUid() == KMyImplementationUid )
       
    54     			{
       
    55     			uidText = info->DataType().AllocL();
       
    56     			found = ETrue;
       
    57     			}
       
    58     		}
       
    59     		
       
    60     	CleanupStack::PopAndDestroy(); // infoArray
       
    61         }
       
    62 
       
    63     if ( found )
       
    64 		{
       
    65 		CleanupStack::PushL( uidText );
       
    66 		TLex8 lex( *uidText );
       
    67     	TUint value( 0 );
       
    68     	User::LeaveIfError( lex.Val( value, EHex ) );
       
    69         iApplicationUID.iUid = value;
       
    70         CleanupStack::PopAndDestroy( uidText );
       
    71 		}
       
    72     else
       
    73         {
       
    74         User::Leave( KErrNotFound );
       
    75         }
       
    76 
       
    77 	User::LeaveIfError( iApaSession.Connect() );
       
    78 	}
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CTTCNResolverPluginBase::~CTTCNResolverPluginBase
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CTTCNResolverPluginBase::~CTTCNResolverPluginBase()
       
    85 	{
       
    86 	iApaSession.Close();
       
    87 	}
       
    88 	
       
    89 // -----------------------------------------------------------------------------
       
    90 // CTTCNResolverPluginBase::ChannelL
       
    91 // -----------------------------------------------------------------------------
       
    92 //	
       
    93 TUid CTTCNResolverPluginBase::ChannelL( RStringF /*aMethod*/,
       
    94     const TDesC8& /*aRequestUri*/,
       
    95     const RPointerArray<CSIPHeaderBase>& /*aHeaders*/,
       
    96     const TDesC8& /*aContent*/,
       
    97     const CSIPContentTypeHeader* /*aContentType*/)
       
    98     {
       
    99     return iApplicationUID;
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CTTCNResolverPluginBase::ConnectL
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CTTCNResolverPluginBase::ConnectL( TUid aUid )
       
   108 	{
       
   109 	TApaAppInfo appInfo;
       
   110 	User::LeaveIfError( iApaSession.GetAppInfo( appInfo, aUid ) );
       
   111 	CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   112 	#ifdef EKA2
       
   113 	cmdLine->SetExecutableNameL( appInfo.iFullName );
       
   114 	#else
       
   115 	cmdLine->SetLibraryNameL( appInfo.iFullName );
       
   116 	#endif
       
   117 	User::LeaveIfError( iApaSession.StartApp( *cmdLine ) );
       
   118 	CleanupStack::PopAndDestroy( cmdLine ); 
       
   119 	}
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CTTCNResolverPluginBase::ResetAndDestroy
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CTTCNResolverPluginBase::ResetAndDestroy( TAny* anArray )
       
   126 	{
       
   127     RImplInfoPtrArray* array = reinterpret_cast<RImplInfoPtrArray*>( anArray );
       
   128     if (array)
       
   129         {
       
   130         array->ResetAndDestroy();
       
   131         }
       
   132 	}
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CTTCNResolverPluginBase::ReadFileContentsL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 HBufC8* CTTCNResolverPluginBase::ReadFileContentsL( 
       
   139     const TFileName& aFileName )
       
   140     {
       
   141     RFs fs;
       
   142 	User::LeaveIfError( fs.Connect() );
       
   143 	CleanupClosePushL( fs );
       
   144 
       
   145 	RFile file;
       
   146 	TInt err = file.Open( fs, aFileName, EFileRead );
       
   147 	
       
   148 	HBufC8* fileContents = 0;
       
   149 	
       
   150 	if ( err == KErrNone )
       
   151 	    {
       
   152 	    CleanupClosePushL( file );
       
   153 
       
   154         TInt size( 0 );
       
   155         
       
   156         User::LeaveIfError( file.Size( size ) );
       
   157 
       
   158         fileContents = HBufC8::NewLC( size );
       
   159         
       
   160         TPtr8 ptr( fileContents->Des() );
       
   161 	    User::LeaveIfError( file.Read( ptr ) );  
       
   162 	     
       
   163 	    CleanupStack::Pop( fileContents );
       
   164 	    CleanupStack::PopAndDestroy(); // file
       
   165 	    }
       
   166 	
       
   167 	CleanupStack::PopAndDestroy(); // fs
       
   168 	
       
   169 	return fileContents;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CTTCNResolverPluginBase::ConstructUidFileNameL
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CTTCNResolverPluginBase::ConstructUidFileNameL( 
       
   177     const TDesC& aFilePath, 
       
   178     TInt aUid, 
       
   179     const TDesC& aExtension, 
       
   180     TFileName& aFileName )
       
   181     {
       
   182     __ASSERT_ALWAYS( aFilePath.Length() + aExtension.Length() + 14 <= KMaxFileName,
       
   183                      User::Leave( KErrOverflow ) );
       
   184                      
       
   185     aFileName.Copy( aFilePath );
       
   186     aFileName.Append( _L("_") );
       
   187 	aFileName.AppendNum( aUid, EHex );
       
   188 	aFileName.Append( aExtension );
       
   189     }
       
   190