multimediacommsengine/mmcefloorctrlengine/src/fcpluginengine.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 "fcpluginengine.h"
       
    22 #include "fcplugininfo.h"
       
    23 #include "fcinterfaceinitparams.h"
       
    24 #include "fcpluginiter.h"
       
    25 #include "fcsession.h"
       
    26 
       
    27 // ----------------------------------------------------------------------------
       
    28 // CFCPlugInEngine::NewL
       
    29 // ----------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CFCPlugInEngine* CFCPlugInEngine::NewL(MFCObserver& aFCObserver)
       
    32 	{
       
    33 	CFCPlugInEngine* self = CFCPlugInEngine::NewLC(aFCObserver);
       
    34 	CleanupStack::Pop(self);
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CFCPlugInEngine::NewLC
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C CFCPlugInEngine* CFCPlugInEngine::NewLC(MFCObserver& aFCObserver)
       
    43 	{
       
    44 	CFCPlugInEngine* self = new (ELeave) CFCPlugInEngine(aFCObserver);
       
    45 	CleanupStack::PushL(self);
       
    46 	self->ConstructL();
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 // ----------------------------------------------------------------------------
       
    51 // Destructor
       
    52 // ----------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C CFCPlugInEngine::~CFCPlugInEngine()
       
    55 	{
       
    56 	iFCSessions.ResetAndDestroy();	
       
    57 	iFCPlugIns.ResetAndDestroy();	
       
    58 	REComSession::FinalClose();
       
    59 	}
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CFCPlugInEngine::ConstructL
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 void CFCPlugInEngine::ConstructL()
       
    66 	{
       
    67 	ListMechanismImplementationsL();
       
    68 	}
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CFCPlugInEngine::ConstructL
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 CFCPlugInEngine::CFCPlugInEngine(MFCObserver& aFCObserver)
       
    75 : iFCObserver(aFCObserver),
       
    76   iFCPlugInIter(iFCPlugIns)
       
    77 	{
       
    78 	}
       
    79 	
       
    80 // ----------------------------------------------------------------------------
       
    81 // CFCPlugInEngine::FCPlugInIter
       
    82 // ----------------------------------------------------------------------------
       
    83 //	
       
    84 TFCPlugInIter& CFCPlugInEngine::FCPlugInIter()
       
    85 	{
       
    86 	return iFCPlugInIter;
       
    87 	}
       
    88 	
       
    89 // ----------------------------------------------------------------------------
       
    90 // CFCPlugInEngine:: SupportedProtocolL
       
    91 // ----------------------------------------------------------------------------
       
    92 //	
       
    93 EXPORT_C CDesC8Array* CFCPlugInEngine::SupportedProtocolL()
       
    94 	{
       
    95 	CDesC8ArrayFlat* protocols = new (ELeave) CDesC8ArrayFlat(1);
       
    96 	CleanupStack::PushL(protocols);
       
    97 	TFCPlugInIter plugInIter(iFCPlugIns);
       
    98 	CFCPlugInInfo* plugin = plugInIter.First();	
       
    99 
       
   100 	while (plugin)
       
   101 		{
       
   102 		HBufC8* name = HBufC8::NewLC(plugin->Name().Length());
       
   103 		name->Des().Copy(plugin->Name());
       
   104 		protocols->AppendL(*name);
       
   105 		plugin = plugInIter.Next();
       
   106 		CleanupStack::PopAndDestroy(name);
       
   107 		}
       
   108 	CleanupStack::Pop(protocols);
       
   109 	return protocols;
       
   110 	}
       
   111 	
       
   112 // ----------------------------------------------------------------------------
       
   113 // CFCPlugInEngine:: PlugInByNameL
       
   114 // ----------------------------------------------------------------------------
       
   115 //	
       
   116 
       
   117 EXPORT_C MFCPlugIn* CFCPlugInEngine::PlugInByNameL(const TDesC8& aProtocolName) 
       
   118 	{
       
   119 	TFCPlugInIter plugInIter(iFCPlugIns);
       
   120 	CFCPlugInInfo* plugin = NULL;
       
   121 	plugin = plugInIter.First();
       
   122 	while (plugin)
       
   123 		{
       
   124 		if (aProtocolName.CompareF(plugin->Name()) == KErrNone)
       
   125 			{
       
   126 			TFCInterfaceInitParams initParam( *this );
       
   127 			// Instantiate plug-in with UID
       
   128 			return CFCInterface::NewL( plugin->Uid(), initParam );
       
   129 			}
       
   130 		plugin = plugInIter.Next();
       
   131 		}
       
   132 	return NULL;
       
   133 	}
       
   134 	
       
   135 // ----------------------------------------------------------------------------
       
   136 // CFCPlugInEngine:: CreateNewSessionL
       
   137 // ----------------------------------------------------------------------------
       
   138 //	
       
   139 
       
   140 EXPORT_C CFCSession& CFCPlugInEngine::CreateNewSessionL(
       
   141     const TDesC8& aType, 
       
   142     TUint32 aIapId,
       
   143     TUint32 aPort )
       
   144 	{
       
   145 	CFCInterface* plugIn  = ( CFCInterface* ) PlugInByNameL( aType );
       
   146 	CleanupStack::PushL( plugIn );
       
   147 	CFCSession* fcSession = CFCSession::NewL( plugIn, aIapId, aPort );
       
   148 	CleanupStack::Pop( plugIn );
       
   149 	CleanupStack::PushL( fcSession ); 
       
   150 	iFCSessions.AppendL( fcSession );
       
   151 	CleanupStack::Pop( fcSession );
       
   152 	return *fcSession;
       
   153 	}
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CFCPlugInEngine:: ReleaseSession
       
   157 // ----------------------------------------------------------------------------
       
   158 //	
       
   159 
       
   160 EXPORT_C void CFCPlugInEngine::ReleaseSession(const CFCSession& aSession)
       
   161 	{
       
   162 	TInt ind = iFCSessions.Find( &aSession );
       
   163 	if ( ind != KErrNotFound )
       
   164 	    {
       
   165 	    CFCSession* fcSession = iFCSessions[ ind ];
       
   166 	    fcSession->ReleaseSession();
       
   167 	    iFCSessions.Remove( ind );
       
   168 	    delete fcSession;
       
   169 	    fcSession = NULL;
       
   170 	    }
       
   171 	}
       
   172 	
       
   173 // ----------------------------------------------------------------------------
       
   174 // CFCPlugInEngine::FormatAttributeFieldsL
       
   175 // Attribute must set first
       
   176 // ----------------------------------------------------------------------------
       
   177 //	
       
   178 EXPORT_C RPointerArray<CSdpFmtAttributeField>& 
       
   179 	CFCPlugInEngine::FormatAttributeFieldsL(const CFCSession& aSession)
       
   180 	{
       
   181 	TInt ind = iFCSessions.Find( &aSession );
       
   182     User::LeaveIfError( ind );
       
   183 	return iFCSessions[ ind ]->FormatAttributeFields();
       
   184 	}
       
   185 	
       
   186 // ----------------------------------------------------------------------------
       
   187 // CFCPlugInEngine:: SetFormatAttributeFieldsL
       
   188 // Sets the formateAttributeFields
       
   189 // ----------------------------------------------------------------------------
       
   190 //	
       
   191 EXPORT_C void CFCPlugInEngine::SetFormatAttributeFieldsL(
       
   192                             const CFCSession& aSession, 
       
   193 					        RPointerArray<CSdpFmtAttributeField>* aAttributes )
       
   194 	{
       
   195 	TInt ind = iFCSessions.Find( &aSession );
       
   196 	User::LeaveIfError( ind );
       
   197     return iFCSessions[ ind ]->SetFormatAttributeFieldsL(aAttributes);
       
   198 	}
       
   199 
       
   200 // ----------------------------------------------------------------------------
       
   201 // CFCPlugInEngine::UpdateOfferL
       
   202 // Modifies local parameters of FC to offer document
       
   203 // ----------------------------------------------------------------------------
       
   204 //
       
   205 EXPORT_C void CFCPlugInEngine::UpdateOfferL( const CFCSession& aSession, 
       
   206 											 CSdpDocument& aSdpDocument )
       
   207 	{
       
   208 	TInt ind = iFCSessions.Find( &aSession );
       
   209 	User::LeaveIfError( ind );
       
   210 	iFCSessions[ ind ]->UpdateSDPL( aSdpDocument );		
       
   211 	}
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // CFCPlugInEngine::SetSessionPortL()
       
   215 // ----------------------------------------------------------------------------
       
   216 //
       
   217 EXPORT_C void CFCPlugInEngine::SetSessionPortL( CFCSession& aFCSession, 
       
   218                                                 TUint32 aNewPort )
       
   219     {
       
   220     TInt ind = iFCSessions.Find( &aFCSession );
       
   221     User::LeaveIfError( ind );
       
   222     iFCSessions[ ind ]->SetPort( aNewPort );
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CFCPlugInEngine::UpdateSession
       
   227 // Modifies local parameters of FC to offer document
       
   228 // ----------------------------------------------------------------------------
       
   229 //
       
   230 EXPORT_C void CFCPlugInEngine::UpdateSessionL( CFCSession& aFCSession, 
       
   231                                                TUint32 aNewPort )
       
   232     {
       
   233     TInt ind = iFCSessions.Find( &aFCSession );
       
   234     User::LeaveIfError( ind );
       
   235     iFCSessions[ ind ]->Update( aNewPort );
       
   236     }
       
   237 			
       
   238 // ----------------------------------------------------------------------------
       
   239 // CFCPlugInEngine::UpdateAnswerL
       
   240 // Modifies local parameters of FC to anser document
       
   241 // ----------------------------------------------------------------------------
       
   242 //
       
   243 EXPORT_C void CFCPlugInEngine::UpdateAnswerL( const CFCSession& aSession, 
       
   244 											  CSdpDocument& aSdpDocument )
       
   245 	{
       
   246 	// Updating the remote port and address using the original 
       
   247 	// port and own address into the SDP doc
       
   248 	TInt ind = iFCSessions.Find( &aSession );
       
   249 	User::LeaveIfError( ind );
       
   250 	iFCSessions[ ind ]->UpdateSDPL( aSdpDocument );
       
   251 	}
       
   252 	
       
   253 // ----------------------------------------------------------------------------
       
   254 // CFCPlugInEngine::PeekDocumentL
       
   255 // Reads remote parameters of FC from offer/answer document.
       
   256 // ----------------------------------------------------------------------------
       
   257 //		
       
   258 EXPORT_C void CFCPlugInEngine::PeekDocumentL( 
       
   259                                         const CFCSession& aSession, 
       
   260 									    const CSdpDocument& aSdpDocument )
       
   261 	{
       
   262 	//Store the value inside of the SDP remote address and port value
       
   263 	TInt ind = iFCSessions.Find( &aSession );
       
   264 	User::LeaveIfError( ind );
       
   265 	iFCSessions[ ind ]->StoreInfoL(aSdpDocument);
       
   266 	}
       
   267 
       
   268 // ----------------------------------------------------------------------------
       
   269 // CFCPlugInEngine::StartConnectionL
       
   270 // ----------------------------------------------------------------------------
       
   271 //		
       
   272 EXPORT_C void CFCPlugInEngine::StartConnectionL( const CFCSession& aSession )
       
   273 	{
       
   274 	TInt ind = iFCSessions.Find( &aSession );
       
   275 	User::LeaveIfError( ind );
       
   276 	iFCSessions[ ind ]->ConnectionReadyL();
       
   277 	}
       
   278 
       
   279 // ----------------------------------------------------------------------------
       
   280 // CFCPlugInEngine::SendToNetL
       
   281 // ----------------------------------------------------------------------------
       
   282 //			
       
   283 EXPORT_C void CFCPlugInEngine::SendToNetL( const CFCSession& aSession, 
       
   284                                            HBufC8* aData)
       
   285 	{
       
   286 	TInt ind = iFCSessions.Find( &aSession );
       
   287 	User::LeaveIfError( ind );
       
   288 	iFCSessions[ ind ]->SendToNetL(aData);
       
   289 	}
       
   290 
       
   291 // ----------------------------------------------------------------------------
       
   292 // CFCPlugInEngine::IsReceiverL 
       
   293 // ----------------------------------------------------------------------------
       
   294 //				
       
   295 EXPORT_C TBool CFCPlugInEngine::IsReceiverL( const CFCSession& aSession )
       
   296     {
       
   297     TInt ind = iFCSessions.Find( &aSession );
       
   298 	User::LeaveIfError( ind );
       
   299 	return iFCSessions[ ind ]->IsReceiver();
       
   300     }
       
   301 
       
   302 // ----------------------------------------------------------------------------
       
   303 // CFCPlugInEngine:: UpdateNeeded
       
   304 // ----------------------------------------------------------------------------
       
   305 //			
       
   306 EXPORT_C TBool CFCPlugInEngine::UpdateNeededL( const CFCSession& aSession ) 
       
   307 	{
       
   308 	TInt ind = iFCSessions.Find( &aSession );
       
   309 	User::LeaveIfError( ind );
       
   310 	return iFCSessions[ ind ]->UpdateNeeded();
       
   311 	}    
       
   312 	   	
       
   313 // ----------------------------------------------------------------------------
       
   314 // CFCPlugInEngine::ReceivedData 
       
   315 // ----------------------------------------------------------------------------
       
   316 //			
       
   317 void CFCPlugInEngine::ReceivedData( HBufC8* aData, MFCPlugIn* aPlugIn ) 
       
   318 	{
       
   319 	CFCSession* fcSession = FindFCSession( aPlugIn );
       
   320 	if ( fcSession )
       
   321 	    {
       
   322 	    iFCObserver.FCReceivedData( aData, fcSession );   
       
   323 	    }
       
   324 	}
       
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // CFCPlugInEngine:: ReceivedData
       
   328 // ----------------------------------------------------------------------------
       
   329 //			
       
   330 void CFCPlugInEngine::ErrorNotify( TInt aErrCode, MFCPlugIn* aPlugIn ) 
       
   331 	{
       
   332 	CFCSession* fcSession = FindFCSession( aPlugIn );
       
   333 	if ( fcSession )
       
   334 	    {
       
   335 	    iFCObserver.FCErrorNotify( aErrCode, fcSession );    
       
   336 	    }
       
   337 	}
       
   338 	
       
   339 // ----------------------------------------------------------------------------
       
   340 // CFCPlugInEngine::ListMechanismImplementationsL
       
   341 // ----------------------------------------------------------------------------
       
   342 //
       
   343 void CFCPlugInEngine::ListMechanismImplementationsL()
       
   344 	{
       
   345 	// List implementations in ECom registry for our launcher interface
       
   346 	RImplInfoPtrArray infoArray;		
       
   347 	CleanupStack::PushL( TCleanupItem( ArrayCleanup, &infoArray ) );	
       
   348 	REComSession::ListImplementationsL( KCFCInterfaceUid,
       
   349 										infoArray );
       
   350 
       
   351 	// Go trough the ECom entries and parse them into TFCPlugInInfo objects	
       
   352 	for( TInt i = 0; i < infoArray.Count(); i++ )
       
   353 		{
       
   354 		CFCPlugInInfo* plugin = 
       
   355 		    CFCPlugInInfo::NewL( infoArray[i]->ImplementationUid(), 
       
   356 		                         infoArray[i]->DataType() );
       
   357 		CleanupStack::PushL( plugin );                         
       
   358 		//add to the Plugin Iter
       
   359 		User::LeaveIfError( iFCPlugIns.Append( plugin ) );
       
   360 		CleanupStack::Pop( plugin );
       
   361 		
       
   362 		}
       
   363 			
       
   364 	CleanupStack::PopAndDestroy(&infoArray); //TCleanupItem
       
   365 	}
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CFCPlugInEngine::ArrayCleanup
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 void CFCPlugInEngine::ArrayCleanup(TAny* aArray)
       
   372 	{
       
   373     RImplInfoPtrArray* array = reinterpret_cast<RImplInfoPtrArray*>(aArray);
       
   374     if (array)
       
   375         {
       
   376         array->ResetAndDestroy();
       
   377         }
       
   378 	}
       
   379 	
       
   380 	
       
   381 // -----------------------------------------------------------------------------
       
   382 // CFCPlugInEngine::FindFCSession
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 CFCSession* CFCPlugInEngine::FindFCSession( MFCPlugIn* aPlugIn )
       
   386     {
       
   387     CFCSession* fcSession = NULL;
       
   388     TBool found = EFalse;
       
   389     for ( TInt ind = 0; !found && ind < iFCSessions.Count(); ind++ )
       
   390         {
       
   391         fcSession = iFCSessions[ ind ];
       
   392         if ( aPlugIn == fcSession->PlugIn() )
       
   393             {
       
   394             found = ETrue;
       
   395             }
       
   396         }
       
   397     return fcSession;
       
   398     }
       
   399 
       
   400 
       
   401 //  End of File