25
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-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 "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: ESMR policymmanager implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "cesmrpolicymanager.h"
|
|
20 |
#include "cesmrpolicy.h"
|
|
21 |
#include "esmrdef.h"
|
|
22 |
#include "esmrinternaluid.h"
|
|
23 |
#include "cesmrcalimportexporter.h"
|
|
24 |
#include "tesmrentryfield.h"
|
|
25 |
#include "cmrpolicyresolver.h"
|
|
26 |
#include "esmrentryhelper.h"
|
|
27 |
#include "mesmrcalentry.h"
|
|
28 |
|
|
29 |
#include "emailtrace.h"
|
|
30 |
|
|
31 |
#include <esmrpolicies.rsg>
|
|
32 |
|
|
33 |
|
|
34 |
/// Unnamed namespace for local definitions
|
|
35 |
namespace {
|
|
36 |
|
|
37 |
#ifdef _DEBUG
|
|
38 |
|
|
39 |
_LIT( KESMRPolicyMgrPanic, "ESMRPolicyManager" );
|
|
40 |
|
|
41 |
enum TESMRPolicyManagerPanic
|
|
42 |
{
|
|
43 |
EESMRPolicyMgrNoPolicyFound = 1,
|
|
44 |
EESMRPolicyMgrPopWithoutPush
|
|
45 |
};
|
|
46 |
|
|
47 |
void Panic( TESMRPolicyManagerPanic aPanic )
|
|
48 |
{
|
|
49 |
User::Panic( KESMRPolicyMgrPanic, aPanic );
|
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Logs policy information.
|
|
54 |
*
|
|
55 |
* @param aPolicy Reference to policy.
|
|
56 |
*/
|
|
57 |
void LogPolicy(
|
|
58 |
const CESMRPolicy& aPolicy )
|
|
59 |
{
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
const RArray<TESMREntryField>& fieldArray = aPolicy.Fields();
|
|
66 |
TInt fieldCount( fieldArray.Count() );
|
|
67 |
|
|
68 |
|
|
69 |
for ( TInt i(0); i < fieldCount; ++i )
|
|
70 |
{
|
|
71 |
const TESMREntryField& field = fieldArray[i];
|
|
72 |
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
#define LOG_POLICY( x ) { LogPolicy( x ); }
|
|
77 |
|
|
78 |
#else
|
|
79 |
|
|
80 |
#define LOG_POLICY( x )
|
|
81 |
|
|
82 |
#endif // _DEBUG
|
|
83 |
|
|
84 |
} // namespace
|
|
85 |
|
|
86 |
// ======== MEMBER FUNCTIONS ========
|
|
87 |
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
// CESMRPolicyManager::CESMRPolicyManager
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
inline CESMRPolicyManager::CESMRPolicyManager()
|
|
93 |
{
|
|
94 |
FUNC_LOG;
|
|
95 |
//do nothing
|
|
96 |
}
|
|
97 |
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
// CESMRPolicyManager::~CESMRPolicyManager
|
|
100 |
// ---------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
EXPORT_C CESMRPolicyManager::~CESMRPolicyManager()
|
|
103 |
{
|
|
104 |
FUNC_LOG;
|
|
105 |
delete iResolverPlugin;
|
|
106 |
delete iCurrentPolicy;
|
|
107 |
iPolicyStack.ResetAndDestroy();
|
|
108 |
}
|
|
109 |
|
|
110 |
// ---------------------------------------------------------------------------
|
|
111 |
// CESMRPolicyManager::NewL
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
//
|
|
114 |
EXPORT_C CESMRPolicyManager* CESMRPolicyManager::NewL()
|
|
115 |
{
|
|
116 |
FUNC_LOG;
|
|
117 |
|
|
118 |
CESMRPolicyManager* self = new (ELeave) CESMRPolicyManager;
|
|
119 |
CleanupStack::PushL( self );
|
|
120 |
self->ConstructL();
|
|
121 |
CleanupStack::Pop(self);
|
|
122 |
|
|
123 |
return self;
|
|
124 |
}
|
|
125 |
|
|
126 |
// ---------------------------------------------------------------------------
|
|
127 |
// CESMRPolicyManager::ConstructL
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
//
|
|
130 |
void CESMRPolicyManager::ConstructL()
|
|
131 |
{
|
|
132 |
FUNC_LOG;
|
|
133 |
|
|
134 |
}
|
|
135 |
|
|
136 |
// -----------------------------------------------------------------------------
|
|
137 |
// CESMRPolicyManager::CurrentPolicy
|
|
138 |
// -----------------------------------------------------------------------------
|
|
139 |
//
|
|
140 |
EXPORT_C CESMRPolicy& CESMRPolicyManager::CurrentPolicy()
|
|
141 |
{
|
|
142 |
CESMRPolicy* currentPolicy = iCurrentPolicy;
|
|
143 |
if ( !currentPolicy && iPolicyStack.Count() )
|
|
144 |
{
|
|
145 |
currentPolicy = iPolicyStack[ iPolicyStack.Count() - 1 ];
|
|
146 |
}
|
|
147 |
|
|
148 |
ASSERT( currentPolicy );
|
|
149 |
return *currentPolicy;
|
|
150 |
}
|
|
151 |
|
|
152 |
// ---------------------------------------------------------------------------
|
|
153 |
// CESMRPolicyManager::ResolvePolicyL
|
|
154 |
// ---------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
EXPORT_C void CESMRPolicyManager::ResolvePolicyL(
|
|
157 |
const TESMRScenarioData& aScenarioData,
|
|
158 |
MESMRCalEntry& aESMREntry,
|
|
159 |
MMRPolicyResolver* aPolicyResolver )
|
|
160 |
{
|
|
161 |
FUNC_LOG;
|
|
162 |
|
|
163 |
MMRPolicyResolver* policyResolver = NULL;
|
|
164 |
|
|
165 |
if ( aPolicyResolver )
|
|
166 |
{
|
|
167 |
policyResolver = aPolicyResolver;
|
|
168 |
}
|
|
169 |
else
|
|
170 |
{
|
|
171 |
TESMRCalendarEventType type =
|
|
172 |
ESMREntryHelper::EventTypeL( aESMREntry.Entry() );
|
|
173 |
|
|
174 |
if ( !iResolverPlugin || !iResolverPlugin->SupportsTypeL( type ) )
|
|
175 |
{
|
|
176 |
// Instantiate correct resolver
|
|
177 |
policyResolver = CMRPolicyResolver::NewL( type );
|
|
178 |
delete iResolverPlugin;
|
|
179 |
iResolverPlugin = policyResolver;
|
|
180 |
}
|
|
181 |
else
|
|
182 |
{
|
|
183 |
// Use default resolver
|
|
184 |
policyResolver = iResolverPlugin;
|
|
185 |
}
|
|
186 |
}
|
|
187 |
|
|
188 |
delete iCurrentPolicy;
|
|
189 |
iCurrentPolicy = NULL;
|
|
190 |
|
|
191 |
iCurrentPolicy = policyResolver->ResolveL( aScenarioData );
|
|
192 |
|
|
193 |
// Matching policy not found --> Panic
|
|
194 |
__ASSERT_DEBUG( iCurrentPolicy, Panic(EESMRPolicyMgrNoPolicyFound) );
|
|
195 |
|
|
196 |
if ( !iCurrentPolicy )
|
|
197 |
{
|
|
198 |
User::Leave( KErrNotFound );
|
|
199 |
}
|
|
200 |
|
|
201 |
// Logging policy for debugging purposes
|
|
202 |
LOG_POLICY( *iCurrentPolicy )
|
|
203 |
}
|
|
204 |
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
// CESMRPolicyManager::PushPolicyL
|
|
207 |
// ---------------------------------------------------------------------------
|
|
208 |
//
|
|
209 |
EXPORT_C void CESMRPolicyManager::PushPolicyL()
|
|
210 |
{
|
|
211 |
if ( iCurrentPolicy )
|
|
212 |
{
|
|
213 |
iPolicyStack.AppendL( iCurrentPolicy );
|
|
214 |
iCurrentPolicy = NULL;
|
|
215 |
}
|
|
216 |
}
|
|
217 |
|
|
218 |
// ---------------------------------------------------------------------------
|
|
219 |
// CESMRPolicyManager::PopPolicy
|
|
220 |
// ---------------------------------------------------------------------------
|
|
221 |
//
|
|
222 |
EXPORT_C CESMRPolicy* CESMRPolicyManager::PopPolicy()
|
|
223 |
{
|
|
224 |
delete iCurrentPolicy;
|
|
225 |
iCurrentPolicy = NULL;
|
|
226 |
|
|
227 |
TInt stackCount = iPolicyStack.Count();
|
|
228 |
if ( stackCount )
|
|
229 |
{
|
|
230 |
iCurrentPolicy = iPolicyStack[ --stackCount ];
|
|
231 |
iPolicyStack.Remove( stackCount );
|
|
232 |
}
|
|
233 |
|
|
234 |
__ASSERT_DEBUG( iCurrentPolicy, Panic( EESMRPolicyMgrPopWithoutPush ) );
|
|
235 |
|
|
236 |
return iCurrentPolicy;
|
|
237 |
}
|
|
238 |
|
|
239 |
// ---------------------------------------------------------------------------
|
|
240 |
// CESMRPolicyManager::CurrentPolicy
|
|
241 |
// ---------------------------------------------------------------------------
|
|
242 |
//
|
|
243 |
const CESMRPolicy& CESMRPolicyManager::CurrentPolicy() const
|
|
244 |
{
|
|
245 |
CESMRPolicy& policy =
|
|
246 |
const_cast< CESMRPolicyManager* >( this )->CurrentPolicy();
|
|
247 |
|
|
248 |
return policy;
|
|
249 |
}
|
|
250 |
|
|
251 |
// EOF
|
|
252 |
|