ncdengine/provider/protocol/src/ncd_pp_paymentimpl.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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:   CNcdPreminetProtocolPaymentImpl implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncd_pp_paymentimpl.h"
       
    20 #include "ncd_pp_purchase.h"
       
    21 #include "ncdprotocolutils.h"
       
    22 #include "ncdpaymentmethod.h"
       
    23 #include "catalogsutils.h"
       
    24 #include "ncdstring.h"
       
    25 #include "ncd_pp_smsdetailsimpl.h"
       
    26 #include "catalogsdebug.h"
       
    27 
       
    28 CNcdPreminetProtocolPaymentImpl* 
       
    29 CNcdPreminetProtocolPaymentImpl::NewL() 
       
    30     {
       
    31     CNcdPreminetProtocolPaymentImpl* self =
       
    32         new (ELeave) CNcdPreminetProtocolPaymentImpl;
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38     
       
    39 CNcdPreminetProtocolPaymentImpl* 
       
    40 CNcdPreminetProtocolPaymentImpl::NewLC() 
       
    41     {
       
    42     CNcdPreminetProtocolPaymentImpl* self =
       
    43         new (ELeave) CNcdPreminetProtocolPaymentImpl;
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL();
       
    46     return self;
       
    47     }
       
    48 
       
    49 void CNcdPreminetProtocolPaymentImpl::ConstructL()
       
    50     {
       
    51     NcdProtocolUtils::AssignEmptyDesL( iQueryId );
       
    52     iName = CNcdString::NewL();
       
    53     }
       
    54 
       
    55 CNcdPreminetProtocolPaymentImpl::~CNcdPreminetProtocolPaymentImpl()
       
    56     {
       
    57     delete iQueryId;
       
    58     delete iName;
       
    59     iSmsDetails.ResetAndDestroy();
       
    60     }
       
    61 
       
    62 void CNcdPreminetProtocolPaymentImpl::ExternalizeL( RWriteStream& aStream )
       
    63     {
       
    64     DLTRACEIN((""));
       
    65     aStream.WriteInt32L( iMethod );
       
    66 
       
    67     // For name and queryid:
       
    68     // if not given in protocol, still constructed in ConstructL.
       
    69     // So they exist in any case and can be externalized.
       
    70     ExternalizeDesL( *iQueryId, aStream );
       
    71     iName->ExternalizeL( aStream );
       
    72     
       
    73     // And then there can be sms details or not
       
    74     const TInt KSmsDetailsCount( iSmsDetails.Count() );
       
    75     aStream.WriteInt32L( KSmsDetailsCount );
       
    76     
       
    77     TInt smsIndexer( 0 );
       
    78     while ( smsIndexer < KSmsDetailsCount )
       
    79         {
       
    80         MNcdPreminetProtocolSmsDetails*
       
    81             currentSmsDetail = iSmsDetails[ smsIndexer ];
       
    82         
       
    83         CNcdPreminetProtocolSmsDetailsImpl* currentCastedSmsDetail =
       
    84             static_cast<CNcdPreminetProtocolSmsDetailsImpl*>(
       
    85                 currentSmsDetail );
       
    86         currentCastedSmsDetail->ExternalizeL( aStream );        
       
    87         ++smsIndexer;
       
    88         }
       
    89     }
       
    90 
       
    91 void CNcdPreminetProtocolPaymentImpl::InternalizeL( RReadStream& aStream )
       
    92     {
       
    93     DLTRACEIN((""));
       
    94     iMethod = static_cast<MNcdPaymentMethod::TNcdPaymentMethodType>(
       
    95                   aStream.ReadInt32L() );
       
    96     
       
    97     InternalizeDesL( iQueryId, aStream );
       
    98     iName->InternalizeL( aStream );
       
    99     
       
   100     // And then there can be sms details or not
       
   101     iSmsDetails.ResetAndDestroy();
       
   102     const TInt KSmsDetailsCount( aStream.ReadInt32L() );
       
   103     TInt smsIndexer( 0 );
       
   104     while ( smsIndexer < KSmsDetailsCount )
       
   105         {
       
   106         CNcdPreminetProtocolSmsDetailsImpl* smsDetails = 
       
   107             CNcdPreminetProtocolSmsDetailsImpl::NewLC();
       
   108         iSmsDetails.AppendL( smsDetails );
       
   109         CleanupStack::Pop( smsDetails );
       
   110         smsDetails->InternalizeL( aStream );
       
   111         ++smsIndexer;
       
   112         }     
       
   113     }
       
   114 
       
   115 MNcdPaymentMethod::TNcdPaymentMethodType
       
   116 CNcdPreminetProtocolPaymentImpl::Method() const
       
   117     {
       
   118     return iMethod;
       
   119     }
       
   120 
       
   121 const TDesC& 
       
   122 CNcdPreminetProtocolPaymentImpl::QueryId() const
       
   123     {
       
   124     return *iQueryId;
       
   125     }
       
   126 
       
   127 const CNcdString& 
       
   128 CNcdPreminetProtocolPaymentImpl::Name() const
       
   129     {
       
   130     return *iName;
       
   131     }
       
   132 
       
   133 const MNcdPreminetProtocolSmsDetails&
       
   134 CNcdPreminetProtocolPaymentImpl::SmsDetailsL(TInt aIndex) const
       
   135     {
       
   136     DASSERT( aIndex >= 0 && aIndex < iSmsDetails.Count() );
       
   137     if ( aIndex < 0 || aIndex >= iSmsDetails.Count() ) 
       
   138         {
       
   139         User::Leave(KErrArgument);
       
   140         }
       
   141     return *iSmsDetails[aIndex];
       
   142     }
       
   143 
       
   144 TInt CNcdPreminetProtocolPaymentImpl::SmsDetailsCount() const 
       
   145     {
       
   146     return iSmsDetails.Count();
       
   147     }
       
   148     
       
   149 CNcdPreminetProtocolPaymentImpl* CNcdPreminetProtocolPaymentImpl::CloneL() const 
       
   150     {
       
   151     DLTRACEIN((""));
       
   152     CNcdPreminetProtocolPaymentImpl* clone =
       
   153         CNcdPreminetProtocolPaymentImpl::NewLC();
       
   154     clone->iMethod = iMethod;
       
   155     AssignDesL( clone->iQueryId, *iQueryId );
       
   156     clone->iName->SetKeyL( iName->Key() );
       
   157     clone->iName->SetDataL( iName->Data() );
       
   158     
       
   159     for ( TInt i = 0; i < iSmsDetails.Count(); i++ ) 
       
   160         {
       
   161         MNcdPreminetProtocolSmsDetails* details = iSmsDetails[i]->CloneL();
       
   162         CleanupStack::PushL( details );
       
   163         clone->iSmsDetails.AppendL( details );
       
   164         CleanupStack::Pop( details );
       
   165         }
       
   166     
       
   167     CleanupStack::Pop( clone );
       
   168     return clone;
       
   169     }