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