ncdengine/provider/client/src/ncdpurchasehistoryproxy.cpp
changeset 4 32704c33136d
equal deleted inserted replaced
-1:000000000000 4:32704c33136d
       
     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:   Implements CNcdPurchaseHistoryProxy class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32err.h>
       
    20 #include <s32mem.h>
       
    21 
       
    22 #include "catalogsinterfaceidentifier.h"
       
    23 #include "catalogsclientserver.h"
       
    24 #include "ncdpurchasehistoryproxy.h"
       
    25 #include "ncdnodefunctionids.h"
       
    26 #include "ncdpurchasedetails.h"
       
    27 #include "ncdutils.h"
       
    28 #include "ncdpurchasehistoryfilter.h"
       
    29 #include "catalogsutils.h"
       
    30 #include "catalogsconstants.h"
       
    31 #include "catalogsdebug.h"
       
    32 
       
    33 
       
    34 CNcdPurchaseHistoryProxy::CNcdPurchaseHistoryProxy(
       
    35     MCatalogsClientServer& aSession, 
       
    36     TInt aHandle,
       
    37     CCatalogsInterfaceBase* aParent,
       
    38     CNcdOperationManagerProxy& aOperationManager )
       
    39         : CNcdInterfaceBaseProxy( aSession, aHandle, aParent ),
       
    40         iOperationManager( aOperationManager )
       
    41     {
       
    42     }
       
    43 
       
    44 void CNcdPurchaseHistoryProxy::ConstructL()
       
    45     {
       
    46     MNcdPurchaseHistory* history( this );
       
    47     AddInterfaceL( 
       
    48         CCatalogsInterfaceIdentifier::NewL(
       
    49             history,
       
    50             this,
       
    51             MNcdPurchaseHistory::KInterfaceUid ) );
       
    52     }
       
    53 
       
    54 
       
    55 CNcdPurchaseHistoryProxy* CNcdPurchaseHistoryProxy::NewL(
       
    56     MCatalogsClientServer& aSession,
       
    57     TInt aHandle,
       
    58     CCatalogsInterfaceBase* aParent,
       
    59     CNcdOperationManagerProxy& aOperationManager )
       
    60     {
       
    61     CNcdPurchaseHistoryProxy* self = 
       
    62         CNcdPurchaseHistoryProxy::NewLC(
       
    63             aSession,
       
    64             aHandle,
       
    65             aParent,
       
    66             aOperationManager );
       
    67     CleanupStack::Pop( self );
       
    68     return self;        
       
    69     }
       
    70 
       
    71 CNcdPurchaseHistoryProxy* CNcdPurchaseHistoryProxy::NewLC(
       
    72     MCatalogsClientServer& aSession,
       
    73     TInt aHandle,
       
    74     CCatalogsInterfaceBase* aParent,
       
    75     CNcdOperationManagerProxy& aOperationManager )
       
    76     {
       
    77     CNcdPurchaseHistoryProxy* self = 
       
    78         new( ELeave ) CNcdPurchaseHistoryProxy(
       
    79             aSession,
       
    80             aHandle,
       
    81             aParent,
       
    82             aOperationManager );
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85     return self;        
       
    86     }
       
    87 
       
    88 CNcdPurchaseHistoryProxy::~CNcdPurchaseHistoryProxy()
       
    89     {
       
    90     // Remove interfaces implemented by this class from the interface list.
       
    91     // So, the interface list is up to date when this class object is deleted.
       
    92     RemoveInterface( MNcdPurchaseHistory::KInterfaceUid );
       
    93     }
       
    94 
       
    95 void CNcdPurchaseHistoryProxy::SavePurchaseL(
       
    96     const MNcdPurchaseDetails& aDetails,
       
    97     TBool aSaveIcon )
       
    98     {
       
    99     DLTRACEIN((""));
       
   100     
       
   101     DLINFO(("Save purchase details to purchase history"));
       
   102     
       
   103     CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
       
   104     CleanupStack::PushL( buf );        
       
   105     
       
   106     RBufWriteStream stream( *buf );
       
   107     CleanupClosePushL( stream );
       
   108     
       
   109     static_cast<const CNcdPurchaseDetails*>(&aDetails)->ExternalizeL( stream );
       
   110     
       
   111     CleanupStack::PopAndDestroy( &stream );    
       
   112     
       
   113     TInt funcId( NcdNodeFunctionIds::ENcdPurchaseHistorySavePurchase );
       
   114     if ( !aSaveIcon )
       
   115         {
       
   116         funcId = 
       
   117             NcdNodeFunctionIds::ENcdPurchaseHistorySavePurchaseWithOldIcon;
       
   118         }
       
   119         
       
   120     HBufC8* dummyBuf = NULL;
       
   121 
       
   122     User::LeaveIfError( ClientServerSession().SendSyncAlloc(
       
   123         funcId,
       
   124         buf->Ptr( 0 ),
       
   125         dummyBuf,
       
   126         Handle(),
       
   127         0 ) );
       
   128     delete dummyBuf;
       
   129 
       
   130     CleanupStack::PopAndDestroy( buf );
       
   131     
       
   132     DLTRACEOUT((""));
       
   133     }
       
   134 
       
   135 RArray<TUint> CNcdPurchaseHistoryProxy::PurchaseIdsL(
       
   136     const MNcdPurchaseHistoryFilter& aFilter )
       
   137     {
       
   138     DLTRACEIN((""));
       
   139     
       
   140     DLINFO(("Get purchase IDs from purchase history"));
       
   141     
       
   142     CBufBase* filterBuf = CBufFlat::NewL( KBufExpandSize );
       
   143     CleanupStack::PushL( filterBuf );
       
   144     
       
   145     RBufWriteStream stream( *filterBuf );
       
   146     CleanupClosePushL( stream );
       
   147     
       
   148     TArray<TUid> clientUids = aFilter.ClientUids();
       
   149     TUint count = clientUids.Count();
       
   150     stream.WriteUint32L( count );
       
   151     for ( TInt i = 0; i < count; i++ )
       
   152         {
       
   153         stream.WriteInt32L( clientUids[i].iUid );
       
   154         }
       
   155     ExternalizeDesL( aFilter.Namespace(), stream );
       
   156     ExternalizeDesL( aFilter.EntityId(), stream );
       
   157     stream.WriteUint32L( aFilter.EventId() );
       
   158     
       
   159     CleanupStack::PopAndDestroy( &stream );
       
   160 
       
   161     HBufC8* idBuf = NULL;
       
   162     User::LeaveIfError( ClientServerSession().SendSyncAlloc(
       
   163         NcdNodeFunctionIds::ENcdPurchaseHistoryGetPurchaseIds,
       
   164         filterBuf->Ptr( 0 ),
       
   165         idBuf,
       
   166         Handle(),
       
   167         0 ) );
       
   168         
       
   169     CleanupStack::PopAndDestroy( filterBuf );
       
   170 
       
   171     CleanupStack::PushL( idBuf );
       
   172 
       
   173     TInt size = sizeof(TUint);
       
   174     count = Des8ToUint( idBuf->Mid( 0, size ) );
       
   175 
       
   176     RArray<TUint> purchaseIds;    
       
   177     CleanupClosePushL( purchaseIds );
       
   178     
       
   179     for ( TInt i = 0; i < count; i++ )
       
   180         {
       
   181         purchaseIds.Append(
       
   182             Des8ToUint( idBuf->Mid( ( i + 1 ) * size, size ) ) );
       
   183         }
       
   184 
       
   185     CleanupStack::Pop( &purchaseIds );
       
   186     CleanupStack::PopAndDestroy( idBuf );
       
   187     
       
   188     DLTRACEOUT((""));
       
   189 
       
   190     return purchaseIds;
       
   191     }
       
   192 
       
   193 CNcdPurchaseDetails* CNcdPurchaseHistoryProxy::PurchaseDetailsL(
       
   194     TUint aPurchaseId,
       
   195     TBool aLoadIcon )
       
   196     {
       
   197     DLTRACEIN(("Load with icon: %d", aLoadIcon));
       
   198     
       
   199     DLINFO(("Get purchase details from purchase history"));
       
   200     
       
   201     HBufC8* id = UintToDes8LC( aPurchaseId );
       
   202 
       
   203     HBufC8* detailsBuf = NULL;
       
   204     
       
   205     
       
   206     if ( aLoadIcon ) 
       
   207         {        
       
   208         User::LeaveIfError( ClientServerSession().SendSyncAlloc(
       
   209             NcdNodeFunctionIds::ENcdPurchaseHistoryGetPurchase,
       
   210             *id,
       
   211             detailsBuf,
       
   212             Handle(),
       
   213             0 ) );
       
   214         }
       
   215     else
       
   216         {
       
   217         User::LeaveIfError( ClientServerSession().SendSyncAlloc(
       
   218             NcdNodeFunctionIds::ENcdPurchaseHistoryGetPurchaseNoIcon,
       
   219             *id,
       
   220             detailsBuf,
       
   221             Handle(),
       
   222             0 ) );
       
   223         }
       
   224     CleanupStack::PopAndDestroy( id );
       
   225     CleanupStack::PushL( detailsBuf );
       
   226 
       
   227     CNcdPurchaseDetails* details = CNcdPurchaseDetails::NewLC();
       
   228 
       
   229     RDesReadStream stream( *detailsBuf );
       
   230     CleanupClosePushL( stream );
       
   231     
       
   232     details->InternalizeL( stream );
       
   233     
       
   234     CleanupStack::PopAndDestroy( &stream );
       
   235     CleanupStack::Pop( details );
       
   236     CleanupStack::PopAndDestroy( detailsBuf );
       
   237     
       
   238     DLTRACEOUT((""));
       
   239     
       
   240     return details;
       
   241     }
       
   242 
       
   243 void CNcdPurchaseHistoryProxy::RemovePurchaseL( TUint aPurchaseId )
       
   244     {
       
   245     DLTRACEIN((""));
       
   246     
       
   247     DLINFO(("Remove purchase from purchase history"));
       
   248     
       
   249     HBufC8* id = UintToDes8LC( aPurchaseId );
       
   250 
       
   251     HBufC8* dummyBuf = NULL;
       
   252     User::LeaveIfError( ClientServerSession().SendSyncAlloc(
       
   253         NcdNodeFunctionIds::ENcdPurchaseHistoryRemovePurchase,
       
   254         *id,
       
   255         dummyBuf,
       
   256         Handle(),
       
   257         0 ) );
       
   258     delete dummyBuf;
       
   259     
       
   260     CleanupStack::PopAndDestroy( id );
       
   261 
       
   262     DLTRACEOUT((""));
       
   263     }
       
   264 
       
   265 TUint CNcdPurchaseHistoryProxy::EventCountL()
       
   266     {
       
   267     DLTRACEIN((""));
       
   268     
       
   269     DLINFO(("Get event count from purchase history"));
       
   270     
       
   271     HBufC8* countBuf = NULL;
       
   272     User::LeaveIfError( ClientServerSession().SendSyncAlloc(
       
   273         NcdNodeFunctionIds::ENcdPurchaseHistoryEventCount,
       
   274         KNullDesC8,
       
   275         countBuf,
       
   276         Handle(),
       
   277         0 ) );
       
   278     CleanupStack::PushL( countBuf );
       
   279 
       
   280     TUint count = Des8ToUint( *countBuf );
       
   281     
       
   282     CleanupStack::PopAndDestroy( countBuf );
       
   283     
       
   284     DLTRACEOUT((""));
       
   285     
       
   286     return count;
       
   287     }