diff -r 000000000000 -r c40eb8fe8501 wlan_bearer/wlanldd/wlan_common/osa_common/inc/osahandle.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wlan_bearer/wlanldd/wlan_common/osa_common/inc/osahandle.inl Tue Feb 02 02:03:13 2010 +0200 @@ -0,0 +1,265 @@ +/* +* Copyright (c) 2007 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: inline implementation of Handle +* +*/ + +/* +* %version: 4 % +*/ + +#include "algorithm.h" // for operator != +#include // for assert + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +template +inline Handle::Handle( T& aElem ) + : iData( &aElem ), iRefCount( new TInt( 1 ) ) + { + TraceDump(INFO_LEVEL, (("[WLAN] Handle ctor +: 0x%08x"), this)); + TraceDump(INFO_LEVEL, (("[WLAN] data: 0x%08x"), iData)); + TraceDump(INFO_LEVEL, (("[WLAN] refcount: 0x%08x"), iRefCount)); + + if ( iRefCount ) + { + // allocation success + TraceDump(INFO_LEVEL, + (("[WLAN] reference count: %d"), *iRefCount)); + Validate(); + } + else + { + // allocation failure + TraceDump(ERROR_LEVEL, ("[WLAN] error: allocation")); + Trace( ERROR_LEVEL, + reinterpret_cast(WLAN_FILE), __LINE__ ); + + InValidate(); + } + + TraceDump(INFO_LEVEL, (("[WLAN] Handle ctor -: 0x%08x"), this)); + } + + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +template +inline Handle::~Handle() + { + TraceDump(INFO_LEVEL, (("[WLAN] Handle dtor +: 0x%08x"), this)); + + Dispose(); + + TraceDump(INFO_LEVEL, (("[WLAN] Handle dtor -: 0x%08x"), this)); + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +template +inline Handle::Handle( const Self& aElem ) + : iData( aElem.iData ), iRefCount( aElem.iRefCount ) + { + TraceDump(INFO_LEVEL, (("[WLAN] Handle copy ctor +: 0x%08x"), this)); + TraceDump(INFO_LEVEL, (("[WLAN] data: 0x%08x"), iData)); + TraceDump(INFO_LEVEL, (("[WLAN] refcount: 0x%08x"), iRefCount)); + + + MWlanOsa::Assert( reinterpret_cast(WLAN_FILE), + __LINE__, (iRefCount != NULL) ); + + ++(*iRefCount); + TraceDump(INFO_LEVEL, (("[WLAN] reference count: %d"), *iRefCount)); + + TraceDump(INFO_LEVEL, (("[WLAN] Handle copy ctor -: 0x%08x"), this)); + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +template +inline Handle& Handle::operator=( const Self& aElem ) + { + TraceDump(INFO_LEVEL, + (("[WLAN] Handle assignement operator +: 0x%08x"), this)); + + if ( *this != aElem ) + { + Dispose(); + + iData = aElem.iData; + iRefCount = aElem.iRefCount; + + TraceDump(INFO_LEVEL, (("[WLAN] data: 0x%08x"), iData)); + TraceDump(INFO_LEVEL, (("[WLAN] refcount: 0x%08x"), iRefCount)); + + MWlanOsa::Assert( reinterpret_cast(WLAN_FILE), + __LINE__, (iRefCount != NULL) ); + + ++(*iRefCount); + } + else + { + // left intentionally empty + } + + TraceDump(INFO_LEVEL, (("[WLAN] reference count: %d"), *iRefCount)); + TraceDump(INFO_LEVEL, + (("[WLAN] Handle assignement operator -: 0x%08x"), this)); + + return *this; + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +template +inline T* Handle::operator->() + { + return iData; + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +template +inline T* Handle::Data() + { + MWlanOsa::Assert( reinterpret_cast(WLAN_FILE), + __LINE__, (iData != NULL) ); + return iData; + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +template +inline const T* Handle::Data() const + { + MWlanOsa::Assert( reinterpret_cast(WLAN_FILE), + __LINE__, (iData != NULL) ); + return iData; + } + +// ----------------------------------------------------------------------------- +// only upon allocation failure return EFalse +// ----------------------------------------------------------------------------- +// +template +inline TBool Handle::Bind( T& aElem ) + { + TraceDump(INFO_LEVEL, (("[WLAN] Handle::Bind +: 0x%08x"), this)); + + TBool ret( ETrue ); + + if ( aElem != *iData ) + { + if ( --(*iRefCount) == 0 ) + { + TraceDump(INFO_LEVEL, + ("[WLAN] Handle::Bind deallocate referenced data")); + TraceDump(INFO_LEVEL, + (("[WLAN] old data delloac: 0x%08x"), iData)); + TraceDump(INFO_LEVEL, (("[WLAN] refcount: 0x%08x"), iRefCount)); + + delete iData; + ++(*iRefCount); // recycle counter + } + else + { + // references still exist after this critter is a goner + // as we are doing a rebind we shall create a new counter + iRefCount = new TInt( 1 ); + if ( !iRefCount ) + { + TraceDump(ERROR_LEVEL, ("[WLAN] error: allocation")); + Trace( ERROR_LEVEL, + reinterpret_cast(WLAN_FILE), __LINE__ ); + + ret = EFalse; + } + else + { + // allocation success + // left intentionally empty + TraceDump(INFO_LEVEL, + (("[WLAN] new refcount: 0x%08x"), iRefCount)); + } + } + + iData = &aElem; + TraceDump(INFO_LEVEL, (("[WLAN] new data: 0x%08x"), iData)); + } + else + { + // left intentionally empty + } + + TraceDump(INFO_LEVEL, (("[WLAN] reference count: %d"), *iRefCount)); + TraceDump(INFO_LEVEL, (("[WLAN] Handle::Bind -: 0x%08x"), this)); + + return ret; + } + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +template +inline void Handle::Dispose() + { + TraceDump(INFO_LEVEL, (("[WLAN] Handle::Dispose +: 0x%08x"), this)); + + if ( IsValid() ) + { + // we are a valid object + MWlanOsa::Assert( reinterpret_cast(WLAN_FILE), + __LINE__, (iRefCount != NULL) ); + + if ( --(*iRefCount) == 0 ) + { + TraceDump(INFO_LEVEL, + ("[WLAN] Handle::Dispose deallocate referenced data")); + + TraceDump(INFO_LEVEL, (("[WLAN] data: 0x%08x"), iData)); + delete iData; + TraceDump(INFO_LEVEL, (("[WLAN] refcount: 0x%08x"), iRefCount)); + delete iRefCount; + } + else + { + // references still exist after this critter is a goner + // left intentionally empty + TraceDump(INFO_LEVEL, + (("[WLAN] reference count: %d"), *iRefCount)); + } + } + else + { + // we are an invalid object + // left intentionally empty + } + + TraceDump(INFO_LEVEL, (("[WLAN] Handle::Dispose -: 0x%08x"), this)); + }