bluetoothengine/btui/Ecom/src/btuipluginman.cpp
changeset 42 b72428996822
parent 32 19bd632b5100
child 43 7d241e669870
equal deleted inserted replaced
32:19bd632b5100 42:b72428996822
     1 /*
       
     2 * Copyright (c) 2007 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:  Find and load plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknview.h>
       
    20 #include "btuipluginman.h"
       
    21 #include "debug.h"  
       
    22 
       
    23 // ======== MEMBER FUNCTIONS ========
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // NewL
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 CBTUIPluginMan* CBTUIPluginMan::NewL( CAknViewAppUi* aAppUi )
       
    30     {
       
    31     CBTUIPluginMan* self = new( ELeave ) CBTUIPluginMan( aAppUi );
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop( self );
       
    35     return self;
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // Destructor
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CBTUIPluginMan::~CBTUIPluginMan()
       
    43     {
       
    44     TRACE_FUNC_ENTRY
       
    45     
       
    46     iPluginInfoArray.ResetAndDestroy();
       
    47     iPluginInfoArray.Close();
       
    48     iPluginArray.Reset();//Do not destroy - Plugins are owned by iAppUi
       
    49 
       
    50     TRACE_FUNC_EXIT
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Check if availability of some plug-in
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 TBool CBTUIPluginMan::IsPluginAvaiable(TBTDeviceClass aDeviceClassInfo)
       
    58 	{
       
    59 	for( TInt i=0; i<iPluginArray.Count(); i++ )
       
    60 		{
       
    61 		TBTDeviceClass devClass = iPluginArray[i]->GetCOD(); 
       
    62 		if( devClass.MajorDeviceClass() == aDeviceClassInfo.MajorDeviceClass() && 
       
    63 			devClass.MinorDeviceClass() == aDeviceClassInfo.MinorDeviceClass() )
       
    64 			return ETrue;
       
    65 		}
       
    66 	return EFalse;
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // Get the setting view from PluginArrary based on the COD 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CAknView* CBTUIPluginMan::GetSettingViewL(TBTDevice& aDevice)
       
    74 	{
       
    75 	for (TInt ii = 0; ii < iPluginArray.Count(); ii++ )
       
    76 		{
       
    77 		TBTDeviceClass tmpCOD = iPluginArray[ii]->GetCOD();
       
    78 		//Currently one device - one view - one plugin, 
       
    79 		//in future maybe other device properties will decide on getting the view. 
       
    80 		if(aDevice.iDeviceClass.MajorDeviceClass() == tmpCOD.MajorDeviceClass() &&
       
    81 				aDevice.iDeviceClass.MinorDeviceClass() == 	tmpCOD.MinorDeviceClass())
       
    82 			{
       
    83 			return (CAknView*)iPluginArray[ii];
       
    84 			}
       
    85 		}
       
    86 	
       
    87 	return NULL;	
       
    88 	}
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // C++ default constructor
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CBTUIPluginMan::CBTUIPluginMan( CAknViewAppUi* aAppUi )
       
    95     : iAppUi(aAppUi)
       
    96     {
       
    97 
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Symbian 2nd-phase constructor
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CBTUIPluginMan::ConstructL()
       
   105     {   
       
   106     LoadPluginsL();
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Load ECom plug-ins
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CBTUIPluginMan::LoadPluginsL()
       
   114 	{
       
   115 	TRACE_FUNC_ENTRY
       
   116 	
       
   117 	REComSession::ListImplementationsL( KCBtuiPluginInterfaceUid, iPluginInfoArray );
       
   118 	TInt count = iPluginInfoArray.Count();
       
   119 	TRACE_INFO( ( _L( "[BTUI]\t CBTUIPluginMan::LoadSettingPluginL() PluginArray count=%d" ), count) )
       
   120 
       
   121     iPluginArray.Reset();
       
   122 	for ( TUint ii = 0 ; ii < count; ++ii )
       
   123 		{
       
   124 		CImplementationInformation* impl = iPluginInfoArray[ii];
       
   125 		//Only append the plugins which datatype() is for HID devices. 
       
   126 	    if(impl->DataType().Length())
       
   127 	    	{
       
   128 	    	TLex8 lex( impl->DataType() );
       
   129 	    	TUint major = 0, minor = 0;
       
   130 	    	TInt err1 = lex.Val(major, EHex);
       
   131 	    	lex.SkipSpace();
       
   132 	    	TInt err2 = lex.Val(minor, EHex);
       
   133 	    	if( !err1 && !err2)
       
   134 	    	    {
       
   135 	    	    TRACE_INFO( ( _L( "[BTUI]\t CBTUIPluginMan::LoadSettingPluginL() MajorCOD=%d MinorCOD=%d" ), major, minor) )
       
   136  	            TBTDeviceClass cod(0x00, major, minor);
       
   137 	    	                
       
   138 	    	    CBtuiPluginInterface* plugin = NULL;
       
   139 	    	    TRAPD( ret, plugin = CBtuiPluginInterface::NewL( impl->ImplementationUid() ) );
       
   140 	    	    if( !ret )
       
   141 	    	        {
       
   142 	    	        CleanupStack::PushL(plugin);
       
   143 	    	        
       
   144 	    	        // Transfer the ownership to AppUi
       
   145 	    	        iAppUi->AddViewL( (CAknView*)plugin ); 
       
   146 	    	        plugin->SetCOD(cod);
       
   147 	    	        iPluginArray.AppendL(plugin);
       
   148 	    	        CleanupStack::Pop(plugin);              
       
   149 	    	        }	    	        
       
   150 	    	    }
       
   151 	        }
       
   152 		}
       
   153 	
       
   154 	TRACE_FUNC_EXIT
       
   155 	}
       
   156