sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "upslog.h" sl@0: sl@0: using namespace UserPromptService; sl@0: sl@0: /** sl@0: Default implementation of a policy evaluator. sl@0: This is returned if no policy evaluator is defined in the policy file OR sl@0: the policy evaluator implementation UID is zero. sl@0: */ sl@0: NONSHARABLE_CLASS(CDefaultPolicyEvaluator) : public CPolicyEvaluator sl@0: { sl@0: public: sl@0: static CDefaultPolicyEvaluator* NewL(); sl@0: sl@0: void GenerateFingerprints( sl@0: const CPromptRequest& aRequest, const CPolicy& aPolicy, sl@0: RPointerArray& aFingerprints, const CClientEntity*& aClientEntity, sl@0: const TAny*& aDialogCreatorParams, sl@0: TRequestStatus& aStatus); sl@0: sl@0: // Empty implementations of CActive pure virtual functions sl@0: // RunL is never called because the request is completed immediately. sl@0: void RunL() {}; sl@0: void DoCancel() {}; sl@0: sl@0: ~CDefaultPolicyEvaluator(); sl@0: sl@0: private: sl@0: CDefaultPolicyEvaluator(); sl@0: }; sl@0: sl@0: EXPORT_C CPolicyEvaluator::CPolicyEvaluator() sl@0: /** sl@0: Constructor sl@0: */ sl@0: : CActive(EPriorityStandard) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CPolicyEvaluator::~CPolicyEvaluator() sl@0: /** sl@0: Destructor sl@0: */ sl@0: { sl@0: REComSession::DestroyedImplementation(iDtor_ID_Key); sl@0: } sl@0: sl@0: EXPORT_C CPolicyEvaluator* CPolicyEvaluator::NewL(const TUid& aPolicyEvaluatorImplementationId) sl@0: /** sl@0: Creates a new policy evaluator. sl@0: @param aPolicyEvaluatorImplementationId The UID of the policy evaluator implemenation sl@0: as specified in the policy file. sl@0: sl@0: @return A pointer to the new dialog creator implementation. sl@0: */ sl@0: { sl@0: if (aPolicyEvaluatorImplementationId.iUid == 0) sl@0: { sl@0: DEBUG_PRINTF(_L8("Instantiating default policy evaluator")); sl@0: return CDefaultPolicyEvaluator::NewL(); sl@0: } sl@0: sl@0: TAny* plugin(0); sl@0: DEBUG_PRINTF2(_L8("Instantiating policy evaluator 0x%08x"), aPolicyEvaluatorImplementationId); sl@0: TRAPD(err, plugin = sl@0: REComSession::CreateImplementationL(aPolicyEvaluatorImplementationId, sl@0: _FOFF(CPolicyEvaluator,iDtor_ID_Key))); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: DEBUG_PRINTF3(_L8("Failed to instantiate policy evaluator 0x%08x, err = %d"), sl@0: aPolicyEvaluatorImplementationId.iUid, err); sl@0: } sl@0: sl@0: if (err == KErrNotFound) sl@0: { sl@0: err = KErrUpsMissingPolicyEvaluator; sl@0: } sl@0: User::LeaveIfError(err); sl@0: return reinterpret_cast(plugin); sl@0: } sl@0: sl@0: /** sl@0: If a decision record matching one of the fingerprints created by \ref CPolicyEvaluator::GenerateFingerprints sl@0: was found then this method will be invoked. This allows the policy evaluator sl@0: to instruct the user prompt service to ignore the result of the decision record and prompt sl@0: the user.\p sl@0: This functionality could be used to trigger periodic prompts if an application sl@0: makes very high usage of a service e.g. after 100 SMS messages have been sent. sl@0: The usage could be tracked externally or via the evaluatorInfo field in the decision record.\n sl@0: N.B. The User Prompt Service does not mandate the contents or usage of the evaluatorInfo field. sl@0: sl@0: - The default implementation CPolicyEvaluator::ForcePromptL always returns EFalse and does sl@0: not modifiy aNewEvaluatorInfo. sl@0: sl@0: @param aDecision The first decision record that matched a fingerprint generated by sl@0: \ref CPolicyEvaluator::GenerateFingerprints sl@0: @param aNewEvaluatorInfo A reference to a copy of the evaluatorInfo field from the decision record. sl@0: If this method modifies this value then this field will be updated in the sl@0: decision record regardless of whether a prompt is required. sl@0: @return ETrue if a prompt should be displayed; otherwise, sl@0: EFalse if the result of the decision record should be used. sl@0: */ sl@0: EXPORT_C TBool CPolicyEvaluator::ForcePromptL(const CDecisionRecord& aDecision, TUint& aNewEvaluatorInfo) sl@0: { sl@0: (void) aDecision; sl@0: (void) aNewEvaluatorInfo; sl@0: return EFalse; sl@0: } sl@0: sl@0: EXPORT_C TInt CPolicyEvaluator::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1) sl@0: /** sl@0: Allows extension of this interface. Calls Extension_ sl@0: sl@0: @param aExtensionId The UID of the interface to instantiate. sl@0: @param a0 A reference to a pointer that should be set to the newly sl@0: instantiated object. sl@0: @param a1 Data specific to the instantiate of the specified interface. sl@0: sl@0: @return KErrNone if the extension is supported or KErrNotSupported if the extension is not sl@0: recognised; otherwise, a system wide error may be returned. sl@0: */ sl@0: { sl@0: return Extension_(aExtensionId, a0, a1); sl@0: } sl@0: sl@0: EXPORT_C TInt CPolicyEvaluator::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1) sl@0: { sl@0: return CActive::Extension_(aExtensionId, a0, a1); sl@0: } sl@0: sl@0: CDefaultPolicyEvaluator* CDefaultPolicyEvaluator::NewL() sl@0: /** sl@0: Factory method that creates a new default policy evaluator object. sl@0: @return A pointer to the new default policy evaluator object. sl@0: */ sl@0: { sl@0: CDefaultPolicyEvaluator* self = new(ELeave) CDefaultPolicyEvaluator(); sl@0: return self; sl@0: } sl@0: sl@0: CDefaultPolicyEvaluator::CDefaultPolicyEvaluator() sl@0: /** sl@0: Constructor sl@0: */ sl@0: : CPolicyEvaluator() sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: CDefaultPolicyEvaluator::~CDefaultPolicyEvaluator() sl@0: /** sl@0: Destructor sl@0: */ sl@0: { sl@0: Deque(); sl@0: } sl@0: sl@0: void CDefaultPolicyEvaluator::GenerateFingerprints( sl@0: const CPromptRequest& /* aRequest */, const CPolicy& /* aPolicy */, sl@0: RPointerArray& aFingerprints, const CClientEntity*& /* aClientEntity */, sl@0: const TAny*& /* aDialogCreatorParams */, sl@0: TRequestStatus& aStatus) sl@0: /** sl@0: Returns a single, null fingerprint and completes immediately. sl@0: */ sl@0: { sl@0: CFingerprint* f(0); sl@0: TRAPD(retVal, f = CFingerprint::NewLC(KNullDesC8, KNullDesC); sl@0: aFingerprints.AppendL(f); sl@0: CleanupStack::Pop(f)); sl@0: sl@0: TRequestStatus *status = &aStatus; sl@0: *status = KRequestPending; sl@0: User::RequestComplete(status, retVal); sl@0: }