|
1 /* |
|
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cfstokentypeclient.h" |
|
20 #include <certificateapps.h> |
|
21 #include <ct/mcttoken.h> |
|
22 #include <mctcertapps.h> |
|
23 |
|
24 //////////////////////////////////////////////////////////////// |
|
25 // CCertificateAppInfoManager |
|
26 //////////////////////////////////////////////////////////////// |
|
27 |
|
28 EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewLC() |
|
29 { |
|
30 CCertificateAppInfoManager* self = new(ELeave) CCertificateAppInfoManager(); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 return self; |
|
34 } |
|
35 |
|
36 EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewL() |
|
37 { |
|
38 CCertificateAppInfoManager* self = NewLC(); |
|
39 CleanupStack::Pop(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // deprecated |
|
44 EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewLC(RFs& /*aFs*/, |
|
45 TBool /*aOpenedForWrite*/) |
|
46 { |
|
47 return NewLC(); |
|
48 } |
|
49 |
|
50 // deprecated |
|
51 EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewL(RFs& /*aFs*/, |
|
52 TBool /*aOpenedForWrite*/) |
|
53 { |
|
54 return NewL(); |
|
55 } |
|
56 |
|
57 EXPORT_C CCertificateAppInfoManager::~CCertificateAppInfoManager() |
|
58 { |
|
59 iClients.Close(); |
|
60 if (iCertAppsIf) |
|
61 { |
|
62 iCertAppsIf->Release(); |
|
63 } |
|
64 } |
|
65 |
|
66 CCertificateAppInfoManager::CCertificateAppInfoManager() |
|
67 { |
|
68 } |
|
69 |
|
70 void CCertificateAppInfoManager::ConstructL() |
|
71 { |
|
72 // This method is the second phase of the construction process. |
|
73 // |
|
74 // It will open the cert apps token type, get the token, and |
|
75 // then get the token interface. |
|
76 // |
|
77 // This class is not an active object but we can safely |
|
78 // wait for requests to complete because the filetokens |
|
79 // server completes requests immediately |
|
80 MCTTokenType* tokenType = CFSTokenTypeClient::NewL(TUid::Uid(KTokenTypeCertApps)); |
|
81 CleanupReleasePushL(*tokenType); |
|
82 |
|
83 // Now extract all the tokens this token type contains |
|
84 RCPointerArray<HBufC> tokenArray; |
|
85 CleanupClosePushL(tokenArray); |
|
86 |
|
87 TRequestStatus stat; |
|
88 tokenType->List(tokenArray, stat); |
|
89 User::WaitForRequest(stat); |
|
90 |
|
91 // make sure we have at least one token, otherwise leave |
|
92 User::LeaveIfError(stat.Int()); |
|
93 __ASSERT_DEBUG(tokenArray.Count(), User::Panic(_L("CCertificateAppInfoManager"), 1)); |
|
94 |
|
95 MCTToken* token = NULL; |
|
96 |
|
97 // We assume the 1st token is the one we want |
|
98 tokenType->OpenToken(*tokenArray[0], token, stat); |
|
99 User::WaitForRequest(stat); |
|
100 User::LeaveIfError(stat.Int()); |
|
101 CleanupReleasePushL(*token); |
|
102 |
|
103 // Now try and get the appropriate token interface |
|
104 MCTTokenInterface* tokenIf = NULL; |
|
105 token->GetInterface(TUid::Uid(KInterfaceCertApps), tokenIf, stat); |
|
106 User::WaitForRequest(stat); |
|
107 User::LeaveIfError(stat.Int()); |
|
108 __ASSERT_DEBUG(tokenIf, User::Panic(_L("CCertificateAppInfoManager"), 1)); |
|
109 |
|
110 // now upcast to a certapps interface. This should be a fairly safe cast |
|
111 // since we specifically requested for this interface |
|
112 iCertAppsIf = static_cast<MCTCertApps*>(tokenIf); |
|
113 |
|
114 // Now we can release the token and the token type and destroy the token |
|
115 // array |
|
116 token->Release(); |
|
117 tokenType->Release(); |
|
118 tokenArray.Close(); |
|
119 |
|
120 // Pop the stuff from the cleanup stack - could have done a |
|
121 // PopAndDestroy instead of Release()/Close() but thought I'd be |
|
122 // more explicit |
|
123 CleanupStack::Pop(3); |
|
124 |
|
125 // Populate the applications array |
|
126 iCertAppsIf->ApplicationsL(iClients); |
|
127 } |
|
128 |
|
129 EXPORT_C void CCertificateAppInfoManager::AddL(const TCertificateAppInfo& aClient) |
|
130 { |
|
131 // We have to update our cached applications array, but must keep this in |
|
132 // sync with the server in the face of leaves and OOM |
|
133 User::LeaveIfError(iClients.Append(aClient)); |
|
134 TRAPD(err, iCertAppsIf->AddL(aClient)); |
|
135 if (err != KErrNone) |
|
136 { |
|
137 iClients.Remove(iClients.Count() - 1); |
|
138 User::Leave(err); |
|
139 } |
|
140 } |
|
141 |
|
142 EXPORT_C void CCertificateAppInfoManager::RemoveL(const TUid& aUid) |
|
143 { |
|
144 // We have to update our cached applications array, but must keep this in |
|
145 // sync with the server in the face of leaves and OOM |
|
146 iCertAppsIf->RemoveL(aUid); |
|
147 |
|
148 // Count backwards so we don't have to worry about the size changing |
|
149 for (TInt i = iClients.Count() - 1 ; i >= 0 ; --i) |
|
150 { |
|
151 if (iClients[i].Id() == aUid) |
|
152 { |
|
153 iClients.Remove(i); |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 EXPORT_C const TCertificateAppInfo& CCertificateAppInfoManager::ApplicationL(const TUid& aUid, TInt& aIndex) const |
|
159 { |
|
160 aIndex = KErrNotFound; |
|
161 |
|
162 for (TInt i = 0 ; i < iClients.Count() ; ++i) |
|
163 { |
|
164 if (iClients[i].Id() == aUid) |
|
165 { |
|
166 aIndex = i; |
|
167 break; |
|
168 } |
|
169 } |
|
170 |
|
171 User::LeaveIfError(aIndex); |
|
172 return iClients[aIndex]; |
|
173 } |
|
174 |
|
175 EXPORT_C const RArray<TCertificateAppInfo>& CCertificateAppInfoManager::Applications() const |
|
176 { |
|
177 return iClients; |
|
178 } |