os/security/authorisation/userpromptservice/server/source/upsserver/viewevaluator.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/server/source/upsserver/viewevaluator.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,152 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Implements CViewEvaluator.	 See class and function definitions for
    1.19 +* more information.
    1.20 +*
    1.21 +*/
    1.22 +
    1.23 +
    1.24 +/**
    1.25 + @file
    1.26 +*/
    1.27 +#include "upsserver.h"
    1.28 +#include "viewevaluator.h"
    1.29 +#include <ups/upsdbw.h>
    1.30 +#include <scs/ipcstream.h>
    1.31 +#include <scs/nullstream.h>
    1.32 +
    1.33 +namespace UserPromptService
    1.34 +{
    1.35 +inline CUpsSession *CViewEvaluator::UpsSession()
    1.36 +	{
    1.37 +	return static_cast<CUpsSession*>(iSession);
    1.38 +	}
    1.39 +
    1.40 +CViewEvaluator* CViewEvaluator::NewLC(CUpsSession* aSession, const RMessage2& aMessage)
    1.41 +	{
    1.42 +	CViewEvaluator* self = new(ELeave) CViewEvaluator(aSession, aMessage);
    1.43 +	CleanupStack::PushL(self);
    1.44 +	self->ConstructL(aMessage);
    1.45 +	return self;
    1.46 +	}
    1.47 +
    1.48 +CViewEvaluator::~CViewEvaluator()
    1.49 +/**
    1.50 +	Normally cleanup should be done when DoCleanup function is called by the framework.
    1.51 +	Sometime later, possibly after our parent CUpsSession has been deleted, this
    1.52 +	destructor will be run. In this case the framework will have cleared our iSession variable
    1.53 +	and we must do NOTHING.
    1.54 +
    1.55 +	Unfortunately there is a special case where this object fails inside ConstructL, when we must do 
    1.56 +	some cleanup. We can detect this be seeing iSession (and hence UpsServer()) is non-NULL.
    1.57 +*/
    1.58 +	{
    1.59 +	CUpsSession *session = UpsSession();
    1.60 +	if(session)
    1.61 +		{
    1.62 +		/*lint -save -e1506 */ // ignore warning about calling virtual function in destructor
    1.63 +		DoCleanup();
    1.64 +		/*lint -restore */
    1.65 +		}
    1.66 +	}
    1.67 +
    1.68 +void CViewEvaluator::StartEvaluatingView()
    1.69 +	/// Starts evaluating the database view
    1.70 +	{
    1.71 +	UpsSession()->iManagementView->EvaluateView(iStatus);
    1.72 +	SetActive();
    1.73 +	}
    1.74 +
    1.75 +CViewEvaluator::CViewEvaluator(CUpsSession* aSession, const RMessage2& aMessage)
    1.76 +	:	CAsyncRequest(aSession, 0, aMessage)
    1.77 +	{
    1.78 +	}
    1.79 +
    1.80 +void CViewEvaluator::ConstructL(const RMessage2& aMessage)
    1.81 +	{
    1.82 +	// Read filter from the client
    1.83 +	RIpcReadStream ipcstream;
    1.84 +	ipcstream.Open(aMessage, 0);
    1.85 +	CleanupClosePushL(ipcstream);
    1.86 +	CDecisionFilter *filter = CDecisionFilter::NewLC();
    1.87 +	ipcstream >> *filter;
    1.88 +
    1.89 +	// Set the session slave DB handle callback to us, so we know if the handle is about to be 
    1.90 +	// deleted...
    1.91 +	//RDebug::Printf("CViewEvaluator::ConstructL calling SetCallback(%x)\n", this);
    1.92 +	UpsSession()->iDbViewHandle.SetCallback(this);
    1.93 +
    1.94 +	// Create the CDecisionView object
    1.95 +	// nb. We do not need to check iManagementView is NULL here because CUpsSession would have failed the request with KErrServerBusy if it were not.
    1.96 +	UpsSession()->iManagementView = UpsSession()->iDbViewHandle->CreateViewL(*filter);
    1.97 +
    1.98 +	CleanupStack::PopAndDestroy(filter);
    1.99 +	CleanupStack::PopAndDestroy(&ipcstream);
   1.100 +}
   1.101 +
   1.102 +
   1.103 +void CViewEvaluator::DoCleanup()
   1.104 +/// implement CAsyncRequest
   1.105 +	{
   1.106 +	Cancel();
   1.107 +	// Reset slave DB handle callback to the session object
   1.108 +	//RDebug::Printf("CViewEvaluator::DoCleanup - %x calling SetCallback(%x)\n", this, UpsSession());
   1.109 +	UpsSession()->iDbViewHandle.SetCallback(UpsSession());
   1.110 +	}
   1.111 +
   1.112 +void CViewEvaluator::DoCancel()
   1.113 +	/// implement CActive - Cancel the database CreateView
   1.114 +	{
   1.115 +	CDecisionView *view = UpsSession()->iManagementView;
   1.116 +	ASSERT(view != 0);
   1.117 +	view->Cancel();
   1.118 +
   1.119 +	// Cancelled so cleanup view 
   1.120 +	UpsSession()->CleanupView();
   1.121 +	}
   1.122 +
   1.123 +	
   1.124 +void CViewEvaluator::RunL()
   1.125 +	/// implement CActive, override CAsyncRequset
   1.126 +	{
   1.127 +	User::LeaveIfError(iStatus.Int());
   1.128 +	UpsSession()->PrefetchRecordAndWriteLengthToClientL(iMessagePtr2);
   1.129 +	CompleteAndMarkForDeletion(KErrNone);
   1.130 +	}
   1.131 +
   1.132 +TInt CViewEvaluator::RunError(TInt aError)
   1.133 +	{
   1.134 +	// Something bad happened so delete the view objects
   1.135 +	UpsSession()->CleanupView();
   1.136 +	return CAsyncRequest::RunError(aError);
   1.137 +	}
   1.138 +
   1.139 +void CViewEvaluator::DbHandleAboutToBeDeleted()
   1.140 +/**
   1.141 +	Called just before the master database handle is shut.
   1.142 +	Need to cancel and cleanup/delete our view and fail the client request.
   1.143 +*/
   1.144 +	{
   1.145 +	// Make sure our request is cancelled
   1.146 +	// If the view create is in progress, or has completed but our RunL hasn't had a chance to run yet, we will still be active
   1.147 +	// so the DoCancel will get called and cleanup the view.
   1.148 +	// If RunL fails, RunError will cleanup the view, if it completes we will no longer be registered to be called.
   1.149 +	Cancel();
   1.150 +
   1.151 +	// Abort the client view request.
   1.152 +	CompleteAndMarkForDeletion(KErrAbort);
   1.153 +	}
   1.154 +}
   1.155 +// End of file