webengine/widgetregistry/Server/src/UidAllocator.cpp
changeset 0 dd21522fd290
child 35 1f3c3f2f5b0a
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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 the License "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:  Class which allocates random UIDs from a given range
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32std.h>
       
    19 #include "UidAllocator.h"
       
    20 
       
    21 // MEMBER FUNCTION DEFINITIONS
       
    22 
       
    23 // ============================================================================
       
    24 // TUidAllocator::AllocateL()
       
    25 // Allocate a UID or leave with KErrNotFound
       
    26 //
       
    27 // @since 3.1
       
    28 // ============================================================================
       
    29 //
       
    30 TInt TUidAllocator::AllocateL( const RUidArray& aUsedUids, TInt aDriveLetter )
       
    31     {
       
    32     if ( 'C' == aDriveLetter )
       
    33         {
       
    34         aDriveLetter = 'c';
       
    35         }
       
    36 
       
    37     TInt uidStart = ( ('c' == aDriveLetter) ?
       
    38                       KWidgetUidInternalMemoryStart :
       
    39                       KWidgetUidExternalMemoryStart );
       
    40     TInt uidStop = ( ('c' == aDriveLetter) ?
       
    41                      KWidgetUidExternalMemoryStart :
       
    42                      KWidgetUidExternalMemoryStop + 1);
       
    43 
       
    44     TInt uid = uidStart;
       
    45     for ( ; uid < uidStop; ++uid )
       
    46         {
       
    47         if ( KErrNotFound == aUsedUids.Find( TUid::Uid( uid ) ) )
       
    48             {
       
    49             break;
       
    50             }
       
    51         }
       
    52     if ( uid == uidStop )
       
    53         {
       
    54         User::Leave( KErrNotFound );
       
    55         }
       
    56     return uid;
       
    57     }
       
    58 
       
    59 TBool TUidAllocator::IsWidget( TUid aUid )
       
    60     {
       
    61     return ( ( aUid.iUid >= KWidgetUidLowerBound
       
    62                && aUid.iUid <= KWidgetUidUpperBound )?
       
    63              ETrue : EFalse );
       
    64     }