First public contribution.
2 * Copyright (c) 2007-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 <ups/policyevaluator.h>
20 #include <ups/upserr.h>
21 #include <ecom/ecom.h>
24 using namespace UserPromptService;
27 Default implementation of a policy evaluator.
28 This is returned if no policy evaluator is defined in the policy file OR
29 the policy evaluator implementation UID is zero.
31 NONSHARABLE_CLASS(CDefaultPolicyEvaluator) : public CPolicyEvaluator
34 static CDefaultPolicyEvaluator* NewL();
36 void GenerateFingerprints(
37 const CPromptRequest& aRequest, const CPolicy& aPolicy,
38 RPointerArray<CFingerprint>& aFingerprints, const CClientEntity*& aClientEntity,
39 const TAny*& aDialogCreatorParams,
40 TRequestStatus& aStatus);
42 // Empty implementations of CActive pure virtual functions
43 // RunL is never called because the request is completed immediately.
47 ~CDefaultPolicyEvaluator();
50 CDefaultPolicyEvaluator();
53 EXPORT_C CPolicyEvaluator::CPolicyEvaluator()
57 : CActive(EPriorityStandard)
61 EXPORT_C CPolicyEvaluator::~CPolicyEvaluator()
66 REComSession::DestroyedImplementation(iDtor_ID_Key);
69 EXPORT_C CPolicyEvaluator* CPolicyEvaluator::NewL(const TUid& aPolicyEvaluatorImplementationId)
71 Creates a new policy evaluator.
72 @param aPolicyEvaluatorImplementationId The UID of the policy evaluator implemenation
73 as specified in the policy file.
75 @return A pointer to the new dialog creator implementation.
78 if (aPolicyEvaluatorImplementationId.iUid == 0)
80 DEBUG_PRINTF(_L8("Instantiating default policy evaluator"));
81 return CDefaultPolicyEvaluator::NewL();
85 DEBUG_PRINTF2(_L8("Instantiating policy evaluator 0x%08x"), aPolicyEvaluatorImplementationId);
87 REComSession::CreateImplementationL(aPolicyEvaluatorImplementationId,
88 _FOFF(CPolicyEvaluator,iDtor_ID_Key)));
92 DEBUG_PRINTF3(_L8("Failed to instantiate policy evaluator 0x%08x, err = %d"),
93 aPolicyEvaluatorImplementationId.iUid, err);
96 if (err == KErrNotFound)
98 err = KErrUpsMissingPolicyEvaluator;
100 User::LeaveIfError(err);
101 return reinterpret_cast<CPolicyEvaluator*>(plugin);
105 If a decision record matching one of the fingerprints created by \ref CPolicyEvaluator::GenerateFingerprints
106 was found then this method will be invoked. This allows the policy evaluator
107 to instruct the user prompt service to ignore the result of the decision record and prompt
109 This functionality could be used to trigger periodic prompts if an application
110 makes very high usage of a service e.g. after 100 SMS messages have been sent.
111 The usage could be tracked externally or via the evaluatorInfo field in the decision record.\n
112 N.B. The User Prompt Service does not mandate the contents or usage of the evaluatorInfo field.
114 - The default implementation CPolicyEvaluator::ForcePromptL always returns EFalse and does
115 not modifiy aNewEvaluatorInfo.
117 @param aDecision The first decision record that matched a fingerprint generated by
118 \ref CPolicyEvaluator::GenerateFingerprints
119 @param aNewEvaluatorInfo A reference to a copy of the evaluatorInfo field from the decision record.
120 If this method modifies this value then this field will be updated in the
121 decision record regardless of whether a prompt is required.
122 @return ETrue if a prompt should be displayed; otherwise,
123 EFalse if the result of the decision record should be used.
125 EXPORT_C TBool CPolicyEvaluator::ForcePromptL(const CDecisionRecord& aDecision, TUint& aNewEvaluatorInfo)
128 (void) aNewEvaluatorInfo;
132 EXPORT_C TInt CPolicyEvaluator::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1)
134 Allows extension of this interface. Calls Extension_
136 @param aExtensionId The UID of the interface to instantiate.
137 @param a0 A reference to a pointer that should be set to the newly
139 @param a1 Data specific to the instantiate of the specified interface.
141 @return KErrNone if the extension is supported or KErrNotSupported if the extension is not
142 recognised; otherwise, a system wide error may be returned.
145 return Extension_(aExtensionId, a0, a1);
148 EXPORT_C TInt CPolicyEvaluator::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
150 return CActive::Extension_(aExtensionId, a0, a1);
153 CDefaultPolicyEvaluator* CDefaultPolicyEvaluator::NewL()
155 Factory method that creates a new default policy evaluator object.
156 @return A pointer to the new default policy evaluator object.
159 CDefaultPolicyEvaluator* self = new(ELeave) CDefaultPolicyEvaluator();
163 CDefaultPolicyEvaluator::CDefaultPolicyEvaluator()
169 CActiveScheduler::Add(this);
172 CDefaultPolicyEvaluator::~CDefaultPolicyEvaluator()
180 void CDefaultPolicyEvaluator::GenerateFingerprints(
181 const CPromptRequest& /* aRequest */, const CPolicy& /* aPolicy */,
182 RPointerArray<CFingerprint>& aFingerprints, const CClientEntity*& /* aClientEntity */,
183 const TAny*& /* aDialogCreatorParams */,
184 TRequestStatus& aStatus)
186 Returns a single, null fingerprint and completes immediately.
190 TRAPD(retVal, f = CFingerprint::NewLC(KNullDesC8, KNullDesC);
191 aFingerprints.AppendL(f);
192 CleanupStack::Pop(f));
194 TRequestStatus *status = &aStatus;
195 *status = KRequestPending;
196 User::RequestComplete(status, retVal);