omaprovisioning/provisioning/ProvisioningEngine/Src/CWPAdapterManager.cpp
changeset 0 b497e44ab2fc
child 21 504e41245867
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:  Manager for all adapters.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include "WPAdapterFactory.h"
       
    21 #include "CWPAdapterManager.h"
       
    22 #include "CWPAdapter.h"
       
    23 #include "CWPRoot.h"
       
    24 #include "CWPEngine.pan"
       
    25 #include "MWPContextManager.h"
       
    26 #include "MWPContextExtension.h"
       
    27 #include "ProvisioningDebug.h"
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CWPAdapterManager::NewL
       
    33 // Two-phased constructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CWPAdapterManager* CWPAdapterManager::NewL()
       
    37     {
       
    38     CWPAdapterManager* self = NewLC();
       
    39     CleanupStack::Pop();
       
    40     
       
    41     return self;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CWPAdapterManager::NewLC
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CWPAdapterManager* CWPAdapterManager::NewLC()
       
    50     {
       
    51     CWPAdapterManager* self = new( ELeave ) CWPAdapterManager();
       
    52     
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     
       
    56     return self;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CWPAdapterManager::CWPAdapterManager
       
    61 // C++ default constructor can NOT contain any code, that
       
    62 // might leave.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CWPAdapterManager::CWPAdapterManager()
       
    66     {
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CWPAdapterManager::ConstructL
       
    71 // Symbian 2nd phase constructor can leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CWPAdapterManager::ConstructL()
       
    75     {
       
    76     // Create the adapters
       
    77 	FLOG( _L( "CWPAdapterManager::ConstructL : Enter" ) );
       
    78     iAdapters = WPAdapterFactory::CreateAdaptersL();
       
    79     FLOG( _L( "CWPAdapterManager::ConstructL : Exit" ) );
       
    80     }
       
    81 
       
    82 // Destructor
       
    83 CWPAdapterManager::~CWPAdapterManager()
       
    84     {
       
    85     if( iAdapters )
       
    86         {
       
    87         iAdapters->ResetAndDestroy();
       
    88         delete iAdapters;
       
    89         }
       
    90     REComSession::FinalClose();
       
    91     iItemIndexes.Close();
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CWPAdapterManager::MwpceCount
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt CWPAdapterManager::MwpceCount() const
       
    99     {
       
   100     TInt count( 0 );
       
   101     for( TInt i( 0 ); i < iAdapters->Count(); i++ )
       
   102         {
       
   103         MWPContextExtension* extension = NULL;
       
   104         if( iAdapters->At( i )->ContextExtension( extension ) == KErrNone )
       
   105             {
       
   106             count++;
       
   107             }
       
   108         }
       
   109 
       
   110     return count;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CWPAdapterManager::MwpcePoint
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 MWPContextExtension& CWPAdapterManager::MwpcePoint( TInt aIndex )
       
   118     {
       
   119     MWPContextExtension* extension = NULL;
       
   120     for( TInt i( 0 ); i < iAdapters->Count() && aIndex >= 0; i++ )
       
   121         {
       
   122         if( iAdapters->At( i )->ContextExtension( extension ) == KErrNone )
       
   123             {
       
   124             --aIndex;
       
   125             }
       
   126         }
       
   127 
       
   128     return *extension;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CWPAdapterManager::PopulateL
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void CWPAdapterManager::PopulateL( CWPRoot& aRoot )
       
   136     {
       
   137     FLOG( _L( "[Provisioning] CWPAdapterManager::PopulateL" ) );
       
   138     if( iAdapters->Count() > 0 )
       
   139         {
       
   140         // Feed the document into adapters.
       
   141         TInt i( 0 );
       
   142         for( i = 0; i < iAdapters->Count(); i++ )
       
   143             {
       
   144             FTRACE(RDebug::Print(_L("[Provisioning] CWPAdapterManager::PopulateL() (%d) out of (%d)"), i, iAdapters->Count()));
       
   145             CWPAdapter* adapter = iAdapters->At( i );
       
   146             TRAPD(retVal, aRoot.AcceptL( *adapter ) );
       
   147             if (retVal != KErrNone )
       
   148                 {
       
   149                 FTRACE(RDebug::Print(_L("[Provisioning] CWPAdapterManager::PopulateL() aRoot.AcceptL leaved (%d)"), retVal));
       
   150                 }
       
   151             }
       
   152         }
       
   153 
       
   154     // Update item indexes.
       
   155     iItemCount = 0;
       
   156     for( TInt i( 0 ); i < iAdapters->Count(); i++ )
       
   157         {
       
   158         FTRACE(RDebug::Print(_L("[Provisioning] CWPAdapterManager::Append (%d) out of (%d)"), i, iAdapters->Count()));        
       
   159         User::LeaveIfError( iItemIndexes.Append( iItemCount ) );
       
   160         TInt count( iAdapters->At( i )->ItemCount() );
       
   161         iItemCount += count;
       
   162         }
       
   163     FLOG( _L( "[Provisioning] CWPAdapterManager::PopulateL done" ) );
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CWPAdapterManager::ItemCount
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 TInt CWPAdapterManager::ItemCount() const
       
   171     {
       
   172     return iItemCount;
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CWPAdapterManager::SummaryTitle
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 const TDesC16& CWPAdapterManager::SummaryTitle(TInt aIndex) const
       
   180     {
       
   181     __ASSERT_DEBUG( aIndex < iItemCount, Panic( EWPIndexOverflow ) );
       
   182 
       
   183     TInt adapter( 0 );
       
   184     TInt index( 0 );
       
   185     ItemIndex( aIndex, adapter, index );
       
   186     return iAdapters->At( adapter )->SummaryTitle( index );
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CWPAdapterManager::SummaryText
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 const TDesC16& CWPAdapterManager::SummaryText(TInt aIndex) const
       
   194     {
       
   195     __ASSERT_DEBUG( aIndex < iItemCount, Panic( EWPIndexOverflow ) );
       
   196 
       
   197     TInt adapter( 0 );
       
   198     TInt index( 0 );
       
   199     ItemIndex( aIndex, adapter, index );
       
   200     return iAdapters->At( adapter )->SummaryText( index );
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CWPAdapterManager::DetailsL
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 TInt CWPAdapterManager::DetailsL(TInt aIndex, MWPPairVisitor& aVisitor)
       
   208     {
       
   209     __ASSERT_DEBUG( aIndex < iItemCount, Panic( EWPIndexOverflow ) );
       
   210 
       
   211     TInt adapter( 0 );
       
   212     TInt index( 0 );
       
   213     ItemIndex( aIndex, adapter, index );
       
   214     return iAdapters->At( adapter )->DetailsL( index, aVisitor );
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CWPAdapterManager::SaveL
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void CWPAdapterManager::SaveL( MWPContextManager& aManager, TInt aItem )
       
   222     {
       
   223     __ASSERT_DEBUG( aItem < iItemCount, Panic( EWPIndexOverflow ) );
       
   224 
       
   225     TInt index( 0 );
       
   226     TInt adapter( 0 );
       
   227     ItemIndex( aItem, adapter, index );
       
   228     CWPAdapter* a = iAdapters->At( adapter );
       
   229     a->SaveL( index );
       
   230 
       
   231     MWPContextExtension* extension = NULL;
       
   232     if( a->ContextExtension( extension ) == KErrNone )
       
   233         {
       
   234         aManager.SaveL( *extension, index );
       
   235         }
       
   236 
       
   237 // Code block based on the APPREF & TO-APPREF parameter handling starts here.
       
   238 
       
   239     // Place [0] is reserved for APPID parameter, [1] for APPREF parameter 
       
   240     // and [2] for storage id i.e. id that identifies the saved settings in its storage.
       
   241     RPointerArray< HBufC8 > savingInfo;
       
   242     a->GetSavingInfoL( index, savingInfo );
       
   243 
       
   244     // If the adapter had something to tell to the other adapters...
       
   245     if( ( savingInfo.Count() == 3 ) && ( savingInfo[ 1 ]->Length() > 0) )
       
   246         {
       
   247         // Information of the saved item is interesting only if it carries a 
       
   248         // value for APPREF parameter.
       
   249         if ( savingInfo[ 1 ] && ( savingInfo[ 1 ]->Length() > 0 ) )
       
   250             {
       
   251             TInt adaptersQuantity( iAdapters->Count() );
       
   252 
       
   253             for( TInt adaptersIndex = 0; adaptersIndex < adaptersQuantity; 
       
   254                 adaptersIndex++ )
       
   255                 {
       
   256                 CWPAdapter* theInfoReceivingAdapter = iAdapters->At( adaptersIndex );
       
   257                 if ( theInfoReceivingAdapter->ItemCount() > 0 )
       
   258                     {
       
   259                     // Value of APPID parameter: savingInfo[ 0 ].
       
   260                     HBufC8* tmpAppId = savingInfo[ 0 ]->Des().AllocLC();//CS:++
       
   261                     // savingInfo[ 1 ] holds the value of APPREF parameter of the characteristic 
       
   262                     // that was saved.
       
   263                     HBufC8* tmpAppRef = savingInfo[ 1 ]->Des().AllocLC();//CS:++
       
   264                     // savingInfo[ 2 ] holds the value that is the identitier of the settings in  its 
       
   265                     // own storage.
       
   266                     HBufC8* tmpStorageId = savingInfo[ 2 ]->Des().AllocLC();//CS:++
       
   267                     theInfoReceivingAdapter->SettingsSavedL ( tmpAppId->Des(), 
       
   268                     tmpAppRef->Des(), tmpStorageId->Des() );
       
   269                     theInfoReceivingAdapter = NULL;
       
   270                     CleanupStack::PopAndDestroy( tmpStorageId );//CS:--
       
   271                     tmpStorageId = NULL;
       
   272                     CleanupStack::PopAndDestroy( tmpAppRef );//CS:--
       
   273                     tmpAppRef = NULL;
       
   274                     CleanupStack::PopAndDestroy( tmpAppId );//CS:--
       
   275                     tmpAppId = NULL;
       
   276                     }// if
       
   277                 }// for
       
   278 
       
   279             }// if
       
   280 	    }// if
       
   281 	savingInfo.ResetAndDestroy();
       
   282     savingInfo.Close();
       
   283     
       
   284     // Tell the adapters that all the settings have been now saved.
       
   285     TInt quantityOfAdapter( iAdapters->Count() );
       
   286     CWPAdapter* tmpAdapter = NULL;
       
   287     if (  aItem == ( iItemCount - 1 ))
       
   288         {
       
   289         for ( TInt adapterIndex = 0; adapterIndex < quantityOfAdapter; adapterIndex++ )
       
   290             {
       
   291             tmpAdapter = iAdapters->At( adapterIndex );
       
   292             tmpAdapter->SavingFinalizedL();
       
   293             tmpAdapter = NULL;
       
   294             }// for
       
   295         }
       
   296     
       
   297 // Code block based on the APPREF & TO-APPREF parameter handling ends here.
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CWPAdapterManager::CanSetAsDefault
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 TBool CWPAdapterManager::CanSetAsDefault( TInt aItem ) const
       
   305     {
       
   306     __ASSERT_DEBUG( aItem < iItemCount, Panic( EWPIndexOverflow ) );
       
   307 
       
   308     TInt index( 0 );
       
   309     TInt adapter( 0 );
       
   310     ItemIndex( aItem, adapter, index );
       
   311     return iAdapters->At( adapter )->CanSetAsDefault( index );
       
   312     }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CWPAdapterManager::SetAsDefaultL
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CWPAdapterManager::SetAsDefaultL( TInt aItem )
       
   319     {
       
   320     __ASSERT_DEBUG( aItem < iItemCount, Panic( EWPIndexOverflow ) );
       
   321 
       
   322     TInt index( 0 );
       
   323     TInt adapter( 0 );
       
   324     ItemIndex( aItem, adapter, index );
       
   325     iAdapters->At( adapter )->SetAsDefaultL( index );
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CWPAdapterManager::ItemIndex
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CWPAdapterManager::ItemIndex(TInt aGlobalIndex, 
       
   333                                   TInt& aAdapter, 
       
   334                                   TInt& aAdapterIndex ) const
       
   335     {
       
   336     // Find the adapter which provides item number aGlobalIndex
       
   337     aAdapter = iItemIndexes.Count()-1;
       
   338     for( TInt i( 0 ); i < iItemIndexes.Count(); i++ )
       
   339         {
       
   340         if( iItemIndexes[i] <= aGlobalIndex )
       
   341             {
       
   342             aAdapter = i;
       
   343             }
       
   344         }
       
   345 
       
   346     // Find out the adapter local item number
       
   347     aAdapterIndex = aGlobalIndex - iItemIndexes[aAdapter];
       
   348 
       
   349     __ASSERT_DEBUG( aAdapter < iAdapters->Count(), Panic( EWPIndexOverflow ) );
       
   350     }
       
   351 
       
   352 //  End of File