os/security/authorisation/userpromptservice/server/source/upsserver/viewevaluator.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * Implements CViewEvaluator.	 See class and function definitions for
    16 * more information.
    17 *
    18 */
    19 
    20 
    21 /**
    22  @file
    23 */
    24 #include "upsserver.h"
    25 #include "viewevaluator.h"
    26 #include <ups/upsdbw.h>
    27 #include <scs/ipcstream.h>
    28 #include <scs/nullstream.h>
    29 
    30 namespace UserPromptService
    31 {
    32 inline CUpsSession *CViewEvaluator::UpsSession()
    33 	{
    34 	return static_cast<CUpsSession*>(iSession);
    35 	}
    36 
    37 CViewEvaluator* CViewEvaluator::NewLC(CUpsSession* aSession, const RMessage2& aMessage)
    38 	{
    39 	CViewEvaluator* self = new(ELeave) CViewEvaluator(aSession, aMessage);
    40 	CleanupStack::PushL(self);
    41 	self->ConstructL(aMessage);
    42 	return self;
    43 	}
    44 
    45 CViewEvaluator::~CViewEvaluator()
    46 /**
    47 	Normally cleanup should be done when DoCleanup function is called by the framework.
    48 	Sometime later, possibly after our parent CUpsSession has been deleted, this
    49 	destructor will be run. In this case the framework will have cleared our iSession variable
    50 	and we must do NOTHING.
    51 
    52 	Unfortunately there is a special case where this object fails inside ConstructL, when we must do 
    53 	some cleanup. We can detect this be seeing iSession (and hence UpsServer()) is non-NULL.
    54 */
    55 	{
    56 	CUpsSession *session = UpsSession();
    57 	if(session)
    58 		{
    59 		/*lint -save -e1506 */ // ignore warning about calling virtual function in destructor
    60 		DoCleanup();
    61 		/*lint -restore */
    62 		}
    63 	}
    64 
    65 void CViewEvaluator::StartEvaluatingView()
    66 	/// Starts evaluating the database view
    67 	{
    68 	UpsSession()->iManagementView->EvaluateView(iStatus);
    69 	SetActive();
    70 	}
    71 
    72 CViewEvaluator::CViewEvaluator(CUpsSession* aSession, const RMessage2& aMessage)
    73 	:	CAsyncRequest(aSession, 0, aMessage)
    74 	{
    75 	}
    76 
    77 void CViewEvaluator::ConstructL(const RMessage2& aMessage)
    78 	{
    79 	// Read filter from the client
    80 	RIpcReadStream ipcstream;
    81 	ipcstream.Open(aMessage, 0);
    82 	CleanupClosePushL(ipcstream);
    83 	CDecisionFilter *filter = CDecisionFilter::NewLC();
    84 	ipcstream >> *filter;
    85 
    86 	// Set the session slave DB handle callback to us, so we know if the handle is about to be 
    87 	// deleted...
    88 	//RDebug::Printf("CViewEvaluator::ConstructL calling SetCallback(%x)\n", this);
    89 	UpsSession()->iDbViewHandle.SetCallback(this);
    90 
    91 	// Create the CDecisionView object
    92 	// nb. We do not need to check iManagementView is NULL here because CUpsSession would have failed the request with KErrServerBusy if it were not.
    93 	UpsSession()->iManagementView = UpsSession()->iDbViewHandle->CreateViewL(*filter);
    94 
    95 	CleanupStack::PopAndDestroy(filter);
    96 	CleanupStack::PopAndDestroy(&ipcstream);
    97 }
    98 
    99 
   100 void CViewEvaluator::DoCleanup()
   101 /// implement CAsyncRequest
   102 	{
   103 	Cancel();
   104 	// Reset slave DB handle callback to the session object
   105 	//RDebug::Printf("CViewEvaluator::DoCleanup - %x calling SetCallback(%x)\n", this, UpsSession());
   106 	UpsSession()->iDbViewHandle.SetCallback(UpsSession());
   107 	}
   108 
   109 void CViewEvaluator::DoCancel()
   110 	/// implement CActive - Cancel the database CreateView
   111 	{
   112 	CDecisionView *view = UpsSession()->iManagementView;
   113 	ASSERT(view != 0);
   114 	view->Cancel();
   115 
   116 	// Cancelled so cleanup view 
   117 	UpsSession()->CleanupView();
   118 	}
   119 
   120 	
   121 void CViewEvaluator::RunL()
   122 	/// implement CActive, override CAsyncRequset
   123 	{
   124 	User::LeaveIfError(iStatus.Int());
   125 	UpsSession()->PrefetchRecordAndWriteLengthToClientL(iMessagePtr2);
   126 	CompleteAndMarkForDeletion(KErrNone);
   127 	}
   128 
   129 TInt CViewEvaluator::RunError(TInt aError)
   130 	{
   131 	// Something bad happened so delete the view objects
   132 	UpsSession()->CleanupView();
   133 	return CAsyncRequest::RunError(aError);
   134 	}
   135 
   136 void CViewEvaluator::DbHandleAboutToBeDeleted()
   137 /**
   138 	Called just before the master database handle is shut.
   139 	Need to cancel and cleanup/delete our view and fail the client request.
   140 */
   141 	{
   142 	// Make sure our request is cancelled
   143 	// 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
   144 	// so the DoCancel will get called and cleanup the view.
   145 	// If RunL fails, RunError will cleanup the view, if it completes we will no longer be registered to be called.
   146 	Cancel();
   147 
   148 	// Abort the client view request.
   149 	CompleteAndMarkForDeletion(KErrAbort);
   150 	}
   151 }
   152 // End of file