sl@0: /* sl@0: * Copyright (c) 1998-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 "CFSTokenTypeClient.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "mctcertappinterface.h" sl@0: sl@0: sl@0: //////////////////////////////////////////////////////////////// sl@0: // CCertificateAppInfoManager sl@0: //////////////////////////////////////////////////////////////// sl@0: sl@0: EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewLC() sl@0: { sl@0: CCertificateAppInfoManager* self = new(ELeave) CCertificateAppInfoManager(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewL() sl@0: { sl@0: CCertificateAppInfoManager* self = NewLC(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: // deprecated sl@0: EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewLC(RFs& /*aFs*/, sl@0: TBool /*aOpenedForWrite*/) sl@0: { sl@0: return NewLC(); sl@0: } sl@0: sl@0: // deprecated sl@0: EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewL(RFs& /*aFs*/, sl@0: TBool /*aOpenedForWrite*/) sl@0: { sl@0: return NewL(); sl@0: } sl@0: sl@0: EXPORT_C CCertificateAppInfoManager::~CCertificateAppInfoManager() sl@0: { sl@0: iClients.Close(); sl@0: if (iCertAppsIf) sl@0: { sl@0: iCertAppsIf->Release(); sl@0: } sl@0: } sl@0: sl@0: CCertificateAppInfoManager::CCertificateAppInfoManager() sl@0: { sl@0: } sl@0: sl@0: void CCertificateAppInfoManager::ConstructL() sl@0: { sl@0: // This method is the second phase of the construction process. sl@0: // sl@0: // It will open the cert apps token type, get the token, and sl@0: // then get the token interface. sl@0: // sl@0: // This class is not an active object but we can safely sl@0: // wait for requests to complete because the filetokens sl@0: // server completes requests immediately sl@0: MCTTokenType* tokenType = CFSTokenTypeClient::NewL(TUid::Uid(KTokenTypeCertApps)); sl@0: CleanupReleasePushL(*tokenType); sl@0: sl@0: // Now extract all the tokens this token type contains sl@0: RCPointerArray tokenArray; sl@0: CleanupClosePushL(tokenArray); sl@0: sl@0: TRequestStatus stat; sl@0: tokenType->List(tokenArray, stat); sl@0: User::WaitForRequest(stat); sl@0: sl@0: // make sure we have at least one token, otherwise leave sl@0: User::LeaveIfError(stat.Int()); sl@0: __ASSERT_DEBUG(tokenArray.Count(), User::Panic(_L("CCertificateAppInfoManager"), 1)); sl@0: sl@0: MCTToken* token = NULL; sl@0: sl@0: // We assume the 1st token is the one we want sl@0: tokenType->OpenToken(*tokenArray[0], token, stat); sl@0: User::WaitForRequest(stat); sl@0: User::LeaveIfError(stat.Int()); sl@0: CleanupReleasePushL(*token); sl@0: sl@0: // Now try and get the appropriate token interface sl@0: MCTTokenInterface* tokenIf = NULL; sl@0: token->GetInterface(TUid::Uid(KInterfaceCertApps), tokenIf, stat); sl@0: User::WaitForRequest(stat); sl@0: User::LeaveIfError(stat.Int()); sl@0: __ASSERT_DEBUG(tokenIf, User::Panic(_L("CCertificateAppInfoManager"), 1)); sl@0: sl@0: // now upcast to a certapps interface. This should be a fairly safe cast sl@0: // since we specifically requested for this interface sl@0: iCertAppsIf = static_cast(tokenIf); sl@0: sl@0: // Now we can release the token and the token type and destroy the token sl@0: // array sl@0: token->Release(); sl@0: tokenType->Release(); sl@0: tokenArray.Close(); sl@0: sl@0: // Pop the stuff from the cleanup stack - could have done a sl@0: // PopAndDestroy instead of Release()/Close() but thought I'd be sl@0: // more explicit sl@0: CleanupStack::Pop(3); sl@0: sl@0: // Populate the applications array sl@0: iCertAppsIf->ApplicationsL(iClients); sl@0: } sl@0: sl@0: EXPORT_C void CCertificateAppInfoManager::AddL(const TCertificateAppInfo& aClient) sl@0: { sl@0: // We have to update our cached applications array, but must keep this in sl@0: // sync with the server in the face of leaves and OOM sl@0: User::LeaveIfError(iClients.Append(aClient)); sl@0: TRAPD(err, iCertAppsIf->AddL(aClient)); sl@0: if (err != KErrNone) sl@0: { sl@0: iClients.Remove(iClients.Count() - 1); sl@0: User::Leave(err); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCertificateAppInfoManager::RemoveL(const TUid& aUid) sl@0: { sl@0: // We have to update our cached applications array, but must keep this in sl@0: // sync with the server in the face of leaves and OOM sl@0: iCertAppsIf->RemoveL(aUid); sl@0: sl@0: // Count backwards so we don't have to worry about the size changing sl@0: for (TInt i = iClients.Count() - 1 ; i >= 0 ; --i) sl@0: { sl@0: if (iClients[i].Id() == aUid) sl@0: { sl@0: iClients.Remove(i); sl@0: } sl@0: } sl@0: } sl@0: sl@0: EXPORT_C const TCertificateAppInfo& CCertificateAppInfoManager::ApplicationL(const TUid& aUid, TInt& aIndex) const sl@0: { sl@0: aIndex = KErrNotFound; sl@0: sl@0: for (TInt i = 0 ; i < iClients.Count() ; ++i) sl@0: { sl@0: if (iClients[i].Id() == aUid) sl@0: { sl@0: aIndex = i; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: User::LeaveIfError(aIndex); sl@0: return iClients[aIndex]; sl@0: } sl@0: sl@0: EXPORT_C const RArray& CCertificateAppInfoManager::Applications() const sl@0: { sl@0: return iClients; sl@0: }