diff -r 000000000000 -r 3da2a79470a7 testexecmgmt/ucc/Source/hacontroller/CNetworkPartitionManager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testexecmgmt/ucc/Source/hacontroller/CNetworkPartitionManager.cpp Mon Mar 08 15:04:18 2010 +0800 @@ -0,0 +1,254 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "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: +* CNetworkPartitionManager +* System Includes +* +*/ + + + + +#ifdef WIN32 +#include +#else +#include +#endif +#include +#include + + +/******************************************************************************* + * + * Local Includes + * + ******************************************************************************/ +#include "CNetworkPartitionManager.h" + + +/******************************************************************************* + * + * PUBLIC METHOD: CNetworkPartitionManager + * + ******************************************************************************/ +CNetworkPartitionManager::CNetworkPartitionManager() +{ +} + + +/******************************************************************************* + * + * PUBLIC METHOD: ~CNetworkPartitionManager + * + ******************************************************************************/ +CNetworkPartitionManager::~CNetworkPartitionManager() +{ +} + + +/******************************************************************************* + * + * PUBLIC METHOD: SetConfiguration + * + ******************************************************************************/ +int CNetworkPartitionManager::SetConfiguration( int aBaseNetworkAddress, int aBaseNetworkBitCount, int aSegmentSize ) +{ + int err; + int i; + + // check the params + assert( aBaseNetworkBitCount > 0 ); + assert( aBaseNetworkBitCount <= 31 ); + assert( aSegmentSize > 0 ); + + // check that the chunk size is a power of two + err = IsPowerOfTwo( aSegmentSize ); + if( err == 0 ) { + return -1; + } + + // calculate the number of bits for each part + iBaseNetworkPartBitcount = aBaseNetworkBitCount; + iHostPartBitcount = log2( aSegmentSize ); + iSegmentPartBitcount = 32 - iBaseNetworkPartBitcount - iHostPartBitcount; + if( iSegmentPartBitcount < 1 ) { + return -1; + } + iSegmentCount = 1<> iHostPartBitcount; + segment_number &= lower_bits_segment_mask; + + // make sure this number is in the expected range + assert( (segment_number >= 0) && (segment_number < iSegmentCount) ); + + // free the segment - this will assert that there are no duplicates + err = iAddressAllocator.FreeInteger( segment_number ); + assert( err == 0 ); + + // done + return 0; +} + + +/**************************************************************************************** + * + * PRIVATE: log2 + * + ***************************************************************************************/ +int CNetworkPartitionManager::log2( int aValue ) +{ + double base; + double value; + double simple_result, integer_result; + int rv; + + // if the value is less than zero then we have an error which I want to catch NOW + assert( aValue >= 0 ); + + // if the value is zero then - this is also an error? + assert( aValue > 0 ); + + // calculate the logarithm using doubles (we have to) and convert back to integer + base = 2; + value = (double)aValue; + simple_result = log(value) / log(base); + integer_result = ceil(simple_result); + rv = (int)integer_result; + + // since this is not very nice (the need for ceil) I verify the result + if( (1< %d (%g,%g,%g,%g).\n", aValue, rv, base, value, + simple_result, integer_result ); + } + assert( (1< 1) ? 0 : 1); +} + + +/**************************************************************************************** + * + * PRIVATE: NetmaskFromBitcount + * + ***************************************************************************************/ +int CNetworkPartitionManager::NetmaskFromBitcount( int aBitCount ) +{ + int i, netmask = 0; + for( netmask = 0, i = 0; i < aBitCount; i++ ) { + netmask |= 1<<(31-i); + } + return netmask; +}