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