omadrm/drmengine/server/src/drmparentstorage.cpp
changeset 0 95b198f216e5
child 12 8a03a285ab14
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2003 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:  Implementation of the parent storage for Decision Making Machine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "drmparentstorage.h"
       
    21 #include "drmpermission.h"
       
    22 #include "drmlog.h"
       
    23 
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES  
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 LOCAL_C const TUint KDefaultGranularity = 4;
       
    35 
       
    36 // MODULE DATA STRUCTURES
       
    37 
       
    38 // LOCAL FUNCTION PROTOTYPES
       
    39 
       
    40 // FORWARD DECLARATIONS
       
    41 
       
    42 
       
    43 // ============================= LOCAL FUNCTIONS ===============================
       
    44 
       
    45     
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CDRMParentStorage::CDRMParentStorage
       
    50 //
       
    51 // Default constructor 
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CDRMParentStorage::CDRMParentStorage():
       
    55 iParents( 1 )
       
    56     {
       
    57     }
       
    58     
       
    59 // -----------------------------------------------------------------------------
       
    60 // CDRMParentStorage::~CDRMParentStorage
       
    61 //
       
    62 // Desetructor.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CDRMParentStorage::~CDRMParentStorage()
       
    66     {
       
    67     if ( iParentIDs )
       
    68         {
       
    69         iParentIDs->Reset();
       
    70         delete iParentIDs;
       
    71         }
       
    72         
       
    73     // The lists inside are autocleaning, so deletion causes
       
    74     // the contents to also be deleted    
       
    75     iParents.ResetAndDestroy();
       
    76     }
       
    77     
       
    78 // -----------------------------------------------------------------------------
       
    79 // CDRMParentStorage::NewLC
       
    80 //
       
    81 // Two-phase constructor
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CDRMParentStorage* CDRMParentStorage::NewLC()
       
    85     {
       
    86     CDRMParentStorage* self = new( ELeave ) CDRMParentStorage;
       
    87     CleanupStack::PushL( self );
       
    88     
       
    89     self->ConstructL();
       
    90     
       
    91     return self;
       
    92     }
       
    93     
       
    94 // -----------------------------------------------------------------------------
       
    95 // CDRMParentStorage::NewL
       
    96 //
       
    97 // Two-phase constructor
       
    98 // -----------------------------------------------------------------------------
       
    99 //    
       
   100 CDRMParentStorage* CDRMParentStorage::NewL()
       
   101     {
       
   102     CDRMParentStorage* self = CDRMParentStorage::NewLC();
       
   103     CleanupStack::Pop(); // sefl
       
   104     
       
   105     return self;
       
   106     }
       
   107     
       
   108 // -----------------------------------------------------------------------------
       
   109 // CDRMParentStorage::ConstructL
       
   110 //
       
   111 // 2nd phase constructor
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CDRMParentStorage::ConstructL()
       
   115     {
       
   116     iParentIDs = new( ELeave ) CDesC8ArraySeg( KDefaultGranularity );
       
   117     }
       
   118     
       
   119 // -----------------------------------------------------------------------------
       
   120 // CDRMParentStorage::NewListL
       
   121 //
       
   122 // Insert a new list to the storage, and return a handle to it.
       
   123 // -----------------------------------------------------------------------------
       
   124 //    
       
   125 CDRMPermissionList& CDRMParentStorage::NewListL()
       
   126     {
       
   127     __ASSERT_DEBUG( iParents.Count() >= iParentIDs->Count(), User::Invariant() );
       
   128         
       
   129     if ( iParents.Count() == iParentIDs->Count() )
       
   130         {
       
   131         // Balanced lists.
       
   132         CDRMPermissionList* newList = CDRMPermissionList::NewLC();
       
   133         newList->SetAutoCleanup( ETrue );
       
   134         
       
   135         iParents.AppendL( newList );
       
   136         CleanupStack::Pop();
       
   137         }
       
   138         
       
   139     return *( iParents[ iParents.Count() - 1 ] );
       
   140     }
       
   141     
       
   142 // -----------------------------------------------------------------------------
       
   143 // CDRMParentStorage::AddL
       
   144 //
       
   145 // Add an entry to the ID table.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CDRMParentStorage::AddL( const TDesC8& aCID )
       
   149     {
       
   150     TInt pos = iParentIDs->InsertIsqL( aCID );
       
   151     if ( pos != iParentIDs->Count() - 1 )
       
   152         {
       
   153         // Sort iParents
       
   154         CDRMPermissionList* list = iParents[ iParents.Count() - 1 ];
       
   155         User::LeaveIfError( iParents.Insert( list, pos ) );
       
   156         iParents.Remove( iParents.Count() -1 );
       
   157         }
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CDRMParentStorage::HasPermissions
       
   162 //
       
   163 // Check the count of the stored permissions for an id
       
   164 // -----------------------------------------------------------------------------
       
   165 //    
       
   166 TBool CDRMParentStorage::HasPermissions( const TDesC8& aCID )
       
   167     {
       
   168     TBool r = EFalse;
       
   169     TInt pos;
       
   170     
       
   171     if ( iParentIDs->FindIsq( aCID, pos ) == KErrNone )
       
   172         {
       
   173         r = ETrue;
       
   174         }
       
   175     return r;
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CDRMParentStorage::operator[]
       
   180 //
       
   181 // Operator.
       
   182 // -----------------------------------------------------------------------------
       
   183 //    
       
   184 CDRMPermissionList& CDRMParentStorage::operator[]( const TDesC8& aCID )
       
   185     {
       
   186     TInt pos;
       
   187     
       
   188     iParentIDs->FindIsq( aCID, pos );
       
   189     return *( iParents[ pos ] );
       
   190     }
       
   191     
       
   192 // End of File