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: * Implements used to process RUpsManagement::UpdateDecisionL. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "upsserver.h" sl@0: #include sl@0: #include "updateevaluator.h" sl@0: sl@0: namespace UserPromptService sl@0: { sl@0: inline CUpsSession *CUpdateEvaluator::UpsSession() sl@0: { sl@0: return static_cast(iSession); sl@0: } sl@0: sl@0: inline CUpsServer *CUpdateEvaluator::UpsServer() sl@0: { sl@0: return static_cast( sl@0: &static_cast(iSession)->iServer); sl@0: } sl@0: sl@0: CUpdateEvaluator* CUpdateEvaluator::NewLC(CUpsSession* aSession, const RMessage2& aMessage) sl@0: { sl@0: CUpdateEvaluator* self = new(ELeave) CUpdateEvaluator(aSession, aMessage); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aMessage); sl@0: return self; sl@0: } sl@0: sl@0: CUpdateEvaluator::~CUpdateEvaluator() sl@0: /** sl@0: Normally cleanup should be done when DoCleanup function is called by the framework. sl@0: Sometime later, possibly after our parent CUpsSession has been deleted, this sl@0: destructor will be run. In this case the framework will have cleared our iSession variable sl@0: and we must do NOTHING. sl@0: sl@0: Unfortunately there is a special case where this object fails inside ConstructL, when we must do sl@0: some cleanup. We can detect this be seeing iSession (and hence UpsServer()) is non-NULL. sl@0: */ sl@0: { sl@0: CUpsSession *session = UpsSession(); sl@0: if(session) sl@0: { sl@0: /*lint -save -e1506*/ // ignore warning about calling a virtual function in a destructor sl@0: DoCleanup(); sl@0: /*lint -restore*/ sl@0: } sl@0: } sl@0: sl@0: void CUpdateEvaluator::StartUpdate() sl@0: /// Starts evaluating the database view sl@0: { sl@0: iUpdateView->EvaluateView(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: CUpdateEvaluator::CUpdateEvaluator(CUpsSession* aSession, const RMessage2& aMessage) sl@0: : CAsyncRequest(aSession, 0, aMessage), sl@0: iUpdateDbHandle(UpsServer()->iDbHandle, this) sl@0: { sl@0: } sl@0: sl@0: void CUpdateEvaluator::ConstructL(const RMessage2& aMessage) sl@0: { sl@0: // Read record id and new yes/no decision from client sl@0: TUint32 recordId = aMessage.Int0(); sl@0: iNewResult = (aMessage.Int1() != 0); sl@0: sl@0: CDecisionFilter *filter= CDecisionFilter::NewLC(); sl@0: filter->SetRecordId(recordId, EEqual); sl@0: sl@0: // Create the CDecisionView object sl@0: iUpdateView = iUpdateDbHandle->CreateViewL(*filter); sl@0: sl@0: CleanupStack::PopAndDestroy(filter); sl@0: } sl@0: sl@0: sl@0: void CUpdateEvaluator::DoCleanup() sl@0: /// implement CAsyncRequest sl@0: { sl@0: Cancel(); sl@0: sl@0: delete iUpdateView; sl@0: iUpdateView = 0; sl@0: sl@0: iUpdateDbHandle.Close(); sl@0: } sl@0: sl@0: void CUpdateEvaluator::DoCancel() sl@0: /// implement CActive - Cancel the database CreateView sl@0: { sl@0: ASSERT(iUpdateView != 0); sl@0: iUpdateView->Cancel(); sl@0: } sl@0: sl@0: sl@0: void CUpdateEvaluator::RunL() sl@0: /// implement CActive, override CAsyncRequset sl@0: { sl@0: User::LeaveIfError(iStatus.Int()); sl@0: sl@0: // We have created the view, which should have matched a single record..... sl@0: CDecisionRecord *record = iUpdateView->NextDecisionL(); sl@0: CleanupStack::PushL(record); sl@0: if(record == 0) sl@0: { sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: sl@0: // Update the result sl@0: record->iResult = iNewResult; sl@0: sl@0: // Prepare a filter with our complete key in it. sl@0: CDecisionFilter *filter = CDecisionFilter::NewLC(record->iClientSid, sl@0: record->iEvaluatorId, sl@0: record->iServiceId, sl@0: record->iServerSid, sl@0: record->iFingerprint, sl@0: record->iClientEntity, sl@0: record->iMajorPolicyVersion); sl@0: sl@0: sl@0: // Update the record sl@0: iUpdateDbHandle->UpdateDecisionL(*filter, *record); sl@0: sl@0: // Cleanup sl@0: CleanupStack::PopAndDestroy(filter); sl@0: CleanupStack::PopAndDestroy(record); sl@0: sl@0: CompleteAndMarkForDeletion(KErrNone); sl@0: } sl@0: sl@0: TInt CUpdateEvaluator::RunError(TInt aError) sl@0: { sl@0: iUpdateDbHandle.CloseMaster(); sl@0: return CAsyncRequest::RunError(aError); sl@0: } sl@0: sl@0: void CUpdateEvaluator::DbHandleAboutToBeDeleted() sl@0: /** sl@0: Called just before the master database handle is shut. sl@0: Need to cancel and cleanup/delete our view and fail the client request. sl@0: */ sl@0: { sl@0: // Make sure our request is cancelled sl@0: Cancel(); sl@0: sl@0: // Cleanup/delete our view object sl@0: DoCleanup(); sl@0: sl@0: // Abort the client view request. sl@0: CompleteAndMarkForDeletion(KErrAbort); sl@0: } sl@0: sl@0: } // End of namespace UserPromptServer sl@0: // End of file