XDMEngine/XdmProvisioning/src/xdmprovadapter.cpp
changeset 33 ad6f19461b2a
parent 0 c8caa15ef882
child 18 52d91a16fec3
equal deleted inserted replaced
29:0da3f27f7ab2 33:ad6f19461b2a
       
     1 /*
       
     2 * Copyright (c) 2006 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:    XDM Provisioning Adapter implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <CWPCharacteristic.h>
       
    24 #include <WPAdapterUtil.h>
       
    25 #include <xdmprovisioningtexts.rsg>
       
    26 #include <XdmSettingsApi.h>
       
    27 
       
    28 #include "xdmprovitem.h"
       
    29 #include "xdmprovadapter.h"
       
    30 
       
    31 
       
    32 #ifdef _DEBUG
       
    33     #include <flogger.h>
       
    34 #endif
       
    35 
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CXdmProvAdapter::CXdmProvAdapter
       
    41 //
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CXdmProvAdapter::CXdmProvAdapter():
       
    45 iDefaultName( NULL ),
       
    46 iTitle( NULL ),
       
    47 iProvItems( 1 )
       
    48     {    
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CXdmProvAdapter::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CXdmProvAdapter::ConstructL()
       
    57     {
       
    58     // AdapterUtil needs the name of the resource file without the prefix and
       
    59     // the path returned by Dll::FileName. Note that Dll::FileName is an
       
    60     // undocumented method.
       
    61     //
       
    62     _LIT( KXdmAdapterName, "xdmprovisioningtexts");  //  xdmprovisioningtexts.rss
       
    63     TFileName fileName;
       
    64     Dll::FileName(fileName);
       
    65    
       
    66     iTitle       = WPAdapterUtil::ReadHBufCL( fileName,
       
    67                                               KXdmAdapterName,
       
    68                                               R_QTN_SM_HEAD_CONNECTION);
       
    69     iDefaultName = WPAdapterUtil::ReadHBufCL( fileName,
       
    70                                               KXdmAdapterName,
       
    71                                               R_QTN_XDM_PROVISIONING_NAME);
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CXdmProvAdapter::NewL
       
    76 // Two-phased constructor.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CXdmProvAdapter* CXdmProvAdapter::NewL()
       
    80     {
       
    81 #ifdef _DEBUG 
       
    82     WriteToLog( _L8( "CXdmProvAdapter::NewL" ) );
       
    83 #endif        
       
    84     CXdmProvAdapter* self = new(ELeave) CXdmProvAdapter;
       
    85     CleanupStack::PushL(self);
       
    86     self->ConstructL();
       
    87     CleanupStack::Pop();
       
    88     return self;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CXdmProvAdapter::~CXdmProvAdapter
       
    93 // Destructor
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CXdmProvAdapter::~CXdmProvAdapter()
       
    97     {
       
    98 #ifdef _DEBUG 
       
    99     WriteToLog( _L8( "CXdmProvAdapter::~CXdmProvAdapter" ) );
       
   100 #endif   
       
   101     delete iTitle;
       
   102     delete iDefaultName;
       
   103     iProvItems.ResetAndDestroy();
       
   104     iProvItems.Close();
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CXdmProvAdapter::ItemCount
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TInt CXdmProvAdapter::ItemCount() const
       
   112     {
       
   113 #ifdef _DEBUG 
       
   114     WriteToLog( _L8( "CXdmProvAdapter::ItemCount returns %d" ), iProvItems.Count());
       
   115 #endif   
       
   116     return iProvItems.Count();  
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CXdmProvAdapter::SummaryTitle
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 const TDesC16& CXdmProvAdapter::SummaryTitle(TInt /*aIndex*/) const
       
   124     {
       
   125 #ifdef _DEBUG 
       
   126     WriteToLog( _L8( "CXdmProvAdapter::SummaryTitle" ) );
       
   127 #endif   
       
   128     return *iTitle;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CXdmProvAdapter::SummaryText
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 const TDesC16& CXdmProvAdapter::SummaryText( TInt aIndex ) const
       
   136     {
       
   137 #ifdef _DEBUG 
       
   138     WriteToLog( _L8( "CXdmProvAdapter::SummaryText" ) );
       
   139 #endif  
       
   140     TInt count = iProvItems.Count();
       
   141     if( aIndex < count )
       
   142         {
       
   143         if( 0 < iProvItems[aIndex]->Name().Length() )
       
   144             {
       
   145             return iProvItems[aIndex]->Name();
       
   146             }
       
   147         }
       
   148     return *iDefaultName;   
       
   149     }
       
   150     
       
   151 // -----------------------------------------------------------------------------
       
   152 // CXdmProvAdapter::SaveL
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CXdmProvAdapter::SaveL( TInt aItem )
       
   156     {
       
   157     if ( aItem < iProvItems.Count() - 1 )
       
   158         {
       
   159 #ifdef _DEBUG 
       
   160     WriteToLog( _L8( "CXdmProvAdapter::SaveL leaves with KErrArgument" ) );
       
   161 #endif
       
   162         User::Leave ( KErrArgument );
       
   163         }
       
   164     iProvItems[aItem]->SaveL();
       
   165 #ifdef _DEBUG 
       
   166     WriteToLog( _L8( "CXdmProvAdapter::SaveL done" ) );
       
   167 #endif
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CXdmProvAdapter::CanSetAsDefault
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TBool CXdmProvAdapter::CanSetAsDefault( TInt /*aItem*/ ) const
       
   175     {
       
   176 #ifdef _DEBUG 
       
   177     WriteToLog( _L8( "CXdmProvAdapter::CanSetAsDefault" ) );
       
   178 #endif   
       
   179     return EFalse;
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CXdmProvAdapter::SetAsDefaultL
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void CXdmProvAdapter::SetAsDefaultL( TInt /*aItem*/ )
       
   187     {
       
   188 #ifdef _DEBUG 
       
   189     WriteToLog( _L8( "CXdmProvAdapter::SetAsDefaultL" ) );
       
   190 #endif   
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CXdmProvAdapter::DetailsL
       
   195 //
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TInt CXdmProvAdapter::DetailsL( TInt /*aItem*/, MWPPairVisitor& /*aVisitor*/ )
       
   199     {
       
   200 #ifdef _DEBUG 
       
   201     WriteToLog( _L8( "CXdmProvAdapter::DetailsL" ) );
       
   202 #endif
       
   203     return KErrNotSupported;
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CXdmProvAdapter::VisitL
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CXdmProvAdapter::VisitL( CWPCharacteristic& aCharacteristic )
       
   211     {
       
   212 #ifdef _DEBUG 
       
   213     WriteToLog( _L8( "CXdmProvAdapter::VisitL( CWPCharacteristic& aCharacteristic)" ) );
       
   214 #endif   
       
   215     if( KWPApplication == aCharacteristic.Type()  )
       
   216         {       
       
   217         CXdmProvItem* item = CXdmProvItem::NewL();
       
   218         CleanupStack::PushL( item );    // << item
       
   219         aCharacteristic.AcceptL( *item );
       
   220     
       
   221         if( item->Validate() )
       
   222             {
       
   223             iProvItems.AppendL( item );
       
   224             CleanupStack::Pop( item );  // >> item
       
   225             }
       
   226         else
       
   227             {
       
   228             CleanupStack::PopAndDestroy( item );    // >>> item                                
       
   229             }
       
   230         }
       
   231     }
       
   232         
       
   233 // -----------------------------------------------------------------------------
       
   234 // CXdmProvAdapter::VisitL
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CXdmProvAdapter::VisitL( CWPParameter& /*aParameter*/ )
       
   238     {
       
   239 #ifdef _DEBUG 
       
   240     WriteToLog( _L8( "CXdmProvAdapter::VisitL( CWPParameter& /*aParameter*/" ) );
       
   241 #endif
       
   242     // Not used.
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CXdmProvAdapter::VisitLinkL
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 void CXdmProvAdapter::VisitLinkL( CWPCharacteristic& /*aLink*/ )
       
   250     {
       
   251 #ifdef _DEBUG 
       
   252     WriteToLog( _L8( "CXdmProvAdapter::VisitLinkL( CWPCharacteristic& aLink" ) );
       
   253 #endif
       
   254     // Not used.
       
   255     }
       
   256     
       
   257 // -----------------------------------------------------------------------------
       
   258 // CXdmProvAdapter::SettingsSavedL
       
   259 //
       
   260 // -----------------------------------------------------------------------------
       
   261 void CXdmProvAdapter::SettingsSavedL( const TDesC8& aAppIdOfSavingItem,
       
   262                                       const TDesC8& aAppRef, 
       
   263                                       const TDesC8& aStorageIdValue )
       
   264     {
       
   265 #ifdef _DEBUG 
       
   266     WriteToLog( _L8( "CXdmProvAdapter::SettingsSavedL" ) );
       
   267 #endif
       
   268     // Convert aAppRef
       
   269     HBufC* appRef16 = HBufC::NewLC( aAppRef.Length() ); // << aAppRef16
       
   270     appRef16->Des().Copy( aAppRef );
       
   271     
       
   272     // Offer application references to all provisioned XDM settings
       
   273     TInt provItemsCount( iProvItems.Count() );
       
   274     for( TInt i(0); i < provItemsCount; i++ )
       
   275         {
       
   276         CXdmProvItem* item = iProvItems[i];
       
   277         const RArray<TPtrC>& toAppRefs = item->ToAppReferences();
       
   278     
       
   279         // Find application reference that is being offered
       
   280         TInt toAppRefsCount( toAppRefs.Count() );
       
   281         for( TInt j(0); j < toAppRefsCount; j++ )
       
   282             {
       
   283             const TDesC& toAppRef = toAppRefs[j];
       
   284             if( !toAppRef.Compare( *appRef16 ) )
       
   285                 {
       
   286                 // Set correct application reference
       
   287                 if( !aAppIdOfSavingItem.Compare( KXdmProvSipIdentifier ) )
       
   288                     {
       
   289                     item->SetSipSettingsIdL( aStorageIdValue );
       
   290                     break;
       
   291                     }   
       
   292                 }               
       
   293             }
       
   294         }
       
   295         CleanupStack::PopAndDestroy( appRef16 );    // >>> appRef16
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CXdmProvAdapter::GetSavingInfoL
       
   300 //
       
   301 // -----------------------------------------------------------------------------
       
   302 void CXdmProvAdapter::GetSavingInfoL( TInt aIndex,
       
   303                                       RPointerArray<HBufC8>& aSavingInfo )
       
   304     {
       
   305 #ifdef _DEBUG 
       
   306     WriteToLog( _L8( "CXdmProvAdapter::GetSavingInfoL" ) );
       
   307 #endif    
       
   308     if ( aIndex < iProvItems.Count() - 1 )
       
   309         {
       
   310 #ifdef _DEBUG 
       
   311     WriteToLog( _L8( "CXdmProvAdapter::GetSavingInfoL leaves with KErrArgument" ) );
       
   312 #endif
       
   313         User::Leave ( KErrArgument );
       
   314         }
       
   315     TInt length ( iProvItems[aIndex]->AppReference().Length() );
       
   316     // if the APPREF exists
       
   317     if ( 0 < length )
       
   318         {
       
   319         // APPID into place [0].
       
   320         TPtrC8 appId ( KXdmProvAppId8 );
       
   321         HBufC8* appIdBuf = appId.AllocLC();             // << appIdBuf
       
   322         aSavingInfo.AppendL( appIdBuf );
       
   323         CleanupStack::Pop( appIdBuf );                  // >> appIdBuf
       
   324         appIdBuf = NULL;
       
   325         
       
   326         // APPREF into place [1].
       
   327         HBufC8* appRefBuf = HBufC8::NewLC( length );    // << appRefBuf
       
   328         TPtr8 appRef = appRefBuf->Des();
       
   329         appRef.Copy( iProvItems[aIndex]->AppReference() );
       
   330         aSavingInfo.AppendL( appRefBuf );
       
   331         CleanupStack::Pop( appRefBuf );                 // >> appRefBuf
       
   332         appRefBuf = NULL;
       
   333         
       
   334         // Xdm settings id into place [2]. 
       
   335         HBufC8* idBuf = HBufC8::NewLC( KXdmProvIntMaxLength );            // << idBuf
       
   336         TPtr8 id = idBuf->Des();
       
   337         id.Num( iProvItems[aIndex]->XdmSettingsId() );
       
   338         aSavingInfo.AppendL( idBuf );
       
   339         CleanupStack::Pop( idBuf );                     // >> idBuf
       
   340         idBuf = NULL;
       
   341         }
       
   342         
       
   343 #ifdef _DEBUG 
       
   344     WriteToLog( _L8( "CXdmProvAdapter::GetSavingInfoL done" ) );
       
   345 #endif
       
   346     }
       
   347     
       
   348 // -----------------------------------------------------------------------------
       
   349 // CXdmProvAdapter::SavingFinalizedL()
       
   350 //
       
   351 // -----------------------------------------------------------------------------
       
   352 void CXdmProvAdapter::SavingFinalizedL()
       
   353     {
       
   354 #ifdef _DEBUG 
       
   355     WriteToLog( _L8( "CXdmProvAdapter::SavingFinalizedL" ) );
       
   356 #endif   
       
   357     }
       
   358     
       
   359     
       
   360 // ----------------------------------------------------
       
   361 // CXdmProvAdapter::WriteToLog
       
   362 // _DEBUG only
       
   363 // ----------------------------------------------------
       
   364 //
       
   365 #ifdef _DEBUG
       
   366 void CXdmProvAdapter::WriteToLog( TRefByValue<const TDesC8> aFmt,... )                                 
       
   367     {
       
   368     VA_LIST list;
       
   369     VA_START( list, aFmt );
       
   370     TBuf8<KXdmProvAdapterBufferMaxSize> buf;
       
   371     buf.FormatList( aFmt, list );
       
   372     RFileLogger::Write( KXdmProvAdapterLogDir, KXdmProvAdapterLogFile, EFileLoggingModeAppend, buf );
       
   373     }
       
   374 #endif
       
   375 //  End of File