os/security/authorisation/userpromptservice/server/source/upsserver/updateevaluator.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 used to process RUpsManagement::UpdateDecisionL.
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22 */
    23 
    24 #include "upsserver.h"
    25 #include <ups/upsdbw.h>
    26 #include "updateevaluator.h"
    27 
    28 namespace UserPromptService
    29 {
    30 inline CUpsSession *CUpdateEvaluator::UpsSession()
    31 	{
    32 	return static_cast<CUpsSession*>(iSession);
    33 	}
    34 
    35 inline CUpsServer *CUpdateEvaluator::UpsServer()
    36 	{
    37 	return static_cast<CUpsServer *>(
    38 		&static_cast<CUpsSession*>(iSession)->iServer);
    39 	}
    40 
    41 CUpdateEvaluator* CUpdateEvaluator::NewLC(CUpsSession* aSession, const RMessage2& aMessage)
    42 	{
    43 	CUpdateEvaluator* self = new(ELeave) CUpdateEvaluator(aSession, aMessage);
    44 	CleanupStack::PushL(self);
    45 	self->ConstructL(aMessage);
    46 	return self;
    47 	}
    48 
    49 CUpdateEvaluator::~CUpdateEvaluator()
    50 /**
    51 	Normally cleanup should be done when DoCleanup function is called by the framework.
    52 	Sometime later, possibly after our parent CUpsSession has been deleted, this
    53 	destructor will be run. In this case the framework will have cleared our iSession variable
    54 	and we must do NOTHING.
    55 
    56 	Unfortunately there is a special case where this object fails inside ConstructL, when we must do 
    57 	some cleanup. We can detect this be seeing iSession (and hence UpsServer()) is non-NULL.
    58 */
    59 	{
    60 	CUpsSession *session = UpsSession();
    61 	if(session)
    62 		{
    63 		/*lint -save -e1506*/ // ignore warning about calling a virtual function in a destructor
    64 		DoCleanup();
    65 		/*lint -restore*/
    66 		}
    67 	}
    68 
    69 void CUpdateEvaluator::StartUpdate()
    70 	/// Starts evaluating the database view
    71 	{
    72 	iUpdateView->EvaluateView(iStatus);
    73 	SetActive();
    74 	}
    75 
    76 CUpdateEvaluator::CUpdateEvaluator(CUpsSession* aSession, const RMessage2& aMessage)
    77 	:	CAsyncRequest(aSession, 0, aMessage),
    78 		iUpdateDbHandle(UpsServer()->iDbHandle, this)
    79 	{
    80 	}
    81 
    82 void CUpdateEvaluator::ConstructL(const RMessage2& aMessage)
    83 	{
    84 	// Read record id and new yes/no decision from client
    85 	TUint32 recordId = aMessage.Int0();
    86 	iNewResult = (aMessage.Int1() != 0);
    87 
    88 	CDecisionFilter *filter= CDecisionFilter::NewLC();
    89 	filter->SetRecordId(recordId, EEqual);
    90 	
    91 	// Create the CDecisionView object
    92 	iUpdateView = iUpdateDbHandle->CreateViewL(*filter);
    93 
    94 	CleanupStack::PopAndDestroy(filter);
    95 }
    96 
    97 
    98 void CUpdateEvaluator::DoCleanup()
    99 /// implement CAsyncRequest
   100 	{
   101 	Cancel();
   102 
   103 	delete iUpdateView;
   104 	iUpdateView = 0;
   105 
   106 	iUpdateDbHandle.Close();
   107 	}
   108 
   109 void CUpdateEvaluator::DoCancel()
   110 	/// implement CActive - Cancel the database CreateView
   111 	{
   112 	ASSERT(iUpdateView != 0);
   113 	iUpdateView->Cancel();
   114 	}
   115 
   116 	
   117 void CUpdateEvaluator::RunL()
   118 	/// implement CActive, override CAsyncRequset
   119 	{
   120 	User::LeaveIfError(iStatus.Int());
   121 
   122 	// We have created the view, which should have matched a single record.....
   123 	CDecisionRecord *record = iUpdateView->NextDecisionL();
   124 	CleanupStack::PushL(record);
   125 	if(record == 0)
   126 		{
   127 		User::Leave(KErrNotFound);
   128 		}
   129 
   130 	// Update the result
   131 	record->iResult = iNewResult;
   132 
   133 	// Prepare a filter with our complete key in it.
   134 	CDecisionFilter *filter = CDecisionFilter::NewLC(record->iClientSid,
   135 													 record->iEvaluatorId,
   136 													 record->iServiceId,
   137 													 record->iServerSid,
   138 													 record->iFingerprint,
   139 													 record->iClientEntity,
   140 													 record->iMajorPolicyVersion);
   141 
   142 
   143 	// Update the record
   144 	iUpdateDbHandle->UpdateDecisionL(*filter, *record);
   145 
   146 	// Cleanup	
   147 	CleanupStack::PopAndDestroy(filter);
   148 	CleanupStack::PopAndDestroy(record);
   149 
   150 	CompleteAndMarkForDeletion(KErrNone);
   151 	}
   152 
   153 TInt CUpdateEvaluator::RunError(TInt aError)
   154 	{
   155 	iUpdateDbHandle.CloseMaster();
   156 	return CAsyncRequest::RunError(aError);
   157 	}
   158 
   159 void CUpdateEvaluator::DbHandleAboutToBeDeleted()
   160 /**
   161 	Called just before the master database handle is shut.
   162 	Need to cancel and cleanup/delete our view and fail the client request.
   163 */
   164 	{
   165 	// Make sure our request is cancelled
   166 	Cancel();
   167 
   168 	// Cleanup/delete our view object
   169 	DoCleanup();
   170 	
   171 	// Abort the client view request.
   172 	CompleteAndMarkForDeletion(KErrAbort);
   173 	}
   174 
   175 } // End of namespace UserPromptServer
   176 // End of file