First public contribution.
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "CFSTokenTypeClient.h"
20 #include <certificateapps.h>
21 #include <ct/mcttoken.h>
22 #include <mctcertapps.h>
23 #include "mctcertappinterface.h"
26 ////////////////////////////////////////////////////////////////
27 // CCertificateAppInfoManager
28 ////////////////////////////////////////////////////////////////
30 EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewLC()
32 CCertificateAppInfoManager* self = new(ELeave) CCertificateAppInfoManager();
33 CleanupStack::PushL(self);
38 EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewL()
40 CCertificateAppInfoManager* self = NewLC();
46 EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewLC(RFs& /*aFs*/,
47 TBool /*aOpenedForWrite*/)
53 EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewL(RFs& /*aFs*/,
54 TBool /*aOpenedForWrite*/)
59 EXPORT_C CCertificateAppInfoManager::~CCertificateAppInfoManager()
64 iCertAppsIf->Release();
68 CCertificateAppInfoManager::CCertificateAppInfoManager()
72 void CCertificateAppInfoManager::ConstructL()
74 // This method is the second phase of the construction process.
76 // It will open the cert apps token type, get the token, and
77 // then get the token interface.
79 // This class is not an active object but we can safely
80 // wait for requests to complete because the filetokens
81 // server completes requests immediately
82 MCTTokenType* tokenType = CFSTokenTypeClient::NewL(TUid::Uid(KTokenTypeCertApps));
83 CleanupReleasePushL(*tokenType);
85 // Now extract all the tokens this token type contains
86 RCPointerArray<HBufC> tokenArray;
87 CleanupClosePushL(tokenArray);
90 tokenType->List(tokenArray, stat);
91 User::WaitForRequest(stat);
93 // make sure we have at least one token, otherwise leave
94 User::LeaveIfError(stat.Int());
95 __ASSERT_DEBUG(tokenArray.Count(), User::Panic(_L("CCertificateAppInfoManager"), 1));
97 MCTToken* token = NULL;
99 // We assume the 1st token is the one we want
100 tokenType->OpenToken(*tokenArray[0], token, stat);
101 User::WaitForRequest(stat);
102 User::LeaveIfError(stat.Int());
103 CleanupReleasePushL(*token);
105 // Now try and get the appropriate token interface
106 MCTTokenInterface* tokenIf = NULL;
107 token->GetInterface(TUid::Uid(KInterfaceCertApps), tokenIf, stat);
108 User::WaitForRequest(stat);
109 User::LeaveIfError(stat.Int());
110 __ASSERT_DEBUG(tokenIf, User::Panic(_L("CCertificateAppInfoManager"), 1));
112 // now upcast to a certapps interface. This should be a fairly safe cast
113 // since we specifically requested for this interface
114 iCertAppsIf = static_cast<MCTCertApps*>(tokenIf);
116 // Now we can release the token and the token type and destroy the token
119 tokenType->Release();
122 // Pop the stuff from the cleanup stack - could have done a
123 // PopAndDestroy instead of Release()/Close() but thought I'd be
125 CleanupStack::Pop(3);
127 // Populate the applications array
128 iCertAppsIf->ApplicationsL(iClients);
131 EXPORT_C void CCertificateAppInfoManager::AddL(const TCertificateAppInfo& aClient)
133 // We have to update our cached applications array, but must keep this in
134 // sync with the server in the face of leaves and OOM
135 User::LeaveIfError(iClients.Append(aClient));
136 TRAPD(err, iCertAppsIf->AddL(aClient));
139 iClients.Remove(iClients.Count() - 1);
144 EXPORT_C void CCertificateAppInfoManager::RemoveL(const TUid& aUid)
146 // We have to update our cached applications array, but must keep this in
147 // sync with the server in the face of leaves and OOM
148 iCertAppsIf->RemoveL(aUid);
150 // Count backwards so we don't have to worry about the size changing
151 for (TInt i = iClients.Count() - 1 ; i >= 0 ; --i)
153 if (iClients[i].Id() == aUid)
160 EXPORT_C const TCertificateAppInfo& CCertificateAppInfoManager::ApplicationL(const TUid& aUid, TInt& aIndex) const
162 aIndex = KErrNotFound;
164 for (TInt i = 0 ; i < iClients.Count() ; ++i)
166 if (iClients[i].Id() == aUid)
173 User::LeaveIfError(aIndex);
174 return iClients[aIndex];
177 EXPORT_C const RArray<TCertificateAppInfo>& CCertificateAppInfoManager::Applications() const