1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptomgmtlibs/cryptotokenfw/source/ctframework/MCTToken.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,90 @@
1.4 +/*
1.5 +* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <e32base.h>
1.23 +#include <ct.h>
1.24 +#include "ct/logger.h"
1.25 +
1.26 +// As it's easier for the implementer to initialise the ref
1.27 +// count to 0 than 1, reference count values are 1 less than you
1.28 +// might expect. The object should be deleted when the count reaches -1
1.29 +EXPORT_C void MCTToken::Release()
1.30 + {
1.31 + --ReferenceCount();
1.32 +
1.33 + LOG2(_L("MCTToken::Release: token released, ref count == %d: %-32S"), ReferenceCount(), &Label());
1.34 + LOG_INC_INDENT();
1.35 +
1.36 + if (ReferenceCount() < 0)
1.37 + {
1.38 + MCTTokenType& tokenType = TokenType();
1.39 + DoRelease();
1.40 + // FROM THIS POINT ON, THE OBJECT MAY BE DELETED
1.41 + tokenType.Release();
1.42 + }
1.43 +
1.44 + LOG_DEC_INDENT();
1.45 + }
1.46 +
1.47 +EXPORT_C void MCTToken::DoRelease()
1.48 + {
1.49 + LOG1(_L("MCTToken::DoRelease: destroying token: %-32S"), &Label());
1.50 + LOG_INC_INDENT();
1.51 +
1.52 + delete this;
1.53 +
1.54 + LOG_DEC_INDENT();
1.55 + }
1.56 +
1.57 +// Dummy removal notification for use on non-removable tokens
1.58 +EXPORT_C void MCTToken::NotifyOnRemoval(TRequestStatus& /*aStatus*/)
1.59 + {
1.60 + }
1.61 +
1.62 +EXPORT_C void MCTToken::CancelNotify()
1.63 + {
1.64 + }
1.65 +
1.66 +// Base implementation of GetInterface. This just does the reference counting
1.67 +EXPORT_C void MCTToken::GetInterface(TUid aRequiredInterface,
1.68 + MCTTokenInterface*& aReturnedInterface,
1.69 + TRequestStatus& aStatus)
1.70 + {
1.71 + ++ReferenceCount();
1.72 + LOG2(_L("MCTToken::GetInterface: getting interface, ref count == %d: %-32S"), ReferenceCount(), &Label());
1.73 + LOG_INC_INDENT();
1.74 +
1.75 + DoGetInterface(aRequiredInterface, aReturnedInterface, aStatus);
1.76 +
1.77 + LOG_DEC_INDENT();
1.78 + }
1.79 +
1.80 +/** Cancel a GetInterface operation */
1.81 +EXPORT_C void MCTToken::CancelGetInterface()
1.82 + {
1.83 + if (DoCancelGetInterface())
1.84 + {
1.85 + Release();
1.86 + }
1.87 + }
1.88 +
1.89 +void MCTToken::ObjectCreated()
1.90 + {
1.91 + ++ReferenceCount();
1.92 + LOG2(_L("MCTToken::ObjectCreated: token object created, ref count == %d: %-32S"), ReferenceCount(), &Label());
1.93 + }