webengine/widgetregistry/Server/src/UidAllocator.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 24 Sep 2009 12:53:48 +0300
changeset 11 c8a366e56285
parent 0 dd21522fd290
child 35 1f3c3f2f5b0a
permissions -rw-r--r--
Revision: 200937 Kit: 200939

/*
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Class which allocates random UIDs from a given range
*
*/

#include <e32std.h>
#include "UidAllocator.h"

// MEMBER FUNCTION DEFINITIONS

// ============================================================================
// TUidAllocator::AllocateL()
// Allocate a UID or leave with KErrNotFound
//
// @since 3.1
// ============================================================================
//
TInt TUidAllocator::AllocateL( const RUidArray& aUsedUids, TInt aDriveLetter )
    {
    if ( 'C' == aDriveLetter )
        {
        aDriveLetter = 'c';
        }

    TInt uidStart = ( ('c' == aDriveLetter) ?
                      KWidgetUidInternalMemoryStart :
                      KWidgetUidExternalMemoryStart );
    TInt uidStop = ( ('c' == aDriveLetter) ?
                     KWidgetUidExternalMemoryStart :
                     KWidgetUidExternalMemoryStop + 1);

    TInt uid = uidStart;
    for ( ; uid < uidStop; ++uid )
        {
        if ( KErrNotFound == aUsedUids.Find( TUid::Uid( uid ) ) )
            {
            break;
            }
        }
    if ( uid == uidStop )
        {
        User::Leave( KErrNotFound );
        }
    return uid;
    }

TBool TUidAllocator::IsWidget( TUid aUid )
    {
    return ( ( aUid.iUid >= KWidgetUidLowerBound
               && aUid.iUid <= KWidgetUidUpperBound )?
             ETrue : EFalse );
    }