os/security/authorisation/userpromptservice/server/source/upsserver/viewevaluator.cpp
Update contrib.
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.
15 * Implements CViewEvaluator. See class and function definitions for
24 #include "upsserver.h"
25 #include "viewevaluator.h"
26 #include <ups/upsdbw.h>
27 #include <scs/ipcstream.h>
28 #include <scs/nullstream.h>
30 namespace UserPromptService
32 inline CUpsSession *CViewEvaluator::UpsSession()
34 return static_cast<CUpsSession*>(iSession);
37 CViewEvaluator* CViewEvaluator::NewLC(CUpsSession* aSession, const RMessage2& aMessage)
39 CViewEvaluator* self = new(ELeave) CViewEvaluator(aSession, aMessage);
40 CleanupStack::PushL(self);
41 self->ConstructL(aMessage);
45 CViewEvaluator::~CViewEvaluator()
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.
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.
56 CUpsSession *session = UpsSession();
59 /*lint -save -e1506 */ // ignore warning about calling virtual function in destructor
65 void CViewEvaluator::StartEvaluatingView()
66 /// Starts evaluating the database view
68 UpsSession()->iManagementView->EvaluateView(iStatus);
72 CViewEvaluator::CViewEvaluator(CUpsSession* aSession, const RMessage2& aMessage)
73 : CAsyncRequest(aSession, 0, aMessage)
77 void CViewEvaluator::ConstructL(const RMessage2& aMessage)
79 // Read filter from the client
80 RIpcReadStream ipcstream;
81 ipcstream.Open(aMessage, 0);
82 CleanupClosePushL(ipcstream);
83 CDecisionFilter *filter = CDecisionFilter::NewLC();
86 // Set the session slave DB handle callback to us, so we know if the handle is about to be
88 //RDebug::Printf("CViewEvaluator::ConstructL calling SetCallback(%x)\n", this);
89 UpsSession()->iDbViewHandle.SetCallback(this);
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);
95 CleanupStack::PopAndDestroy(filter);
96 CleanupStack::PopAndDestroy(&ipcstream);
100 void CViewEvaluator::DoCleanup()
101 /// implement CAsyncRequest
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());
109 void CViewEvaluator::DoCancel()
110 /// implement CActive - Cancel the database CreateView
112 CDecisionView *view = UpsSession()->iManagementView;
116 // Cancelled so cleanup view
117 UpsSession()->CleanupView();
121 void CViewEvaluator::RunL()
122 /// implement CActive, override CAsyncRequset
124 User::LeaveIfError(iStatus.Int());
125 UpsSession()->PrefetchRecordAndWriteLengthToClientL(iMessagePtr2);
126 CompleteAndMarkForDeletion(KErrNone);
129 TInt CViewEvaluator::RunError(TInt aError)
131 // Something bad happened so delete the view objects
132 UpsSession()->CleanupView();
133 return CAsyncRequest::RunError(aError);
136 void CViewEvaluator::DbHandleAboutToBeDeleted()
138 Called just before the master database handle is shut.
139 Need to cancel and cleanup/delete our view and fail the client request.
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.
148 // Abort the client view request.
149 CompleteAndMarkForDeletion(KErrAbort);