|
1 /* |
|
2 * Copyright (c) 2002-2007 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 "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: A class offers an API to find copy policy for different stores |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <CVPbkContactCopyPolicyManager.h> |
|
22 |
|
23 #include <CVPbkContactCopyPolicy.h> |
|
24 #include <TVPbkContactStoreUriPtr.h> |
|
25 #include <VPbkPolicyUid.h> |
|
26 #include <ecom/ecom.h> |
|
27 |
|
28 // ============================= LOCAL FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CleanupResetAndDestroy |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 namespace |
|
35 { |
|
36 void CleanupResetAndDestroy(TAny* aObj) |
|
37 { |
|
38 if (aObj) |
|
39 { |
|
40 static_cast<RImplInfoPtrArray*>(aObj)->ResetAndDestroy(); |
|
41 } |
|
42 } |
|
43 } |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CVPbkContactCopyPolicyManager::CVPbkContactCopyPolicyManager |
|
49 // C++ default constructor can NOT contain any code, that |
|
50 // might leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CVPbkContactCopyPolicyManager::CVPbkContactCopyPolicyManager() |
|
54 { |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CVPbkContactCopyPolicyManager::ConstructL |
|
59 // Symbian 2nd phase constructor can leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CVPbkContactCopyPolicyManager::ConstructL() |
|
63 { |
|
64 RImplInfoPtrArray implementations; |
|
65 TEComResolverParams resolverParams; |
|
66 |
|
67 resolverParams.SetWildcardMatch(ETrue); |
|
68 _LIT8(KPbkExtension, KVPbkCopyPolicyDataString); |
|
69 resolverParams.SetDataType(KPbkExtension); |
|
70 |
|
71 REComSession::ListImplementationsL( |
|
72 TUid::Uid(KVPbkCopyPolicyInterfaceUID), |
|
73 resolverParams, KRomOnlyResolverUid, implementations); |
|
74 |
|
75 CleanupStack::PushL(TCleanupItem(CleanupResetAndDestroy, &implementations)); |
|
76 |
|
77 const TInt count = implementations.Count(); |
|
78 for (TInt i = count-1; i >= 0; --i) |
|
79 { |
|
80 CImplementationInformation* implInfo = implementations[i]; |
|
81 CleanupStack::PushL(implInfo); |
|
82 implementations.Remove(i); |
|
83 iImplementationInfoArray.AppendL(implInfo); |
|
84 CleanupStack::Pop(implInfo); |
|
85 } |
|
86 CleanupStack::PopAndDestroy(); // implementations |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CVPbkContactCopyPolicyManager::NewL |
|
91 // Two-phased constructor. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C CVPbkContactCopyPolicyManager* CVPbkContactCopyPolicyManager::NewL() |
|
95 { |
|
96 CVPbkContactCopyPolicyManager* self = |
|
97 new( ELeave ) CVPbkContactCopyPolicyManager; |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL(); |
|
100 CleanupStack::Pop( self ); |
|
101 return self; |
|
102 } |
|
103 |
|
104 |
|
105 // Destructor |
|
106 CVPbkContactCopyPolicyManager::~CVPbkContactCopyPolicyManager() |
|
107 { |
|
108 iImplementationInfoArray.ResetAndDestroy(); |
|
109 iPolicyArray.ResetAndDestroy(); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CVPbkContactCopyPolicyManager::GetPolicyL |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 EXPORT_C MVPbkContactCopyPolicy* CVPbkContactCopyPolicyManager::GetPolicyL( |
|
117 CVPbkContactManager& aContactManager, |
|
118 const TVPbkContactStoreUriPtr& aUri) |
|
119 { |
|
120 MVPbkContactCopyPolicy* policy = NULL; |
|
121 CImplementationInformation* info = FindInfoL(aUri); |
|
122 if (info) |
|
123 { |
|
124 TUid uid(info->ImplementationUid()); |
|
125 policy = FindPolicy(uid); |
|
126 if (!policy) |
|
127 { |
|
128 policy = LoadPolicyL(uid, aContactManager); |
|
129 } |
|
130 } |
|
131 return policy; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CVPbkContactCopyPolicyManager::FindInfoL |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 CImplementationInformation* CVPbkContactCopyPolicyManager::FindInfoL( |
|
139 const TVPbkContactStoreUriPtr& aUri) |
|
140 { |
|
141 CImplementationInformation* info = NULL; |
|
142 const TPtrC domain = aUri.Component( |
|
143 TVPbkContactStoreUriPtr::EContactStoreUriStoreType); |
|
144 const TInt count = iImplementationInfoArray.Count(); |
|
145 for (TInt i = 0; i < count && !info; ++i) |
|
146 { |
|
147 const TInt length = iImplementationInfoArray[i]->OpaqueData().Length(); |
|
148 HBufC* opaqueBuf = HBufC::NewLC(length); |
|
149 TPtr opaque = opaqueBuf->Des(); |
|
150 opaque.Copy(iImplementationInfoArray[i]->OpaqueData()); |
|
151 |
|
152 if (opaque.CompareF(domain) == 0) |
|
153 { |
|
154 info = iImplementationInfoArray[i]; |
|
155 } |
|
156 CleanupStack::PopAndDestroy(opaqueBuf); |
|
157 } |
|
158 return info; |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CVPbkContactCopyPolicyManager::FindPolicy |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 MVPbkContactCopyPolicy* CVPbkContactCopyPolicyManager::FindPolicy(TUid aUid) |
|
166 { |
|
167 const TInt count = iPolicyArray.Count(); |
|
168 for (TInt i = 0; i < count; ++i) |
|
169 { |
|
170 if (iPolicyArray[i]->ImplementationUid() == aUid) |
|
171 { |
|
172 return iPolicyArray[i]; |
|
173 } |
|
174 } |
|
175 return NULL; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CVPbkContactCopyPolicyManager::LoadPolicyL |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 MVPbkContactCopyPolicy* CVPbkContactCopyPolicyManager::LoadPolicyL(TUid aUid, |
|
183 CVPbkContactManager& aContactManager) |
|
184 { |
|
185 CVPbkContactCopyPolicy::TParam param(aContactManager); |
|
186 CVPbkContactCopyPolicy* policy = CVPbkContactCopyPolicy::NewL(aUid, param); |
|
187 CleanupStack::PushL(policy); |
|
188 iPolicyArray.AppendL(policy); |
|
189 CleanupStack::Pop(policy); |
|
190 return policy; |
|
191 } |
|
192 // End of File |