wmdrm/wmdrmengine/wmdrmserver/server/src/slotenumerator.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2007 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:  WMDRM Server implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 
       
    21 #include "wmdrmserver.h"
       
    22 #include "slotenumerator.h"
       
    23 #include "enumeratordata.h"
       
    24 #include "slotenumeratorcache.h"
       
    25 #include "wmdrmdb.h"
       
    26 
       
    27 #define _LOGGING_FILE L"wmdrmserver.txt"
       
    28 
       
    29 #include "flogger.h"
       
    30 #include "logfn.h"
       
    31 
       
    32 CSlotEnumerator* CSlotEnumerator::NewL(
       
    33     CWmDrmServer* aServer,
       
    34     const TDesC8& aStore,
       
    35     const TDesC8& aNameSpace,
       
    36     const TDesC8& aHashKey )
       
    37     {
       
    38     CSlotEnumerator* self = new (ELeave) CSlotEnumerator();
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( aServer, aStore, aNameSpace, aHashKey );
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 void CSlotEnumerator::ConstructL(
       
    46     CWmDrmServer* aServer,
       
    47     const TDesC8& aStore,
       
    48     const TDesC8& aNameSpace,
       
    49     const TDesC8& aHashKey )
       
    50     {
       
    51     LOGFN( "CSlotEnumerator::ConstructL" );
       
    52     iServer = aServer;
       
    53     iStore.Copy( aStore );
       
    54 	iNamespace.Copy( aNameSpace );
       
    55 	LOG( iNamespace );
       
    56 	iHashKey.Copy( aHashKey );
       
    57     LOG( iHashKey );
       
    58     }
       
    59 
       
    60 CSlotEnumerator::CSlotEnumerator():
       
    61     iPosition( 0 ),
       
    62     iEnumeratorData( NULL )
       
    63     {
       
    64     }
       
    65 
       
    66 CSlotEnumerator::~CSlotEnumerator()
       
    67     {
       
    68     if ( iEnumeratorData != NULL )
       
    69         {
       
    70         iEnumeratorData->Close();
       
    71         }
       
    72     }
       
    73 
       
    74 TInt CSlotEnumerator::OpenL()
       
    75     {
       
    76     TInt r = KErrNone;
       
    77     
       
    78 	LOGFNR( "CSlotEnumerator::Open", r );
       
    79 	iEnumeratorData = iServer->EnumeratorCache()->GetEnumeratorDataL( iStore, iNamespace, iHashKey );
       
    80     LOG2( "Slotenumerator entries %d", iEnumeratorData->iEntries.Count() );
       
    81     iPosition = 0;
       
    82     return r;
       
    83     }
       
    84 	
       
    85 TInt CSlotEnumerator::NextL()
       
    86     {
       
    87     TInt r = KErrNone;
       
    88     
       
    89 	LOGFNR( "CSlotEnumerator::Next", r );
       
    90 	if ( iEnumeratorData != NULL && iPosition < iEnumeratorData->iEntries.Count() )
       
    91 	    {
       
    92         iHashKey.Copy( iEnumeratorData->iHashKey  );
       
    93         iUniqueKey.Copy( *iEnumeratorData->iEntries[iPosition] );
       
    94         iPosition++;
       
    95         LOG3( "Saved slot info %S, %S", &iHashKey, &iUniqueKey );
       
    96         }
       
    97     else
       
    98         {
       
    99         LOG1( "Enumerate finished" );
       
   100         r = KErrNotFound;
       
   101         Close();
       
   102         }
       
   103     return r;
       
   104     }
       
   105 	
       
   106 void CSlotEnumerator::Close()
       
   107     {
       
   108 	LOGFN( "CSlotEnumerator::Close" );
       
   109 	if ( iEnumeratorData != NULL )
       
   110 	    {
       
   111         iEnumeratorData->Close();
       
   112         iEnumeratorData = NULL;
       
   113         }
       
   114     }
       
   115