sl@0: /* sl@0: * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "ct/logger.h" sl@0: sl@0: // As it's easier for the implementer to initialise the ref sl@0: // count to 0 than 1, reference count values are 1 less than you sl@0: // might expect. The object should be deleted when the count reaches -1 sl@0: EXPORT_C void MCTToken::Release() sl@0: { sl@0: --ReferenceCount(); sl@0: sl@0: LOG2(_L("MCTToken::Release: token released, ref count == %d: %-32S"), ReferenceCount(), &Label()); sl@0: LOG_INC_INDENT(); sl@0: sl@0: if (ReferenceCount() < 0) sl@0: { sl@0: MCTTokenType& tokenType = TokenType(); sl@0: DoRelease(); sl@0: // FROM THIS POINT ON, THE OBJECT MAY BE DELETED sl@0: tokenType.Release(); sl@0: } sl@0: sl@0: LOG_DEC_INDENT(); sl@0: } sl@0: sl@0: EXPORT_C void MCTToken::DoRelease() sl@0: { sl@0: LOG1(_L("MCTToken::DoRelease: destroying token: %-32S"), &Label()); sl@0: LOG_INC_INDENT(); sl@0: sl@0: delete this; sl@0: sl@0: LOG_DEC_INDENT(); sl@0: } sl@0: sl@0: // Dummy removal notification for use on non-removable tokens sl@0: EXPORT_C void MCTToken::NotifyOnRemoval(TRequestStatus& /*aStatus*/) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void MCTToken::CancelNotify() sl@0: { sl@0: } sl@0: sl@0: // Base implementation of GetInterface. This just does the reference counting sl@0: EXPORT_C void MCTToken::GetInterface(TUid aRequiredInterface, sl@0: MCTTokenInterface*& aReturnedInterface, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: ++ReferenceCount(); sl@0: LOG2(_L("MCTToken::GetInterface: getting interface, ref count == %d: %-32S"), ReferenceCount(), &Label()); sl@0: LOG_INC_INDENT(); sl@0: sl@0: DoGetInterface(aRequiredInterface, aReturnedInterface, aStatus); sl@0: sl@0: LOG_DEC_INDENT(); sl@0: } sl@0: sl@0: /** Cancel a GetInterface operation */ sl@0: EXPORT_C void MCTToken::CancelGetInterface() sl@0: { sl@0: if (DoCancelGetInterface()) sl@0: { sl@0: Release(); sl@0: } sl@0: } sl@0: sl@0: void MCTToken::ObjectCreated() sl@0: { sl@0: ++ReferenceCount(); sl@0: LOG2(_L("MCTToken::ObjectCreated: token object created, ref count == %d: %-32S"), ReferenceCount(), &Label()); sl@0: }