omaprovisioning/provisioning/ProvisioningEngine/Src/WPAdapterFactory.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Factory for adapters.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <e32std.h>
       
    21 #include <ecom/ecom.h>
       
    22 #include "WPAdapterFactory.h"
       
    23 #include "ProvisioningDebug.h"
       
    24 #include "CWPAdapter.h"
       
    25 
       
    26 // CONSTANTS
       
    27 const TInt KDefaultPriority = 9999;
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // WPAdapterFactory::CreateAdaptersL
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CArrayPtr<CWPAdapter>* WPAdapterFactory::CreateAdaptersL()
       
    36     {
       
    37     // Create an array for adapter information
       
    38     RImplInfoPtrArray implArray;
       
    39     CleanupStack::PushL( TCleanupItem( CleanupImplArray, &implArray ) );
       
    40 
       
    41     // Get the list of adapters
       
    42     CWPAdapter::ListL( implArray );
       
    43 
       
    44     // Sort them in priority order
       
    45     implArray.Sort( 
       
    46         TLinearOrder<CImplementationInformation>( WPAdapterFactory::Compare ) );
       
    47 
       
    48     // Create an array for adapters
       
    49     CArrayPtr<CWPAdapter>* adapters = 
       
    50         new(ELeave) CArrayPtrFlat<CWPAdapter>( Max( 1, implArray.Count() ) );
       
    51     CleanupStack::PushL( TCleanupItem( CleanupAdapterArray, adapters ) );
       
    52 
       
    53     // Create the adapters
       
    54     for( TInt i( 0 ); i < implArray.Count(); i++ )
       
    55         {
       
    56         CImplementationInformation& info = *implArray[i];
       
    57         TUid implementation( info.ImplementationUid() );
       
    58         FTRACE(RDebug::Print(_L("[Provisioning] WPAdapterFactory::CreateAdaptersL(): ROM: %d UID: %x"),info.RomBased(), info.ImplementationUid()));
       
    59         CWPAdapter* adapter = NULL;
       
    60         TRAPD( error, adapter = CWPAdapter::NewL( implementation ) );
       
    61         
       
    62         if( adapter && ( error == KErrNone ) )
       
    63             {
       
    64             CleanupStack::PushL( adapter );
       
    65             adapters->AppendL( adapter );
       
    66             CleanupStack::Pop( adapter );
       
    67             }
       
    68         else
       
    69             {
       
    70             FTRACE(RDebug::Print(_L("[Provisioning] WPAdapterFactory::CreateAdaptersL(): failed UID: %x with error %d"), info.ImplementationUid(), error));
       
    71             }
       
    72         }
       
    73 
       
    74     CleanupStack::Pop( adapters );
       
    75     CleanupStack::PopAndDestroy(); // implArray
       
    76 
       
    77     FLOG( _L( "[Provisioning] WPAdapterFactory::CreateAdaptersL(): End" ) );
       
    78     return adapters;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // WPAdapterFactory::CleanupImplArray
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void WPAdapterFactory::CleanupImplArray( TAny* aAny )
       
    86     {
       
    87     RImplInfoPtrArray* implArray = 
       
    88         reinterpret_cast<RImplInfoPtrArray*>( aAny );
       
    89     implArray->ResetAndDestroy();
       
    90     implArray->Close();
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // WPAdapterFactory::CleanupAdapterArray
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void WPAdapterFactory::CleanupAdapterArray( TAny* aAny )
       
    98     {
       
    99     CArrayPtr<CWPAdapter>* adapters = 
       
   100         reinterpret_cast<CArrayPtr<CWPAdapter>*>( aAny );
       
   101     adapters->ResetAndDestroy();
       
   102     delete adapters;
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // WPAdapterFactory::Compare
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 TInt WPAdapterFactory::Compare( const CImplementationInformation& aImpl1, 
       
   110                                const CImplementationInformation& aImpl2 )
       
   111     {
       
   112     // Compare the numerical values of opaque_data 
       
   113     TLex8 lex( aImpl1.OpaqueData() );
       
   114     TInt impl1( KDefaultPriority );
       
   115     if( lex.Val( impl1 ) != KErrNone )
       
   116         {
       
   117         impl1 = KMaxTInt;
       
   118         }
       
   119 
       
   120     lex.Assign( aImpl2.OpaqueData() );
       
   121     TInt impl2( KDefaultPriority );
       
   122     if( lex.Val( impl2 ) != KErrNone )
       
   123         {
       
   124         impl2 = KMaxTInt;
       
   125         }
       
   126 
       
   127     return impl1 - impl2;
       
   128     }
       
   129 
       
   130 //  End of File